Skip to content
Draft
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
48 changes: 48 additions & 0 deletions cc/compiler/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,54 @@ load("//cc/toolchains:compiler_flag.bzl", "compiler_flag")

package(default_visibility = ["//visibility:public"])

# Constraint setting and values for platform-based toolchain selection.
# Use these in your platform() definitions to constrain by compiler type.
#
# Example:
# platform(
# name = "windows_clang_cl",
# constraint_values = [
# "@platforms//os:windows",
# "@rules_cc//cc/compiler:clang-cl",
# ],
# )

constraint_setting(
name = "cc_compiler",
# This is the canonical location for compiler constraint values.
# The values in cc/private/toolchain are aliases to these for backward compatibility.
)

constraint_value(
name = "clang_constraint",
constraint_setting = ":cc_compiler",
)

constraint_value(
name = "gcc_constraint",
constraint_setting = ":cc_compiler",
)

constraint_value(
name = "msvc_constraint",
constraint_setting = ":cc_compiler",
)

constraint_value(
name = "clang-cl_constraint",
constraint_setting = ":cc_compiler",
)

constraint_value(
name = "mingw_constraint",
constraint_setting = ":cc_compiler",
)

constraint_value(
name = "msys_constraint",
constraint_setting = ":cc_compiler",
)

licenses(["notice"])

compiler_flag(name = "compiler")
Expand Down
42 changes: 28 additions & 14 deletions cc/private/toolchain/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,51 @@ package(default_visibility = ["//visibility:public"])

licenses(["notice"]) # Apache 2.0

# It is frequently necessary to constrain platforms based on the cc compiler type.
constraint_setting(name = "cc_compiler")
# DEPRECATED: Use //cc/compiler:cc_compiler and //cc/compiler:<compiler>_constraint instead.
# These aliases are kept for backward compatibility.
#
# Prefer using the public API in //cc/compiler:
# @rules_cc//cc/compiler:cc_compiler (constraint_setting)
# @rules_cc//cc/compiler:clang_constraint
# @rules_cc//cc/compiler:gcc_constraint
# @rules_cc//cc/compiler:msvc_constraint
# @rules_cc//cc/compiler:clang-cl_constraint
# @rules_cc//cc/compiler:mingw_constraint
# @rules_cc//cc/compiler:msys_constraint

constraint_value(
alias(
name = "cc_compiler",
actual = "//cc/compiler:cc_compiler",
)

alias(
name = "clang",
constraint_setting = ":cc_compiler",
actual = "//cc/compiler:clang_constraint",
)

constraint_value(
alias(
name = "gcc",
constraint_setting = ":cc_compiler",
actual = "//cc/compiler:gcc_constraint",
)

constraint_value(
alias(
name = "msvc",
constraint_setting = ":cc_compiler",
actual = "//cc/compiler:msvc_constraint",
)

constraint_value(
alias(
name = "clang-cl",
constraint_setting = ":cc_compiler",
actual = "//cc/compiler:clang-cl_constraint",
)

constraint_value(
alias(
name = "mingw",
constraint_setting = ":cc_compiler",
actual = "//cc/compiler:mingw_constraint",
)

constraint_value(
alias(
name = "msys",
constraint_setting = ":cc_compiler",
actual = "//cc/compiler:msys_constraint",
)

cc_library(
Expand Down
4 changes: 2 additions & 2 deletions cc/private/toolchain/BUILD.windows.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ toolchain(
exec_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
"@rules_cc//cc/private/toolchain:clang-cl",
"@rules_cc//cc/compiler:clang-cl_constraint",
],
target_compatible_with = [
"@platforms//cpu:x86_64",
Expand Down Expand Up @@ -732,7 +732,7 @@ toolchain(
name = "cc-toolchain-arm64_windows-clang-cl",
exec_compatible_with = [
"@platforms//os:windows",
"@rules_cc//cc/private/toolchain:clang-cl",
"@rules_cc//cc/compiler:clang-cl_constraint",
],
target_compatible_with = [
"@platforms//cpu:arm64",
Expand Down