Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 376b54c

Browse files
committed
rust: add a way to build cxxbridge-cmd
1 parent fcb9428 commit 376b54c

4 files changed

Lines changed: 989 additions & 7 deletions

File tree

WORKSPACE

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,21 @@ crate_universe_dependencies()
249249

250250
load("@rules_rust//crate_universe:defs.bzl", "crates_repository")
251251

252+
# If we don't specify which platforms to build, rust_*_library targets will
253+
# select() across platforms that are not guaranteed to exist in the local Bazel,
254+
# which breaks the build.
255+
#
256+
# This is probably a Bazel bug, because rules_rust
257+
# specifies the correct module dependency and Bazel just ignores it and fetches
258+
# an old version.
259+
#
260+
# TODO(the80srobot): Find the right Bazel subproject and file a bug.
261+
RUST_SUPPORTED_PLATFORM_TRIPLES = [
262+
"i686-apple-darwin",
263+
"x86_64-apple-darwin",
264+
"aarch64-apple-darwin",
265+
]
266+
252267
crates_repository(
253268
name = "crate_index",
254269
cargo_lockfile = "//:Cargo.lock",
@@ -259,15 +274,32 @@ crates_repository(
259274
# the root Cargo file.
260275
"//:Source/santad/Logs/EndpointSecurity/ParquetLogger/Cargo.toml",
261276
],
262-
# Removing this causes rust_*_library targets to select across platforms that
263-
# might not be defined, breaking the build.
264-
supported_platform_triples = [
265-
"i686-apple-darwin",
266-
"x86_64-apple-darwin",
267-
"aarch64-apple-darwin",
268-
],
277+
supported_platform_triples = RUST_SUPPORTED_PLATFORM_TRIPLES,
269278
)
270279

271280
load("@crate_index//:defs.bzl", "crate_repositories")
272281

273282
crate_repositories()
283+
284+
# cxxbridge is a codegen tool for Rust/C++ bindings. To understand why this is
285+
# set up the way it is, read
286+
# http://bazelbuild.github.io/rules_rust/crate_universe.html#binary-dependencies.
287+
http_archive(
288+
name = "cxxbridge-cmd",
289+
build_file = "//external_patches/cxxbridge-cmd:BUILD",
290+
sha256 = "dc5db43c367778010dff55b602f71eccff712b8edf54a3f08687bd1c7cbad6df",
291+
strip_prefix = "cxxbridge-cmd-1.0.110",
292+
type = "tar.gz",
293+
urls = ["https://crates.io/api/v1/crates/cxxbridge-cmd/1.0.110/download"],
294+
)
295+
296+
# See above for notes.
297+
crates_repository(
298+
name = "cxxbridge_cmd_deps",
299+
cargo_lockfile = "//external_patches/cxxbridge-cmd:Cargo.lock",
300+
lockfile = "//external_patches/cxxbridge-cmd:Cargo.Bazel.lock",
301+
manifests = ["@cxxbridge-cmd//:Cargo.toml"],
302+
supported_platform_triples = RUST_SUPPORTED_PLATFORM_TRIPLES,
303+
)
304+
load("@cxxbridge_cmd_deps//:defs.bzl", cxxbridge_cmd_deps = "crate_repositories")
305+
cxxbridge_cmd_deps()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
load("@cxxbridge_cmd_deps//:defs.bzl", "aliases", "all_crate_deps")
2+
load("@rules_rust//rust:defs.bzl", "rust_binary")
3+
4+
licenses(["notice"])
5+
6+
# cxxbridge-cmd is a codegen tool for cxx.
7+
#
8+
# Note that you must build this target as @cxxbridge-cmd//:cxxbridge-cmd, not as
9+
# //external_patches/cxxbridge-cmd:cxxbridge-cmd or any other path.
10+
rust_binary(
11+
name = "cxxbridge-cmd",
12+
srcs = glob(["src/**/*.rs"]),
13+
data = [
14+
"src/gen/include/cxx.h",
15+
],
16+
edition = "2021",
17+
aliases = aliases(),
18+
deps = all_crate_deps(),
19+
)

0 commit comments

Comments
 (0)