Skip to content

Commit 83c2771

Browse files
authored
Add libudev-sys well-known annotation (#140)
1 parent 84abd06 commit 83c2771

15 files changed

Lines changed: 3181 additions & 2541 deletions

File tree

.bazelrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ common --disk_cache=~/bazel_cache
1111

1212
common --@llvm//config:experimental_stub_libgcc_s
1313
common --enable_platform_specific_config
14-
common:linux --host_platform=//:local_gnu_platform
1514

1615
common --remote_cache=grpcs://remote.buildbuddy.io
1716
common --experimental_remote_downloader=grpcs://remote.buildbuddy.io
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
bazel_dep(name = "systemd", version = "260.1")
2+
3+
crate = use_extension("@rules_rs//rs:extensions.bzl", "crate")
4+
crate.annotation(
5+
crate = "libudev-sys",
6+
gen_build_script = "off",
7+
deps = ["@systemd//:libudev"],
8+
)
9+
10+
inject_repo(crate, "systemd")

README.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,18 @@ use_repo(crate, "crates")
6666

6767
### `.bazelrc`
6868

69-
Set an explicit host platform for operating systems with ABI choices. Linux and Windows host platforms need an ABI constraint so Rust toolchain resolution can choose the matching exec toolchain.
69+
Linux hosts work with Bazel's default host platform. If you also build on Windows,
70+
set an explicit host platform there so Rust toolchain resolution can choose the
71+
right ABI.
7072

7173
```bazelrc
7274
common --enable_platform_specific_config
73-
common:linux --host_platform=//platforms:local_gnu
7475
common:windows --host_platform=//platforms:local_windows_msvc
7576
```
7677

7778
### `platforms/BUILD.bazel`
7879

7980
```bzl
80-
platform(
81-
name = "local_gnu",
82-
parents = ["@platforms//host"],
83-
constraint_values = [
84-
"@llvm//constraints/libc:gnu.2.28",
85-
],
86-
)
87-
8881
platform(
8982
name = "local_windows_msvc",
9083
parents = ["@platforms//host"],

rs/experimental/miri/private/declare_toolchains.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
load("@rules_rust//rust/platform:triple.bzl", _parse_triple = "triple")
22
load("//rs/experimental/miri/private:sysroot.bzl", "miri_sysroot")
33
load("//rs/experimental/miri/private:toolchain.bzl", "miri_sysroot_toolchain", "miri_toolchain")
4-
load("//rs/platforms:triples.bzl", "ALL_TARGET_TRIPLES", "SUPPORTED_EXEC_TRIPLES", "triple_to_constraint_set")
4+
load("//rs/platforms:triples.bzl", "ALL_TARGET_TRIPLES", "SUPPORTED_EXEC_TRIPLES", "triple_to_rust_constraint_set")
55
load("//rs/toolchains:toolchain_utils.bzl", "sanitize_triple", "sanitize_version")
66

77
def declare_miri_toolchains(
@@ -61,7 +61,7 @@ def declare_miri_toolchains(
6161

6262
for target_triple in ALL_TARGET_TRIPLES:
6363
target_key = sanitize_triple(target_triple)
64-
target_compatible_with = triple_to_constraint_set(target_triple)
64+
target_compatible_with = triple_to_rust_constraint_set(target_triple)
6565

6666
native.toolchain(
6767
name = "%s_to_%s_%s_miri_sysroot" % (triple_suffix, target_key, version_key),
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Config settings for Rust target triples."""
22

3-
load("//rs/platforms:triples.bzl", "ALL_TARGET_TRIPLES", "triple_to_constraint_set")
3+
load("//rs/platforms:triples.bzl", "ALL_TARGET_TRIPLES", "triple_to_rust_constraint_set")
44

55
def declare_config_settings(targets = ALL_TARGET_TRIPLES):
66
for target_triple in targets:
77
native.config_setting(
88
name = target_triple,
9-
constraint_values = triple_to_constraint_set(target_triple),
9+
constraint_values = triple_to_rust_constraint_set(target_triple),
1010
visibility = ["//visibility:public"],
1111
)

rs/platforms/constraints/BUILD.bazel

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
package(default_visibility = ["//visibility:public"])
22

3+
constraint_setting(
4+
name = "linux_libc",
5+
# Keep plain Linux platforms on the normal GNU path unless they explicitly
6+
# opt into musl. This lets Rust toolchains match either a versioned LLVM
7+
# glibc platform or the generic LLVM glibc platform without depending on
8+
# LLVM's concrete libc version constraint.
9+
default_constraint_value = "glibc",
10+
)
11+
12+
constraint_value(
13+
name = "glibc",
14+
constraint_setting = "linux_libc",
15+
)
16+
17+
constraint_value(
18+
name = "musl",
19+
constraint_setting = "linux_libc",
20+
)
21+
322
alias(
423
name = "windows_abi",
524
actual = "@llvm//constraints/windows/abi:abi",

rs/platforms/triples.bzl

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ load(
44
_triple_to_constraint_set = "triple_to_constraint_set",
55
)
66

7-
def triple_to_constraint_set(target_triple):
7+
def triple_to_rust_constraint_set(target_triple):
88
constraints = _triple_to_constraint_set(target_triple)
99
t = triple(target_triple)
1010

1111
if t.system in ("linux", "nixos"):
1212
if t.abi == "musl" or "musl" in target_triple:
13-
# Rustc passes `-no-pie` on musl so make sure we align.
14-
constraints.append("@llvm//constraints/libc:musl")
15-
constraints.append("@llvm//constraints/pie:off")
13+
constraints.append("@rules_rs//rs/platforms/constraints:musl")
1614
else:
17-
constraints.append("@llvm//constraints/libc:gnu.2.28")
15+
constraints.append("@rules_rs//rs/platforms/constraints:glibc")
1816
elif t.system == "windows":
1917
constraints.append("@llvm//constraints/windows/abi:" + t.abi)
2018

@@ -26,6 +24,23 @@ def triple_to_constraint_set(target_triple):
2624

2725
return constraints
2826

27+
def triple_to_constraint_set(target_triple):
28+
constraints = triple_to_rust_constraint_set(target_triple)
29+
t = triple(target_triple)
30+
31+
if t.system in ("linux", "nixos"):
32+
if t.abi == "musl" or "musl" in target_triple:
33+
# Rustc passes `-no-pie` on musl so make sure we align.
34+
constraints.append("@llvm//constraints/libc:musl")
35+
constraints.append("@llvm//constraints/pie:off")
36+
else:
37+
# Leave the concrete glibc version to the consuming workspace. The
38+
# generated rules_rs platforms should still select LLVM's GNU
39+
# toolchains when used directly.
40+
constraints.append("@llvm//constraints/libc:unconstrained")
41+
42+
return constraints
43+
2944
SUPPORTED_EXEC_TRIPLES = [
3045
"x86_64-unknown-linux-gnu",
3146
"aarch64-unknown-linux-gnu",

rs/toolchains/declare_rustc_toolchains.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@rules_rust//rust:toolchain.bzl", "rust_toolchain")
22
load("@rules_rust//rust/platform:triple.bzl", _parse_triple = "triple")
3-
load("//rs/platforms:triples.bzl", "ALL_TARGET_TRIPLES", "SUPPORTED_EXEC_TRIPLES", "SUPPORTED_TIER_3_TRIPLES", "triple_to_constraint_set")
3+
load("//rs/platforms:triples.bzl", "ALL_TARGET_TRIPLES", "SUPPORTED_EXEC_TRIPLES", "SUPPORTED_TIER_3_TRIPLES", "triple_to_rust_constraint_set")
44
load("//rs/toolchains:toolchain_utils.bzl", "sanitize_triple", "sanitize_version")
55

66
def _channel(version):
@@ -38,7 +38,7 @@ def declare_rustc_toolchains(
3838
config_setting = "source_stdlib_building_" + target_key
3939
native.config_setting(
4040
name = config_setting,
41-
constraint_values = triple_to_constraint_set(target_triple),
41+
constraint_values = triple_to_rust_constraint_set(target_triple),
4242
flag_values = {
4343
"@rules_rs//rs/private:source_stdlib_building": "true",
4444
},
@@ -179,7 +179,7 @@ def declare_rustc_toolchains(
179179
"@platforms//os:" + exec_triple.system,
180180
"@platforms//cpu:" + exec_triple.arch,
181181
],
182-
target_compatible_with = triple_to_constraint_set(target_triple),
182+
target_compatible_with = triple_to_rust_constraint_set(target_triple),
183183
target_settings = [
184184
"@rules_rust//rust/private:bootstrapped",
185185
"@rules_rust//rust/toolchain/channel:" + channel,
@@ -195,7 +195,7 @@ def declare_rustc_toolchains(
195195
"@platforms//os:" + exec_triple.system,
196196
"@platforms//cpu:" + exec_triple.arch,
197197
],
198-
target_compatible_with = triple_to_constraint_set(target_triple),
198+
target_compatible_with = triple_to_rust_constraint_set(target_triple),
199199
target_settings = [
200200
"@rules_rust//rust/private:bootstrapping",
201201
"@rules_rust//rust/toolchain/channel:" + channel,

test/BUILD.bazel

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,23 +357,46 @@ ALL_PLATFORMS = [
357357
"x86_64-pc-windows-gnullvm",
358358
]
359359

360+
LINUX_GNU_PLATFORMS = {
361+
"aarch64-unknown-linux-gnu": ":aarch64-unknown-linux-gnu",
362+
"x86_64-unknown-linux-gnu": ":x86_64-unknown-linux-gnu",
363+
}
364+
360365
[
361366
platform_transition_filegroup(
362367
name = "all_builds_" + platform,
363368
srcs = ["all_builds"],
364-
target_platform = "@rules_rs//rs/platforms:" + platform,
369+
target_platform = LINUX_GNU_PLATFORMS.get(platform, "@rules_rs//rs/platforms:" + platform),
365370
)
366371
for platform in ALL_PLATFORMS
367372
]
368373

374+
platform(
375+
name = "aarch64-unknown-linux-gnu",
376+
constraint_values = [
377+
"@platforms//cpu:aarch64",
378+
"@platforms//os:linux",
379+
"@llvm//constraints/libc:gnu.2.35",
380+
],
381+
)
382+
383+
platform(
384+
name = "x86_64-unknown-linux-gnu",
385+
constraint_values = [
386+
"@platforms//cpu:x86_64",
387+
"@platforms//os:linux",
388+
"@llvm//constraints/libc:gnu.2.35",
389+
],
390+
)
391+
369392
platform(
370393
name = "rbe",
371394
constraint_values = [
372395
"@platforms//cpu:x86_64",
373396
"@platforms//os:linux",
374397
# Note: We need this so that Rust cfg=exec builds (build script, tools, proc_macros)
375398
# can properly target the remote.
376-
"@llvm//constraints/libc:gnu.2.28",
399+
"@llvm//constraints/libc:gnu.2.35",
377400
],
378401
exec_properties = {
379402
"container-image": "docker://ubuntu:22.04",

test/MODULE.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ single_version_override(
8888
patches = ["//:libffi-aarch64-trampoline.patch"],
8989
)
9090

91+
single_version_override(
92+
module_name = "systemd",
93+
patch_strip = 1,
94+
patches = ["//:systemd-codegen.patch"],
95+
)
96+
9197
# Fix swift toolchains...
9298
bazel_dep(name = "rules_swift", version = "3.5.0")
9399
single_version_override(
@@ -281,6 +287,7 @@ include("//:3rd_party/bzip2-sys/include.MODULE.bazel")
281287
include("//:3rd_party/glib-sys/include.MODULE.bazel")
282288
include("//:3rd_party/libssh2-sys/include.MODULE.bazel")
283289
include("//:3rd_party/lzma-sys/include.MODULE.bazel")
290+
include("//:3rd_party/libudev-sys/include.MODULE.bazel")
284291
include("//:3rd_party/apriltag-sys/include.MODULE.bazel")
285292
include("//:3rd_party/zstd-sys/include.MODULE.bazel")
286293

0 commit comments

Comments
 (0)