Skip to content

Commit fdb9574

Browse files
committed
Add option for base platform tc definition
1 parent b3e4f9f commit fdb9574

5 files changed

Lines changed: 31 additions & 11 deletions

File tree

examples/.bazelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ build:shared --host_platform=@score_bazel_platforms//:x86_64-linux
2424
# Config dedicated to host platform CPU:x86_64 and OS:Linux
2525
# -------------------------------------------------------------------------------
2626
build:x86_64-linux --config=shared
27-
build:x86_64-linux --platforms=@score_bazel_platforms//:x86_64-linux-gcc_12.2.0-posix
2827

2928
# -------------------------------------------------------------------------------
3029
# Different toolchain configuration for x86_64-linux
3130
# -------------------------------------------------------------------------------
3231
build:host_config_1 --config=x86_64-linux
33-
build:host_config_1 --extra_toolchains=@score_gcc_toolchain//:x86_64-linux-gcc_12.2.0-posix
32+
build:host_config_1 --extra_toolchains=@score_gcc_toolchain//:x86_64-linux
3433
build:host_config_1 --features=use_pthread
3534

3635
# -------------------------------------------------------------------------------
3736
# Different toolchain configuration for x86_64-linux
3837
# -------------------------------------------------------------------------------
3938
build:host_config_2 --config=x86_64-linux
39+
build:host_config_2 --platforms=@score_bazel_platforms//:x86_64-linux-gcc_12.2.0-posix
4040
build:host_config_2 --extra_toolchains=@my_toolchain//:x86_64-linux-gcc_12.2.0-posix
4141

4242
# -------------------------------------------------------------------------------

examples/MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ gcc.toolchain(
7070
target_os = "linux",
7171
version = "12.2.0",
7272
use_default_package = True,
73+
use_base_constraints_only = True,
7374
)
7475

7576
# *******************************************************************************

extensions/gcc.bzl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,16 @@ _attrs_tc = {
6262
),
6363
"use_system_toolchain": attr.bool(
6464
default = False,
65-
doc = "TBD",
65+
doc = "Flag for toolchain creation to use host installed binaries. Not yet supported!",
66+
),
67+
"use_base_constraints_only": attr.bool(
68+
default = False,
69+
doc = "Experimental. Attribute for flag toolchain creation to use only base platform constraints. Limits toolchain registration to 1 per base platform definition."
6670
),
6771
"runtime_ecosystem": attr.string(
6872
default = "posix",
6973
mandatory = False,
70-
doc = "TBD",
74+
doc = "Attribute for identifing the system-level runtime environment a binary or target is built to run in.",
7175
),
7276
"target_cpu": attr.string(
7377
mandatory = True,
@@ -162,6 +166,7 @@ def _get_toolchains(tags):
162166
"sdp_to_link": tag.sdp_to_link,
163167
"use_default_package": tag.use_default_package,
164168
"use_system_toolchain": tag.use_system_toolchain,
169+
"use_base_constraints_only": tag.use_base_constraints_only,
165170
"tc_extra_compile_flags": tag.extra_compile_flags,
166171
"tc_extra_link_flags": tag.extra_link_flags,
167172
"sdp_version": tag.sdp_version,
@@ -263,6 +268,7 @@ def _impl(mctx):
263268
gcc_version = toolchain_info["tc_version"],
264269
cc_toolchain_config = toolchain_info["cc_toolchain_config"],
265270
cc_toolchain_flags = toolchain_info["cc_toolchain_flags"],
271+
use_base_constraints_only = toolchain_info["use_base_constraints_only"]
266272
)
267273

268274
gcc = module_extension(

rules/gcc.bzl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ def _impl(rctx):
101101
else:
102102
fail("Unsupported OS detected!")
103103

104+
tc_identifier_short_1 = ""
105+
tc_identifier_long_1 = "[]"
106+
tc_identifier_short_2 = ""
107+
tc_identifier_long_2 = "[]"
108+
if not rctx.attr.use_base_constraints_only:
109+
tc_identifier_short_1 = "-{}".format(tc_identifier)
110+
tc_identifier_long_1 = "[\"@score_bazel_platforms//version:{}\"]".format(tc_identifier)
111+
tc_identifier_short_2 = "-{}".format(rctx.attr.tc_runtime_ecosystem)
112+
tc_identifier_long_2 = "[\"@score_bazel_platforms//runtime_es:{}\"]".format(rctx.attr.tc_runtime_ecosystem)
113+
104114
rctx.template(
105115
"BUILD",
106116
rctx.attr._cc_toolchain_build,
@@ -110,15 +120,16 @@ def _impl(rctx):
110120
"%{tc_cpu}": rctx.attr.tc_cpu,
111121
"%{tc_os}": rctx.attr.tc_os,
112122
"%{tc_version}": rctx.attr.gcc_version,
113-
"%{tc_identifier}": tc_identifier,
114-
"%{tc_runtime_es}": rctx.attr.tc_runtime_ecosystem,
123+
"%{tc_identifier_short_1}": tc_identifier_short_1,
124+
"%{tc_identifier_short_2}": tc_identifier_short_2,
125+
"%{tc_identifier_long_1}": tc_identifier_long_1,
126+
"%{tc_identifier_long_2}": tc_identifier_long_2,
115127
},
116128
)
117129

118130
extra_compile_flags = get_flag_groups(rctx.attr.extra_compile_flags)
119131
extra_link_flags = get_flag_groups(rctx.attr.extra_link_flags)
120132

121-
122133
template_dict = {
123134
"%{tc_version}": rctx.attr.gcc_version,
124135
"%{tc_identifier}": "gcc",
@@ -188,6 +199,7 @@ gcc_toolchain = repository_rule(
188199
"cc_toolchain_flags": attr.label(
189200
doc = "Path to the Bazel BUILD file template for the toolchain.",
190201
),
202+
"use_base_constraints_only": attr.bool(doc="Boolean flag to state only base constraints should be used for toolchain compatibility definition"),
191203
"_cc_toolchain_build": attr.label(
192204
default = "@score_bazel_cpp_toolchains//templates:BUILD.template",
193205
doc = "Path to the Bazel BUILD file template for the toolchain.",

templates/BUILD.template

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,19 @@ cc_toolchain(
3737
toolchain_config = ":cc_toolchain_config",
3838
)
3939

40+
# "@score_bazel_platforms//version:%{tc_runtime_es}",
41+
# "@score_bazel_platforms//version:%{tc_identifier}",
42+
4043
toolchain(
41-
name = "%{tc_cpu}-%{tc_os}-%{tc_identifier}-%{tc_runtime_es}",
44+
name = "%{tc_cpu}-%{tc_os}%{tc_identifier_short_1}%{tc_identifier_short_2}",
4245
exec_compatible_with = [
4346
"@platforms//cpu:x86_64",
4447
"@platforms//os:linux",
4548
],
4649
target_compatible_with = [
4750
"@platforms//cpu:%{tc_cpu}",
4851
"@platforms//os:%{tc_os}",
49-
"@score_bazel_platforms//runtime_es:%{tc_runtime_es}",
50-
"@score_bazel_platforms//version:%{tc_identifier}",
51-
],
52+
] + %{tc_identifier_long_1} + %{tc_identifier_long_2},
5253
toolchain = ":cc_toolchain",
5354
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
5455
visibility = [

0 commit comments

Comments
 (0)