Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
98c3e5d
Add bidirectional C++ and Rust interop with rules_rust cdylib support
justhecuke Oct 31, 2026
403e079
fix(rules_rust): switch to -Bstatic for trailing static libraries on …
justhecuke Oct 31, 2026
978046d
fix(cc): link C++ libraries statically and configure runtime library …
justhecuke Oct 31, 2026
fa37036
fix(rules_rust): add DT_SONAME support for ELF dynamic libraries in p…
justhecuke Oct 31, 2026
0535389
ci: add macos-latest runner to CI matrix and configure macos rpath
justhecuke Nov 1, 2026
f6bc009
build(macos): set toolchain_linker_preference=rust on macOS to suppor…
justhecuke Nov 1, 2026
b137218
fix(toolchain): bypass Zig CC on macOS to use native Apple Clang tool…
justhecuke Nov 1, 2026
e27bdea
build(macos): use default cc linker preference with native Apple Clang
justhecuke Nov 1, 2026
5d36a5e
fix(rules_rust): support direct linker drivers on macOS for cdylib in…
justhecuke Nov 1, 2026
2fa4dcd
fix(go): resolve nested bazel invocation and working directory in sta…
justhecuke Nov 1, 2026
87175a6
fix(tools): robustly locate staticcheck binary in python runfiles acr…
justhecuke Nov 1, 2026
95cfc72
fix(tools): locate staticcheck binary before chdir to workspace
justhecuke Nov 1, 2026
33cfd2a
fix(go): provision hermetic go in staticcheck runfiles to prevent baz…
justhecuke Nov 1, 2026
1ebd6b2
fix(toolchain): support dynamic linking in hermetic_cc_toolchain and …
justhecuke Nov 1, 2026
4e9dae3
fix(toolchain): align solib symlink with soname for cdylib and restor…
justhecuke Nov 1, 2026
bded37c
fix(toolchain): pass -Wl,-no-as-needed on Linux in hermetic_cc_toolchain
justhecuke Nov 1, 2026
e219593
fix(toolchain): use double dash --no-as-needed for zig cc
justhecuke Nov 1, 2026
f5f42c7
fix(toolchain): emit -Wl,--no-as-needed before libraries_to_link on L…
reinwzhang Nov 27, 2026
f065c83
build(linux): set --dynamic_mode=off to prevent duplicate static libc…
reinwzhang Nov 27, 2026
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
8 changes: 8 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ build:windows --nolegacy_external_runfiles
# hermetic x86_64-pc-windows-gnu toolchain instead of the C++ toolchain wrapper.
build:windows --@rules_rust//rust/settings:toolchain_linker_preference=rust

# Linux-specific settings
# Zig CC statically links libc++/libc++abi/libunwind into every shared library,
# duplicating C++ runtime state and breaking exception propagation across
# dynamically linked cc_library (.so) boundaries. Link cc_library targets
# statically while still linking explicit shared libraries (e.g. Rust cdylibs)
# dynamically.
build:linux --dynamic_mode=off

# Linting settings
# To run linting: bazel build --config=lint //...
build:lint --aspects=//tools:lint.bzl%ruff,@rules_rust//rust:defs.bzl%rust_clippy_aspect,@rules_rust//rust:defs.bzl%rustfmt_aspect
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ on:

jobs:
ci:
name: Continuous Testing
runs-on: ubuntu-latest
name: Continuous Testing (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]

steps:
- name: Checkout repository
Expand Down
14 changes: 13 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ bazel_dep(name = "rules_python_gazelle_plugin", version = "0.37.0")
bazel_dep(name = "hermetic_cc_toolchain", version = "4.1.0")
bazel_dep(name = "platforms", version = "1.1.0")
bazel_dep(name = "rules_rust", version = "0.75.0")
bazel_dep(name = "rules_cc", version = "0.2.17")

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
Expand Down Expand Up @@ -75,8 +76,19 @@ use_repo(rust, "rust_toolchains")

register_toolchains("@rust_toolchains//:all")

single_version_override(
module_name = "hermetic_cc_toolchain",
patch_strip = 1,
patches = [
"//patches:hermetic_cc_toolchain.patch",
],
)

single_version_override(
module_name = "rules_rust",
patch_strip = 1,
patches = ["//patches:rules_rust_windows_gnu.patch"],
patches = [
"//patches:rules_rust_windows_gnu.patch",
"//patches:rules_rust_cdylib_windows.patch",
],
)
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ To run the Rust calculator example:
bazel run //rs:main -- calc "2 + 3 * 4"
```

To run the C++ calculator example:
```shell
bazel run //cc:main -- calc "2 + 3 * 4"
```

To run the Rust calling C++ FFI interop example:
```shell
bazel run //rs:main -- calc-cpp "2 * (3 + 4) ^ 2"
```

To run the C++ calling Rust FFI interop example:
```shell
bazel run //cc:main -- calc-rs "2 * (3 + 4) ^ 2"
```

To format Bazel files:
```shell
buildifier BUILD.bazel
Expand Down
56 changes: 56 additions & 0 deletions cc/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")

cc_library(
name = "calculator",
srcs = ["calculator.cc"],
hdrs = ["calculator.hh"],
copts = [
"-fno-exceptions",
"-fno-rtti",
],
visibility = ["//visibility:public"],
)

cc_library(
name = "rust_calculator",
srcs = ["rust_calculator.cc"],
hdrs = ["rust_calculator.hh"],
visibility = ["//visibility:public"],
deps = ["//rs:rust_calculator"],
)

cc_binary(
name = "main",
srcs = ["main.cc"],
env = select({
"@platforms//os:windows": {
"PATH": "rs;.",
},
"//conditions:default": {},
}),
visibility = ["//visibility:public"],
deps = [
":calculator",
":rust_calculator",
],
)

cc_test(
name = "calculator_test",
srcs = ["calculator_test.cc"],
deps = [":calculator"],
)

cc_test(
name = "rust_calculator_test",
srcs = ["rust_calculator_test.cc"],
env = select({
"@platforms//os:windows": {
"PATH": "rs;.",
},
"//conditions:default": {},
}),
deps = [
":rust_calculator",
],
)
Loading
Loading