Skip to content

Commit dcd105e

Browse files
committed
Address review comments
1 parent d32726b commit dcd105e

File tree

5 files changed

+65
-32
lines changed

5 files changed

+65
-32
lines changed

rust/private/providers.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ DepInfo = provider(
5050
"transitive_build_infos": "depset[BuildInfo]",
5151
"transitive_crate_outputs": "depset[File]: All transitive crate outputs.",
5252
"transitive_crates": "depset[CrateInfo]",
53-
"transitive_metadata_outputs": "depset[File]: All transitive metadata dependencies (.rlib, for crates that provide them) and all transitive object dependencies (.rlib) for crates that don't provide metadata.",
53+
"transitive_metadata_outputs": "depset[File]: All transitive metadata dependencies (.rmeta, for crates that provide them) and all transitive object dependencies (.rlib) for crates that don't provide metadata.",
5454
"transitive_noncrates": "depset[LinkerInput]: All transitive dependencies that aren't crates.",
5555
},
5656
)

rust/private/rustc.bzl

+7-9
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,7 @@ def _depend_on_metadata(crate_info, force_depend_on_objects):
542542
if force_depend_on_objects:
543543
return False
544544

545-
is_lib = crate_info.type in ("rlib", "lib")
546-
build_metadata = crate_info.metadata != None
547-
return is_lib and build_metadata
545+
return crate_info.type in ("rlib", "lib")
548546

