Skip to content

Commit

Permalink
provide flag to exclude data at compile time
Browse files Browse the repository at this point in the history
  • Loading branch information
ajwerner committed Nov 18, 2024
1 parent 60515a1 commit 5e7e310
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions crate_universe/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ alias(
rust_test(
name = "unit_test",
aliases = aliases(),
compile_data = glob(["test_data/**"]),
crate = ":cargo_bazel",
data = glob(["test_data/**"]) + [
"//crate_universe/test_data/serialized_configs",
Expand Down
8 changes: 7 additions & 1 deletion rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,14 @@ def collect_inputs(
if build_info.flags:
build_info_inputs.append(build_info.flags)

# The old default behavior was to include data files at compile time.
# This flag controls whether to include data files in compile_data.
data_included_in_inputs = []
if not toolchain._incompatible_do_not_include_data_in_compile_data:
data_included_in_inputs = getattr(files, "data", [])

nolinkstamp_compile_inputs = depset(
getattr(files, "data", []) +
data_included_in_inputs +
build_info_inputs +
([toolchain.target_json] if toolchain.target_json else []) +
([] if linker_script == None else [linker_script]),
Expand Down
8 changes: 8 additions & 0 deletions rust/settings/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,11 @@ per_crate_rustc_flag(
build_setting_default = [],
visibility = ["//visibility:public"],
)

# A flag to control whether to include data files in compile_data.
incompatible_flag(
name = "incompatible_do_not_include_data_in_compile_data",
build_setting_default = False,
issue = "https://github.com/bazelbuild/rules_rust/issues/2977",
visibility = ["//visibility:public"],
)
5 changes: 5 additions & 0 deletions rust/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ def _rust_toolchain_impl(ctx):
_experimental_use_coverage_metadata_files = ctx.attr._experimental_use_coverage_metadata_files[BuildSettingInfo].value,
_incompatible_change_rust_test_compilation_output_directory = ctx.attr._incompatible_change_rust_test_compilation_output_directory[IncompatibleFlagInfo].enabled,
_toolchain_generated_sysroot = ctx.attr._toolchain_generated_sysroot[BuildSettingInfo].value,
_incompatible_do_not_include_data_in_compile_data = ctx.attr._incompatible_do_not_include_data_in_compile_data[IncompatibleFlagInfo].enabled,
_no_std = no_std,
)
return [
Expand Down Expand Up @@ -886,6 +887,10 @@ rust_toolchain = rule(
"_incompatible_change_rust_test_compilation_output_directory": attr.label(
default = Label("//rust/settings:incompatible_change_rust_test_compilation_output_directory"),
),
"_incompatible_do_not_include_data_in_compile_data": attr.label(
default = Label("//rust/settings:incompatible_do_not_include_data_in_compile_data"),
doc = "Label to a boolean build setting that controls whether to include data files in compile_data.",
),
"_no_std": attr.label(
default = Label("//:no_std"),
),
Expand Down
2 changes: 1 addition & 1 deletion test/build_env/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package(default_visibility = ["//visibility:public"])
rust_test(
name = "conflicting_deps_test",
srcs = ["tests/manifest_dir.rs"],
data = ["src/manifest_dir_file.txt"],
compile_data = ["src/manifest_dir_file.txt"],
edition = "2018",
)

Expand Down

0 comments on commit 5e7e310

Please sign in to comment.