From b5295debfaf4b1681404ac76793c02229850679b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Guti=C3=A9rrez=20Alonso?= Date: Thu, 3 Nov 2022 22:38:12 +0000 Subject: [PATCH] Made the change to use lib.rs (#2) * Made the change to use lib.rs * Removed unnecessary comment * Improved compilation script --- .gitignore | 5 +++-- Cargo.lock | 2 +- Cargo.toml | 2 +- compile.sh | 21 ++++++++++----------- src/{lib => }/board.rs | 4 ++-- src/{lib => }/chip.rs | 0 src/{lib => }/client.rs | 2 +- src/{lib => }/errors.rs | 0 src/lib.rs | 5 +++++ src/lib/mod.rs | 9 --------- src/main.rs | 6 +++--- src/{lib => }/server.rs | 5 ++--- 12 files changed, 28 insertions(+), 33 deletions(-) rename src/{lib => }/board.rs (99%) rename src/{lib => }/chip.rs (100%) rename src/{lib => }/client.rs (99%) rename src/{lib => }/errors.rs (100%) create mode 100644 src/lib.rs delete mode 100644 src/lib/mod.rs rename src/{lib => }/server.rs (98%) diff --git a/.gitignore b/.gitignore index 8e9ee34..5671a14 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ -/target +**/target +**/bin run_debug.sh -**/.fleet/ \ No newline at end of file +**/.fleet/ diff --git a/Cargo.lock b/Cargo.lock index 471850b..6d98f81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -112,7 +112,7 @@ dependencies = [ [[package]] name = "connect4" -version = "0.1.0" +version = "1.0.1" dependencies = [ "clap", "colored", diff --git a/Cargo.toml b/Cargo.toml index 87b04dc..4addb56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "connect4" -version = "0.1.0" +version = "1.0.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/compile.sh b/compile.sh index e579fa3..855bc06 100755 --- a/compile.sh +++ b/compile.sh @@ -2,15 +2,14 @@ CARGO_DIR=$HOME/.cargo/bin -echo Compiling linux gnu -$CARGO_DIR/cross build --target x86_64-unknown-linux-gnu --release - -echo Compiling linux musl -$CARGO_DIR/cross build --target x86_64-unknown-linux-musl --release - -echo Compiling windows -$CARGO_DIR/cross build --target x86_64-pc-windows-gnu --release - -echo Compiling android -$CARGO_DIR/cross build --target aarch64-linux-android --release +targets=(x86_64-unknown-linux-gnu x86_64-unknown-linux-musl x86_64-pc-windows-gnu aarch64-linux-android) +mkdir ./bin + +for target in "${targets[@]}" +do + echo Compiling $target + $CARGO_DIR/cross build --target $target --release || exit + mkdir ./bin/$target + mv "./target/$target/release" "./bin/$target" +done diff --git a/src/lib/board.rs b/src/board.rs similarity index 99% rename from src/lib/board.rs rename to src/board.rs index 9223268..d16e4b4 100644 --- a/src/lib/board.rs +++ b/src/board.rs @@ -1,6 +1,6 @@ use tabled::{builder::Builder, Style}; - -use super::{BoardError, Chip}; +use crate::chip::Chip; +use crate::errors::BoardError; // Chips in a row needed to win pub const CHIPS_IN_A_ROW: i32 = 4; diff --git a/src/lib/chip.rs b/src/chip.rs similarity index 100% rename from src/lib/chip.rs rename to src/chip.rs diff --git a/src/lib/client.rs b/src/client.rs similarity index 99% rename from src/lib/client.rs rename to src/client.rs index 741798c..6bd29d0 100644 --- a/src/lib/client.rs +++ b/src/client.rs @@ -1,7 +1,7 @@ use std::io::{Read, Write}; use std::net::TcpStream; -use crate::lib::Board; +use crate::board::Board; pub fn run(ip: String, port: String) { match TcpStream::connect(ip + ":" + &port) { diff --git a/src/lib/errors.rs b/src/errors.rs similarity index 100% rename from src/lib/errors.rs rename to src/errors.rs diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..27b369b --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,5 @@ +mod board; +mod chip; +pub mod client; +mod errors; +pub mod server; diff --git a/src/lib/mod.rs b/src/lib/mod.rs deleted file mode 100644 index 6b67472..0000000 --- a/src/lib/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -mod board; -mod chip; -pub mod client; -mod errors; -pub mod server; - -pub use board::{Board, CHIPS_IN_A_ROW}; -pub use chip::Chip; -pub use errors::BoardError; diff --git a/src/main.rs b/src/main.rs index 659bba6..c7b42fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,8 @@ -pub mod lib; - use clap::Parser; use inquire::Select; -use lib::{client, server}; + +use connect4::client; +use connect4::server; #[derive(Parser)] struct Cli { diff --git a/src/lib/server.rs b/src/server.rs similarity index 98% rename from src/lib/server.rs rename to src/server.rs index aa40bc7..3268e3d 100644 --- a/src/lib/server.rs +++ b/src/server.rs @@ -1,6 +1,5 @@ -use crate::lib::Chip; - -use super::Board; +use crate::chip::Chip; +use crate::board::Board; use std::io::{Error, Read, Write}; use std::net::{Shutdown, TcpListener, TcpStream};