549547
def collect_inputs(
550548
ctx,
@@ -705,7 +703,7 @@ def construct_arguments(
705703
remap_path_prefix = ".",
706704
use_json_output = False,
707705
build_metadata = False,
708-
force_link_to_objects = False):
706+
force_depend_on_objects = False):
709707
"""Builds an Args object containing common rustc flags
710708
711709
Args:
@@ -734,7 +732,7 @@ def construct_arguments(
734732
remap_path_prefix (str, optional): A value used to remap `${pwd}` to. If set to a falsey value, no prefix will be set.
735733
use_json_output (bool): Have rustc emit json and process_wrapper parse json messages to output rendered output.
736734
build_metadata (bool): Generate CLI arguments for building *only* .rmeta files. This requires use_json_output.
737-
force_link_to_objects (bool): Force linking to concrete (rlib) dependencies, instead of metadata (rlib) even if they are available.
735+
force_depend_on_objects (bool): Force using `.rlib` object files instead of metadata (`.rmeta`) files even if they are available.
738736
739737
Returns:
740738
tuple: A tuple of the following items
@@ -842,9 +840,9 @@ def construct_arguments(
842840

843841
error_format = "json"
844842

845-
if build_metadata:
846-
# Configure process_wrapper to terminate rustc when metadata are emitted
847-
process_wrapper_flags.add("--rustc-quit-on-rmeta", "true")
843+
if build_metadata:
844+
# Configure process_wrapper to terminate rustc when metadata are emitted
845+
process_wrapper_flags.add("--rustc-quit-on-rmeta", "true")
848846

849847
rustc_flags.add("--error-format=" + error_format)
850848

@@ -918,7 +916,7 @@ def construct_arguments(
918916

919917
_add_native_link_flags(rustc_flags, dep_info, linkstamp_outs, ambiguous_libs, crate_info.type, toolchain, cc_toolchain, feature_configuration)
920918

921-
use_metadata = _depend_on_metadata(crate_info, force_link_to_objects)
919+
use_metadata = _depend_on_metadata(crate_info, force_depend_on_objects)
922920

923921
# These always need to be added, even if not linking this crate.
924922
add_crate_link_flags(rustc_flags, dep_info, force_all_deps_direct, use_metadata)

rust/private/rustdoc.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def rustdoc_compile_action(
121121
emit = [],
122122
remap_path_prefix = None,
123123
force_link = True,
124-
force_link_to_objects = is_test,
124+
force_depend_on_objects = is_test,
125125
)
126126

127127
# Because rustdoc tests compile tests outside of the sandbox, the sysroot

test/unit/pipelined_compilation/pipelined_compilation_test.bzl

+56-20
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _pipelined_compilation_test():
112112
second_lib_test(name = "second_lib_test", target_under_test = ":second", target_compatible_with = NOT_WINDOWS)
113113
bin_test(name = "bin_test", target_under_test = ":bin", target_compatible_with = NOT_WINDOWS)
114114

115-
def _custom_rule_test_impl(ctx):
115+
def _rmeta_is_propagated_through_custom_rule_test_impl(ctx):
116116
env = analysistest.begin(ctx)
117117
tut = analysistest.target_under_test(env)
118118

@@ -124,54 +124,88 @@ def _custom_rule_test_impl(ctx):
124124
rlib_inputs = [i for i in rust_action.inputs.to_list() if i.path.endswith(".rlib")]
125125

126126
seen_wrapper_metadata = False
127-
seen_to_wrap = False
127+
seen_to_wrap_metadata = False
128128
for mi in metadata_inputs:
129129
if "libwrapper" in mi.path:
130130
seen_wrapper_metadata = True
131131
if "libto_wrap" in mi.path:
132-
seen_to_wrap = True
132+
seen_to_wrap_metadata = True
133133

134-
seen_wrapper_rlib = True
134+
seen_wrapper_rlib = False
135+
seen_to_wrap_rlib = False
135136
for ri in rlib_inputs:
136137
if "libwrapper" in ri.path:
137138
seen_wrapper_rlib = True
139+
if "libto_wrap" in ri.path:
140+
seen_to_wrap_rlib = True
138141

139142
if ctx.attr.generate_metadata:
140143
asserts.true(env, seen_wrapper_metadata, "expected dependency on metadata for 'wrapper' but not found")
144+
asserts.false(env, seen_wrapper_rlib, "expected no dependency on object for 'wrapper' but it was found")
141145
else:
142-
asserts.true(env, seen_wrapper_rlib, "expected dependency on rlib for 'wrapper' but not found")
146+
asserts.true(env, seen_wrapper_rlib, "expected dependency on object for 'wrapper' but not found")
147+
asserts.false(env, seen_wrapper_metadata, "expected no dependency on metadata for 'wrapper' but it was found")
143148

144-
asserts.true(env, seen_to_wrap, "expected dependency on metadata for 'to_wrap' but not found")
149+
asserts.true(env, seen_to_wrap_metadata, "expected dependency on metadata for 'to_wrap' but not found")
150+
asserts.false(env, seen_to_wrap_rlib, "expected no dependency on object for 'to_wrap' but it was found")
145151

146152
return analysistest.end(env)
147153

148-
custom_rule_test = analysistest.make(_custom_rule_test_impl, attrs = {"generate_metadata": attr.bool()}, config_settings = ENABLE_PIPELINING)
154+
def _rmeta_is_used_when_building_custom_rule_test_impl(ctx):
155+
env = analysistest.begin(ctx)
156+
tut = analysistest.target_under_test(env)
157+
158+
# This is the custom rule invocation of rustc.
159+
rust_action = [act for act in tut.actions if act.mnemonic == "Rustc"][0]
149160

150-
def _custom_rule_test(generate_metadata, prefix):
161+
# We want to check that the action depends on metadata, regardless of ctx.attr.generate_metadata
162+
seen_to_wrap_rlib = False
163+
seen_to_wrap_rmeta = False
164+
for act in rust_action.inputs.to_list():
165+
if "libto_wrap" in act.path and act.path.endswith('.rlib'):
166+
seen_to_wrap_rlib = True
167+
elif "libto_wrap" in act.path and act.path.endswith('.rmeta'):
168+
seen_to_wrap_rmeta = True
169+
170+
asserts.true(env, seen_to_wrap_rmeta, "expected dependency on metadata for 'to_wrap' but not found")
171+
asserts.false(env, seen_to_wrap_rlib, "expected no dependency on object for 'to_wrap' but it was found")
172+
173+
return analysistest.end(env)
174+
175+
rmeta_is_propagated_through_custom_rule_test = analysistest.make(_rmeta_is_propagated_through_custom_rule_test_impl, attrs = {"generate_metadata": attr.bool()}, config_settings = ENABLE_PIPELINING)
176+
rmeta_is_used_when_building_custom_rule_test = analysistest.make(_rmeta_is_used_when_building_custom_rule_test_impl, config_settings = ENABLE_PIPELINING)
177+
178+
def _custom_rule_test(generate_metadata, suffix):
151179
rust_library(
152-
name = "to_wrap" + prefix,
180+
name = "to_wrap" + suffix,
153181
crate_name = "to_wrap",
154182
srcs = ["custom_rule_test/to_wrap.rs"],
155183
edition = "2021",
156184
)
157185
wrap(
158-
name = "wrapper" + prefix,
186+
name = "wrapper" + suffix,
159187
crate_name = "wrapper",
160-
target = ":to_wrap" + prefix,
188+
target = ":to_wrap" + suffix,
161189
generate_metadata = generate_metadata,
162190
)
163191
rust_library(
164-
name = "uses_wrapper" + prefix,
192+
name = "uses_wrapper" + suffix,
165193
srcs = ["custom_rule_test/uses_wrapper.rs"],
166-
deps = [":wrapper" + prefix],
194+
deps = [":wrapper" + suffix],
167195
edition = "2021",
168196
)
169197

170-
custom_rule_test(
171-
name = "custom_rule_test" + prefix,
198+
rmeta_is_propagated_through_custom_rule_test(
199+
name = "rmeta_is_propagated_through_custom_rule_test" + suffix,
172200
generate_metadata = generate_metadata,
173201
target_compatible_with = NOT_WINDOWS,
174-
target_under_test = ":uses_wrapper" + prefix,
202+
target_under_test = ":uses_wrapper" + suffix,
203+
)
204+
205+
rmeta_is_used_when_building_custom_rule_test(
206+
name = "rmeta_is_used_when_building_custom_rule_test" + suffix,
207+
target_compatible_with = NOT_WINDOWS,
208+
target_under_test = ":wrapper" + suffix,
175209
)
176210

177211
def pipelined_compilation_test_suite(name):
@@ -181,15 +215,17 @@ def pipelined_compilation_test_suite(name):
181215
name: Name of the macro.
182216
"""
183217
_pipelined_compilation_test()
184-
_custom_rule_test(generate_metadata = True, prefix = "_with_metadata")
185-
_custom_rule_test(generate_metadata = False, prefix = "_without_metadata")
218+
_custom_rule_test(generate_metadata = True, suffix = "_with_metadata")
219+
_custom_rule_test(generate_metadata = False, suffix = "_without_metadata")
186220

187221
native.test_suite(
188222
name = name,
189223
tests = [
190224
":bin_test",
191225
":second_lib_test",
192-
":custom_rule_test_with_metadata",
193-
":custom_rule_test_without_metadata",
226+
":rmeta_is_propagated_through_custom_rule_test_with_metadata",
227+
":rmeta_is_propagated_through_custom_rule_test_without_metadata",
228+
":rmeta_is_used_when_building_custom_rule_test_with_metadata",
229+
":rmeta_is_used_when_building_custom_rule_test_without_metadata",
194230
],
195231
)

test/unit/pipelined_compilation/wrap.bzl

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ EOF
7878
is_test = False,
7979
),
8080
output_hash = output_hash,
81-
force_all_deps_direct = True,
8281
)
8382

8483
wrap = rule(

0 commit comments

Comments
 (0)