From c58af232d77f6bef5fd728d345f90b3e098c5612 Mon Sep 17 00:00:00 2001 From: Jisu-Woniu <31986081+Jisu-Woniu@users.noreply.github.com> Date: Tue, 23 Jan 2024 18:56:25 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=9A=80=20Packaging=20stuff.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cargo/config.toml | 2 +- .github/workflows/testing.yml | 2 +- Cargo.lock | 244 ++++++++++++---------------------- Cargo.toml | 55 +++++--- build.rs | 21 ++- debian/postinst | 12 +- debian/postrm | 7 +- debian/service | 4 +- docs/manpages/rsjudge.adoc | 10 +- src/cli.rs | 2 +- xtask/Cargo.toml | 2 + xtask/src/dist/deb.rs | 25 ++++ xtask/src/dist/mod.rs | 56 ++++++++ xtask/src/main.rs | 50 +++++-- 14 files changed, 285 insertions(+), 207 deletions(-) create mode 100644 xtask/src/dist/deb.rs create mode 100644 xtask/src/dist/mod.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index e11d56a..35049cb 100755 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ [alias] -xtask = "run --release --package xtask --" +xtask = "run --package xtask --" diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 5d51ceb..22cb1c6 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -11,7 +11,7 @@ env: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 diff --git a/Cargo.lock b/Cargo.lock index 812613e..8f30006 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,9 +37,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.5" +version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6" +checksum = "3fde6067df7359f2d6335ec1a50c1f8f825801687d10da0cc4c6b08e3f6afd15" dependencies = [ "anstyle", "anstyle-parse", @@ -158,12 +158,12 @@ dependencies = [ [[package]] name = "axum" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d09dbe0e490df5da9d69b36dca48a76635288a82f92eca90024883a56202026d" +checksum = "1236b4b292f6c4d6dc34604bb5120d85c3fe1d1aa596bd5cc52ca054d13e7b9e" dependencies = [ "async-trait", - "axum-core 0.4.2", + "axum-core 0.4.3", "bytes", "futures-util", "http 1.0.0", @@ -209,9 +209,9 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87c8503f93e6d144ee5690907ba22db7ba79ab001a932ab99034f0fe836b3df" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" dependencies = [ "async-trait", "bytes", @@ -245,9 +245,9 @@ dependencies = [ [[package]] name = "base64" -version = "0.21.5" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "bitflags" @@ -257,9 +257,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "block-buffer" @@ -315,9 +315,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.13" +version = "4.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52bdc885e4cacc7f7c9eedc1ef6da641603180c783c41a15c264944deeaab642" +checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" dependencies = [ "clap_builder", "clap_derive", @@ -325,9 +325,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.12" +version = "4.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9" +checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" dependencies = [ "anstream", "anstyle", @@ -335,6 +335,15 @@ dependencies = [ "strsim", ] +[[package]] +name = "clap_complete" +version = "4.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfb0d4825b75ff281318c393e8e1b80c4da9fb75a6b1d98547d389d6fe1f48d2" +dependencies = [ + "clap", +] + [[package]] name = "clap_derive" version = "4.4.7" @@ -355,9 +364,9 @@ checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "clap_mangen" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10b5db60b3310cdb376fbeb8826e875a38080d0c61bdec0a91a3da8338948736" +checksum = "4a7c2b01e5e779c19f46a94bbd398f33ae63b0f78c07108351fb4536845bb7fd" dependencies = [ "clap", "roff", @@ -421,12 +430,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.18" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3a430a770ebd84726f584a90ee7f020d28db52c6d02138900f22341f866d39c" -dependencies = [ - "cfg-if", -] +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] name = "crypto-common" @@ -457,27 +463,6 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "dirs" -version = "5.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" -dependencies = [ - "dirs-sys", -] - -[[package]] -name = "dirs-sys" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" -dependencies = [ - "libc", - "option-ext", - "redox_users", - "windows-sys 0.48.0", -] - [[package]] name = "duct" version = "0.13.7" @@ -572,9 +557,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "libc", @@ -593,7 +578,7 @@ version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbf97ba92db08df386e10c8ede66a2a0369bd277090afd8710e19e38de9ec0cd" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.4.2", "libc", "libgit2-sys", "log", @@ -602,9 +587,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.22" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" +checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" dependencies = [ "bytes", "fnv", @@ -621,9 +606,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d308f63daf4181410c242d34c11f928dcb3aa105852019e043c9d1f4e4368a" +checksum = "31d030e59af851932b72ceebadf4a2b5986dba4c3b99dd2493f8273a0f151943" dependencies = [ "bytes", "fnv", @@ -658,9 +643,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" [[package]] name = "http" @@ -740,7 +725,7 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2 0.3.22", + "h2 0.3.24", "http 0.2.11", "http-body 0.4.6", "httparse", @@ -763,7 +748,7 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2 0.4.0", + "h2 0.4.2", "http 1.0.0", "http-body 1.0.0", "httparse", @@ -880,18 +865,18 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.66" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" +checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" dependencies = [ "wasm-bindgen", ] [[package]] name = "libc" -version = "0.2.151" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "libgit2-sys" @@ -905,22 +890,11 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "libredox" -version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" -dependencies = [ - "bitflags 2.4.1", - "libc", - "redox_syscall", -] - [[package]] name = "libz-sys" -version = "1.1.12" +version = "1.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d97137b25e321a73eef1418d1d5d2eda4d77e12813f8e6dead84bc52c5870a7b" +checksum = "295c17e837573c8c821dbaeb3cceb3d745ad082f7572191409e69cbc1b3fd050" dependencies = [ "cc", "libc", @@ -988,7 +962,7 @@ version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.4.2", "cfg-if", "libc", ] @@ -1027,12 +1001,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "option-ext" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" - [[package]] name = "os_pipe" version = "1.1.5" @@ -1083,9 +1051,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" +checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" [[package]] name = "powerfmt" @@ -1125,9 +1093,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" dependencies = [ "unicode-ident", ] @@ -1180,26 +1148,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "redox_users" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" -dependencies = [ - "getrandom", - "libredox", - "thiserror", -] - [[package]] name = "regex" version = "1.10.2" @@ -1239,9 +1187,11 @@ checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316" name = "rsjudge" version = "0.1.0" dependencies = [ - "axum 0.7.3", + "anyhow", + "axum 0.7.4", "cgroups", "clap", + "clap_complete", "clap_mangen", "duct", "nix", @@ -1275,7 +1225,6 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "shellexpand", "syn 2.0.48", "walkdir", ] @@ -1319,18 +1268,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.194" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b114498256798c94a0689e1a15fec6005dee8ac1f41de56404b67afc2a4b773" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.194" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3385e45322e8f9931410f01b3031ec534c3947d0e94c18049af4d9f9907d4e0" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", @@ -1392,9 +1341,9 @@ dependencies = [ [[package]] name = "shadow-rs" -version = "0.26.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "878cb1e3162d98ee1016b832efbb683ad6302b462a2894c54f488dc0bd96f11c" +checksum = "3e5c5c8276991763b44ede03efaf966eaa0412fafbf299e6380704678ca3b997" dependencies = [ "const_format", "git2", @@ -1413,15 +1362,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "shellexpand" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da03fa3b94cc19e3ebfc88c4229c49d8f08cdbd1228870a45f0ffdf84988e14b" -dependencies = [ - "dirs", -] - [[package]] name = "slab" version = "0.4.9" @@ -1480,26 +1420,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" -[[package]] -name = "thiserror" -version = "1.0.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - [[package]] name = "time" version = "0.3.31" @@ -1654,7 +1574,7 @@ dependencies = [ "axum 0.6.20", "base64", "bytes", - "h2 0.3.22", + "h2 0.3.24", "http 0.2.11", "http-body 0.4.6", "hyper 0.14.28", @@ -1786,9 +1706,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" @@ -1830,9 +1750,9 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "utoipa" -version = "4.1.0" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ff05e3bac2c9428f57ade702667753ca3f5cf085e2011fe697de5bfd49aa72d" +checksum = "272ebdfbc99111033031d2f10e018836056e4d2c8e2acda76450ec7974269fa7" dependencies = [ "indexmap 2.1.0", "serde", @@ -1842,9 +1762,9 @@ dependencies = [ [[package]] name = "utoipa-gen" -version = "4.1.0" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0b6f4667edd64be0e820d6631a60433a269710b6ee89ac39525b872b76d61d" +checksum = "d3c9f4d08338c1bfa70dde39412a040a884c6f318b3d09aaaf3437a1e52027fc" dependencies = [ "proc-macro-error", "proc-macro2", @@ -1855,11 +1775,11 @@ dependencies = [ [[package]] name = "utoipa-swagger-ui" -version = "5.0.0" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f839caa8e09dddc3ff1c3112a91ef7da0601075ba5025d9f33ae99c4cb9b6e51" +checksum = "0b39868d43c011961e04b41623e050aedf2cc93652562ff7935ce0f819aaf2da" dependencies = [ - "axum 0.7.3", + "axum 0.7.4", "mime_guess", "regex", "rust-embed", @@ -1908,9 +1828,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" +checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1918,9 +1838,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" +checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" dependencies = [ "bumpalo", "log", @@ -1933,9 +1853,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" +checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1943,9 +1863,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" +checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", "quote", @@ -1956,9 +1876,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" +checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" [[package]] name = "winapi" @@ -2134,9 +2054,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.32" +version = "0.5.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8434aeec7b290e8da5c3f0d628cb0eac6cabcb31d14bb74f779a08109a5914d6" +checksum = "b7cf47b659b318dccbd69cc4797a39ae128f533dce7902a1096044d1967b9c16" dependencies = [ "memchr", ] @@ -2162,6 +2082,8 @@ version = "0.1.0" dependencies = [ "anyhow", "clap", + "serde", + "serde_json", "xshell", ] diff --git a/Cargo.toml b/Cargo.toml index 3f5b29b..81df049 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,32 +4,55 @@ name = "rsjudge" version = "0.1.0" authors = ["NJUPT-SAST"] edition = "2021" -license = "Unknown" +license = "Apache-2.0" description = "An online judge sandbox server in Rust." [package.metadata.deb] assets = [ [ "target/release/rsjudge", - "/usr/bin/rsjudge", + "usr/bin/rsjudge", "755", ], [ "templates/executors.toml", - "/etc/rsjudge/executors.toml", + "etc/rsjudge/executors.toml", "644", ], [ "templates/server.toml", - "/etc/rsjudge/server.toml", + "etc/rsjudge/server.toml", "644", ], [ "docs/manpages/rsjudge.1", - "/usr/share/man/man1/rsjudge.1", + "usr/share/man/man1/rsjudge.1", + "644", + ], + [ + "README.adoc", + "usr/share/doc/rsjudge/README", + "644", + ], + [ + "target/release/out/rsjudge.bash", + "usr/share/bash-completion/completions/rsjudge", + "644", + ], + [ + "target/release/out/rsjudge.fish", + "usr/share/fish/vendor_completions.d/rsjudge.fish", + "644", + ], + [ + "target/release/out/_rsjudge", + "usr/share/zsh/vendor-completions/_rsjudge", "644", ], ] +copyright = "2023-2024 NJUPT-SAST" +features = ["default"] +conf-files = ["/etc/rsjudge/server.toml", "/etc/rsjudge/executors.toml"] maintainer-scripts = "debian/" depends = "$auto, libc6, libgcc-s1, libstdc++6, libssl1.1, libzstd1, libzstd-dev" recommends = "gcc, g++, python3" @@ -39,20 +62,20 @@ systemd-units = { enable = false } [dependencies] cgroups = "0.1.0" -clap = { version = "4.4.13", features = ["derive"] } +clap = { version = "4.4.18", features = ["derive"] } nix = { version = "0.27.1", features = ["fs"] } serde = { version = "1.0.194", features = ["derive"] } -shadow-rs = "0.26.0" +shadow-rs = "0.26.1" strfmt = "0.2.4" tokio = { version = "1.35.1", features = ["fs"] } toml = "0.8.8" # Optional dependencies -axum = { version = "0.7.3", optional = true } -tonic = { version = "0.10.2", optional = true } -utoipa = { version = "4.1.0", features = ["axum_extras"], optional = true } -utoipa-swagger-ui = { version = "5.0.0", features = ["axum"], optional = true } +axum = { version = "0.7.4", optional = true } duct = "0.13.7" +tonic = { version = "0.10.2", optional = true } +utoipa = { version = "4.2.0", features = ["axum_extras"], optional = true } +utoipa-swagger-ui = { version = "6.0.0", features = ["axum"], optional = true } [dev-dependencies] tokio = { version = "1.35.1", features = ["rt-multi-thread", "macros"] } @@ -61,9 +84,11 @@ tokio = { version = "1.35.1", features = ["rt-multi-thread", "macros"] } grpc = ["dep:tonic"] rest = ["dep:axum"] openapi = ["rest", "dep:utoipa", "dep:utoipa-swagger-ui"] -default = [] +default = ["grpc"] [build-dependencies] -clap = { version = "4.4.13", features = ["derive"] } -clap_mangen = "0.2.16" -shadow-rs = "0.26.0" +anyhow = "1.0.79" +clap = { version = "4.4.18", features = ["derive"] } +clap_complete = "4.4.7" +clap_mangen = "0.2.17" +shadow-rs = "0.26.1" diff --git a/build.rs b/build.rs index 493c7aa..fa4c8c9 100644 --- a/build.rs +++ b/build.rs @@ -3,25 +3,32 @@ mod cli; use std::{ env::var_os, - fs, - io::{self, ErrorKind}, + fs::File, + io::{self, ErrorKind, Write}, path::PathBuf, }; use clap::CommandFactory; +use clap_complete::{generate_to, shells::Shell}; use clap_mangen::Man; use crate::cli::Args; -fn main() -> io::Result<()> { +fn main() -> anyhow::Result<()> { shadow_rs::new().unwrap(); - let out_dir = PathBuf::from(var_os("OUT_DIR").ok_or(ErrorKind::NotFound)?); + let out_dir = PathBuf::from(var_os("OUT_DIR").ok_or(io::Error::from(ErrorKind::NotFound))?); - let mut buffer: Vec = Vec::new(); + let mut cmd = Args::command(); - Man::new(Args::command()).render(&mut buffer)?; + for shell in [Shell::Bash, Shell::Fish, Shell::Zsh] { + generate_to(shell, &mut cmd, "rsjudge", &out_dir)?; + } - fs::write(out_dir.join("rsjudge.1"), buffer)?; + let mut manpage = File::create(out_dir.join("rsjudge.1"))?; + Man::new(cmd).render(&mut manpage)?; + manpage.flush()?; + + println!("cargo:rerun-if-changed=src/cli.rs"); Ok(()) } diff --git a/debian/postinst b/debian/postinst index 3d27bff..17f3bd5 100644 --- a/debian/postinst +++ b/debian/postinst @@ -1,13 +1,19 @@ #!/bin/sh set -e -RSJUDGE_HOME="/var/lib/rsjudge/" +RSJUDGE_HOME_BASE="/var/lib/rsjudge" RSJUDGE_USER="rsjudge" case "$1" in configure) - if ! id ${RSJUDGE_USER} >/dev/null 2>&1; then - adduser --system --home "${RSJUDGE_HOME}" --group "${RSJUDGE_USER}" + if ! id ${RSJUDGE_USER}-supervisor >/dev/null 2>&1; then + adduser --system --home "${RSJUDGE_HOME_BASE}-supervisor" --group "${RSJUDGE_USER}-supervisor" + fi + if ! id ${RSJUDGE_USER}-builder >/dev/null 2>&1; then + adduser --system --home "${RSJUDGE_HOME_BASE}-builder" --group "${RSJUDGE_USER}-builder" + fi + if ! id ${RSJUDGE_USER}-runner >/dev/null 2>&1; then + adduser --system --home "${RSJUDGE_HOME_BASE}-runner" --group "${RSJUDGE_USER}-runner" fi ;; esac diff --git a/debian/postrm b/debian/postrm index d8544a0..2a7ee1f 100644 --- a/debian/postrm +++ b/debian/postrm @@ -9,9 +9,10 @@ purge) rm "${RSJUDGE_CONF}" fi - if [ -n "${RSJUDGE_USER}" ]; then - deluser --system --remove-home --group "${RSJUDGE_USER}" || true - fi + deluser --system --remove-home --group "${RSJUDGE_USER}-supervisor" || true + deluser --system --remove-home --group "${RSJUDGE_USER}-builder" || true + deluser --system --remove-home --group "${RSJUDGE_USER}-runner" || true + ;; esac diff --git a/debian/service b/debian/service index 6ca19e5..fdbffb6 100644 --- a/debian/service +++ b/debian/service @@ -3,8 +3,8 @@ Description=RsJudge autostart service. [Service] ExecStart=/usr/bin/rsjudge --config /etc/rsjudge/ -User=rsjudge -Group=rsjudge +User=rsjudge-supervisor +Group=rsjudge-supervisor [Install] WantedBy=multi-user.target diff --git a/docs/manpages/rsjudge.adoc b/docs/manpages/rsjudge.adoc index dce141f..8ee5fd7 100644 --- a/docs/manpages/rsjudge.adoc +++ b/docs/manpages/rsjudge.adoc @@ -9,13 +9,13 @@ v0.1.0 rsjudge - an online judge sandbox server in Rust -== Synopsis +== Usage *rsjudge* [_OPTIONS_]... == Options -*-c, --config*=:: +*-c, --config-dir* :: Specify the configuration directory [default: ./config] *-h, --help*:: Print help @@ -28,4 +28,8 @@ See the repository for RsJudge at for a == Copyright -Copyright (c) 2023 NJUPT-SAST +Copyright (c) 2023-2024 NJUPT-SAST + +== License + +RsJudge is licensed under the Apache License, Version 2.0. See LICENSE for the full license text. diff --git a/src/cli.rs b/src/cli.rs index 928e7ef..685ec71 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -7,5 +7,5 @@ use clap::Parser; pub(crate) struct Args { #[arg(short, long, default_value = "./config", value_name = "DIR")] /// Specify the configuration directory - pub(crate) config: PathBuf, + pub(crate) config_dir: PathBuf, } diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 6872279..026e6e6 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -8,4 +8,6 @@ edition = "2021" [dependencies] anyhow = "1.0.79" clap = { version = "4.4.13", features = ["derive"] } +serde = { version = "1.0.195", features = ["derive"] } +serde_json = "1.0.111" xshell = "0.2.5" diff --git a/xtask/src/dist/deb.rs b/xtask/src/dist/deb.rs new file mode 100644 index 0000000..1a03813 --- /dev/null +++ b/xtask/src/dist/deb.rs @@ -0,0 +1,25 @@ +use xshell::Shell; +#[cfg(unix)] +pub(crate) fn deb_package(sh: Shell) -> anyhow::Result<()> { + use std::os::unix::fs::symlink; + + use xshell::cmd; + + use crate::dist::{build_script_out_dir, Profile}; + + cmd!(sh, "cargo build --release").run()?; + let build_script_out_dir = build_script_out_dir(&sh, Profile::Release)?; + + // Link out_dir to target/out, so that cargo-deb can find it. + symlink(build_script_out_dir, "target/release/out")?; + cmd!(sh, "cargo deb").run()?; + + Ok(()) +} + +#[cfg(not(unix))] +pub(crate) fn deb_package(sh: Shell) -> anyhow::Result<()> { + use anyhow::anyhow; + + Err(anyhow!("Not supported on non-unix platforms.")) +} diff --git a/xtask/src/dist/mod.rs b/xtask/src/dist/mod.rs new file mode 100644 index 0000000..90acb33 --- /dev/null +++ b/xtask/src/dist/mod.rs @@ -0,0 +1,56 @@ +use std::path::PathBuf; + +use anyhow::anyhow; +use serde::{Deserialize, Serialize}; +use serde_json::from_str; +use xshell::{cmd, Shell}; + +pub(crate) mod deb; + +#[derive(Deserialize, Debug, Serialize)] +#[serde(tag = "reason", rename_all = "kebab-case")] +pub(crate) enum CargoCheckMessage { + CompilerArtifact, + BuildScriptExecuted { + package_id: String, + out_dir: PathBuf, + }, + BuildFinished, +} + +#[derive(Debug, Clone, Copy)] +pub(crate) enum Profile { + Release, + Debug, +} + +impl Profile { + fn flag(self) -> &'static str { + match self { + Profile::Release => "--release", + Profile::Debug => "", + } + } +} + +pub(crate) fn build_script_out_dir(sh: &Shell, profile: Profile) -> anyhow::Result { + let pkgid = cmd!(sh, "cargo pkgid").read()?; + let pkgid: Vec<_> = pkgid.split("#").collect(); + // dbg!(&pkgid); + let flag = profile.flag(); + + cmd!(sh, "cargo check {flag} --message-format=json") + .read()? + .lines() + .find_map(|line| { + let msg = from_str::(line).expect("Not a valid message"); + match msg { + CargoCheckMessage::BuildScriptExecuted { + package_id, + out_dir, + } if package_id.contains(pkgid[0]) => Some(out_dir), + _ => None, + } + }) + .ok_or(anyhow!("No build script executed.")) +} diff --git a/xtask/src/main.rs b/xtask/src/main.rs index eb9cf0c..1e9ac5e 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,33 +1,63 @@ -use clap::Parser; +use std::env::set_current_dir; + +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)] +/// Package distribution-specific packages. +enum Package { + /// Build DEB package. + Deb, + /// Build RPM package (unimplemented). + Rpm, +} + #[derive(Debug, Parser)] +#[clap(about, long_about)] /// Build related tasks. enum Command { /// Generate Rust modules from Protobuf definitions. Codegen, /// Package distribution-specific packages. - Dist, + Dist { + /// Which package to build. + #[arg(value_enum)] + package: Package, + }, /// Build Docker image. Docker, + /// Debug a command. + Debug, } +mod dist; + 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 + set_current_dir(format!("{}/..", env!("CARGO_MANIFEST_DIR")))?; + let sh = Shell::new()?; - if sh - .current_dir() - .file_name() - .is_some_and(|n| n.eq_ignore_ascii_case("rsjudge")) { match command { Command::Codegen => cmd!(sh, "echo Not implemented"), - Command::Dist => cmd!(sh, "cargo deb"), + Command::Dist { package } => match package { + Package::Deb => return Ok(deb_package(sh)?), + Package::Rpm => Err(anyhow!("Not implemented"))?, + }, Command::Docker => cmd!(sh, "docker build -t rsjudge ."), + Command::Debug => { + return Ok(println!( + "{:#?}", + build_script_out_dir(&sh, Profile::Debug)? + )) + } } .run()? - } else { - println!("Please run this command in the root directory of the project.") - }; + } Ok(()) }