Skip to content

Commit 4fff6f2

Browse files
authored
[workerd-cxx] merge kj-rs project in (#23)
1 parent be8c5ca commit 4fff6f2

39 files changed

+3010
-65
lines changed

.bazelrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ build:clippy --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
3131
build:clippy --output_groups=+clippy_checks
3232
build:clippy --@rules_rust//:clippy_flags=-Dclippy::all,-Dclippy::pedantic
3333

34+
## Sanitizers
35+
36+
build:sanitizer-common --copt="-fsanitize-link-c++-runtime" --linkopt="-fsanitize-link-c++-runtime"
37+
build:sanitizer-common --copt="-Og"
38+
build:sanitizer-common --copt="-g" --strip=never
39+
build:sanitizer-common --copt="-fno-optimize-sibling-calls"
40+
build:sanitizer-common --copt="-fno-omit-frame-pointer" --copt="-mno-omit-leaf-frame-pointer"
41+
42+
# Address sanitizer (https://github.com/google/sanitizers/wiki/AddressSanitizer)
43+
build:asan --config=sanitizer-common
44+
build:asan --copt="-fsanitize=address" --linkopt="-fsanitize=address"
45+
build:asan --test_env=ASAN_OPTIONS=abort_on_error=true
46+
build:asan --test_env=LSAN_OPTIONS=report_objects=1
47+
build:asan --test_env=KJ_CLEAN_SHUTDOWN=1
48+
3449
###############################################################################
3550
## Custom user flags
3651
##

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ jobs:
4949
- run: sudo apt-get install lld
5050
- run: bazel build --config=clippy ... --verbose_failures
5151

52+
asan:
53+
name: Address Sanitizer
54+
runs-on: ubuntu-latest
55+
if: github.event_name != 'pull_request'
56+
timeout-minutes: 45
57+
steps:
58+
- uses: actions/checkout@v4
59+
- run: sudo apt-get install lld
60+
- run: bazel test --config=asan ... --verbose_failures
61+
5262
clang-tidy:
5363
name: Clang Tidy
5464
runs-on: ubuntu-latest

.vscode/settings.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
22
"search.exclude": {
3-
"**/target": true
3+
"bazel-*/": true
4+
},
5+
"rust-analyzer.workspace.discoverConfig": {
6+
"command": [
7+
"just",
8+
"_rust-analyzer"
9+
],
10+
"progressLabel": "generating rust analyzer config",
11+
"filesToWatch": [
12+
"BUILD.bazel"
13+
]
414
}
515
}

MODULE.bazel

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,3 @@ use_repo(crate_repositories, "crates.io", "vendor")
2828

2929
capnp_cpp = use_extension("//:capnp_cpp.bzl", "capnp_cpp")
3030
use_repo(capnp_cpp, "capnp-cpp")
31-
32-
kj_rs = use_extension("//:kj_rs.bzl", "kj_rs")
33-
use_repo(kj_rs, "kj-rs")

MODULE.bazel.lock

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

gen/src/include.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub(super) fn write(out: &mut OutFile) {
189189
writeln!(out, "#endif");
190190
}
191191
if kj_rs && !cxx_header {
192-
writeln!(out, "#include <kj-rs/kj-rs.h>");
192+
writeln!(out, "#include \"kj-rs/kj-rs.h\"");
193193
}
194194
}
195195

justfile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ alias b := build
33
alias t := test
44

55
watch +WATCH_TARGET='test':
6-
watchexec -rc -w tests -w src -w gen -w macro -w syntax -- just {{WATCH_TARGET}}
6+
watchexec -rc -w tests -w src -w gen -w macro -w syntax -w kj-rs -- just {{WATCH_TARGET}}
77

88
build:
99
bazel build //...
@@ -15,4 +15,22 @@ clippy:
1515
bazel build --config=clippy //...
1616

1717
cargo-update:
18-
bazel run //third-party:vendor
18+
bazel run //third-party:vendor
19+
20+
format: rustfmt clang-format
21+
22+
rustfmt:
23+
bazel run @rules_rust//:rustfmt
24+
25+
clang-format:
26+
clang-format -i kj/*.h kj/*.c++ kj/tests/*.h kj/tests/*.c++
27+
28+
29+
compile-commands:
30+
bazel run @hedron_compile_commands//:refresh_all
31+
32+
# called by rust-analyzer discoverConfig (quiet recipe with no output)
33+
@_rust-analyzer:
34+
rm -rf ./rust-project.json
35+
# rust-analyzer doesn't like stderr output, redirect it to /dev/null
36+
bazel run @rules_rust//tools/rust_analyzer:discover_bazel_rust_project 2>/dev/null

kj-rs/BUILD.bazel

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
load("//tools/bazel:rust_cxx_bridge.bzl", "rust_cxx_bridge")
2+
load("@rules_rust//rust:defs.bzl", "rust_library")
3+
4+
cc_library(
5+
name = "kj-rs-lib",
6+
srcs = glob(["*.c++"]),
7+
hdrs = glob(["*.h"]),
8+
include_prefix = "kj-rs",
9+
linkstatic = select({
10+
"@platforms//os:windows": True,
11+
"//conditions:default": False,
12+
}),
13+
deps = [
14+
":bridge",
15+
],
16+
)
17+
18+
rust_library(
19+
name = "kj-rs",
20+
srcs = glob(["*.rs"]),
21+
compile_data = glob(["*.h"]),
22+
edition = "2024",
23+
visibility = ["//visibility:public"],
24+
deps = [
25+
":bridge",
26+
":kj-rs-lib",
27+
"@workerd-cxx//:cxx",
28+
"@crates.io//:static_assertions",
29+
],
30+
)
31+
32+
rust_cxx_bridge(
33+
name = "bridge",
34+
src = "lib.rs",
35+
hdrs = glob(["*.h"]),
36+
include_prefix = "kj-rs",
37+
deps = [
38+
":cxx",
39+
"@capnp-cpp//src/kj:kj",
40+
"@capnp-cpp//src/kj:kj-async",
41+
"@workerd-cxx//:cxx",
42+
],
43+
)
44+
45+
genrule(
46+
name = "cxx/generated",
47+
outs = ["cxx.h"],
48+
cmd = "$(location @workerd-cxx//:codegen) --header > \"$@\"",
49+
tools = ["@workerd-cxx//:codegen"],
50+
)
51+
52+
cc_library(
53+
name = "cxx",
54+
hdrs = ["cxx.h"],
55+
include_prefix = "rust",
56+
)

kj-rs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# KJ
2+
3+
This directory contains supporting code for the integration with kj library.

0 commit comments

Comments
 (0)