From b38b786c27800876dde3badebd1f9c1bb35fbe4e Mon Sep 17 00:00:00 2001 From: Jisu-Woniu <31986081+Jisu-Woniu@users.noreply.github.com> Date: Fri, 22 Mar 2024 16:12:46 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=F0=9F=93=9D=20specify=20protoc=20minim?= =?UTF-8?q?al=20version=20in=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cargo/config.toml | 5 ++-- .github/workflows/testing.yml | 12 +++++++-- Cargo.lock | 32 +++++++++++------------ README.adoc | 49 +++++++++++++++++++++-------------- README.zh-CN.adoc | 32 +++++++++++++++-------- crates/rsjudge-grpc/build.rs | 4 +-- 6 files changed, 82 insertions(+), 52 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 4c223be..6fb68ce 100755 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -2,5 +2,6 @@ xtask = "run --package xtask --" xtask-dbg = "run --package xtask --features dbg --" -[build] -rustflags = ["-Clink-arg=-fuse-ld=lld"] +# Use custom linker for faster linking +# [build] +# rustflags = ["-Clink-arg=-fuse-ld=mold"] diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 511be71..31ebbe9 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -25,8 +25,10 @@ jobs: - name: Install dependencies run: | sudo apt-get update && sudo apt-get upgrade -y && \ - sudo apt-get install -y lld lintian - - name: Setup Buf + sudo apt-get install -y wget lintian clang + - name: Setup mold + uses: rui314/setup-mold@v1 + - name: Setup buf uses: bufbuild/buf-setup-action@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }} @@ -34,6 +36,12 @@ jobs: uses: arduino/setup-protoc@v3 with: repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup sccache + uses: mozilla-actions/sccache-action@v0.0.3 + - name: Enable sccache + run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV - name: Lint protobuf files uses: bufbuild/buf-lint-action@v1 - name: Run clippy lint diff --git a/Cargo.lock b/Cargo.lock index 5f8e23a..2e96bf2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -221,9 +221,9 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.69" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +checksum = "95d8e92cac0961e91dbd517496b00f7e9b92363dbe6d42c3198268323798860c" dependencies = [ "addr2line", "cc", @@ -248,9 +248,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "bytes" @@ -864,7 +864,7 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "cfg-if", "cfg_aliases", "libc", @@ -1167,11 +1167,11 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.38.31" +version = "0.38.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "errno", "libc", "linux-raw-sys", @@ -1303,9 +1303,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" @@ -1342,9 +1342,9 @@ checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" [[package]] name = "temp-dir" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd16aa9ffe15fe021c6ee3766772132c6e98dfa395a167e16864f61a9cfb71d6" +checksum = "1f227968ec00f0e5322f9b8173c7a0cbcff6181a0a5b28e9892491c286277231" [[package]] name = "tempfile" @@ -1464,9 +1464,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.8" +version = "0.22.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c12219811e0c1ba077867254e5ad62ee2c9c190b0d957110750ac0cda1ae96cd" +checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4" dependencies = [ "indexmap 2.2.5", "serde", diff --git a/README.adoc b/README.adoc index bedff0d..05d56b6 100644 --- a/README.adoc +++ b/README.adoc @@ -46,45 +46,54 @@ https://mango-dune-07a8b7110.1.azurestaticapps.net/?repo=NJUPT-SAST%2Frsjudge[ === Prerequisites * Rust 1.74 or later, -* `lld` for faster linking, -** You can use other linkers instead, just update the `.cargo/config.toml` file. * Linux kernel >= 4.5, ** Required for Seccomp BPF support. * For gRPC support (under `grpc` feature): -** `protoc` as Protocol Buffers compiler, -** `buf` for gRPC dependencies management. +** https://github.com/protocolbuffers/protobuf?tab=readme-ov-file#protobuf-compiler-installation[`protoc`] >= 3.15, +** https://github.com/bufbuild/buf/[`buf`] for gRPC dependencies management. * For `.deb` package generation, a Debian/Ubuntu system with `dpkg-dev` and `liblzma-dev` installed. === Install dependencies -==== Debian/Ubuntu +You can install Rust toolchain with `rustup`: [,bash] ---- -sudo apt install -y lld protobuf-compiler libprotobuf-dev +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh +source $HOME/.cargo/env +---- -# For buf support -curl -sSL -o buf \ - "https://github.com/bufbuild/buf/releases/download/latest/buf-Linux-$(uname -m)" -# You may replace `/usr/local/bin` with your preferred directory, -# and ensure it is added to `PATH`. -sudo install -Dm755 buf /usr/local/bin/buf +==== Debian/Ubuntu + +. Install buf manually, if they are not available in the package manager. + +. Ensure a `protoc` binary with version >= 3.15 is available in your PATH, or install it manually by downloading from https://github.com/protocolbuffers/protobuf/releases/[the release page]. -# If you want to build `.deb` package -sudo apt install -y dpkg-dev liblzma-dev +** On Debian 12, Ubuntu 23.04 or later versions, you can install a compatible `protoc` with `apt`: ++ +[,bash] +---- +sudo apt install -y protobuf-compiler libprotobuf-dev +---- + +. Install packaging related packages with `apt`: ++ +[,bash] +---- +sudo apt install dpkg-dev liblzma-dev ---- ==== Alpine [,bash] ---- -sudo apk add lld protoc protobuf-dev +sudo apk add protoc protobuf-dev -# For buf support +# Installing buf curl -sSL -o buf \ "https://github.com/bufbuild/buf/releases/download/latest/buf-Linux-$(uname -m)" -# Replace `/usr/local/bin` with your preferred directory, -# remember to add it to `PATH` +# You can replace `/usr/local/bin` with your preferred directory, +# but remember to add it to `PATH` sudo install -Dm755 buf /usr/local/bin/buf ---- @@ -92,7 +101,7 @@ sudo install -Dm755 buf /usr/local/bin/buf [,bash] ---- -sudo pacman -S --needed lld protobuf buf +sudo pacman -S --needed protobuf buf ---- === Build @@ -118,3 +127,5 @@ Generate `.deb` package: ---- cargo xtask dist deb ---- + +The `.deb` package will be generated in `target/debian`. diff --git a/README.zh-CN.adoc b/README.zh-CN.adoc index f80cbf2..3d3feb3 100644 --- a/README.zh-CN.adoc +++ b/README.zh-CN.adoc @@ -1,4 +1,5 @@ -= RsJudge += rsjudge +:lang: zh-CN :toc: preamble :toc-title: 目录 @@ -47,28 +48,35 @@ https://mango-dune-07a8b7110.1.azurestaticapps.net/?repo=NJUPT-SAST%2Frsjudge[ === 先决条件 * Rust 1.74 或更高版本。 -* `lld` 用于更快的链接。 -** 你也可以使用其他链接器,只需更新 `.cargo/config.toml` 文件。 * Linux 内核 >= 4.5 ** 这是为了支持 Seccomp BPF。 -* 对于 gRPC 支持,需要 `protoc` 协议缓冲区编译器,以及协议缓冲区资源文件(在 `grpc` 特性下) +* 对于 gRPC 支持(在 `grpc` 特性下) +** https://github.com/protocolbuffers/protobuf?tab=readme-ov-file#protobuf-compiler-installation[`protoc`] >= 3.15, +** https://github.com/bufbuild/buf/[`buf`] 用于 gRPC 依赖管理。 * 对于 `.deb` 包的生成,需要安装了 `dpkg-dev` 和 `liblzma-dev` 的 Debian/Ubuntu 系统。 === 安装额外的依赖 ==== Debian/Ubuntu +. 确保 `PATH` 中包含 `protoc` >= 3.15,可以从 +https://github.com/protocolbuffers/protobuf/releases/[发布页]下载最新版本。 + +** 在 Debian 12, Ubuntu 23.04 或更高版本的系统上,可以使用 `apt` 安装符合版本要求的 `protoc`: ++ [,bash] ---- -sudo apt install -y lld protobuf-compiler libprotobuf-dev +sudo apt install -y protobuf-compiler libprotobuf-dev +protoc --version +# libprotoc +---- -# 安装 `buf` 工具 -curl -sSL -o buf \ - "https://github.com/bufbuild/buf/releases/download/latest/buf-Linux-$(uname -m)" -# 您可以用自己喜欢的目录替换 `/usr/local/bin`,并确保将其添加到 `PATH` 中。 -sudo install -Dm755 buf /usr/local/bin/buf +. 手动安装 `buf`。 -# 如果你想构建 `.deb` 包 +. 使用 `apt` 安装打包 `.deb` 需要的软件包: ++ +[,bash] +---- sudo apt install -y dpkg-dev liblzma-dev ---- @@ -115,3 +123,5 @@ cargo build --release ---- cargo xtask dist deb ---- + +生成的软件包位于 `target/debian` 目录下。 diff --git a/crates/rsjudge-grpc/build.rs b/crates/rsjudge-grpc/build.rs index 8f61517..3812ec5 100644 --- a/crates/rsjudge-grpc/build.rs +++ b/crates/rsjudge-grpc/build.rs @@ -1,6 +1,6 @@ use std::{env, io::BufRead, path::PathBuf, process::Command}; -use tonic_build::compile_protos; +use tonic_build::configure; /// Generate Rust code from the proto files. /// @@ -43,7 +43,7 @@ fn main() -> anyhow::Result<()> { ); for proto in protos { - compile_protos(proto_out_dir.join(proto))?; + configure().compile(&[proto_out_dir.join(proto)], &[&proto_out_dir])?; } println!("cargo:rerun-if-changed=proto");