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
19 changes: 19 additions & 0 deletions cc/settings/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("@bazel_skylib//lib:selects.bzl", "selects")

selects.config_setting_group(
name = "default_apple_constraint",
match_any = [
"@platforms//os:ios",
"@platforms//os:macos",
"@platforms//os:tvos",
"@platforms//os:visionos",
"@platforms//os:watchos",
],
visibility = ["//visibility:private"],
)

label_flag(
name = "apple_constraint",
build_setting_default = ":default_apple_constraint",
visibility = ["//visibility:public"],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, didn't catch this on my first pass:

Does this need to be public? Considering it's a flag, anyone can set it to match their own canonical definition. I'd prefer this doesn't become load-bearing. If it does, we might want to bikeshed for a moment on naming:

@rules_cc//cc/constraint:apple
@rules_cc//cc/toolchains/constraint:apple

platform doesn't seem correct to me, since that's a very distinct thing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea very good question. I think the downside of not making it public is that downstream toolchains cannot perfectly mirror what happens in the default cc_args that read this version. realistically that's minor, but it would cause very subtly issues for the few people who would ever need to change this.

it being load bearing is annoying because actual downstream users should use apple_support's definitions for this instead, I just don't want to try to add that circular dependency here.

it's also possible that the best solution is to move this into platforms_contrib (since it's unlikely platforms itself wants this)

Copy link
Copy Markdown
Collaborator

@armandomontanez armandomontanez Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest putting it in @rules_cc/cc/settings:apple_constraint if we're going to make this public. Centralizing the configuration flags makes for a better user experience, and is consistent with existing rules_* modules.

Other rulesets have varying naming patterns for centralized settings:

Then we should pursue putting the flag and base definition in platforms_contrib, and we can just swap the label_flag with an alias eventually.

@trybka this will be setting a precedent, so flagging the discussion.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine with me, moved it to the suggestion

)
16 changes: 12 additions & 4 deletions cc/toolchains/args/archiver_flags/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("//cc/toolchains:args.bzl", "cc_args")
load("//cc/toolchains:args_list.bzl", "cc_args_list")
Expand All @@ -13,9 +14,16 @@ bool_flag(
)

config_setting(
name = "use_libtool_on_macos_setting",
constraint_values = ["@platforms//os:macos"],
name = "use_libtool_setting",
flag_values = {":use_libtool_on_macos": "true"},
)

selects.config_setting_group(
name = "use_libtool_on_apple_setting",
match_all = [
"//cc/settings:apple_constraint",
":use_libtool_setting",
],
visibility = ["//visibility:public"],
)

