diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 0bee7e2..35a4141 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -25,7 +25,13 @@ jobs: - name: Install dependencies run: | sudo apt-get update && sudo apt-get upgrade -y && \ - sudo apt-get install -y lld protobuf-compiler libprotobuf-dev lintian + sudo apt-get install -y lld protobuf-compiler libprotobuf-dev lintian + - name: Setup Buf + uses: bufbuild/buf-setup-action@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Lint protobuf files + uses: bufbuild/buf-lint-action@v1 - name: Run clippy lint run: cargo hack clippy --all-targets --each-feature --workspace - name: Run tests diff --git a/Cargo.lock b/Cargo.lock index ffdd586..5f8e23a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1126,6 +1126,7 @@ dependencies = [ "tokio", "tokio-stream", "tonic", + "tonic-buf-build", "tonic-build", ] @@ -1135,10 +1136,8 @@ version = "0.1.0" dependencies = [ "async-trait", "futures", - "pin-project", "temp-dir", "tokio", - "tokio-stream", ] [[package]] @@ -1191,6 +1190,12 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "serde" version = "1.0.197" @@ -1253,6 +1258,19 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_yaml" +version = "0.9.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0623d197252096520c6f2a5e1171ee436e5af99a5d7caa2891e55e61950e6d9" +dependencies = [ + "indexmap 2.2.5", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + [[package]] name = "sh" version = "0.2.1" @@ -1407,7 +1425,6 @@ dependencies = [ "futures-core", "pin-project-lite", "tokio", - "tokio-util", ] [[package]] @@ -1485,6 +1502,20 @@ dependencies = [ "tracing", ] +[[package]] +name = "tonic-buf-build" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89fb2d0fdd379526f80038c2bfbc5be061ff966b84b402b8131dbff4015ba25d" +dependencies = [ + "prost-build", + "scopeguard", + "serde", + "serde_yaml", + "tonic-build", + "uuid", +] + [[package]] name = "tonic-build" version = "0.11.0" @@ -1574,12 +1605,28 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + [[package]] name = "utf8parse" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "uuid" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" +dependencies = [ + "getrandom", + "rand", +] + [[package]] name = "uzers" version = "0.11.3" @@ -1758,29 +1805,11 @@ dependencies = [ "memchr", ] -[[package]] -name = "xshell" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce2107fe03e558353b4c71ad7626d58ed82efaf56c54134228608893c77023ad" -dependencies = [ - "xshell-macros", -] - -[[package]] -name = "xshell-macros" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e2c411759b501fb9501aac2b1b2d287a6e93e5bdcf13c25306b23e1b716dd0e" - [[package]] name = "xtask" version = "0.1.0" dependencies = [ "anyhow", "clap", - "serde", - "serde_json", "sh", - "xshell", ] diff --git a/Cargo.toml b/Cargo.toml index 234309a..c8bb990 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,6 +75,27 @@ suggests = "pypy3" section = "net" systemd-units = { enable = false } +[package.metadata.generate-rpm] + +[[package.metadata.generate-rpm.assets]] +source = "target/release/rsjudge" +dest = "/usr/bin/rsjudge" +mode = "755" + +[[package.metadata.generate-rpm.assets]] +source = "templates/*" +dest = "/etc/rsjudge/" +mode = "644" + +[[package.metadata.generate-rpm.assets]] +source = "target/assets/rsjudge.1" +dest = "/usr/share/man/man1/rsjudge.1" +mode = "644" + +[[package.metadata.generate-rpm.assets]] +source = "README.adoc" +dest = "/usr/share/doc/rsjudge/README" + [dependencies] # Workspace dependencies rsjudge-judger = { version = "0.1.0", path = "crates/rsjudge-judger" } diff --git a/buf.work.yaml b/buf.work.yaml new file mode 100644 index 0000000..0b7a593 --- /dev/null +++ b/buf.work.yaml @@ -0,0 +1,3 @@ +version: v1 +directories: + - crates/rsjudge-grpc/proto diff --git a/crates/rsjudge-grpc/build.rs b/crates/rsjudge-grpc/build.rs index 34e643b..8f61517 100644 --- a/crates/rsjudge-grpc/build.rs +++ b/crates/rsjudge-grpc/build.rs @@ -9,9 +9,16 @@ use tonic_build::compile_protos; /// /// `buf` is needed to run this build script. fn main() -> anyhow::Result<()> { - let proto_out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); - - let buf_ls_files = Command::new("buf").args(["ls-files"]).output()?; + let proto_out_dir = { + let mut out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); + out_dir.push("proto"); + out_dir + }; + + let buf_ls_files = Command::new("buf") + .current_dir("proto") + .args(["ls-files"]) + .output()?; assert!( buf_ls_files.status.success(), diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 973fb1a..bdf060c 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -11,10 +11,7 @@ rust-version.workspace = true [dependencies] anyhow = "1.0.80" clap = { version = "4.5.1", features = ["derive"] } -serde = { version = "1.0.197", features = ["derive"] } -serde_json = "1.0.114" sh = "0.2.1" -xshell = "0.2.5" [features] dbg = [] diff --git a/xtask/src/main.rs b/xtask/src/main.rs index d82cf38..dbd980f 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,7 +1,7 @@ use std::{env::set_current_dir, path::Path}; use clap::{Parser, ValueEnum}; -use xshell::{cmd, Shell}; +use sh::cmd; #[derive(Debug, ValueEnum, Clone, Copy, PartialEq, Eq)] /// Package distribution-specific packages. @@ -32,22 +32,19 @@ enum Command { fn main() -> anyhow::Result<()> { let command = Command::parse(); - // chdir to the workspace root so that the xtask can be invoked from anywhere. - // Assume that the xtask is in {project_root}/xtask + // chdir to the workspace root so that `cargo xtask` can be invoked from anywhere. set_current_dir(Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap())?; - let sh = Shell::new()?; - { - match command { - Command::Dist { package } => match package { - Package::Deb => cmd!(sh, "cargo deb -v"), - Package::Rpm => todo!("Not implemented"), - }, - Command::Docker => cmd!(sh, "docker build -t rsjudge ."), - #[cfg(feature = "dbg")] - Command::Debug => return Ok(()), - } - .run()? + match command { + Command::Dist { package } => match package { + Package::Deb => cmd!(cargo deb "-v"), + Package::Rpm => todo!("Not implemented"), + }, + Command::Docker => cmd!(docker build "-t" rsjudge "."), + #[cfg(feature = "dbg")] + Command::Debug => return Ok(()), } + .try_for_each(|cmd| cmd.exec())?; + Ok(()) }