Skip to content

Commit

Permalink
[nfc] wd_rust_capnp_library and wd_capnp_library
Browse files Browse the repository at this point in the history
wd_capnp_library generates both c++ and rust versions
  • Loading branch information
mikea committed Sep 30, 2024
1 parent 3800fd6 commit 1ca74bb
Show file tree
Hide file tree
Showing 15 changed files with 383 additions and 84 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ build:limited-dbg-info --copt='-g1' --copt="-fdebug-info-for-profiling"
# Miscellaneous platform-independent options
build --@capnp-cpp//src/kj:openssl=True --@capnp-cpp//src/kj:zlib=True --@capnp-cpp//src/kj:brotli=True
build --cxxopt="-fbracket-depth=512" --host_cxxopt="-fbracket-depth=512"
build --@capnp-cpp//src/capnp:gen_rust=True

# Additional Rust flags (see https://doc.rust-lang.org/rustc/codegen-options/index.html)
# Need to disable debug-assertions for fastbuild, should be off automatically for opt. As long as
Expand Down
8 changes: 4 additions & 4 deletions build/deps/gen/dep_capnp_cpp.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

load("@//:build/http.bzl", "http_archive")

URL = "https://github.com/capnproto/capnproto/tarball/cd7b20ad0dbd0b1917d0dc3178f7ba05639ea65d"
STRIP_PREFIX = "capnproto-capnproto-cd7b20a/c++"
SHA256 = "2cf78cbc45ab306a7d71de0eac62f1317a976a3be75339a1df80abd187edd7a3"
URL = "https://github.com/capnproto/capnproto/tarball/b279a2776d13c997689fb0a36ea9f1c91e881aba"
STRIP_PREFIX = "capnproto-capnproto-b279a27/c++"
SHA256 = "f633ccd5922b512c3aea69c861340149ad2aa51f389ba5aca50f01334d23b9a9"
TYPE = "tgz"
COMMIT = "cd7b20ad0dbd0b1917d0dc3178f7ba05639ea65d"
COMMIT = "b279a2776d13c997689fb0a36ea9f1c91e881aba"

