Skip to content

Commit d3428af

Browse files
amit-kumarhjwnrt
authored andcommitted
[bazel] Refactor platform selection
Change host vs device platform selection to use a constraint setting rather than a string comparison, as these don't work across bazel modules. Signed-off-by: Amit Kumar-Hermosillo <[email protected]> (cherry picked from commit 00a2d37)
1 parent d6c1f63 commit d3428af

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

rules/BUILD

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
# SPDX-License-Identifier: Apache-2.0
44

5-
load("//rules/opentitan:defs.bzl", "OPENTITAN_PLATFORM")
6-
load("//rules:stamp.bzl", "stamp_flag")
75
load("//rules:autogen.bzl", "autogen_stamp_include")
6+
load("//rules:stamp.bzl", "stamp_flag")
7+
load("//rules/opentitan:defs.bzl", "OPENTITAN_PLATFORM")
88

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

11-
config_setting(
12-
name = "opentitan_platform",
13-
values = {"platforms": OPENTITAN_PLATFORM},
14-
)
15-
1611
# See stamp.bzl for explanation.
1712
stamp_flag(name = "stamp_flag")
1813

rules/cross_platform.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _merge_and_split_inputs(inputs):
2222

2323
def dual_cc_library(
2424
name,
25-
on_device_config_setting = "//rules:opentitan_platform",
25+
on_device_config_setting = "//toolchain:on_device_config",
2626
srcs = [],
2727
hdrs = [],
2828
copts = [],

toolchain/BUILD

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ load("@rules_cc//cc/toolchains:actions.bzl", "cc_action_type")
66
load("@rules_cc//cc/toolchains:args.bzl", "cc_args")
77
load("@rules_cc//cc/toolchains:args_list.bzl", "cc_args_list")
88
load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature")
9-
load("@rules_cc//cc/toolchains:feature_set.bzl", "cc_feature_set")
109
load("@rules_cc//cc/toolchains:feature_constraint.bzl", "cc_feature_constraint")
10+
load("@rules_cc//cc/toolchains:feature_set.bzl", "cc_feature_set")
1111
load("@rules_cc//cc/toolchains:toolchain.bzl", "cc_toolchain")
1212
load("@rules_cc//cc/toolchains:tool_map.bzl", "cc_tool_map")
1313
load("//rules:actions.bzl", "OT_ACTION_LLVM_PROFDATA", "OT_ACTION_OBJDUMP")
@@ -19,9 +19,27 @@ platform(
1919
constraint_values = [
2020
"@platforms//cpu:riscv32",
2121
"@platforms//os:none",
22+
":device",
2223
],
2324
)
2425

26+
constraint_setting(name = "target")
27+
28+
constraint_value(
29+
name = "host",
30+
constraint_setting = "target",
31+
)
32+
33+
constraint_value(
34+
name = "device",
35+
constraint_setting = "target",
36+
)
37+
38+
config_setting(
39+
name = "on_device_config",
40+
constraint_values = [":device"],
41+
)
42+
2543
toolchain(
2644
name = "cc_toolchain_opentitan",
2745
exec_compatible_with = ["@platforms//cpu:x86_64"],

0 commit comments

Comments
 (0)