Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use cross for linux-arm builds #29

Merged
merged 14 commits into from
Jul 16, 2024
26 changes: 18 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,25 @@ jobs:
include:
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
cross: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a benefit of using cross for x86?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a working cross-configuration, which includes a complete and reproducible non-rustc toolchain is preferable from a developer's standpoint as it makes debugging and testing easier. Cross can still make use of caching, so I don't think there are any major downsides to using it. Additionally, our CI ensures that the cross-configurations remain functional.

- target: aarch64-unknown-linux-musl
os: ubuntu-latest-arm-4core
os: ubuntu-latest
cross: true
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
cross: true
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest-arm-4core
os: ubuntu-latest
cross: true
- target: x86_64-pc-windows-msvc
os: windows-latest
cross: false
- target: aarch64-apple-darwin
os: macos-latest
cross: false
- target: x86_64-apple-darwin
os: macos-13
pavelzw marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -68,20 +75,23 @@ jobs:
- name: Checkout source code
uses: actions/checkout@v4

- name: Set up pixi
uses: prefix-dev/setup-pixi@ba3bb36eb2066252b2363392b7739741bb777659
- uses: dtolnay/rust-toolchain@stable
with:
activate-environment: true
targets: ${{ matrix.target }}

- name: Rust cache
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84
with:
key: build-${{ matrix.target }}-${{ needs.metadata.outputs.optimize-build }}
key: build-${{ matrix.target }}-${{ needs.metadata.outputs.optimize-build }}-${{ matrix.cross}}-${{ matrix.os}}
0xbe7a marked this conversation as resolved.
Show resolved Hide resolved

- name: Install cross
if: matrix.cross
run: cargo install cross --git https://github.com/cross-rs/cross

- name: Build
run: |
pixi run build --color always${{ endsWith(matrix.target, 'musl') && ' --no-default-features --features rustls-tls' || '' }}
mv 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 --release --color always${{ endsWith(matrix.target, 'musl') && ' --no-default-features --features rustls-tls' || '' }} --target ${{matrix.target}}
0xbe7a marked this conversation as resolved.
Show resolved Hide resolved
mv target/${{ matrix.target }}/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
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
matrix:
os:
- ubuntu-latest
- ubuntu-latest-arm-4core
- windows-latest
- macos-latest
- macos-13
Expand Down
11 changes: 11 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[target.aarch64-unknown-linux-gnu]
pre-build = [
"dpkg --add-architecture $CROSS_DEB_ARCH",
"apt-get update && apt-get install --assume-yes libssl-dev:$CROSS_DEB_ARCH",
]

[target.x86_64-unknown-linux-gnu]
pre-build = [
"dpkg --add-architecture $CROSS_DEB_ARCH",
"apt-get update && apt-get install --assume-yes libssl-dev:$CROSS_DEB_ARCH",
]