Skip to content

Commit

Permalink
ci: fix release CI (#34)
Browse files Browse the repository at this point in the history
* Update build.yml

* bump version

* move size optimized release profile to cargo config

* strip true

* use correct output folder

* whitespace

---------

Co-authored-by: Bela Stoyan <bela.stoyan@gmail.com>
  • Loading branch information
pavelzw and 0xbe7a authored Jul 27, 2024
1 parent 9841c55 commit 69bbf4c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
17 changes: 17 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]

# These are some variables that configure the build so that the binary size is reduced.
# Inspiration was taken from this blog: https://arusahni.net/blog/2020/03/optimizing-rust-binary-size.html
# They only enable it on main and releases.
[profile.release-min-size]
inherits = "release"
# Enable Link Time Optimization (LTO) for our release builds. This increases link time but drastically reduces
# binary size.
lto = true
# Use a single code gen unit. This effectively disables parallel linking but ensures that everything is linked
# together in a single unit which reduces the file-size at the cost of link time.
# Default for a release build is 16
codegen-units = 1
# Strip the binaries. This reduces the filesize of the final release.
strip = true
# Optimize the binary for size. This reduces the filesize at the cost of a slower binary.
opt-level = "z"
26 changes: 5 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Build
on:
merge_group:
pull_request:
push:
branches:
- main

jobs:
metadata:
Expand Down Expand Up @@ -50,25 +53,6 @@ jobs:
- target: x86_64-apple-darwin
os: macos-13
cross: false
env:
# These are some environment variables that configure the build so that the binary size is reduced.
# Inspiration was taken from this blog: https://arusahni.net/blog/2020/03/optimizing-rust-binary-size.html
# They only enable it on main and releases.

# Enable Link Time Optimization (LTO) for our release builds. This increases link time but drastically reduces
# binary size.
CARGO_PROFILE_RELEASE_LTO: ${{ needs.metadata.outputs.optimize-build }}

# Use a single code gen unit. This effectively disables parallel linking but ensures that everything is linked
# together in a single unit which reduces the file-size at the cost of link time.
# Default for a release build is 16
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: ${{ needs.metadata.outputs.optimize-build && 1 || 16 }}

# Strip the binaries. This reduces the filesize of the final release.
CARGO_PROFILE_RELEASE_STRIP: ${{ needs.metadata.outputs.optimize-build && 'symbols' || 'false' }}

# Optimize the binary for size. This reduces the filesize at the cost of a slower binary.
CARGO_PROFILE_OPT_LEVEL: ${{ needs.metadata.outputs.optimize-build && 's' || '0' }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
Expand All @@ -88,8 +72,8 @@ jobs:

- name: Build
run: |
${{ matrix.cross && 'cross' || 'cargo' }} build --release --color always${{ endsWith(matrix.target, 'musl') && ' --no-default-features --features rustls-tls' || '' }} --target ${{ matrix.target }}
mv target/${{ matrix.target }}/release/pixi-pack${{ endsWith(matrix.target, 'windows-msvc') && '.exe' || '' }} pixi-pack-${{ matrix.target }}${{ endsWith(matrix.target, 'windows-msvc') && '.exe' || '' }}
${{ matrix.cross && 'cross' || 'cargo' }} build --profile ${{ needs.metadata.outputs.optimize-build && 'release-min-size' || 'release'}} --color always${{ endsWith(matrix.target, 'musl') && ' --no-default-features --features rustls-tls' || '' }} --target ${{ matrix.target }}
mv target/${{ matrix.target }}/${{ needs.metadata.outputs.optimize-build && 'release-min-size' || 'release' }}/pixi-pack${{ endsWith(matrix.target, 'windows-msvc') && '.exe' || '' }} pixi-pack-${{ matrix.target }}${{ endsWith(matrix.target, 'windows-msvc') && '.exe' || '' }}
- name: Upload Artifact
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pixi-pack"
description = "A command line tool to pack and unpack conda environments for easy sharing"
version = "0.1.4"
version = "0.1.5"
edition = "2021"

[features]
Expand Down

0 comments on commit 69bbf4c

Please sign in to comment.