Skip to content

Commit

Permalink
feat: Statically link libiconv on aarch64-darwin; Test static binar…
Browse files Browse the repository at this point in the history
…y in CI (#158)

* omnix-cli: Statically link libiconv

* static libiconv only on aarch64-darwin

* ci: Test static binary

* actions/*-artifact@v4

* chmod om; upload artifact earlier

* build and upload artifact on non x86_64-darwin

* check nix installation before testing static binary

* add description for error on x86_64-darwin upon evaluating static libiconv

* be explicit about the path from where the binary comes

* debug om_static_binary_path

* wrap om_static_binary_path in actions env syntax

* remove debug step
  • Loading branch information
shivaraj-bh authored Aug 2, 2024
1 parent 9520311 commit 88fd9b0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ jobs:
- name: Check static binary size
if: matrix.system == 'x86_64-linux'
run: nix run .#check-closure-size
- name: nix build
if: matrix.system != 'x86_64-darwin'
run: echo "om_static_binary_path=$(nix build --no-link --print-out-paths)" >> "$GITHUB_ENV"
- name: Upload om static binary
if: matrix.system != 'x86_64-darwin'
uses: actions/upload-artifact@v4
with:
name: om-${{ matrix.system }}
path: ${{ env.om_static_binary_path }}/bin/om
- name: nix run
run: nix run . -- --help
# First, build the repos used in the test to cache them locally, so as
Expand All @@ -61,3 +70,29 @@ jobs:
- name: Push to cachix
if: github.ref == 'refs/heads/main'
run: nix --option system "${{ matrix.system }}" run .#cachix-push
static-binary-check:
needs: checks
runs-on: ${{ matrix.system }}
strategy:
matrix:
system: [ ubuntu-latest, macos-latest ]
steps:
- name: Donwload om static binary
uses: actions/download-artifact@v4
with:
name: om-${{ matrix.system == 'ubuntu-latest' && 'x86_64-linux' || matrix.system == 'macos-latest' && 'aarch64-darwin' || matrix.system }}
- name: Check nix installation
run: |
if which nix; then
echo "nix is installed, exiting"
exit 1
elif test -d /nix; then
echo "/nix is present, exiting"
exit 1
else
echo "nix is not installed"
fi
- name: Run om static binary
run: |
chmod +x ./om
./om --help
6 changes: 3 additions & 3 deletions flake.lock

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

9 changes: 7 additions & 2 deletions nix/rust.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@
Security
SystemConfiguration
] ++ [
libiconv
# Packages from `pkgsStatic` require cross-compilation support for the target platform,
# which is not yet available for `x86_64-apple-darwin` in nixpkgs. Upon trying to evaluate
# a static package for `x86_64-apple-darwin`, you may see an error like:
#
# > error: don't yet have a `targetPackages.darwin.LibsystemCross for x86_64-apple-darwin`
(if (stdenv.isDarwin && stdenv.isAarch64) then pkgsStatic.libiconv else libiconv)
pkg-config
];
buildInputs = lib.optionals pkgs.stdenv.isDarwin
Expand All @@ -60,9 +65,9 @@
description = "Command-line interface for Omnix";
mainProgram = "om";
};
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
} //
lib.optionalAttrs pkgs.stdenv.isLinux {
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
};
};
Expand Down

0 comments on commit 88fd9b0

Please sign in to comment.