Skip to content

Commit 0525ff3

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 e2cc813 commit 0525ff3

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed

rust/platform/BUILD.bazel

Lines changed: 19 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",
@@ -21,6 +23,23 @@ constraint_value(
2123
constraint_setting = ":wasi_version",
2224
)
2325

26+
# BPF execution constraints
27+
#
28+
# TODO(https://github.com/bazelbuild/platforms/pull/131): Replace with upstream.
29+
constraint_setting(
30+
name = "bpf_arch",
31+
)
32+
33+
constraint_value(
34+
name = "bpfeb",
35+
constraint_setting = ":bpf_arch",
36+
)
37+
38+
constraint_value(
39+
name = "bpfel",
40+
constraint_setting = ":bpf_arch",
41+
)
42+
2443
package_group(
2544
name = "function_transition_allowlist",
2645
packages = [

rust/platform/triple_mappings.bzl

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

7676
_T3_PLATFORM_TRIPLES = {
7777
"aarch64-unknown-nto-qnx710": _support(std = True, host_tools = False),
78+
"bpfeb-unknown-none": _support(std = False, host_tools = False),
79+
"bpfel-unknown-none": _support(std = False, host_tools = False),
7880
"wasm64-unknown-unknown": _support(std = False, host_tools = False),
7981
}
8082

@@ -416,6 +418,16 @@ def triple_to_constraint_set(target_triple):
416418
Returns:
417419
list: A list of constraints (each represented by a list of strings)
418420
"""
421+
if target_triple == "bpfeb-unknown-none":
422+
return [
423+
"@platforms//os:none",
424+
"@rules_rust//rust/platform:bpfeb",
425+
]
426+
if target_triple == "bpfel-unknown-none":
427+
return [
428+
"@platforms//os:none",
429+
"@rules_rust//rust/platform:bpfel",
430+
]
419431
if target_triple == "wasm32-wasi":
420432
return [
421433
"@platforms//cpu:wasm32",

test/unit/platform_triple/BUILD.bazel

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

5+
bpf_platform_test_suite(
6+
name = "bpf_platform_test_suite",
7+
)
8+
49
platform_triple_test_suite(
510
name = "platform_triple_test_suite",
611
)
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+
"@rules_rust//rust/platform: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+
"@rules_rust//rust/platform: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
@@ -125,6 +125,10 @@ def _construct_known_triples_test_impl(ctx):
125125
_assert_parts(env, triple("thumbv7em-none-eabi"), "thumbv7em", None, "none", "eabi")
126126
_assert_parts(env, triple("thumbv8m.main-none-eabi"), "thumbv8m.main", None, "none", "eabi")
127127

128+
# BPF targets
129+
_assert_parts(env, triple("bpfeb-unknown-none"), "bpfeb", "unknown", "none", None)
130+
_assert_parts(env, triple("bpfel-unknown-none"), "bpfel", "unknown", "none", None)
131+
128132
# Test all WASM32 targets
129133
_assert_parts(env, triple("wasm32-unknown-unknown"), "wasm32", "unknown", "unknown", None)
130134
_assert_parts(env, triple("wasm32-unknown-emscripten"), "wasm32", "unknown", "emscripten", None)

0 commit comments

Comments
 (0)