Expand All @@ -40,7 +48,7 @@ cc_args(
name = "create_static_archive",
actions = ["//cc/toolchains/actions:ar_actions"],
args = select({
":use_libtool_on_macos_setting": [
":use_libtool_on_apple_setting": [
"-D",
"-no_warning_for_no_symbols",
"-static",
Expand All @@ -53,7 +61,7 @@ cc_args(
name = "output_execpath",
actions = ["//cc/toolchains/actions:ar_actions"],
args = select({
":use_libtool_on_macos_setting": ["-o"],
":use_libtool_on_apple_setting": ["-o"],
"//conditions:default": [],
}) + ["{output_execpath}"],
format = {"output_execpath": "//cc/toolchains/variables:output_execpath"},
Expand Down
2 changes: 1 addition & 1 deletion cc/toolchains/args/generate_linkmap/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cc_args(
name = "generate_linkmap",
actions = ["//cc/toolchains/actions:link_actions"],
args = select({
"@platforms//os:macos": ["-Wl,-map,{output_execpath}.map"],
"//cc/settings:apple_constraint": ["-Wl,-map,{output_execpath}.map"],
"//conditions:default": ["-Wl,-Map={output_execpath}.map"],
}),
format = {"output_execpath": "//cc/toolchains/variables:output_execpath"},
Expand Down
6 changes: 3 additions & 3 deletions cc/toolchains/args/layering_check/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ cc_args(
name = "module_name_args",
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
args = select({
"@platforms//os:macos": ["-Xclang"],
"//cc/settings:apple_constraint": ["-Xclang"],
"//conditions:default": [],
}) + ["-fmodule-name={module_name}"],
format = {
Expand All @@ -71,7 +71,7 @@ cc_args(
name = "module_map_file_args",
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
args = select({
"@platforms//os:macos": ["-Xclang"],
"//cc/settings:apple_constraint": ["-Xclang"],
"//conditions:default": [],
}) + ["-fmodule-map-file={module_map_file}"],
format = {
Expand All @@ -84,7 +84,7 @@ cc_args(
name = "dependent_module_map_files_args",
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
args = select({
"@platforms//os:macos": ["-Xclang"],
"//cc/settings:apple_constraint": ["-Xclang"],
"//conditions:default": [],
}) + [
"-fmodule-map-file={dependent_module_map_files}",
Expand Down
10 changes: 5 additions & 5 deletions cc/toolchains/args/libraries_to_link/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ cc_nested_args(
cc_nested_args(
name = "single_library_args",
nested = select({
"@platforms//os:macos": [],
"//cc/settings:apple_constraint": [],
"//conditions:default": [":optional_whole_archive_start"],
}) + [
":optional_object_file_group",
Expand All @@ -85,11 +85,11 @@ cc_nested_args(
":optional_static_library",
":optional_dynamic_library",
] + select({
# maOS has a minor nuance where it uses the path to the library instead of `-l:{library_name}`.
"@platforms//os:macos": [":macos_optional_versioned_dynamic_library"],
# Apple platforms have a minor nuance where they use the path to the library instead of `-l:{library_name}`.
"//cc/settings:apple_constraint": [":apple_optional_versioned_dynamic_library"],
"//conditions:default": [":generic_optional_versioned_dynamic_library"],
}) + select({
"@platforms//os:macos": [],
"//cc/settings:apple_constraint": [],
"//conditions:default": [":optional_whole_archive_end"],
}),
)
Expand Down Expand Up @@ -166,7 +166,7 @@ cc_nested_args(
)

cc_nested_args(
name = "macos_optional_versioned_dynamic_library",
name = "apple_optional_versioned_dynamic_library",
args = ["{library_path}"],
format = {
"library_path": "//cc/toolchains/variables:libraries_to_link.path",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

load("//cc/toolchains:nested_args.bzl", "cc_nested_args")

def macos_force_load_library_args(name, variable):
def apple_force_load_library_args(name, variable):
"""A helper for declaring -force_load argument expansion for a library.

This creates an argument expansion that will expand to -Wl,-force_load,<library>
Expand Down Expand Up @@ -65,8 +65,8 @@ def library_link_args(name, library_type, from_variable, iterate_over_variable =
},
)

For macos, this expands to a more complex cc_nested_args structure that
handles the -force_load flag.
For Apple platforms, this expands to a more complex cc_nested_args structure
that handles the -force_load flag.

Args:
name: The name of the rule.
Expand All @@ -77,7 +77,7 @@ def library_link_args(name, library_type, from_variable, iterate_over_variable =
native.alias(
name = name,
actual = select({
"@platforms//os:macos": ":macos_{}".format(name),
"//cc/settings:apple_constraint": ":apple_{}".format(name),
"//conditions:default": ":generic_{}".format(name),
}),
)
Expand All @@ -92,13 +92,13 @@ def library_link_args(name, library_type, from_variable, iterate_over_variable =
},
)
cc_nested_args(
name = "macos_{}".format(name),
name = "apple_{}".format(name),
requires_equal = "//cc/toolchains/variables:libraries_to_link.type",
requires_equal_value = library_type,
iterate_over = from_variable if iterate_over_variable else None,
nested = [":{}_maybe_force_load".format(name)],
)
macos_force_load_library_args(
apple_force_load_library_args(
name = "{}_maybe_force_load".format(name),
variable = from_variable,
)
2 changes: 1 addition & 1 deletion cc/toolchains/args/pic_flags/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cc_args(
name = "force_pic_flags",
actions = ["//cc/toolchains/actions:link_executable_actions"],
args = select({
"@platforms//os:macos": ["-Wl,-pie"],
"//cc/settings:apple_constraint": ["-Wl,-pie"],
"//conditions:default": ["-pie"],
}),
requires_not_none = "//cc/toolchains/variables:force_pic",
Expand Down
4 changes: 2 additions & 2 deletions cc/toolchains/args/runtime_library_search_directories/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ cc_nested_args(
"-rpath",
"-Xlinker",
] + select({
"@platforms//os:macos": ["@loader_path/{search_path}"],
"//cc/settings:apple_constraint": ["@loader_path/{search_path}"],
"//conditions:default": ["$ORIGIN/{search_path}"],
}),
format = {
Expand Down Expand Up @@ -106,7 +106,7 @@ cc_nested_args(
"-rpath",
"-Xlinker",
] + select({
"@platforms//os:macos": ["@loader_path/{search_path}"],
"//cc/settings:apple_constraint": ["@loader_path/{search_path}"],
"//conditions:default": ["$ORIGIN/{search_path}"],
}),
format = {
Expand Down
2 changes: 1 addition & 1 deletion cc/toolchains/args/sanitize_pwd/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cc_args(
"//cc/toolchains/actions:objc_fully_link",
],
env = select({
"@platforms//os:macos": {},
"//cc/settings:apple_constraint": {},
"//conditions:default": {"PWD": "/proc/self/cwd"},
}),
)
6 changes: 3 additions & 3 deletions cc/toolchains/args/soname_flags/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ load("//cc/toolchains:feature.bzl", "cc_feature")
cc_feature(
name = "feature",
args = select({
"@platforms//os:macos": [":macos_set_install_name"],
"//cc/settings:apple_constraint": [":apple_set_install_name"],
"//conditions:default": [],
}),
feature_name = "_soname_flags", # Doesn't override legacy feature, but shouldn't be disabled
visibility = ["//visibility:public"],
)

cc_args(
name = "macos_set_install_name",
name = "apple_set_install_name",
actions = ["//cc/toolchains/actions:link_actions"],
args = ["-Wl,-install_name,@rpath/{runtime_solib_name}"],
format = {"runtime_solib_name": "//cc/toolchains/variables:runtime_solib_name"},
requires_not_none = "//cc/toolchains/variables:runtime_solib_name",
target_compatible_with = ["@platforms//os:macos"],
target_compatible_with = ["//cc/settings:apple_constraint"],
)

cc_args(
Expand Down
2 changes: 1 addition & 1 deletion cc/toolchains/args/strip_flags/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ cc_args(
name = "preserve_dates",
actions = ["//cc/toolchains/actions:strip"],
args = select({
"@platforms//os:macos": [],
"//cc/settings:apple_constraint": [],
"@platforms//os:windows": [],
"//conditions:default": ["-p"],
}),
Expand Down