def dep_capnp_cpp():
http_archive(
Expand Down
37 changes: 37 additions & 0 deletions build/wd_capnp_library.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
load("//:build/wd_cc_capnp_library.bzl", "wd_cc_capnp_library")
load("//:build/wd_rust_capnp_library.bzl", "wd_rust_capnp_library")

def wd_capnp_library(
src,
deps = [],
tags = [],
target_compatible_with = None,
visibility = ["//visibility:public"]):
"""Generates capnp library for multiple languages.
For a given file-name.capnp it will produce:
- `file-name_capnp` c++ library
- `file-name_capnp_rust` rust library
"""
base_name = src.removesuffix(".capnp")

wd_cc_capnp_library(
name = base_name + "_capnp",
visibility = visibility,
deps = deps,
srcs = [src],
tags = ["manual"] + tags,
target_compatible_with = target_compatible_with,
)

rust_deps = [dep + "_rust" if dep.endswith("_capnp") else dep for dep in deps]

wd_rust_capnp_library(
name = base_name + "_capnp_rust",
crate_name = base_name.replace("-", "_") + "_capnp",
visibility = visibility,
deps = rust_deps,
srcs = [src],
tags = ["manual"] + tags,
target_compatible_with = target_compatible_with,
)
11 changes: 11 additions & 0 deletions build/wd_rust_capnp_library.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""wd_rust_capnp_library definition"""

load("@capnp-cpp//src/capnp:rust_capnp_library.bzl", "rust_capnp_library")

def wd_rust_capnp_library(**kwargs):
"""Wrapper for rust_capnp_library that sets common attributes
"""
rust_capnp_library(
src_prefix = "src",
**kwargs
)
26 changes: 26 additions & 0 deletions deps/rust/Cargo.lock

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

2 changes: 2 additions & 0 deletions deps/rust/cargo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ PACKAGES = RTTI_PACKAGES | {
git = "https://github.com/cloudflare/lol-html.git",
rev = "7db3d8d9fa9f3fee6ffe36c3f68f14e160476e07",
),
"capnp": crate.spec(version = "0.20"),
"capnpc": crate.spec(version = "0.20"),
}
24 changes: 24 additions & 0 deletions deps/rust/crates/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ alias(
tags = ["manual"],
)

alias(
name = "capnp",
actual = "@crates_vendor__capnp-0.20.1//:capnp",
tags = ["manual"],
)

alias(
name = "capnpc",
actual = "@crates_vendor__capnpc-0.20.0//:capnpc",
tags = ["manual"],
)

alias(
name = "clang-ast",
actual = "@crates_vendor__clang-ast-0.1.26//:clang_ast",
Expand Down Expand Up @@ -74,6 +86,18 @@ alias(
)

# Binaries
alias(
name = "capnpc__capnpc-rust",
actual = "@crates_vendor__capnpc-0.20.0//:capnpc-rust__bin",
tags = ["manual"],
)

alias(
name = "capnpc__capnpc-rust-bootstrap",
actual = "@crates_vendor__capnpc-0.20.0//:capnpc-rust-bootstrap__bin",
tags = ["manual"],
)

alias(
name = "phf_generator__gen_hash_test",
actual = "@crates_vendor__phf_generator-0.8.0//:gen_hash_test__bin",
Expand Down
49 changes: 49 additions & 0 deletions deps/rust/crates/BUILD.capnp-0.20.1.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
###############################################################################
# @generated
# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To
# regenerate this file, run the following:
#
# bazel run @//deps/rust:crates_vendor
###############################################################################

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

package(default_visibility = ["//visibility:public"])

rust_library(
name = "capnp",
srcs = glob(
include = ["**/*.rs"],
allow_empty = True,
),
compile_data = glob(
include = ["**"],
allow_empty = True,
exclude = [
"**/* *",
".tmp_git_root/**/*",
"BUILD",
"BUILD.bazel",
"WORKSPACE",
"WORKSPACE.bazel",
],
),
crate_features = [
"alloc",
"default",
"std",
],
crate_root = "src/lib.rs",
edition = "2021",
rustc_flags = [
"--cap-lints=allow",
],
tags = [
"cargo-bazel",
"crate-name=capnp",
"manual",
"noclippy",
"norustfmt",
],
version = "0.20.1",
)
125 changes: 125 additions & 0 deletions deps/rust/crates/BUILD.capnpc-0.20.0.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
###############################################################################
# @generated
# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To
# regenerate this file, run the following:
#
# bazel run @//deps/rust:crates_vendor
###############################################################################

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

package(default_visibility = ["//visibility:public"])

rust_library(
name = "capnpc",
srcs = glob(
include = ["**/*.rs"],
allow_empty = True,
),
compile_data = glob(
include = ["**"],
allow_empty = True,
exclude = [
"**/* *",
".tmp_git_root/**/*",
"BUILD",
"BUILD.bazel",
"WORKSPACE",
"WORKSPACE.bazel",
],
),
crate_root = "src/lib.rs",
edition = "2021",
rustc_flags = [
"--cap-lints=allow",
],
tags = [
"cargo-bazel",
"crate-name=capnpc",
"manual",
"noclippy",
"norustfmt",
],
version = "0.20.0",
deps = [
"@crates_vendor__capnp-0.20.1//:capnp",
],
)

rust_binary(
name = "capnpc-rust__bin",
srcs = glob(
include = ["**/*.rs"],
allow_empty = True,
),
compile_data = glob(
include = ["**"],
allow_empty = True,
exclude = [
"**/* *",
".tmp_git_root/**/*",
"BUILD",
"BUILD.bazel",
"WORKSPACE",
"WORKSPACE.bazel",
],
),
crate_root = "src/capnpc-rust.rs",
edition = "2021",
rustc_flags = [
"--cap-lints=allow",
],
tags = [
"cargo-bazel",
"crate-name=capnpc",
"manual",
"noclippy",
"norustfmt",
],
version = "0.20.0",
deps = [
":capnpc",
"@crates_vendor__capnp-0.20.1//:capnp",
],
)

rust_binary(
name = "capnpc-rust-bootstrap__bin",
srcs = glob(
include = ["**/*.rs"],
allow_empty = True,
),
compile_data = glob(
include = ["**"],
allow_empty = True,
exclude = [
"**/* *",
".tmp_git_root/**/*",
"BUILD",
"BUILD.bazel",
"WORKSPACE",
"WORKSPACE.bazel",
],
),
crate_root = "src/capnpc-rust-bootstrap.rs",
edition = "2021",
rustc_flags = [
"--cap-lints=allow",
],
tags = [
"cargo-bazel",
"crate-name=capnpc",
"manual",
"noclippy",
"norustfmt",
],
version = "0.20.0",
deps = [
":capnpc",
"@crates_vendor__capnp-0.20.1//:capnp",
],
)
44 changes: 44 additions & 0 deletions deps/rust/crates/BUILD.embedded-io-0.6.1.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
###############################################################################
# @generated
# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To
# regenerate this file, run the following:
#
# bazel run @//deps/rust:crates_vendor
###############################################################################

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

package(default_visibility = ["//visibility:public"])

rust_library(
name = "embedded_io",
srcs = glob(
include = ["**/*.rs"],
allow_empty = True,
),
compile_data = glob(
include = ["**"],
allow_empty = True,
exclude = [
"**/* *",
".tmp_git_root/**/*",
"BUILD",
"BUILD.bazel",
"WORKSPACE",
"WORKSPACE.bazel",
],
),
crate_root = "src/lib.rs",
edition = "2021",
rustc_flags = [
"--cap-lints=allow",
],
tags = [
"cargo-bazel",
"crate-name=embedded-io",
"manual",
"noclippy",
"norustfmt",
],
version = "0.6.1",
)
Loading

0 comments on commit 1ca74bb

Please sign in to comment.