Skip to content

Commit 24aa298

Browse files
committed
Add support for x86_64-unknown-none targets
By default, no sysroot is used. This is useful for bare-metal targets, firmwares, etc. We are actively using this patch in https://github.com/project-oak/oak
1 parent df67928 commit 24aa298

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

platforms/BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ platform(
2222
],
2323
)
2424

25+
platform(
26+
name = "none-x86_64",
27+
constraint_values = [
28+
"@platforms//os:none",
29+
"@platforms//cpu:x86_64",
30+
],
31+
)
32+
2533
platform(
2634
name = "linux-aarch64",
2735
constraint_values = [

toolchain/cc_toolchain_config.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ def cc_toolchain_config(
9797
"clang",
9898
"glibc_unknown",
9999
),
100+
"none-x86_64": (
101+
"clang-x86_64-none",
102+
"k8",
103+
"unknown",
104+
"clang",
105+
"unknown",
106+
"unknown",
107+
),
100108
"wasm32": (
101109
"clang-wasm32",
102110
"wasm32",

toolchain/internal/common.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@ SUPPORTED_TARGETS = [
2020
("darwin", "aarch64"),
2121
("none", "wasm32"),
2222
("none", "wasm64"),
23+
("none", "x86_64"),
2324
("wasip1", "wasm32"),
2425
("wasip1", "wasm64"),
2526
]
2627

28+
# These are targets that can build without a sysroot.
29+
SUPPORTED_NO_SYSROOT_TARGETS = [
30+
("none", "x86_64"),
31+
]
32+
2733
# Map of tool name to its symlinked name in the tools directory.
2834
# See tool_paths in toolchain/cc_toolchain_config.bzl.
2935
_toolchain_tools = {
@@ -126,7 +132,7 @@ def os(rctx):
126132

127133
name = rctx.attr.exec_os
128134
if name:
129-
if name in ("linux", "darwin"):
135+
if name in ("linux", "darwin", "none"):
130136
return name
131137
else:
132138
fail("Unsupported value for exec_os: %s" % name)

toolchain/internal/configure.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ load(
3333
_os_bzl = "os_bzl",
3434
_os_from_rctx = "os_from_rctx",
3535
_pkg_path_from_label = "pkg_path_from_label",
36+
_supported_no_sysroot_targets = "SUPPORTED_NO_SYSROOT_TARGETS",
3637
_supported_targets = "SUPPORTED_TARGETS",
3738
_toolchain_tools = "toolchain_tools",
3839
)
@@ -300,9 +301,11 @@ def _cc_toolchain_str(
300301
if exec_os == target_os and exec_arch == target_arch:
301302
# For darwin -> darwin, we can use the macOS SDK path.
302303
sysroot_path = _default_sysroot_path(rctx, exec_os)
304+
elif target_pair in _supported_no_sysroot_targets:
305+
sysroot_path = ""
303306
else:
304307
# We are trying to cross-compile without a sysroot, let's bail.
305-
# TODO: Are there situations where we can continue?
308+
# TODO: Are there other situations where we can continue?
306309
return ""
307310

308311
extra_files_str = "\":internal-use-files\""
@@ -323,6 +326,7 @@ def _cc_toolchain_str(
323326
"linux-aarch64": "aarch64-unknown-linux-gnu",
324327
"linux-armv7": "armv7-unknown-linux-gnueabihf",
325328
"linux-x86_64": "x86_64-unknown-linux-gnu",
329+
"none-x86_64": "x86_64-unknown-none",
326330
"wasm32": "wasm32-unknown-unknown",
327331
"wasm64": "wasm64-unknown-unknown",
328332
"wasip1-wasm32": "wasm32-wasip1",

0 commit comments

Comments
 (0)