Skip to content

Commit 9726a0b

Browse files
committed
feat: Add BPF triple constraint mapping
Add support for tier 3 targets bpfeb-unknown-none and bpfel-unknown-none (see https://github.com/rust-lang/rust/blob/f5e2df7/src/doc/rustc/src/platform-support.md?plain=1#L311-L312).
1 parent 71470d7 commit 9726a0b

6 files changed

Lines changed: 76 additions & 1 deletion

File tree

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module(
1111

1212
bazel_dep(name = "bazel_features", version = "1.32.0")
1313
bazel_dep(name = "bazel_skylib", version = "1.8.2")
14-
bazel_dep(name = "platforms", version = "1.0.0")
14+
bazel_dep(name = "platforms", version = "1.1.0")
1515
bazel_dep(name = "rules_cc", version = "0.2.4")
1616
bazel_dep(name = "rules_license", version = "1.0.0")
1717
bazel_dep(name = "rules_shell", version = "0.6.1")

rust/platform/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package(default_visibility = ["//visibility:public"])
66
declare_config_settings()
77

88
# WASI Preview version constraint settings
9+
#
10+
# TODO(https://github.com/bazelbuild/platforms/pull/123): Replace with upstream.
911
constraint_setting(
1012
name = "wasi_version",
1113
default_constraint_value = ":wasi_preview_1",

rust/platform/triple_mappings.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ SUPPORTED_T2_PLATFORM_TRIPLES = {
8080

8181
_T3_PLATFORM_TRIPLES = {
8282
"aarch64-unknown-nto-qnx710": _support(std = True, host_tools = False),
83+
"bpfeb-unknown-none": _support(std = False, host_tools = False),
84+
"bpfel-unknown-none": _support(std = False, host_tools = False),
8385
"wasm64-unknown-unknown": _support(std = False, host_tools = False),
8486
}
8587

@@ -449,6 +451,16 @@ def triple_to_constraint_set(target_triple):
449451
Returns:
450452
list: A list of constraints (each represented by a list of strings)
451453
"""
454+
if target_triple == "bpfeb-unknown-none":
455+
return [
456+
"@platforms//os:none",
457+
"@platforms//cpu:bpfeb",
458+
]
459+
if target_triple == "bpfel-unknown-none":
460+
return [
461+
"@platforms//os:none",
462+
"@platforms//cpu:bpfel",
463+
]
452464
if target_triple == "wasm32-wasi":
453465
return [
454466
"@platforms//cpu:wasm32",

test/unit/platform_triple/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
load(":apple_platform_test.bzl", "apple_platform_test_suite")
2+
load(":bpf_platform_test.bzl", "bpf_platform_test_suite")
23
load(":platform_triple_test.bzl", "platform_triple_test_suite")
34
load(":wasi_platform_test.bzl", "wasi_platform_test_suite")
45

56
apple_platform_test_suite(
67
name = "apple_platform_test_suite",
78
)
89

10+
bpf_platform_test_suite(
11+
name = "bpf_platform_test_suite",
12+
)
13+
914
platform_triple_test_suite(
1015
name = "platform_triple_test_suite",
1116
)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""Tests for BPF platform constraint mappings"""
2+
3+
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
4+
load("//rust/platform:triple_mappings.bzl", "triple_to_constraint_set")
5+
6+
def _bpf_platform_constraints_test_impl(ctx):
7+
env = unittest.begin(ctx)
8+
9+
bpfeb_constraints = triple_to_constraint_set("bpfeb-unknown-none")
10+
asserts.equals(
11+
env,
12+
[
13+
"@platforms//os:none",
14+
"@platforms//cpu:bpfeb",
15+
],
16+
bpfeb_constraints,
17+
"bpfeb-unknown-none should map to the BPF big-endian CPU and 'none' OS constraints",
18+
)
19+
20+
bpfel_constraints = triple_to_constraint_set("bpfel-unknown-none")
21+
asserts.equals(
22+
env,
23+
[
24+
"@platforms//os:none",
25+
"@platforms//cpu:bpfel",
26+
],
27+
bpfel_constraints,
28+
"bpfel-unknown-none should map to the BPF little-endian CPU and 'none' OS constraints",
29+
)
30+
31+
return unittest.end(env)
32+
33+
bpf_platform_constraints_test = unittest.make(_bpf_platform_constraints_test_impl)
34+
35+
def bpf_platform_test_suite(name, **kwargs):
36+
"""Define a test suite for BPF platform constraint mappings.
37+
38+
Args:
39+
name (str): The name of the test suite.
40+
**kwargs (dict): Additional keyword arguments for the test_suite.
41+
"""
42+
bpf_platform_constraints_test(
43+
name = "bpf_platform_constraints_test",
44+
)
45+
46+
native.test_suite(
47+
name = name,
48+
tests = [
49+
":bpf_platform_constraints_test",
50+
],
51+
**kwargs
52+
)

test/unit/platform_triple/platform_triple_test.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ def _construct_known_triples_test_impl(ctx):
127127
_assert_parts(env, triple("thumbv7em-none-eabihf"), "thumbv7em", None, "none", "eabihf")
128128
_assert_parts(env, triple("thumbv8m.main-none-eabi"), "thumbv8m.main", None, "none", "eabi")
129129

130+
# BPF targets
131+
_assert_parts(env, triple("bpfeb-unknown-none"), "bpfeb", "unknown", "none", None)
132+
_assert_parts(env, triple("bpfel-unknown-none"), "bpfel", "unknown", "none", None)
133+
130134
# Test all WASM32 targets
131135
_assert_parts(env, triple("wasm32-unknown-unknown"), "wasm32", "unknown", "unknown", None)
132136
_assert_parts(env, triple("wasm32-unknown-emscripten"), "wasm32", "unknown", "emscripten", None)

0 commit comments

Comments
 (0)