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

[toolchain] Make Os and Oz mutually exclusive. #25928

Merged
merged 1 commit into from
Jan 18, 2025
Merged
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
117 changes: 75 additions & 42 deletions toolchain/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,92 @@ cc_action_type(
action_name = OT_ACTION_OBJDUMP,
)

# minsize feature to switch between Os and Oz.
cc_feature(
name = "feat_minsize",
feature_name = "minsize",
)

cc_feature_constraint(
name = "constraint_minsize",
all_of = [":feat_minsize"],
)

cc_feature_constraint(
name = "constraint_no_minsize",
none_of = [":feat_minsize"],
)

cc_feature_constraint(
name = "constraint_minsize_lld",
all_of = [
":feat_minsize",
":feat_use_lld",
],
)

# Built-in Bazel feature enabled for optimized builds.
cc_feature(
name = "feat_opt",
args = [
":opt",
":optsize",
":minsize",
":minsize_inline_cc",
":minsize_inline_ld",
":default_debug_info",
":lto",
],
overrides = "@rules_cc//cc/toolchains/features:opt",
)

cc_args(
name = "opt",
name = "default_debug_info",
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
args = [
"-Os",
"-g",
"-gdwarf-4",
],
)

cc_args(
name = "optsize",
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
args = [
"-Os",
],
requires_any_of = [":constraint_no_minsize"],
)

cc_args(
name = "minsize",
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
args = [
"-Oz",
],
requires_any_of = [":constraint_minsize"],
)

# Inline slightly more which is actually smaller.
cc_args(
name = "minsize_inline_cc",
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
args = [
"-mllvm",
"--inline-threshold=10",
],
requires_any_of = [":constraint_minsize_lld"],
)

cc_args(
name = "minsize_inline_ld",
actions = ["@rules_cc//cc/toolchains/actions:link_actions"],
args = [
"-Wl,-mllvm",
"-Wl,--inline-threshold=10",
],
requires_any_of = [":constraint_minsize_lld"],
)

# Built-in Bazel feature enabled for debug builds.
cc_feature(
name = "feat_dbg",
Expand All @@ -126,18 +192,14 @@ cc_args(
# Built-in Bazel feature for fast builds.
cc_feature(
name = "feat_fastbuild",
args = [":fastbuild"],
overrides = "@rules_cc//cc/toolchains/features:fastbuild",
)

cc_args(
name = "fastbuild",
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
args = [
"-Os",
"-g",
"-gdwarf-4",
":optsize",
":minsize",
":minsize_inline_cc",
":minsize_inline_ld",
":default_debug_info",
],
overrides = "@rules_cc//cc/toolchains/features:fastbuild",
)

cc_args(
Expand Down Expand Up @@ -306,35 +368,6 @@ cc_args(
args = ["-flto"],
)

cc_feature(
name = "feat_minsize",
args = [
":minsize_cc",
":minsize_ld",
],
feature_name = "minsize",
)

cc_args(
name = "minsize_cc",
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
args = [
"-Oz",
# Inline slightly more which is actually smaller.
"-mllvm",
"--inline-threshold=10",
],
)

cc_args(
name = "minsize_ld",
actions = ["@rules_cc//cc/toolchains/actions:link_actions"],
args = [
"-Wl,-mllvm",
"-Wl,--inline-threshold=10",
],
)

cc_args(
name = "unique_sections",
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
Expand Down
Loading