Skip to content

Commit

Permalink
Fix Cargo mismatch on MacOS build
Browse files Browse the repository at this point in the history
The flake.nix uses the default crane toolchain on darwin.
Override the default crane toolchain and specify the target
to use the correct rust toolchain.
  • Loading branch information
SchahinRohani committed Jun 8, 2024
1 parent f59a1d7 commit 9a17700
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/nix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ jobs:
uses: >- # v4
DeterminateSystems/magic-nix-cache-action@fc6aaceb40b9845a02b91e059ec147e78d1b4e41
- name: Run build
run: >
nix build
- name: Test nix run
run: |
nix run -L .#nativelink-is-executable-test
7 changes: 5 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

craneLib =
if pkgs.stdenv.isDarwin
then crane.lib.${system}
then (crane.mkLib pkgs).overrideToolchain stable-rust.default
else
(crane.mkLib pkgs).overrideToolchain (stable-rust.default.override {
targets = ["x86_64-unknown-linux-musl"];
Expand Down Expand Up @@ -138,6 +138,8 @@

local-image-test = import ./tools/local-image-test.nix {inherit pkgs;};

nativelink-is-executable-test = import ./tools/nativelink-is-executable-test.nix {inherit pkgs nativelink;};

generate-toolchains = import ./tools/generate-toolchains.nix {inherit pkgs;};

native-cli = import ./native-cli/default.nix {inherit pkgs;};
Expand Down Expand Up @@ -197,7 +199,7 @@
};
};
packages = rec {
inherit publish-ghcr local-image-test nativelink nativelink-debug native-cli lre-cc;
inherit publish-ghcr local-image-test nativelink-is-executable-test nativelink nativelink-debug native-cli lre-cc;
default = nativelink;

rbe-autogen-lre-cc = rbe-autogen lre-cc;
Expand Down Expand Up @@ -272,6 +274,7 @@

# Additional tools from within our development environment.
local-image-test
nativelink-is-executable-test
generate-toolchains
customClang
native-cli
Expand Down
27 changes: 27 additions & 0 deletions tools/nativelink-is-executable-test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
pkgs,
nativelink,
...
}:
pkgs.writeShellScriptBin "is-executable-test" ''
set -xuo pipefail
nativelink_output="$(${nativelink}/bin/nativelink 2>&1)"
print_error_output=$(cat <<EOF
error: the following required arguments were not provided:
<CONFIG_FILE>
Usage: nativelink <CONFIG_FILE>
For more information, try '--help'.
EOF)
if [ "$nativelink_output" = "$print_error_output" ]; then
echo "The output of nativelink matches the print_error output."
else
echo 'The output of nativelink does not match the print_error output:'
diff <(echo "$nativelink_output") <(echo "$print_error_output") >&2
exit 1
fi
''

0 comments on commit 9a17700

Please sign in to comment.