Skip to content

Commit 6ca559a

Browse files
committed
Sandbox miri test execution so it hopefully finally works in ci
1 parent d987788 commit 6ca559a

File tree

2 files changed

+28
-42
lines changed

2 files changed

+28
-42
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
test_miri:
3434
runs-on: ubuntu-latest
3535
steps:
36-
- uses: actions/checkout@v4
36+
- uses: actions/checkout@v5
3737

3838
- uses: DeterminateSystems/nix-installer-action@main
3939

flake.nix

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@
4949
export PKG_CONFIG_PATH="${pkgs.openssl.dev}/lib/pkgconfig"
5050
${script}
5151
'');
52+
53+
# Pure package for miri-test (built in sandbox)
54+
miriTestPure = pkgs.writeShellApplication {
55+
name = "miri-test-pure";
56+
runtimeInputs = [
57+
nightlyToolchain
58+
] ++ commonBuildInputs;
59+
60+
text = ''
61+
set -e
62+
# Additional environment setup (runtimeInputs handles PATH for binaries)
63+
export LD_LIBRARY_PATH="${pkgs.openssl.out}/lib"
64+
export PKG_CONFIG_PATH="${pkgs.openssl.dev}/lib/pkgconfig"
65+
# MIRI_SYSROOT needs to be writable - use a cache directory
66+
# cargo miri setup will create the sysroot here
67+
export MIRI_SYSROOT="''${MIRI_SYSROOT:-$HOME/.cache/miri}"
68+
mkdir -p "$MIRI_SYSROOT"
69+
cargo miri setup
70+
cargo miri test miri
71+
'';
72+
};
5273
in {
5374
devShells.default = pkgs.mkShell {
5475
buildInputs = [
@@ -104,49 +125,14 @@
104125
'';
105126
};
106127

128+
# Pure package for miri-test (built in sandbox)
129+
packages.miri-test-pure = miriTestPure;
130+
131+
# App that uses the pure package (built in sandbox when run)
132+
# When you run `nix run .#miri-test`, it will build the pure package first
107133
apps.miri-test = {
108134
type = "app";
109-
program = writeShellScriptWithError "miri-test" ''
110-
export PATH="${nightlyToolchain}/bin:$PATH"
111-
# Ensure cargo uses the nightly toolchain from PATH (not rustup)
112-
unset RUSTUP_TOOLCHAIN
113-
# nix run preserves the working directory, but ensure we're in project root
114-
if [ ! -f "Cargo.toml" ]; then
115-
# Try to find project root
116-
while [ "$PWD" != "/" ] && [ ! -f "Cargo.toml" ]; do
117-
cd ..
118-
done
119-
if [ ! -f "Cargo.toml" ]; then
120-
echo "Error: Could not find Cargo.toml" >&2
121-
exit 1
122-
fi
123-
fi
124-
# Verify we're using nightly (using case-insensitive check without grep)
125-
RUSTC_VERSION=$(rustc --version)
126-
case "$RUSTC_VERSION" in
127-
*nightly*) ;;
128-
*) echo "Error: Not using nightly toolchain, got: $RUSTC_VERSION" >&2; exit 1;;
129-
esac
130-
# Verify cargo is also nightly
131-
CARGO_VERSION=$(cargo --version)
132-
case "$CARGO_VERSION" in
133-
*nightly*) ;;
134-
*) echo "Error: cargo is not nightly, got: $CARGO_VERSION" >&2; exit 1;;
135-
esac
136-
# Verify cargo-miri is available and comes from nightly
137-
if ! command -v cargo-miri >/dev/null 2>&1; then
138-
echo "Error: cargo-miri not found in PATH" >&2
139-
exit 1
140-
fi
141-
# Verify cargo-miri is from the nightly toolchain we set in PATH
142-
CARGO_MIRI_PATH=$(command -v cargo-miri)
143-
case "$CARGO_MIRI_PATH" in
144-
*nightly*) ;;
145-
*) echo "Error: cargo-miri not from nightly toolchain, found at: $CARGO_MIRI_PATH" >&2; exit 1;;
146-
esac
147-
cargo miri setup
148-
cargo miri test miri
149-
'';
135+
program = "${miriTestPure}/bin/miri-test-pure";
150136
};
151137

152138
apps.build-book = {

0 commit comments

Comments
 (0)