-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
name: Build | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
metadata: | ||
name: Check if version changed | ||
runs-on: ubuntu-latest | ||
outputs: | ||
optimize-build: ${{ github.event_name == 'push' }} | ||
release: ${{ github.event_name == 'push' && github.repository == 'Quantco/pixi-pack' && steps.version-metadata.outputs.changed == 'true' }} | ||
version: ${{ steps.version-metadata.outputs.newVersion }} | ||
steps: | ||
- name: Checkout source code | ||
uses: actions/checkout@v4 | ||
- uses: Quantco/ui-actions/version-metadata@a0653e9fc0ee3c4be9f7cc88e509e40536e9f3c1 | ||
id: version-metadata | ||
with: | ||
file: ./Cargo.toml | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
version-extraction-override: 'regex:version = "(.*)"' | ||
|
||
build: | ||
name: Build Binary | ||
runs-on: ${{ matrix.os }} | ||
needs: [metadata] | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- target: x86_64-unknown-linux-musl | ||
os: ubuntu-latest-4core | ||
- target: aarch64-unknown-linux-musl | ||
os: ubuntu-latest-arm-4core | ||
- target: x86_64-pc-windows-msvc | ||
os: windows-latest | ||
- target: aarch64-apple-darwin | ||
os: macos-latest | ||
- target: x86_64-apple-darwin | ||
os: macos-13 | ||
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're 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 | ||
|
||
- name: Set up pixi | ||
uses: prefix-dev/setup-pixi@ba3bb36eb2066252b2363392b7739741bb777659 | ||
with: | ||
activate-environment: true | ||
|
||
- name: Use static CRT on Windows | ||
shell: bash | ||
run: echo "RUSTFLAGS=${RUSTFLAGS} -C target-feature=+crt-static" >> "${GITHUB_ENV}" | ||
if: endsWith(matrix.target, 'windows-msvc') | ||
|
||
- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 | ||
with: | ||
key: build-${{ matrix.target }} | ||
|
||
- name: Show version information (Rust, cargo, GCC) | ||
run: | | ||
gcc --version || true | ||
rustup -V | ||
rustup toolchain list | ||
cargo -V | ||
rustc -V | ||
- name: Use rustls on musl targets. | ||
id: build-options | ||
if: contains(matrix.target, '-musl') | ||
run: | | ||
echo "CARGO_BUILD_OPTIONS=${CARGO_BUILD_OPTIONS} --no-default-features --features rustls-tls" >> $GITHUB_OUTPUT | ||
- name: Build | ||
run: > | ||
cargo build | ||
--locked | ||
--release | ||
${{ steps.build-options.outputs.CARGO_BUILD_OPTIONS }} | ||
- name: "Artifact upload: binary" | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: pixi-pack-${{ matrix.target }}${{ endsWith(matrix.target, 'windows-msvc') && '.exe' || '' }} | ||
path: target/${{ matrix.target }}/release/pixi-pack${{ endsWith(matrix.target, 'windows-msvc') && '.exe' || '' }} | ||
|
||
release: | ||
name: Create Release | ||
needs: [metadata, build] | ||
if: needs.metadata.outputs.release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Download artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: pixi-pack-* | ||
path: target | ||
- run: | | ||
tree target | ||
# - name: Push v${{ needs.metadata.outputs.version }} tag | ||
# run: | | ||
# git tag v${{ needs.metadata.outputs.version }} | ||
# git push origin v${{ needs.metadata.outputs.version }} | ||
# - name: Create Release | ||
# uses: softprops/action-gh-release@69320dbe05506a9a39fc8ae11030b214ec2d1f87 | ||
# if: needs.metadata.outputs.release | ||
# with: | ||
# generate_release_notes: true | ||
# tag_name: v${{ needs.metadata.outputs.version }} | ||
# draft: true | ||
# files: | | ||
# target/*/release/pixi-pack* |