Repository navigation
Exclude Rust test harness stdlib crates from non-test CcInfo - #4466
Open
vaibhav-1207 wants to merge 1 commit into
Open
vaibhav-1207 wants to merge 1 commit into
vaibhav-1207 wants to merge 1 commit into
Conversation
Previously, `make_libstd_and_allocator_ccinfo` unconditionally bundled `StdLibInfo.test_files` into the standard `libstd` `CcInfo` exported by `rust_library` targets and linked into non-test binaries. In addition, `_rust_stdlib_filegroup_impl` matched `test_files` via substring matching (`"test" in f.basename`), which left `test`'s exclusive transitive dependencies (`getopts` and `unicode_width`) in `between_core_and_std_files` and could misclassify unrelated crates containing `"test"`. This change separates the test harness sysroot crates from non-test `CcInfo` while preserving linkage for all test targets and `--test` binaries: - Partition `test`, `getopts`, and `unicode_width` into `StdLibInfo.test_files` in topological link order using exact `lib<crate>-` / `lib<crate>.` prefix matching (retaining `proc_macro` and `rustc_literal_escaper` in `between_core_and_std_files` since non-test crates can depend on them). - Remove `test_files` from `make_libstd_and_allocator_ccinfo` and add an allocator-independent `make_libtest_ccinfo` exposed on `ToolchainInfo` as `libtest_ccinfo`. - Collect `crate_info.deps` before `toolchain.libtest_ccinfo`, `_get_std_and_alloc_info(...)`, and `toolchain.stdlib_linkflags` in `_collect_dep_cc_infos`, and include `libtest_ccinfo` under `experimental_use_cc_common_link` whenever `crate_info.is_test` is true or `--test` is passed to `rustc` (via `rustc_flags`, caller `rust_flags`, or `collect_extra_rustc_flags`) and `is_no_std` is false. This preserves the archive link order `deps -> test -> getopts [-> unicode_width] -> std -> ... -> core -> compiler_builtins -> alloc -> allocator`. - Add unit tests in `test/unit/stdlib` and an end-to-end `rust_binary(rustc_flags = ["--test"])` integration test in `test/integration/cc_common_link`. Assisted-by: Gemini
vaibhav-1207
force-pushed
the
filter-test-stdlib-ccinfo
branch
from
November 26, 2026 06:45
6ce9f25 to
5bb7ff1
Compare
krasimirgg
self-requested a review
November 26, 2026 09:35
This branch has not been deployed
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.
Previously,
make_libstd_and_allocator_ccinfounconditionally bundledStdLibInfo.test_filesinto the standardlibstdCcInfoexported byrust_librarytargets and linked into non-test binaries. In addition,_rust_stdlib_filegroup_implmatchedtest_filesvia substring matching ("test" in f.basename), which lefttest's exclusive transitive dependencies (getoptsandunicode_width) inbetween_core_and_std_filesand could misclassify unrelated crates containing"test".This change separates the test harness sysroot crates from non-test
CcInfowhile preserving linkage for all test targets and--testbinaries:test,getopts, andunicode_widthintoStdLibInfo.test_filesin topological link order using exactlib<crate>-/lib<crate>.prefix matching (retainingproc_macroandrustc_literal_escaperinbetween_core_and_std_filessince non-test crates can depend on them).test_filesfrommake_libstd_and_allocator_ccinfoand add an allocator-independentmake_libtest_ccinfoexposed onToolchainInfoaslibtest_ccinfo.crate_info.depsbeforetoolchain.libtest_ccinfo,_get_std_and_alloc_info(...), andtoolchain.stdlib_linkflagsin_collect_dep_cc_infos, and includelibtest_ccinfounderexperimental_use_cc_common_linkwhenevercrate_info.is_testis true or--testis passed torustc(viarustc_flags, callerrust_flags, orcollect_extra_rustc_flags) andis_no_stdis false. This preserves the archive link orderdeps -> test -> getopts [-> unicode_width] -> std -> ... -> core -> compiler_builtins -> alloc -> allocator.test/unit/stdliband an end-to-endrust_binary(rustc_flags = ["--test"])integration test intest/integration/cc_common_link.Assisted-by: Gemini