Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple uses of extra_rustc_flags #1407

Closed
wants to merge 4 commits into from
Closed
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
4 changes: 2 additions & 2 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ tasks:
bazel: "rolling"
ubuntu1804:
name: "Min Bazel Version"
bazel: "4.0.0"
bazel: "5.0.0"
platform: ubuntu1804
build_targets: *default_linux_targets
test_targets: *default_linux_targets
ubuntu1804_with_aspects:
name: "Min Bazel Version With Aspects"
bazel: "4.0.0"
bazel: "5.0.0"
platform: ubuntu1804
build_targets: *default_linux_targets
test_targets: *default_linux_targets
Expand Down
4 changes: 2 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ clippy_flags(
# to that target. This can be useful for passing build-wide options such as LTO.
extra_rustc_flags(
name = "extra_rustc_flags",
build_setting_default = [],
build_setting_default = "",
visibility = ["//visibility:public"],
)

Expand All @@ -61,7 +61,7 @@ extra_rustc_flags(
# to that target. This can be useful for passing build-wide options such as LTO.
extra_exec_rustc_flags(
name = "extra_exec_rustc_flags",
build_setting_default = [],
build_setting_default = "",
visibility = ["//visibility:public"],
)

Expand Down
2 changes: 1 addition & 1 deletion docs/defs.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Change the [--error-format](https://doc.rust-lang.org/rustc/command-line-argumen
extra_rustc_flags(<a href="#extra_rustc_flags-name">name</a>)
</pre>

Add additional rustc_flags from the command line with `--@rules_rust//:extra_rustc_flags`. This flag should only be used for flags that need to be applied across the entire build. For options that apply to individual crates, use the rustc_flags attribute on the individual crate's rule instead. NOTE: These flags not applied to the exec configuration (proc-macros, cargo_build_script, etc); use `--@rules_rust//:extra_exec_rustc_flags` to apply flags to the exec configuration.
Add additional rustc_flags from the command line with `--@rules_rust//:extra_rustc_flags`. This flag should only be used for flags that need to be applied across the entire build. For options that apply to individual crates, use the rustc_flags attribute on the individual crate's rule instead. NOTE: These flags not applied to the exec configuration (proc-macros, cargo_build_script, etc); use `--@rules_rust//:extra_exec_rustc_flags` to apply flags to the exec configuration. Accept comma separated strings and multiple uses of this flag are accumulated.

**ATTRIBUTES**

Expand Down
2 changes: 1 addition & 1 deletion docs/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Change the [--error-format](https://doc.rust-lang.org/rustc/command-line-argumen
extra_rustc_flags(<a href="#extra_rustc_flags-name">name</a>)
</pre>

Add additional rustc_flags from the command line with `--@rules_rust//:extra_rustc_flags`. This flag should only be used for flags that need to be applied across the entire build. For options that apply to individual crates, use the rustc_flags attribute on the individual crate's rule instead. NOTE: These flags not applied to the exec configuration (proc-macros, cargo_build_script, etc); use `--@rules_rust//:extra_exec_rustc_flags` to apply flags to the exec configuration.
Add additional rustc_flags from the command line with `--@rules_rust//:extra_rustc_flags`. This flag should only be used for flags that need to be applied across the entire build. For options that apply to individual crates, use the rustc_flags attribute on the individual crate's rule instead. NOTE: These flags not applied to the exec configuration (proc-macros, cargo_build_script, etc); use `--@rules_rust//:extra_exec_rustc_flags` to apply flags to the exec configuration. Accept comma separated strings and multiple uses of this flag are accumulated.

**ATTRIBUTES**

Expand Down
20 changes: 14 additions & 6 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1493,29 +1493,37 @@ error_format = rule(
)

def _extra_rustc_flags_impl(ctx):
return ExtraRustcFlagsInfo(extra_rustc_flags = ctx.build_setting_value)
extra_rustc_flags = []
for flags in [flags.split(",") for flags in ctx.build_setting_value if flags != ""]:
extra_rustc_flags.extend(flags)
return ExtraRustcFlagsInfo(extra_rustc_flags = extra_rustc_flags)

extra_rustc_flags = rule(
doc = (
"Add additional rustc_flags from the command line with `--@rules_rust//:extra_rustc_flags`. " +
"This flag should only be used for flags that need to be applied across the entire build. For options that " +
"apply to individual crates, use the rustc_flags attribute on the individual crate's rule instead. NOTE: " +
"These flags not applied to the exec configuration (proc-macros, cargo_build_script, etc); " +
"use `--@rules_rust//:extra_exec_rustc_flags` to apply flags to the exec configuration."
"use `--@rules_rust//:extra_exec_rustc_flags` to apply flags to the exec configuration. " +
"Accept comma separated strings and multiple uses of this flag are accumulated."
),
implementation = _extra_rustc_flags_impl,
build_setting = config.string_list(flag = True),
build_setting = config.string(flag = True, allow_multiple = True),
)

def _extra_exec_rustc_flags_impl(ctx):
return ExtraExecRustcFlagsInfo(extra_exec_rustc_flags = ctx.build_setting_value)
extra_exec_rustc_flags = []
for flags in [flags.split(",") for flags in ctx.build_setting_value if flags != ""]:
extra_exec_rustc_flags.extend(flags)
return ExtraExecRustcFlagsInfo(extra_exec_rustc_flags = extra_exec_rustc_flags)

extra_exec_rustc_flags = rule(
doc = (
"Add additional rustc_flags in the exec configuration from the command line with `--@rules_rust//:extra_exec_rustc_flags`. " +
"This flag should only be used for flags that need to be applied across the entire build. " +
"These flags only apply to the exec configuration (proc-macros, cargo_build_script, etc)."
"These flags only apply to the exec configuration (proc-macros, cargo_build_script, etc). " +
"Accept comma separated strings and multiple uses of this flag are accumulated."
),
implementation = _extra_exec_rustc_flags_impl,
build_setting = config.string_list(flag = True),
build_setting = config.string(flag = True, allow_multiple = True),
)