Skip to content

Commit

Permalink
fix(rsjudge-grpc): 💚 fix OUT_DIR handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Jisu-Woniu committed Mar 21, 2024
1 parent 75c03aa commit 361e529
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 43 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 50 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
3 changes: 3 additions & 0 deletions buf.work.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version: v1
directories:
- crates/rsjudge-grpc/proto
13 changes: 10 additions & 3 deletions crates/rsjudge-grpc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 0 additions & 3 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
27 changes: 12 additions & 15 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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(())
}

0 comments on commit 361e529

Please sign in to comment.