Skip to content

Use correct env for rust_test#3764

Closed
nmattia wants to merge 1 commit intobazelbuild:mainfrom
nmattia:nm-rust-test-env
Closed

Use correct env for rust_test#3764
nmattia wants to merge 1 commit intobazelbuild:mainfrom
nmattia:nm-rust-test-env

Conversation

@nmattia
Copy link
Copy Markdown
Contributor

@nmattia nmattia commented Dec 9, 2025

This expands the rust_test environment make variables directly instead of using the "build script" helper. The build script helper is incorrect here and this leads issues in Bazel 8.

Note: this was inspired by rules_shell.

This expands the `rust_test` environment make variables directly
instead of using the "build script" helper. The build script helper
is incorrect here and this leads issues in Bazel 8.
nmattia added a commit to dfinity/ic that referenced this pull request Dec 9, 2025
This introduces a rules_rust patch to work around issues in how the
`rust_test` environment is set up. This issue leads to wasm_spec test
failures in Bazel 8 where the test runner cannot find the spec files.

See also: bazelbuild/rules_rust#3764
github-merge-queue Bot pushed a commit to dfinity/ic that referenced this pull request Dec 9, 2025
This introduces a rules_rust patch to work around issues in how the
`rust_test` environment is set up. This issue leads to wasm_spec test
failures in Bazel 8 where the test runner cannot find the spec files.

See also: bazelbuild/rules_rust#3764
Copy link
Copy Markdown
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

Makes sense, thank you!

Copy link
Copy Markdown
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

Please could you add a test showing this working, which failed without it?

@nmattia
Copy link
Copy Markdown
Contributor Author

nmattia commented Jan 30, 2026

@illicitonion it's been a while, though interestingly I cannot reproduce anymore. Something might have changed in Bazel between the version I originally tried (8.X) and two more recent releases I tried which don't require the patch (8.4.2 & 8.5.1). Or maybe I just hallucinated the whole thing :)

I don't think it's a bad idea to reuse the same implementation as sh_test though but up to you. Feel free to merge as is or close!

@illicitonion
Copy link
Copy Markdown
Collaborator

I'll close for now, but if anyone can repro, please do shout and we can reopen! Thanks!

@nmattia
Copy link
Copy Markdown
Contributor Author

nmattia commented Feb 9, 2026

@illicitonion well, I guess you just had to close the PR for me to run into the issue again 😛

I've created a repro here. Without the changes in this PR, the test fails. With the patch, it succeeds.

The setup is not ideal because I'm pulling the whole wasm test spec (I extracted the repro from this repo). I'm not familiar with the test setup for rules_rust; can I let you take it from here?

@illicitonion
Copy link
Copy Markdown
Collaborator

Thanks for the repro! This was super useful!

The root cause here is that $(locations) is unhelpfully defined - sometimes it expands to an execpath and sometimes a rootpath.

In a test, you always want a rootpath. So instead of using the confusingly defined $(locations), if you apply this diff to your branch things work for me:

diff --git i/test/test_env/BUILD.bazel w/test/test_env/BUILD.bazel
index f2cd0dc8c..8b46d80d0 100644
--- i/test/test_env/BUILD.bazel
+++ w/test/test_env/BUILD.bazel
@@ -73,6 +73,6 @@ rust_test(
     srcs = ["tests/test_env_locations_external.rs"],
     data = ["@wasm_spec_testsuite//:memory64_wast_files"],
     env = {
-        "THE_FILES": "$(locations @wasm_spec_testsuite//:memory64_wast_files)",
+        "THE_FILES": "$(rootpaths @wasm_spec_testsuite//:memory64_wast_files)",
     },
 )

Does this work for you?

nmattia added a commit to dfinity/ic that referenced this pull request Feb 20, 2026
There is a better (more correct) fix for the issue, which is to replace
the underspecified `$(locations)` with `$(rootpaths)`:
bazelbuild/rules_rust#3764
@nmattia
Copy link
Copy Markdown
Contributor Author

nmattia commented Feb 20, 2026

Does this work for you?

It does, thank you very much for taking the time to look into this — and confirm it was a chair-to-keyboard interface error :)

@nmattia nmattia deleted the nm-rust-test-env branch February 20, 2026 11:12
github-merge-queue Bot pushed a commit to dfinity/ic that referenced this pull request Feb 20, 2026
There is a better (more correct) fix for the issue, which is to replace
the underspecified `$(locations)` with `$(rootpaths)`:
bazelbuild/rules_rust#3764
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants