From afd8d395d0afda95cee5dbf20c143b5c2429989a Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Tue, 6 Aug 2024 00:37:10 -0400 Subject: [PATCH 1/3] Split `release` profile into `release` and `release-opt` In `Cargo.toml`: - Add thin LTO to `release` profile. - Create `release-opt` profile with fat LTO and other slow optimizations, as well as stripping all symbols. - Remove some old commented out configuration that has been superseded by more granular configuration (separate from the above changes) In the `release.yml` CI workflow: - Build `release-opt` rather than `release` workflow. - Use an environment variable to name the `release-opt` profile so it is easy to change and identify (and make the style in which long options are passed more consistent). - Remove explicit stripping of debug symbols, since `release-opt` does that. - *Temporarily* disable the step that takes the release from draft to published, to avoid publishing more "DO-NOT-USE" releases than necessary when testing the workflow (since, for example, it is possible for them to appear in users' "Home" feeds on GitHub). This change must be undone, so the workflow will really publish. --- .github/workflows/release.yml | 30 +++++++++--------------------- Cargo.toml | 15 ++++++++------- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0c966a26a20..9119bf23751 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -139,6 +139,7 @@ jobs: TARGET: ${{ matrix.target }} TARGET_FLAGS: --target=${{ matrix.target }} TARGET_DIR: target/${{ matrix.target }} + PROFILE: release-opt steps: - name: Checkout repository @@ -171,23 +172,9 @@ jobs: echo "target flag is: $TARGET_FLAGS" echo "target dir is: $TARGET_DIR" - - name: Build release binary + - name: Build release binary (with extra optimizations) run: | - "$CARGO" build --verbose --release "$TARGET_FLAGS" --no-default-features --features "$FEATURE" - - - name: Strip release binary (x86-64 Linux, and all macOS) - if: matrix.target == 'x86_64-unknown-linux-musl' || matrix.os == 'macos-latest' - run: strip "$TARGET_DIR"/release/{ein,gix} - - - name: Strip release binary (ARM Linux) - if: matrix.target == 'arm-unknown-linux-gnueabihf' - run: | - docker run --rm -v \ - "$PWD/target:/target:Z" \ - rustembedded/cross:arm-unknown-linux-gnueabihf \ - arm-linux-gnueabihf-strip \ - /target/arm-unknown-linux-gnueabihf/release/ein \ - /target/arm-unknown-linux-gnueabihf/release/gix + "$CARGO" build --verbose --profile="$PROFILE" "$TARGET_FLAGS" --no-default-features --features="$FEATURE" - name: Determine archive basename run: echo "ARCHIVE=gitoxide-$FEATURE-$VERSION-$TARGET" >> "$GITHUB_ENV" @@ -200,8 +187,8 @@ jobs: - name: Build archive (Windows) if: matrix.os == 'windows-latest' run: | - file -- "$TARGET_DIR"/release/{ein,gix}.exe - cp -- "$TARGET_DIR"/release/{ein,gix}.exe "$ARCHIVE/" + file -- "$TARGET_DIR/$PROFILE"/{ein,gix}.exe + cp -- "$TARGET_DIR/$PROFILE"/{ein,gix}.exe "$ARCHIVE/" 7z a "$ARCHIVE.zip" "$ARCHIVE" /usr/bin/core_perl/shasum --algorithm=256 --binary "$ARCHIVE.zip" > "$ARCHIVE.zip.sha256" echo "ASSET=$ARCHIVE.zip" >> "$GITHUB_ENV" @@ -210,8 +197,8 @@ jobs: - name: Build archive (Unix) if: matrix.os != 'windows-latest' run: | - file -- "$TARGET_DIR"/release/{ein,gix} - cp -- "$TARGET_DIR"/release/{ein,gix} "$ARCHIVE/" + file -- "$TARGET_DIR/$PROFILE"/{ein,gix} + cp -- "$TARGET_DIR/$PROFILE"/{ein,gix} "$ARCHIVE/" tar czf "$ARCHIVE.tar.gz" "$ARCHIVE" shasum --algorithm=256 --binary "$ARCHIVE.tar.gz" > "$ARCHIVE.tar.gz.sha256" echo "ASSET=$ARCHIVE.tar.gz" >> "$GITHUB_ENV" @@ -346,7 +333,8 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Publish the release + - name: Publish the release # FIXME: Reenable this. + if: false run: gh release --repo="$REPOSITORY" edit "$VERSION" --draft=false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Cargo.toml b/Cargo.toml index 6564976c9e6..f499b848f1d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -206,17 +206,18 @@ sha1_smol = { opt-level = 3 } [profile.release] overflow-checks = false -#lto = "fat" -# this bloats files but assures destructors are called, important for tempfiles. One day I hope we +lto = "thin" +# This bloats files but assures destructors are called, important for tempfiles. One day I hope we # can wire up the 'abrt' signal handler so tempfiles will be removed in case of panics. -panic = 'unwind' -#codegen-units = 1 +panic = "unwind" incremental = false build-override = { opt-level = 0 } -# It's not quite worth building dependencies with more optimizations yet. Let's keep it here for later. -#[profile.dev.package."*"] -#opt-level = 2 +[profile.release-opt] +inherits = "release" +lto = "fat" +codegen-units = 1 +strip = "symbols" [workspace] members = [ From 871eec7ab34c0ffd1f38931e6622a12659d4b095 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Wed, 7 Aug 2024 20:16:14 -0400 Subject: [PATCH 2/3] Reenable publishing; warn that `release-opt` may go away --- .github/workflows/release.yml | 3 +-- Cargo.toml | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9119bf23751..9a3b99fb9b4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -333,8 +333,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Publish the release # FIXME: Reenable this. - if: false + - name: Publish the release run: gh release --repo="$REPOSITORY" edit "$VERSION" --draft=false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Cargo.toml b/Cargo.toml index f499b848f1d..e7b773d22d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -213,6 +213,8 @@ panic = "unwind" incremental = false build-override = { opt-level = 0 } +# This profile is currently used in building releases for GitHub. +# It may be removed at any time and should not otherwise be relied on. [profile.release-opt] inherits = "release" lto = "fat" From 34b1060a63cc6d3461d045371ca2ae1c8341ce2c Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 8 Aug 2024 08:23:14 +0200 Subject: [PATCH 3/3] Make use of profile clear by '-github' suffix Additionally, make current release profile potentially faster by allowing the standard optimizations, probably opt-level 2. In GitHub release mode, optimize even further as time doesn't matter quite as much there. The `build-override` with `opt-leve = 0` was removed in fear this might actually detremental for folks using `cargo install`. --- .github/workflows/release.yml | 2 +- Cargo.toml | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9a3b99fb9b4..0f7555d9f9a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -139,7 +139,7 @@ jobs: TARGET: ${{ matrix.target }} TARGET_FLAGS: --target=${{ matrix.target }} TARGET_DIR: target/${{ matrix.target }} - PROFILE: release-opt + PROFILE: release-github steps: - name: Checkout repository diff --git a/Cargo.toml b/Cargo.toml index e7b773d22d8..f2367338c7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -211,15 +211,17 @@ lto = "thin" # can wire up the 'abrt' signal handler so tempfiles will be removed in case of panics. panic = "unwind" incremental = false -build-override = { opt-level = 0 } # This profile is currently used in building releases for GitHub. # It may be removed at any time and should not otherwise be relied on. -[profile.release-opt] +[profile.release-github] inherits = "release" +overflow-checks = false +panic = "unwind" lto = "fat" codegen-units = 1 strip = "symbols" +build-override = { opt-level = 3 } [workspace] members = [