Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cargo/private/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,8 @@ def _cargo_build_script_impl(ctx):
flags = flags_out,
linker_flags = link_flags,
link_search_paths = link_search_paths,
compile_data = depset([runfiles_dir] + extra_output, transitive = script_data),
build_script_data = depset(transitive = script_data),
compile_data = depset([runfiles_dir] + extra_output),
),
OutputGroupInfo(
**output_groups
Expand Down
2 changes: 2 additions & 0 deletions cargo/private/cargo_dep_env.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def _cargo_dep_env_impl(ctx):
link_search_paths = empty_file,
out_dir = out_dir,
rustc_env = empty_file,
build_script_data = depset([]),
compile_data = depset([]),
))
return [
Expand All @@ -54,6 +55,7 @@ def _cargo_dep_env_impl(ctx):
link_search_paths = empty_file,
out_dir = None,
rustc_env = empty_file,
build_script_data = depset([]),
compile_data = depset([]),
),
# Information here is used directly by dependencies, and it is an error to have more than
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Tests documenting that cargo_build_script `data` files currently act as both
compile_data and runtime data -- they appear in Rustc compile action inputs for
both the direct library and transitive dependents.
"""Tests for cargo_build_script `data` propagation into Rustc compile actions.

See https://github.com/bazelbuild/rules_rust/issues/3609 for context."""

Expand All @@ -21,21 +19,20 @@ def _cbs_data_in_rustc_inputs_impl(ctx):

asserts.false(env, rustc_action == None, "Expected a Rustc action")

# cargo_build_script `data` currently flows into BuildInfo.compile_data
# via script_data, so it appears in Rustc action inputs for both the
# direct dependent and transitive dependents. This documents that
# CBS `data` effectively acts as both compile_data and data today.
data_inputs = [i for i in rustc_action.inputs.to_list() if "cbs_data_dep.txt" in i.path]
asserts.true(
asserts.equals(
env,
ctx.attr.expected_present,
len(data_inputs) > 0,
"Expected CBS data file to appear in Rustc action inputs (CBS data currently acts as compile_data)",
)

return analysistest.end(env)

cbs_data_in_rustc_inputs_test = analysistest.make(
_cbs_data_in_rustc_inputs_impl,
attrs = {
"expected_present": attr.bool(),
},
)

def _define_test_targets():
Expand Down Expand Up @@ -98,11 +95,13 @@ def transitive_cbs_data_test_suite(name):

cbs_data_in_rustc_inputs_test(
name = "cbs_data_in_lib_compile_inputs_test",
expected_present = True,
target_under_test = ":lib",
)

cbs_data_in_rustc_inputs_test(
name = "cbs_data_in_bin_compile_inputs_test",
expected_present = False,
target_under_test = ":bin",
)

Expand Down
1 change: 1 addition & 0 deletions extensions/bindgen/private/bindgen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def _generate_cc_link_build_info(ctx, cc_lib):
)

return BuildInfo(
build_script_data = depset([]),
compile_data = depset(compile_data),
dep_env = None,
flags = rustc_flags_file,
Expand Down
3 changes: 2 additions & 1 deletion rust/private/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ CrateGroupInfo = provider(
BuildInfo = provider(
doc = "A provider containing `rustc` build settings for a given Crate.",
fields = {
"compile_data": "Depset[File]: Compile data provided by the build script that was not copied into `out_dir`.",
"build_script_data": "Depset[File]: Data inputs used by the build script that may also be referenced by its direct dependent.",
"compile_data": "Depset[File]: Compile data that should remain available to transitive dependents.",
"dep_env": "Optional[File]: extra build script environment variables to be set to direct dependencies.",
"flags": "Optional[File]: file containing additional flags to pass to rustc",
"link_search_paths": "Optional[File]: file containing search paths to pass to rustc and linker",
Expand Down
1 change: 1 addition & 0 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,7 @@ def _process_build_scripts(
direct_inputs.append(build_info.linker_flags)

transitive_inputs.append(build_info.compile_data)
transitive_inputs.append(getattr(build_info, "build_script_data", depset()))

# We include transitive dep build_infos because cargo build scripts may generate files which get linked into the final binary.
# This should probably only actually be exposed to actions which link.
Expand Down