Skip to content

Commit

Permalink
fold recapn-sys functionality into recapnc
Browse files Browse the repository at this point in the history
  • Loading branch information
mikea committed Dec 12, 2024
1 parent e918af5 commit 11d1d77
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 21 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[workspace]
members = [
"recapn",
"recapn-sys",
"recapnc",
"recapn-channel",
"recapn-rpc",
Expand Down
9 changes: 0 additions & 9 deletions recapn-sys/Cargo.toml

This file was deleted.

5 changes: 0 additions & 5 deletions recapn-sys/README.md

This file was deleted.

1 change: 0 additions & 1 deletion recapn-sys/src/lib.rs

This file was deleted.

1 change: 0 additions & 1 deletion recapnc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"

[dependencies]
recapn = { path = "../recapn", features = [] }
recapn-sys = { path = "../recapn-sys"}
syn = { version = "2.0", features = ["full"] }
quote = "1.0"
proc-macro2 = "1.0"
Expand Down
5 changes: 2 additions & 3 deletions recapn-sys/build.rs → recapnc/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::process::Command;

fn main() {
println!("cargo::rerun-if-env-changed=CAPNP_TOOL_PATH");
let command = std::env::var_os("CAPNP_TOOL_PATH")
.map(|p| p.into_string().unwrap())
.unwrap_or("capnp".to_string());
Expand All @@ -10,8 +11,6 @@ fn main() {
.expect("capnp tool can't be executed, change PATH or CAPNP_TOOL_PATH");
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
let version = stdout.split_ascii_whitespace().last().unwrap();
if !version.starts_with("1.") && version != "(unknown)" {
panic!("capnp tool 1.x is required, got: {:?}", version);
}
println!("cargo::rustc-env=CAPNP_TOOL_PATH={command}");
println!("cargo::rustc-env=CAPNP_TOOL_VERSION={version}");
}
9 changes: 8 additions & 1 deletion recapnc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ pub fn generate_from_request_stream(r: impl Read, out: impl AsRef<Path>) -> Resu
generate_from_request(&request, out)
}

const CAPNP_TOOL_PATH: &str = env!("CAPNP_TOOL_PATH");
const CAPNP_TOOL_VERSION: &str = env!("CAPNP_TOOL_VERSION");

pub struct CapnpCommand {
files: Vec<Box<Path>>,
src_prefixes: Vec<Box<Path>>,
Expand All @@ -509,6 +512,10 @@ pub struct CapnpCommand {
}

impl CapnpCommand {
pub fn version() -> &'static str {
CAPNP_TOOL_VERSION
}

pub fn new() -> Self {
Self {
files: Vec::new(),
Expand Down Expand Up @@ -544,7 +551,7 @@ impl CapnpCommand {
if let Some(path) = &self.exe_path {
Command::new(path)
} else {
Command::new(recapn_sys::CAPNP_TOOL_PATH)
Command::new(CAPNP_TOOL_PATH)
}
}

Expand Down
5 changes: 5 additions & 0 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ use std::path::PathBuf;
fn main() {
println!("cargo::rerun-if-changed=schemas");

let capnp_version = recapnc::CapnpCommand::version();
if !capnp_version.starts_with("1.") && capnp_version != "(unknown)" {
panic!("capnp tool 1.x is required, got: {capnp_version}");
}

let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());

macro_rules! run {
Expand Down

0 comments on commit 11d1d77

Please sign in to comment.