Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion capnproto/private/codegen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ _PRIVATE_ATTRS = {
cfg = "exec",
),
"_capnpc_rust_dx": attr.label(
default = Label("//capnproto/private/tools/capnpc_rust_dx"),
default = Label("@dx_prebuilt//:dx"),
executable = True,
cfg = "exec",
),
Expand Down Expand Up @@ -292,6 +292,7 @@ def _rust_srcs_impl(ctx):
pkg = ctx.label.package
out_dir = ctx.bin_dir.path + "/" + (pkg + "/" if pkg else "") + out_subdir
args = ctx.actions.args()
args.add("capnpc_rust_dx")
args.add("--capnp", ctx.executable._capnp)
args.add("--root", stage.root)
args.add("--out", out_dir)
Expand Down
9 changes: 5 additions & 4 deletions capnproto/private/tools/capnpc_rust_dx/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
load("@crates//:crates.bzl", "aliases")
load("//core/quality:fixtures.bzl", "real_source_target")
load("//rust:defs.bzl", "rust_binary", "rust_test")
load("//rust:defs.bzl", "rust_library", "rust_test")

# gazelle:resolve rust capnp @dx_capnproto_rust//:capnp
# gazelle:resolve rust capnpc @dx_capnproto_rust//:capnpc

package(default_visibility = ["//capnproto:__subpackages__"])

# Generates capnproto_rust_library sources from the pinned capnp and capnpc crate.
rust_binary(
rust_library(
name = "capnpc_rust_dx",
srcs = ["main.rs"],
srcs = ["lib.rs"],
aliases = aliases(
package_name = "capnproto/private/tools/capnpc_rust_dx",
normal = True,
),
crate_name = "capnpc_rust_dx",
crate_root = "main.rs",
crate_root = "lib.rs",
rustc_flags = ["--cap-lints=allow"],
visibility = ["//cli/cli:__pkg__"],
deps = [
"@dx_capnproto_rust//:capnp",
"@dx_capnproto_rust//:capnpc",
Expand Down
4 changes: 2 additions & 2 deletions capnproto/private/tools/capnpc_rust_dx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ name = "capnpc_rust_dx"
version = "0.0.0"
edition = "2024"

[[bin]]
[lib]
name = "capnpc_rust_dx"
path = "main.rs"
path = "lib.rs"
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,15 @@ fn run(args: &Args) -> Result<(), String> {
.map_err(|e| format!("cannot write lib.rs: {e}"))
}

fn main() {
let raw: Vec<String> = std::env::args().skip(1).collect();
let result = parse_args(&raw).and_then(|args| run(&args));
if let Err(message) = result {
eprintln!("capnpc_rust_dx: {message}");
std::process::exit(1);
/// Runs the driver with the arguments after its name and returns the exit code.
#[must_use]
pub fn run_process(raw: &[String]) -> i32 {
match parse_args(raw).and_then(|args| run(&args)) {
Ok(()) => 0,
Err(message) => {
eprintln!("capnpc_rust_dx: {message}");
1
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions capnproto/tests/failure_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
def _undeclared_rust_impl(ctx):
env = analysistest.begin(ctx)
action = [a for a in analysistest.target_actions(env) if a.mnemonic == "CapnpRust"][0]
asserts.true(env, action.argv[0].removesuffix(".exe").endswith("/dx"), "action runs " + action.argv[0])
asserts.equals(env, "capnpc_rust_dx", action.argv[1])
names = [f.basename for f in action.inputs.to_list()]
asserts.true(env, "lost.capnp" in names, "declared schema missing: " + str(names))
asserts.false(env, "hidden.capnp" in names, "undeclared import is readable: " + str(names))
Expand Down
12 changes: 10 additions & 2 deletions cargo-bazel-lock.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "dcedeacc40377c6d113b841cdec917a45fd395c8fdedde53ca23efec9ad61746",
"checksum": "eff6637cb4837442da580b4ccb34dd74daf19acfc91c2b02c0df64439950185a",
"conditions": {
"aarch64-apple-darwin": [
"aarch64-apple-darwin"
Expand Down Expand Up @@ -2969,13 +2969,21 @@
"common_attrs": {
"edition": "2024"
},
"library_target_name": "capnpc_rust_dx",
"license": "Apache-2.0",
"license_ids": [
"Apache-2.0"
],
"name": "capnpc_rust_dx",
"repository": null,
"targets": [],
"targets": [
{
"Library": {
"crate_name": "capnpc_rust_dx",
"crate_root": "lib.rs"
}
}
],
"version": "0.0.0"
},
"capnproto_tests 0.0.0": {
Expand Down
1 change: 1 addition & 0 deletions cli/cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ rust_binary(
deps = [
":dx_cli",
"//api_spec/private/codegen",
"//capnproto/private/tools/capnpc_rust_dx",
"//cli/adopt:dx_adopt",
"//cli/codegen_shard",
"//cli/exec_core:dx_exec_core",
Expand Down
1 change: 1 addition & 0 deletions cli/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ fn run_as_tool() -> Option<i32> {
Tool::Capture => capture::run_process(args),
Tool::ApiSpecPreflight => api_spec_codegen::preflight::run_process(&lossy(args)),
Tool::OapiCodegen => api_spec_codegen::oapi_codegen::run_process(&lossy(args)),
Tool::CapnpcRustDx => capnpc_rust_dx::run_process(&lossy(args)),
Tool::Archiver => dx_deploy_tools::entry::archiver(&named("archiver", args)),
Tool::Hasher => dx_deploy_tools::entry::hasher(&named("hasher", args)),
Tool::SizeChecker => dx_deploy_tools::entry::size_checker(&named("size_checker", args)),
Expand Down
4 changes: 4 additions & 0 deletions cli/cli/src/multicall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum Tool {
SizeChecker,
CloudflareVerify,
NpmPacker,
CapnpcRustDx,
}

/// The tool `dx` was started as, judged by the file stem of argv[0] so `.exe` does not matter.
Expand Down Expand Up @@ -54,6 +55,7 @@ pub fn subcommand_for(arg1: &OsStr) -> Option<Tool> {
"size_checker" => Some(Tool::SizeChecker),
"cloudflare_verify" => Some(Tool::CloudflareVerify),
"npm_packer" => Some(Tool::NpmPacker),
"capnpc_rust_dx" => Some(Tool::CapnpcRustDx),
_ => None,
}
}
Expand Down Expand Up @@ -127,6 +129,7 @@ mod tests {
("size_checker", Tool::SizeChecker),
("cloudflare_verify", Tool::CloudflareVerify),
("npm_packer", Tool::NpmPacker),
("capnpc_rust_dx", Tool::CapnpcRustDx),
] {
assert_eq!(subcommand_for(OsStr::new(name)), Some(tool), "{name}");
}
Expand All @@ -142,6 +145,7 @@ mod tests {
"oapi_codegen",
"archiver",
"hasher",
"capnpc_rust_dx",
] {
assert_eq!(tool_for(OsStr::new(name)), None, "{name}");
}
Expand Down
Loading