Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 14 additions & 75 deletions book/src/build/bazel.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,84 +35,23 @@ as an illustration of one possible working pattern.
```python
# tools/bazel/rust_cxx_bridge.bzl

load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
load("@rules_cc//cc:defs.bzl", "cc_library")

def rust_cxx_bridge(name, src, deps = []):
native.alias(
name = "%s/header" % name,
actual = src + ".h",
)

native.alias(
name = "%s/source" % name,
actual = src + ".cc",
)

run_binary(
name = "%s/generated" % name,
srcs = [src],
outs = [
src + ".h",
src + ".cc",
],
args = [
"$(location %s)" % src,
"-o",
"$(location %s.h)" % src,
"-o",
"$(location %s.cc)" % src,
],
tool = "//:codegen",
)

cc_library(
name = name,
srcs = [src + ".cc"],
deps = deps + [":%s/include" % name],
)

cc_library(
name = "%s/include" % name,
hdrs = [src + ".h"],
)
{{#include ../../../tools/bazel/rust_cxx_bridge.bzl}}
```

```python
# demo/BUILD.bazel

load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_rust//rust:defs.bzl", "rust_binary")
load("//tools/bazel:rust_cxx_bridge.bzl", "rust_cxx_bridge")

rust_binary(
name = "demo",
srcs = glob(["src/**/*.rs"]),
deps = [
":blobstore-sys",
":bridge",
"//:cxx",
],
)

rust_cxx_bridge(
name = "bridge",
src = "src/main.rs",
deps = [":blobstore-include"],
)

cc_library(
name = "blobstore-sys",
srcs = ["src/blobstore.cc"],
deps = [
":blobstore-include",
":bridge/include",
],
)

cc_library(
name = "blobstore-include",
hdrs = ["include/blobstore.h"],
deps = ["//:core"],
)
{{#include ../../../demo/BUILD.bazel}}
```

```python
# BUILD.bazel

{{#include ../../../BUILD.bazel}}
```

```python
# MODULE.bazel

{{#include ../../../MODULE.bazel}}
```