diff --git a/Cargo.lock b/Cargo.lock index 9f59f04..a21d85f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,6 +34,7 @@ dependencies = [ "serde_json", "tokio", "url", + "uuid", ] [[package]] @@ -44,6 +45,8 @@ dependencies = [ "serde_json", "tokio", "url", + "uuid", + "uuid-simd", ] [[package]] @@ -55,6 +58,17 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "hermit-abi" version = "0.2.6" @@ -127,6 +141,12 @@ dependencies = [ "libc", ] +[[package]] +name = "outref" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4030760ffd992bef45b0ae3f10ce1aba99e33464c90d14dd7c039884963ddc7a" + [[package]] name = "parking_lot" version = "0.12.1" @@ -162,6 +182,12 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "proc-macro2" version = "1.0.55" @@ -180,6 +206,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -346,6 +402,34 @@ dependencies = [ "serde", ] +[[package]] +name = "uuid" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" +dependencies = [ + "getrandom", + "rand", + "serde", +] + +[[package]] +name = "uuid-simd" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b082222b4f6619906941c17eb2297fff4c2fb96cb60164170522942a200bd8" +dependencies = [ + "outref", + "uuid", + "vsimd", +] + +[[package]] +name = "vsimd" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c3082ca00d5a5ef149bb8b555a72ae84c9c59f7250f013ac822ac2e49b19c64" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index 047473f..6df469f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,5 @@ tokio = { version = "1.27.0", features = ["full"] } serde_json = "1.0" serde = { version = "1.0", features = ["derive"]} url = { version = "2.3.1", features = ["serde"]} +uuid-simd = "0.8.0" +uuid = { version = "1.3.0", features = ["v4", "fast-rng", "serde"] } diff --git a/forge-client/Cargo.toml b/forge-client/Cargo.toml index 0671777..ed8cff7 100644 --- a/forge-client/Cargo.toml +++ b/forge-client/Cargo.toml @@ -8,3 +8,4 @@ tokio.workspace = true serde_json.workspace = true serde.workspace = true url.workspace = true +uuid.workspace = true diff --git a/forge-client/src/main.rs b/forge-client/src/main.rs index da49862..6da1db9 100644 --- a/forge-client/src/main.rs +++ b/forge-client/src/main.rs @@ -4,6 +4,7 @@ use std::fmt; use tokio::io::AsyncWriteExt; use tokio::net::TcpStream; use url::Url; +use uuid::Uuid; #[derive(Serialize, Deserialize, Debug)] enum BuildSystem { @@ -62,7 +63,16 @@ struct Command { subcommand: Subcommand, features: Option>, tag: Tag, +} + +#[derive(Serialize, Deserialize)] +struct Message { + uuid: Uuid, + pre_exec: Option, + profile: bool, + command: Command, repository: Url, + basename: String, } #[tokio::main] @@ -75,12 +85,18 @@ async fn main() -> Result<(), Box> { subcommand: Subcommand::Build, features: Some(vec!["one".to_string(), "two".to_string()]), tag: Tag::Debug, + }; + let test_message = Message { + uuid: Uuid::new_v4(), + pre_exec: None, + profile: false, + command: test_command, repository: Url::parse("https://lib.rs/crates/serde_json").unwrap(), + basename: "serde_json".to_string(), }; - let j = serde_json::to_string(&test_command)?; + let j = serde_json::to_string(&test_message)?; println!("{}", j); - // Write some data. stream.write_all(&j.as_bytes()).await?; Ok(()) diff --git a/forge-server/Cargo.toml b/forge-server/Cargo.toml index 9e0e797..56290d5 100644 --- a/forge-server/Cargo.toml +++ b/forge-server/Cargo.toml @@ -8,3 +8,5 @@ tokio.workspace = true serde_json.workspace = true serde.workspace = true url.workspace = true +uuid-simd.workspace = true +uuid.workspace = true diff --git a/forge-server/src/main.rs b/forge-server/src/main.rs index e67ce36..e5f3b8d 100644 --- a/forge-server/src/main.rs +++ b/forge-server/src/main.rs @@ -6,6 +6,8 @@ use std::net::SocketAddr; use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader}; use tokio::net::{TcpListener, TcpStream}; use url::Url; +use uuid::Uuid; +use uuid_simd::UuidExt; #[derive(Serialize, Deserialize, Debug)] enum BuildSystem { @@ -64,42 +66,73 @@ struct Command { subcommand: Subcommand, features: Option>, tag: Tag, +} + +#[derive(Serialize, Deserialize)] +struct Message { + uuid: Uuid, + pre_exec: Option, + profile: bool, + command: Command, repository: Url, + basename: String, +} + +async fn build(msg: Message, address: SocketAddr) { + let mut features = String::new(); + match msg.command.features { + Some(f) => { + features.push_str("--features '"); + for i in f { + features.push_str(&i); + features.push_str(" "); + } + features.push_str("'"); + } + None => features = "".to_string(), + } + + println!( + "Received message from {:?}: {}", + address, + msg.uuid.format_hyphenated() + ); + + println!("git clone {}", msg.repository); + match msg.pre_exec { + Some(e) => println!("Running pre-exec: {}", e), + None => {} + } + println!( + "{} {} {} {}", + msg.command.build_system, msg.command.subcommand, msg.command.tag, features + ); } async fn process_socket(mut socket: TcpStream, address: SocketAddr) { + let (reader, writer) = socket.split(); + + let mut reader = BufReader::new(reader); + let mut line = String::new(); + loop { - let mut reader = BufReader::new(&mut socket); - let mut line = String::new(); - - let bytes_read = match reader.read_line(&mut line).await { - Ok(b) => b, - Err(e) => return, - }; - - let json: Command = match serde_json::from_str(&line) { - Ok(v) => v, - Err(e) => return, - }; - let mut features = String::new(); - match json.features { - Some(f) => { - features.push_str("--features '"); - for i in f { - features.push_str(&i); - features.push_str(" "); - } - features.push_str("'"); - } - None => features = "".to_string(), + let bytes_read = reader.read_line(&mut line).await.unwrap(); + if bytes_read == 0 { + break; } - println!( - "Received message from {:?}: {} {} {} {}", - address, json.build_system, json.subcommand, json.tag, features - ); - // socket.write_all(&line.as_bytes()).await.unwrap(); + + let json: Message = match serde_json::from_str(&line) { + Ok(v) => v, + Err(e) => { + eprintln!("{}", e); + return; + } + }; + + tokio::spawn(async move { + build(json, address).await; + }); } - // println!("client {:?} sent message: '{:?}'", address,); } #[tokio::main]