toolchain files: ensure test depends on std (#1486)
* toolchain files: ensure test depends on std
No functional changes intended.
Among the standard rust libs, libtest depends on libstd:
https://github.com/rust-lang/rust/blob/master/library/test/Cargo.toml#L12
The current implementation was adding it to
`between_core_and_std_files`. This may cause backward reference linker
errors in some configurations where the linker is configured to check
for such backward references and the toolchain uses the static version
of libtest.
* Regenerate documentation
diff --git a/docs/flatten.md b/docs/flatten.md
index e4eef54..27287f6 100644
--- a/docs/flatten.md
+++ b/docs/flatten.md
@@ -1408,7 +1408,7 @@
<pre>
StdLibInfo(<a href="#StdLibInfo-alloc_files">alloc_files</a>, <a href="#StdLibInfo-between_alloc_and_core_files">between_alloc_and_core_files</a>, <a href="#StdLibInfo-between_core_and_std_files">between_core_and_std_files</a>, <a href="#StdLibInfo-core_files">core_files</a>,
- <a href="#StdLibInfo-dot_a_files">dot_a_files</a>, <a href="#StdLibInfo-memchr_files">memchr_files</a>, <a href="#StdLibInfo-self_contained_files">self_contained_files</a>, <a href="#StdLibInfo-srcs">srcs</a>, <a href="#StdLibInfo-std_files">std_files</a>, <a href="#StdLibInfo-std_rlibs">std_rlibs</a>)
+ <a href="#StdLibInfo-dot_a_files">dot_a_files</a>, <a href="#StdLibInfo-memchr_files">memchr_files</a>, <a href="#StdLibInfo-self_contained_files">self_contained_files</a>, <a href="#StdLibInfo-srcs">srcs</a>, <a href="#StdLibInfo-std_files">std_files</a>, <a href="#StdLibInfo-std_rlibs">std_rlibs</a>, <a href="#StdLibInfo-test_files">test_files</a>)
</pre>
A collection of files either found within the `rust-stdlib` artifact or generated based on existing files.
@@ -1428,6 +1428,7 @@
| <a id="StdLibInfo-srcs"></a>srcs | List[Target]: All targets from the original <code>srcs</code> attribute. |
| <a id="StdLibInfo-std_files"></a>std_files | Depset[File]: <code>.a</code> files associated with the <code>std</code> module. |
| <a id="StdLibInfo-std_rlibs"></a>std_rlibs | List[File]: All <code>.rlib</code> files |
+| <a id="StdLibInfo-test_files"></a>test_files | Depset[File]: <code>.a</code> files associated with the <code>test</code> module. |
<a id="cargo_build_script"></a>
diff --git a/docs/providers.md b/docs/providers.md
index 2df30cb..884a154 100644
--- a/docs/providers.md
+++ b/docs/providers.md
@@ -68,7 +68,7 @@
<pre>
StdLibInfo(<a href="#StdLibInfo-alloc_files">alloc_files</a>, <a href="#StdLibInfo-between_alloc_and_core_files">between_alloc_and_core_files</a>, <a href="#StdLibInfo-between_core_and_std_files">between_core_and_std_files</a>, <a href="#StdLibInfo-core_files">core_files</a>,
- <a href="#StdLibInfo-dot_a_files">dot_a_files</a>, <a href="#StdLibInfo-memchr_files">memchr_files</a>, <a href="#StdLibInfo-self_contained_files">self_contained_files</a>, <a href="#StdLibInfo-srcs">srcs</a>, <a href="#StdLibInfo-std_files">std_files</a>, <a href="#StdLibInfo-std_rlibs">std_rlibs</a>)
+ <a href="#StdLibInfo-dot_a_files">dot_a_files</a>, <a href="#StdLibInfo-memchr_files">memchr_files</a>, <a href="#StdLibInfo-self_contained_files">self_contained_files</a>, <a href="#StdLibInfo-srcs">srcs</a>, <a href="#StdLibInfo-std_files">std_files</a>, <a href="#StdLibInfo-std_rlibs">std_rlibs</a>, <a href="#StdLibInfo-test_files">test_files</a>)
</pre>
A collection of files either found within the `rust-stdlib` artifact or generated based on existing files.
@@ -88,5 +88,6 @@
| <a id="StdLibInfo-srcs"></a>srcs | List[Target]: All targets from the original <code>srcs</code> attribute. |
| <a id="StdLibInfo-std_files"></a>std_files | Depset[File]: <code>.a</code> files associated with the <code>std</code> module. |
| <a id="StdLibInfo-std_rlibs"></a>std_rlibs | List[File]: All <code>.rlib</code> files |
+| <a id="StdLibInfo-test_files"></a>test_files | Depset[File]: <code>.a</code> files associated with the <code>test</code> module. |
diff --git a/rust/private/providers.bzl b/rust/private/providers.bzl
index 6009aa0..0a1d924 100644
--- a/rust/private/providers.bzl
+++ b/rust/private/providers.bzl
@@ -94,6 +94,7 @@
"srcs": "List[Target]: All targets from the original `srcs` attribute.",
"std_files": "Depset[File]: `.a` files associated with the `std` module.",
"std_rlibs": "List[File]: All `.rlib` files",
+ "test_files": "Depset[File]: `.a` files associated with the `test` module.",
},
)
diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
index 349c393..a046c4e 100644
--- a/rust/toolchain.bzl
+++ b/rust/toolchain.bzl
@@ -14,6 +14,7 @@
core_files = []
between_core_and_std_files = []
std_files = []
+ test_files = []
memchr_files = []
alloc_files = []
self_contained_files = [
@@ -24,7 +25,8 @@
std_rlibs = [f for f in rust_std if f.basename.endswith(".rlib")]
if std_rlibs:
- # std depends on everything
+ # test depends on std
+ # std depends on everything except test
#
# core only depends on alloc, but we poke adler in there
# because that needs to be before miniz_oxide
@@ -39,14 +41,15 @@
between_core_and_std_files = [
f
for f in dot_a_files
- if "alloc" not in f.basename and "compiler_builtins" not in f.basename and "core" not in f.basename and "adler" not in f.basename and "std" not in f.basename and "memchr" not in f.basename
+ if "alloc" not in f.basename and "compiler_builtins" not in f.basename and "core" not in f.basename and "adler" not in f.basename and "std" not in f.basename and "memchr" not in f.basename and "test" not in f.basename
]
memchr_files = [f for f in dot_a_files if "memchr" in f.basename]
std_files = [f for f in dot_a_files if "std" in f.basename]
+ test_files = [f for f in dot_a_files if "test" in f.basename]
- partitioned_files_len = len(alloc_files) + len(between_alloc_and_core_files) + len(core_files) + len(between_core_and_std_files) + len(memchr_files) + len(std_files)
+ partitioned_files_len = len(alloc_files) + len(between_alloc_and_core_files) + len(core_files) + len(between_core_and_std_files) + len(memchr_files) + len(std_files) + len(test_files)
if partitioned_files_len != len(dot_a_files):
- partitioned = alloc_files + between_alloc_and_core_files + core_files + between_core_and_std_files + memchr_files + std_files
+ partitioned = alloc_files + between_alloc_and_core_files + core_files + between_core_and_std_files + memchr_files + std_files + test_files
for f in sorted(partitioned):
# buildifier: disable=print
print("File partitioned: {}".format(f.basename))
@@ -63,6 +66,7 @@
core_files = core_files,
between_core_and_std_files = between_core_and_std_files,
std_files = std_files,
+ test_files = test_files,
memchr_files = memchr_files,
alloc_files = alloc_files,
self_contained_files = self_contained_files,
@@ -198,10 +202,18 @@
transitive = [between_core_and_std_inputs],
order = "topological",
)
+ test_inputs = depset(
+ [
+ _ltl(f, ctx, cc_toolchain, feature_configuration)
+ for f in rust_stdlib_info.test_files
+ ],
+ transitive = [std_inputs],
+ order = "topological",
+ )
link_inputs = cc_common.create_linker_input(
owner = rust_std.label,
- libraries = std_inputs,
+ libraries = test_inputs,
)
allocator_inputs = None