Skip to content

Commit

Permalink
[#486] support bazel in macos
Browse files Browse the repository at this point in the history
    * select different releases for different os

    * build the cbindgen because its release doesn't support macos

    * setup cxxopts for testing and macos
  • Loading branch information
xieyuschen committed Oct 23, 2024
1 parent 5f6a0dc commit 4b638a3
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 76 deletions.
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
build --enable_platform_specific_config
build:linux --cxxopt="-std=c++17"
build:windows --cxxopt="/std:c++17"
build:macos --cxxopt="-std=c++17"

# this has to be specified manually
build:mingw --cxxopt="-std=c++17"
Expand All @@ -15,6 +16,9 @@ build --action_env=CARGO_BAZEL_REPIN=true
test --test_output=streamed
test --nocache_test_results
test --action_env=RUST_TEST_THREADS=1
test:linux --cxxopt="-std=c++17"
test:windows --cxxopt="/std:c++17"
test:macos --cxxopt="-std=c++17"

#
# feature flags
Expand Down
82 changes: 25 additions & 57 deletions Cargo.Bazel.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "d7b1759c5d28cbeb3fff8b9da5ca81261aa8c593891b9eff7d3c554d07b4c8dd",
"checksum": "0e06dfd9a08fcb09e35b008c85e91abf975fe7a4846366aa3bc10c530cffc688",
"crates": {
"addr2line 0.24.2": {
"name": "addr2line",
Expand Down Expand Up @@ -3938,61 +3938,10 @@
"crate_features": {
"common": [
"default",
"extra_traits",
"std"
],
"selects": {
"aarch64-apple-darwin": [
"extra_traits"
],
"aarch64-apple-ios": [
"extra_traits"
],
"aarch64-apple-ios-sim": [
"extra_traits"
],
"aarch64-fuchsia": [
"extra_traits"
],
"aarch64-linux-android": [
"extra_traits"
],
"armv7-linux-androideabi": [
"extra_traits"
],
"i686-apple-darwin": [
"extra_traits"
],
"i686-linux-android": [
"extra_traits"
],
"i686-unknown-freebsd": [
"extra_traits"
],
"powerpc-unknown-linux-gnu": [
"extra_traits"
],
"s390x-unknown-linux-gnu": [
"extra_traits"
],
"wasm32-wasi": [
"extra_traits"
],
"x86_64-apple-darwin": [
"extra_traits"
],
"x86_64-apple-ios": [
"extra_traits"
],
"x86_64-fuchsia": [
"extra_traits"
],
"x86_64-linux-android": [
"extra_traits"
],
"x86_64-unknown-freebsd": [
"extra_traits"
]
}
"selects": {}
},
"deps": {
"common": [
Expand Down Expand Up @@ -4087,13 +4036,32 @@
],
"crate_features": {
"common": [
"elf",
"errno",
"general",
"ioctl",
"no_std"
],
"selects": {}
"selects": {
"aarch64-unknown-linux-gnu": [
"elf",
"errno"
],
"arm-unknown-linux-gnueabi": [
"elf",
"errno"
],
"armv7-unknown-linux-gnueabi": [
"elf",
"errno"
],
"i686-unknown-linux-gnu": [
"elf",
"errno"
],
"x86_64-unknown-linux-gnu": [
"elf",
"errno"
]
}
},
"edition": "2021",
"version": "0.4.14"
Expand Down
12 changes: 6 additions & 6 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 42 additions & 8 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ maybe(
strip_prefix = "googletest-{version}".format(version = GOOGLETEST_VERSION),
)


# Load Rust rules
# Use v0.26 to support bazel v6.2
maybe(
Expand All @@ -47,6 +46,19 @@ rust_register_toolchains(


# Load prebuilt bindgen
maybe(
name = "bindgen-macos",
repo_rule = http_archive,
strip_prefix = "bindgen-cli-aarch64-apple-darwin",
urls = ["https://github.com/rust-lang/rust-bindgen/releases/download/v0.69.5/bindgen-cli-aarch64-apple-darwin.tar.xz"],
build_file_content = """
filegroup(
name = "bindgen-cli",
srcs = ["bindgen"],
visibility = ["//visibility:public"],
)
""",
)
maybe(
name = "bindgen",
repo_rule = http_archive,
Expand All @@ -61,16 +73,38 @@ filegroup(
)
""",
)
load("@rules_rust//rust:repositories.bzl", "rust_repositories")

# Load prebuilt cbindgen
maybe(
name = "cbindgen",
repo_rule = http_file,
sha256 = "521836d00863cb129283054e5090eb17563614e6328b7a1610e30949a05feaea",
urls = ["https://github.com/mozilla/cbindgen/releases/download/0.26.0/cbindgen"],
executable = True,
rust_repositories()

http_archive(
name = "cbindgen_source",
urls = ["https://github.com/mozilla/cbindgen/archive/refs/tags/0.26.0.tar.gz"],
strip_prefix = "cbindgen-0.26.0",
build_file_content = """
filegroup(
name = "srcs",
srcs = glob(["src/**/*.rs", "build.rs", "Cargo.toml", "Cargo.lock"]),
visibility = ["//visibility:public"],
)
exports_files(["Cargo.toml", "Cargo.lock"], visibility = ["//visibility:public"])
"""
)

load("@rules_rust//rust:defs.bzl", "rust_library")
load("@rules_rust//crate_universe:defs.bzl", "crates_repository")

crates_repository(
name = "cbindgen_deps",
cargo_lockfile = "@cbindgen_source//:Cargo.lock",
manifests = ["@cbindgen_source//:Cargo.toml"],
)

load("@cbindgen_deps//:defs.bzl", cbindgen_deps = "crate_repositories")

cbindgen_deps()

# Load external crates
load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")

Expand Down
28 changes: 26 additions & 2 deletions iceoryx2-ffi/ffi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,33 @@ filegroup(
srcs = glob(["**"]),
)

filegroup(

load("@rules_rust//rust:defs.bzl", "rust_binary")

# load("@cbindgen_source//:BUILD.bazel", "srcs")
rust_binary(
name = "cbindgen-cli",
srcs = ["@cbindgen//file"],
srcs = [
"@cbindgen_source//:srcs",
],
data = [
"@cbindgen_source//:Cargo.toml",
"@cbindgen_source//:Cargo.lock",
],
edition = "2018",
deps = [
"@cbindgen_deps//:clap",
"@cbindgen_deps//:indexmap",
"@cbindgen_deps//:log",
"@cbindgen_deps//:serde",
"@cbindgen_deps//:serde_json",
"@cbindgen_deps//:tempfile",
"@cbindgen_deps//:toml",
"@cbindgen_deps//:proc-macro2",
"@cbindgen_deps//:quote",
"@cbindgen_deps//:heck",
"@cbindgen_deps//:syn",
],
)

genrule(
Expand Down
16 changes: 13 additions & 3 deletions iceoryx2-pal/posix/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,25 @@ cc_library(
visibility = ["//visibility:public"],
)

# Generate the Rust binding file

load("@rules_rust//rust:defs.bzl", "rust_binary")

alias(
name = "bindgen-cli",
actual = select({
"@bazel_tools//src/conditions:darwin": "@bindgen-macos//:bindgen-cli",
"//conditions:default": "@bindgen//:bindgen-cli",
}),
)

genrule(
name = "iceoryx2-pal-posix-bindgen",
srcs = [
"src/c/posix.h",
"@bindgen//:bindgen-cli",
],
outs = ["posix_generated.rs"],
cmd = "$(execpath @bindgen//:bindgen-cli) --use-core --blocklist-type max_align_t $(location src/c/posix.h) --output $(OUTS)",
cmd = "$(execpath :bindgen-cli) --use-core --blocklist-type max_align_t $(location src/c/posix.h) --output $(OUTS)",
tools = [":bindgen-cli"],
)

cargo_build_script(
Expand Down

0 comments on commit 4b638a3

Please sign in to comment.