Include compile_data targets in rustc_env location expansion for rust_test - #4000
Merged
UebelAndre merged 3 commits intoApr 28, 2026
Merged
Conversation
tamasvajk
force-pushed
the
compile-data-in-data-paths
branch
2 times, most recently
from
April 28, 2026 14:31
e1b4935 to
2862fe0
Compare
UebelAndre
requested changes
Apr 28, 2026
UebelAndre
left a comment
Collaborator
There was a problem hiding this comment.
Thanks! Can you add a test for this somewhere in //test/unit?
In rust_test, $(location) and $(rootpath) expansions in rustc_env
only searched data targets. When a compile_data target was referenced
in rustc_env (e.g. include_str!(env!("PATH_TO_GENERATED_FILE"))),
the expansion failed because compile_data wasn't in the search set.
Add compile_data targets to the data_paths depset used by
expand_dict_value_locations in both the crate-wrapping and standalone
rust_test code paths.
tamasvajk
force-pushed
the
compile-data-in-data-paths
branch
from
April 28, 2026 15:21
2862fe0 to
5481876
Compare
UebelAndre
requested changes
Apr 28, 2026
UebelAndre
left a comment
Collaborator
There was a problem hiding this comment.
Looks like CI is failing
(15:23:36) ERROR: /workdir/test/unit/compile_data_env/BUILD.bazel:4:28: Compiling Rust bin crate_wrap_test (1 file) failed: (Exit 1): process_wrapper failed: error executing Rustc command (from rust_test rule target //test/unit/compile_data_env:crate_wrap_test)
(cd /var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/ec321eb2cc2d0f8f91b676b6d4c66c29/sandbox/linux-sandbox/737/execroot/_main && \
exec env - \
CARGO_CFG_TARGET_ARCH=x86_64 \
CARGO_CFG_TARGET_OS=linux \
CARGO_CRATE_NAME=mylib \
CARGO_MANIFEST_DIR='${pwd}/test/unit/compile_data_env' \
CARGO_PKG_AUTHORS='' \
CARGO_PKG_DESCRIPTION='' \
CARGO_PKG_HOMEPAGE='' \
CARGO_PKG_NAME=mylib \
CARGO_PKG_VERSION=0.0.0 \
CARGO_PKG_VERSION_MAJOR=0 \
CARGO_PKG_VERSION_MINOR=0 \
CARGO_PKG_VERSION_PATCH=0 \
CARGO_PKG_VERSION_PRE='' \
GENERATED_PATH='${pwd}/bazel-out/k8-fastbuild/bin/test/unit/compile_data_env/generated.txt' \
PATH=/bin:/usr/bin:/usr/local/bin \
REPOSITORY_NAME='' \
ZERO_AR_DATE=1 \
bazel-out/k8-opt-exec/bin/util/process_wrapper/process_wrapper --subst 'pwd=${pwd}' --subst 'exec_root=${exec_root}' --subst 'output_base=${output_base}' -- bazel-out/k8-fastbuild/bin/external/+rust+rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools/rust_toolchain/bin/rustc test/unit/compile_data_env/lib.rs '--crate-name=mylib' '--crate-type=bin' '--error-format=human' '--codegen=metadata=-3204932321' '--codegen=extra-filename=-3204932321' '--out-dir=bazel-out/k8-fastbuild/bin/test/unit/compile_data_env' '--codegen=opt-level=0' '--codegen=debuginfo=0' '--codegen=strip=none' '--remap-path-prefix=${pwd}=.' '--remap-path-prefix=${exec_root}=.' '--remap-path-prefix=${output_base}=.' '--emit=link=bazel-out/k8-fastbuild/bin/test/unit/compile_data_env/crate_wrap_test' '--emit=dep-info' '--color=always' '--target=x86_64-unknown-linux-gnu' -L bazel-out/k8-fastbuild/bin/external/+rust+rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools/rust_toolchain/lib/rustlib/x86_64-unknown-linux-gnu/lib --test '--edition=2021' '-Cembed-bitcode=no' '--codegen=linker=/usr/bin/gcc' '--codegen=link-arg=-fuse-ld=gold' '--codegen=link-arg=-B/usr/bin' '--codegen=link-arg=-Wl,-no-as-needed' '--codegen=link-arg=-Wl,-z,relro,-z,now' '--codegen=link-arg=-pass-exit-codes' '--codegen=link-arg=-Wl,--push-state,-as-needed' '--codegen=link-arg=-lstdc++' '--codegen=link-arg=-Wl,--pop-state' '--codegen=link-arg=-Wl,--push-state,-as-needed' '--codegen=link-arg=-lm' '--codegen=link-arg=-Wl,--pop-state' '--sysroot=bazel-out/k8-fastbuild/bin/external/+rust+rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools/rust_toolchain')
# Configuration: bbf8a40a9f44b6c42caef393bd2f86fe4f730742c9380170decb994f975e91a7
# Execution platform: @@platforms//host:host
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
error: couldn't read `test/unit/compile_data_env/lib.rs`: No such file or directory (os error 2)
error: aborting due to 1 previous error
added 2 commits
April 28, 2026 15:39
The rust_test(crate=..., compile_data=[generated]) combination causes a build error (source file not found after transform_sources). Keep only the standalone test which covers the fix.
Use a non-generated file in compile_data for the crate-wrap test to avoid a pre-existing bug where rust_test(crate=...) with generated compile_data fails to build (transform_sources doesn't update crate.root). The test still verifies that compile_data targets are included in the rustc_env location expansion.
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Apr 28, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Apr 28, 2026
dzbarsky
pushed a commit
to hermeticbuild/rules_rust
that referenced
this pull request
Apr 30, 2026
…`rust_test` (bazelbuild#4000) ## Summary Include `compile_data` targets in `rustc_env` location expansion for `rust_test`. ## Problem In `rust_test`, `$(location)` and `$(rootpath)` expansions in `rustc_env` only search `data` targets. When a `compile_data` target is referenced in `rustc_env` — for example to pass the path of a generated file via `env!()` and `include_str!()` — the expansion fails because `compile_data` targets are not in the search set. This affects both `rust_test` code paths: the crate-wrapping path (testing an existing `rust_library`) and the standalone path (test with its own sources). ## Fix Add `compile_data` targets to the `data_paths` depset passed to `expand_dict_value_locations` in both `rust_test` code paths. --- > **Note:** This PR was largely AI-generated using Claude Code, with human review and guidance throughout. --------- Co-authored-by: Tamas Vajk <tamas.vajk@databricks.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Include
compile_datatargets inrustc_envlocation expansion forrust_test.Problem
In
rust_test,$(location)and$(rootpath)expansions inrustc_envonly searchdatatargets. When acompile_datatarget is referenced inrustc_env— for example to pass the path of a generated file viaenv!()andinclude_str!()— the expansion fails becausecompile_datatargets are not in the search set.This affects both
rust_testcode paths: the crate-wrapping path (testing an existingrust_library) and the standalone path (test with its own sources).Fix
Add
compile_datatargets to thedata_pathsdepset passed toexpand_dict_value_locationsin bothrust_testcode paths.