Skip to content

Commit 4b638a3

Browse files
committed
[#486] support bazel in macos
* select different releases for different os * build the cbindgen because its release doesn't support macos * setup cxxopts for testing and macos
1 parent 5f6a0dc commit 4b638a3

File tree

6 files changed

+116
-76
lines changed

6 files changed

+116
-76
lines changed

.bazelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
build --enable_platform_specific_config
22
build:linux --cxxopt="-std=c++17"
33
build:windows --cxxopt="/std:c++17"
4+
build:macos --cxxopt="-std=c++17"
45

56
# this has to be specified manually
67
build:mingw --cxxopt="-std=c++17"
@@ -15,6 +16,9 @@ build --action_env=CARGO_BAZEL_REPIN=true
1516
test --test_output=streamed
1617
test --nocache_test_results
1718
test --action_env=RUST_TEST_THREADS=1
19+
test:linux --cxxopt="-std=c++17"
20+
test:windows --cxxopt="/std:c++17"
21+
test:macos --cxxopt="-std=c++17"
1822

1923
#
2024
# feature flags

Cargo.Bazel.lock

Lines changed: 25 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "d7b1759c5d28cbeb3fff8b9da5ca81261aa8c593891b9eff7d3c554d07b4c8dd",
2+
"checksum": "0e06dfd9a08fcb09e35b008c85e91abf975fe7a4846366aa3bc10c530cffc688",
33
"crates": {
44
"addr2line 0.24.2": {
55
"name": "addr2line",
@@ -3938,61 +3938,10 @@
39383938
"crate_features": {
39393939
"common": [
39403940
"default",
3941+
"extra_traits",
39413942
"std"
39423943
],
3943-
"selects": {
3944-
"aarch64-apple-darwin": [
3945-
"extra_traits"
3946-
],
3947-
"aarch64-apple-ios": [
3948-
"extra_traits"
3949-
],
3950-
"aarch64-apple-ios-sim": [
3951-
"extra_traits"
3952-
],
3953-
"aarch64-fuchsia": [
3954-
"extra_traits"
3955-
],
3956-
"aarch64-linux-android": [
3957-
"extra_traits"
3958-
],
3959-
"armv7-linux-androideabi": [
3960-
"extra_traits"
3961-
],
3962-
"i686-apple-darwin": [
3963-
"extra_traits"
3964-
],
3965-
"i686-linux-android": [
3966-
"extra_traits"
3967-
],
3968-
"i686-unknown-freebsd": [
3969-
"extra_traits"
3970-
],
3971-
"powerpc-unknown-linux-gnu": [
3972-
"extra_traits"
3973-
],
3974-
"s390x-unknown-linux-gnu": [
3975-
"extra_traits"
3976-
],
3977-
"wasm32-wasi": [
3978-
"extra_traits"
3979-
],
3980-
"x86_64-apple-darwin": [
3981-
"extra_traits"
3982-
],
3983-
"x86_64-apple-ios": [
3984-
"extra_traits"
3985-
],
3986-
"x86_64-fuchsia": [
3987-
"extra_traits"
3988-
],
3989-
"x86_64-linux-android": [
3990-
"extra_traits"
3991-
],
3992-
"x86_64-unknown-freebsd": [
3993-
"extra_traits"
3994-
]
3995-
}
3944+
"selects": {}
39963945
},
39973946
"deps": {
39983947
"common": [
@@ -4087,13 +4036,32 @@
40874036
],
40884037
"crate_features": {
40894038
"common": [
4090-
"elf",
4091-
"errno",
40924039
"general",
40934040
"ioctl",
40944041
"no_std"
40954042
],
4096-
"selects": {}
4043+
"selects": {
4044+
"aarch64-unknown-linux-gnu": [
4045+
"elf",
4046+
"errno"
4047+
],
4048+
"arm-unknown-linux-gnueabi": [
4049+
"elf",
4050+
"errno"
4051+
],
4052+
"armv7-unknown-linux-gnueabi": [
4053+
"elf",
4054+
"errno"
4055+
],
4056+
"i686-unknown-linux-gnu": [
4057+
"elf",
4058+
"errno"
4059+
],
4060+
"x86_64-unknown-linux-gnu": [
4061+
"elf",
4062+
"errno"
4063+
]
4064+
}
40974065
},
40984066
"edition": "2021",
40994067
"version": "0.4.14"

MODULE.bazel.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WORKSPACE.bazel

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ maybe(
2525
strip_prefix = "googletest-{version}".format(version = GOOGLETEST_VERSION),
2626
)
2727

28-
2928
# Load Rust rules
3029
# Use v0.26 to support bazel v6.2
3130
maybe(
@@ -47,6 +46,19 @@ rust_register_toolchains(
4746

4847

4948
# Load prebuilt bindgen
49+
maybe(
50+
name = "bindgen-macos",
51+
repo_rule = http_archive,
52+
strip_prefix = "bindgen-cli-aarch64-apple-darwin",
53+
urls = ["https://github.com/rust-lang/rust-bindgen/releases/download/v0.69.5/bindgen-cli-aarch64-apple-darwin.tar.xz"],
54+
build_file_content = """
55+
filegroup(
56+
name = "bindgen-cli",
57+
srcs = ["bindgen"],
58+
visibility = ["//visibility:public"],
59+
)
60+
""",
61+
)
5062
maybe(
5163
name = "bindgen",
5264
repo_rule = http_archive,
@@ -61,16 +73,38 @@ filegroup(
6173
)
6274
""",
6375
)
76+
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
6477

65-
# Load prebuilt cbindgen
66-
maybe(
67-
name = "cbindgen",
68-
repo_rule = http_file,
69-
sha256 = "521836d00863cb129283054e5090eb17563614e6328b7a1610e30949a05feaea",
70-
urls = ["https://github.com/mozilla/cbindgen/releases/download/0.26.0/cbindgen"],
71-
executable = True,
78+
rust_repositories()
79+
80+
http_archive(
81+
name = "cbindgen_source",
82+
urls = ["https://github.com/mozilla/cbindgen/archive/refs/tags/0.26.0.tar.gz"],
83+
strip_prefix = "cbindgen-0.26.0",
84+
build_file_content = """
85+
filegroup(
86+
name = "srcs",
87+
srcs = glob(["src/**/*.rs", "build.rs", "Cargo.toml", "Cargo.lock"]),
88+
visibility = ["//visibility:public"],
89+
90+
)
91+
exports_files(["Cargo.toml", "Cargo.lock"], visibility = ["//visibility:public"])
92+
"""
7293
)
7394

95+
load("@rules_rust//rust:defs.bzl", "rust_library")
96+
load("@rules_rust//crate_universe:defs.bzl", "crates_repository")
97+
98+
crates_repository(
99+
name = "cbindgen_deps",
100+
cargo_lockfile = "@cbindgen_source//:Cargo.lock",
101+
manifests = ["@cbindgen_source//:Cargo.toml"],
102+
)
103+
104+
load("@cbindgen_deps//:defs.bzl", cbindgen_deps = "crate_repositories")
105+
106+
cbindgen_deps()
107+
74108
# Load external crates
75109
load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")
76110

iceoryx2-ffi/ffi/BUILD.bazel

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,33 @@ filegroup(
2020
srcs = glob(["**"]),
2121
)
2222

23-
filegroup(
23+
24+
load("@rules_rust//rust:defs.bzl", "rust_binary")
25+
26+
# load("@cbindgen_source//:BUILD.bazel", "srcs")
27+
rust_binary(
2428
name = "cbindgen-cli",
25-
srcs = ["@cbindgen//file"],
29+
srcs = [
30+
"@cbindgen_source//:srcs",
31+
],
32+
data = [
33+
"@cbindgen_source//:Cargo.toml",
34+
"@cbindgen_source//:Cargo.lock",
35+
],
36+
edition = "2018",
37+
deps = [
38+
"@cbindgen_deps//:clap",
39+
"@cbindgen_deps//:indexmap",
40+
"@cbindgen_deps//:log",
41+
"@cbindgen_deps//:serde",
42+
"@cbindgen_deps//:serde_json",
43+
"@cbindgen_deps//:tempfile",
44+
"@cbindgen_deps//:toml",
45+
"@cbindgen_deps//:proc-macro2",
46+
"@cbindgen_deps//:quote",
47+
"@cbindgen_deps//:heck",
48+
"@cbindgen_deps//:syn",
49+
],
2650
)
2751

2852
genrule(

iceoryx2-pal/posix/BUILD.bazel

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,25 @@ cc_library(
3535
visibility = ["//visibility:public"],
3636
)
3737

38-
# Generate the Rust binding file
38+
39+
load("@rules_rust//rust:defs.bzl", "rust_binary")
40+
41+
alias(
42+
name = "bindgen-cli",
43+
actual = select({
44+
"@bazel_tools//src/conditions:darwin": "@bindgen-macos//:bindgen-cli",
45+
"//conditions:default": "@bindgen//:bindgen-cli",
46+
}),
47+
)
48+
3949
genrule(
4050
name = "iceoryx2-pal-posix-bindgen",
4151
srcs = [
4252
"src/c/posix.h",
43-
"@bindgen//:bindgen-cli",
4453
],
4554
outs = ["posix_generated.rs"],
46-
cmd = "$(execpath @bindgen//:bindgen-cli) --use-core --blocklist-type max_align_t $(location src/c/posix.h) --output $(OUTS)",
55+
cmd = "$(execpath :bindgen-cli) --use-core --blocklist-type max_align_t $(location src/c/posix.h) --output $(OUTS)",
56+
tools = [":bindgen-cli"],
4757
)
4858

4959
cargo_build_script(

0 commit comments

Comments
 (0)