From af5ca7c3f9996ded8ae69d4329857294bfba4f6c Mon Sep 17 00:00:00 2001 From: houseme Date: Tue, 14 Jul 2026 18:56:15 +0800 Subject: [PATCH] build: optimize release profile (#4806) --- Cargo.toml | 8 ++++++-- build-rustfs.sh | 4 ++-- flake.nix | 2 -- scripts/test_build_rustfs_options.sh | 10 +++++++++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ad8e9e949..ad6e7e94c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -353,15 +353,19 @@ debug = "line-tables-only" [profile.release] opt-level = 3 +lto = "thin" +codegen-units = 1 +debug = 0 +split-debuginfo = "off" +strip = "symbols" [profile.production] inherits = "release" -lto = "fat" -codegen-units = 1 [profile.profiling] inherits = "release" debug = true +strip = "none" # Pin hyper to a revision that carries the HTTP/1 "flush buffered data before # shutdown" fix (hyperium/hyper#4018, commit 72046cc7). This lands as a diff --git a/build-rustfs.sh b/build-rustfs.sh index ea6d06b3a..70de9b4ec 100755 --- a/build-rustfs.sh +++ b/build-rustfs.sh @@ -217,7 +217,7 @@ setup_rust_environment() { # Set up environment variables for musl targets if [[ "$PLATFORM" == *"musl"* ]]; then print_message $YELLOW "Setting up environment for musl target..." - export RUSTFLAGS="--cfg tokio_unstable -C target-feature=-crt-static" + export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }-C target-feature=-crt-static" # For cargo-zigbuild, set up additional environment variables if command -v cargo-zigbuild &> /dev/null; then @@ -434,7 +434,7 @@ build_binary() { fi else # Native compilation - build_cmd="RUSTFLAGS='--cfg tokio_unstable -Clink-arg=-lm' cargo build" + build_cmd="RUSTFLAGS='${RUSTFLAGS:+$RUSTFLAGS }-Clink-arg=-lm' cargo build" fi if [ "$BUILD_TYPE" = "release" ]; then diff --git a/flake.nix b/flake.nix index 84e51e1b8..bf6519d23 100644 --- a/flake.nix +++ b/flake.nix @@ -85,7 +85,6 @@ # Set environment variables for build PROTOC = "${pkgs.protobuf}/bin/protoc"; - RUSTFLAGS = "--cfg tokio_unstable"; doCheck = false; @@ -123,7 +122,6 @@ ]; PROTOC = "${pkgs.protobuf}/bin/protoc"; - RUSTFLAGS = "--cfg tokio_unstable"; }; } ); diff --git a/scripts/test_build_rustfs_options.sh b/scripts/test_build_rustfs_options.sh index fd8f9e782..aef5baf22 100755 --- a/scripts/test_build_rustfs_options.sh +++ b/scripts/test_build_rustfs_options.sh @@ -38,6 +38,9 @@ cat >"$BIN_DIR/cargo" <<'STUB' set -euo pipefail printf '%s\n' "$*" >>"${CARGO_LOG:?}" +if [[ -n "${RUSTFLAGS_LOG:-}" ]]; then + printf 'RUSTFLAGS=<%s>\n' "${RUSTFLAGS:-}" >>"$RUSTFLAGS_LOG" +fi if [[ -n "${CARGO_ARG_LOG:-}" ]]; then i=0 for arg in "$@"; do @@ -70,9 +73,10 @@ chmod +x "$BIN_DIR/rustup" "$BIN_DIR/git" "$BIN_DIR/cargo" run_log="$TMP_DIR/run.log" cargo_log="$TMP_DIR/cargo.log" +rustflags_log="$TMP_DIR/rustflags.log" ( cd "$PROJECT_DIR" - PATH="$BIN_DIR:$PATH" CARGO_LOG="$cargo_log" ./build-rustfs.sh \ + PATH="$BIN_DIR:$PATH" CARGO_LOG="$cargo_log" RUSTFLAGS_LOG="$rustflags_log" ./build-rustfs.sh \ --dev \ --no-console \ --skip-verification \ @@ -82,6 +86,10 @@ cargo_log="$TMP_DIR/cargo.log" grep -q -- "Features: webdav" "$run_log" grep -q -- "--features webdav" "$cargo_log" +if grep -q -- "--cfg tokio_unstable" "$rustflags_log"; then + echo "Default build must not enable tokio_unstable" >&2 + exit 1 +fi short_run_log="$TMP_DIR/run-short.log" short_cargo_log="$TMP_DIR/cargo-short.log"