Skip to content

Commit

Permalink
build(xtask): ♻️ clean up packaging stuff and prepare for .rpm pack…
Browse files Browse the repository at this point in the history
…aging
  • Loading branch information
Jisu-Woniu committed Mar 20, 2024
1 parent 03e5e05 commit e8353e1
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 134 deletions.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[alias]
xtask = "run --package xtask --"
xtask-dbg = "run --package xtask --features dbg --"

[build]
rustflags = ["-Clink-arg=-fuse-ld=lld"]
31 changes: 31 additions & 0 deletions Cargo.lock

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

13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ assets = [
"644",
],
[
"target/release/out/rsjudge.1",
"target/assets/rsjudge.1",
"usr/share/man/man1/rsjudge.1",
"644",
],
Expand All @@ -47,28 +47,28 @@ assets = [
"644",
],
[
"target/release/out/rsjudge.bash",
"target/assets/rsjudge.bash",
"usr/share/bash-completion/completions/rsjudge",
"644",
],
[
"target/release/out/rsjudge.fish",
"target/assets/rsjudge.fish",
"usr/share/fish/vendor_completions.d/rsjudge.fish",
"644",
],
[
"target/release/out/_rsjudge",
"target/assets/_rsjudge",
"usr/share/zsh/vendor-completions/_rsjudge",
"644",
],
]
copyright = "2023-2024 NJUPT-SAST"
changelog = "debian/changelog"
changelog = "packaging/debian/changelog"
features = ["default"]
conf-files = ["/etc/rsjudge/server.toml", "/etc/rsjudge/executors.toml"]
extended-description = "An online judge sandbox server in Rust, inspired by go-judge, for SAST OJ."
maintainer = "Xiaoqing Xuan <[email protected]>"
maintainer-scripts = "debian/"
maintainer-scripts = "packaging/debian/"
depends = "$auto, adduser, libc6, libgcc-s1, libstdc++6, libssl1.1, libzstd1, libzstd-dev"
recommends = "gcc, g++, python3"
suggests = "pypy3"
Expand Down Expand Up @@ -108,7 +108,6 @@ rest = ["dep:rsjudge-rest"]
default = ["grpc"]

[build-dependencies]
anyhow = "1.0.81"
clap = { version = "4.5.3", features = ["derive"] }
clap_complete = "4.5.1"
clap_mangen = "0.2.20"
Expand Down
19 changes: 12 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ mod cli;

use std::{
env::var_os,
fs::File,
io::{self, ErrorKind, Write},
path::PathBuf,
fs::{create_dir_all, File},
io::{self, Write},
path::Path,
};

use clap::CommandFactory;
Expand All @@ -14,16 +14,21 @@ use clap_mangen::Man;

use crate::cli::Args;

fn main() -> anyhow::Result<()> {
let out_dir = PathBuf::from(var_os("OUT_DIR").ok_or(io::Error::from(ErrorKind::NotFound))?);
fn main() -> io::Result<()> {
let asset_dir = Path::new(
&var_os("CARGO_MANIFEST_DIR").expect("Environment `CARGO_MANIFEST_DIR` not set by cargo."),
)
.join("target/assets");

create_dir_all(&asset_dir)?;

let mut cmd = Args::command();

for shell in [Shell::Bash, Shell::Fish, Shell::Zsh] {
generate_to(shell, &mut cmd, "rsjudge", &out_dir)?;
generate_to(shell, &mut cmd, "rsjudge", &asset_dir)?;
}

let mut manpage = File::create(out_dir.join("rsjudge.1"))?;
let mut manpage = File::create(asset_dir.join("rsjudge.1"))?;
Man::new(cmd).render(&mut manpage)?;
manpage.flush()?;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ 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 = []
21 changes: 0 additions & 21 deletions xtask/src/dist/deb.rs

This file was deleted.

84 changes: 0 additions & 84 deletions xtask/src/dist/mod.rs

This file was deleted.

Empty file removed xtask/src/dist/rpm.rs
Empty file.
20 changes: 5 additions & 15 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::{env::set_current_dir, path::Path};

use anyhow::anyhow;
use clap::{Parser, ValueEnum};
use dist::{build_script_out_dir, deb::deb_package, Profile};
use xshell::{cmd, Shell};

#[derive(Debug, ValueEnum, Clone, Copy, PartialEq, Eq)]
Expand All @@ -18,8 +16,6 @@ enum Package {
#[clap(about, long_about)]
/// Build related tasks.
enum Command {
/// Generate Rust modules from Protobuf definitions.
Codegen,
/// Package distribution-specific packages.
Dist {
/// Which package to build.
Expand All @@ -29,11 +25,10 @@ enum Command {
/// Build Docker image.
Docker,
/// Debug a command.
#[cfg(feature = "dbg")]
Debug,
}

mod dist;

fn main() -> anyhow::Result<()> {
let command = Command::parse();

Expand All @@ -44,18 +39,13 @@ fn main() -> anyhow::Result<()> {
let sh = Shell::new()?;
{
match command {
Command::Codegen => cmd!(sh, "echo Not implemented"),
Command::Dist { package } => match package {
Package::Deb => return deb_package(sh),
Package::Rpm => Err(anyhow!("Not implemented"))?,
Package::Deb => cmd!(sh, "cargo deb -v"),
Package::Rpm => todo!("Not implemented"),
},
Command::Docker => cmd!(sh, "docker build -t rsjudge ."),
Command::Debug => {
return Ok(println!(
"{:#?}",
build_script_out_dir(&sh, Profile::Debug, false)?
))
}
#[cfg(feature = "dbg")]
Command::Debug => return Ok(()),
}
.run()?
}
Expand Down

0 comments on commit e8353e1

Please sign in to comment.