Skip to content

Commit

Permalink
place ttrpc files in OUT_DIR
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Prendes <[email protected]>
  • Loading branch information
jprendes committed Feb 20, 2024
1 parent 397d51e commit c4535cc
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 1,068 deletions.
8 changes: 0 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,6 @@ You can auto-fix most styles using
make fix
```

## Updating protobuf files

Ensure protoc and dev tools have been installed. Run `make build` or to just generate the protos:

```
cargo build -p containerd-shim-wasm --no-default-features --features generate_bindings
```

## Adding new features

Most features will likely have most of the code in the `containerd-shim-wasm` project and a few runtime specific addtions to each runtime shim. The general expectation is that the feature should be added to all runtimes. We will evaluate on a case by case basis exceptions, where runtimes may not be able to support a given feature or requires changes that make it hard to review. In those cases we it may make sense to implement in follow up PR's for other runtimes.
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ build: build-wasm $(RUNTIMES:%=build-%);

build-common: build-wasm;
build-wasm:
$(CARGO) build $(TARGET_FLAG) -p containerd-shim-wasm --no-default-features --features generate_bindings $(RELEASE_FLAG)
$(CARGO) build $(TARGET_FLAG) -p containerd-shim-wasm $(FEATURES_wasm) $(RELEASE_FLAG)

build-%:
Expand Down
3 changes: 1 addition & 2 deletions crates/containerd-shim-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ containerd-client = "0.4.0"
windows-sys = { workspace = true, features = ["Win32_Foundation", "Win32_Storage_FileSystem"] }

[build-dependencies]
ttrpc-codegen = { version = "0.4.2", optional = true }
ttrpc-codegen = { version = "0.4.2" }

[dev-dependencies]
containerd-shim-wasm-test-modules = { workspace = true }
Expand All @@ -59,4 +59,3 @@ oci-tar-builder = { workspace = true}

[features]
testing = ["dep:containerd-shim-wasm-test-modules", "dep:env_logger", "dep:tempfile", "dep:oci-tar-builder"]
generate_bindings = ["ttrpc-codegen"]
45 changes: 22 additions & 23 deletions crates/containerd-shim-wasm/build.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
#[cfg(feature = "generate_bindings")]
use std::fs;
use std::env::var_os;
use std::path::Path;

#[cfg(feature = "generate_bindings")]
use ttrpc_codegen::{Codegen, ProtobufCustomize};

#[cfg(not(feature = "generate_bindings"))]
fn main() {}

#[cfg(feature = "generate_bindings")]
fn main() {
println!("cargo:rerun-if-changed=protos");
fs::metadata("src/services/sandbox.rs").unwrap_or_else(|_| {
fs::create_dir_all("src/services").unwrap();
// always rerun if the directory doesn't exist
println!("cargo:rerun-if-changed=src/services");
fs::metadata("src/services").unwrap()
});
fs::metadata("src/services/sandbox_ttrpc.rs").unwrap_or_else(|_| {
fs::create_dir_all("src/services").unwrap();
// always rerun if the directory doesn't exist
println!("cargo:rerun-if-changed=src/services/sandbox_ttrpc.rs");
fs::metadata("src/services").unwrap()
});
let protos = ["protos/sandbox.proto"];
println!("cargo:rerun-if-changed=protos/sandbox.proto");

let protos = vec!["protos/sandbox.proto"];
let out_dir = var_os("OUT_DIR").unwrap();
let out_dir = Path::new(&out_dir);

Codegen::new()
.out_dir("src/services")
.inputs(&protos)
.out_dir(out_dir)
.inputs(protos)
.include("protos")
.rust_protobuf()
.rust_protobuf_customize(ProtobufCustomize::default().gen_mod_rs(false))
.run()
.expect("failed to generate code");

let sanbox_rs = out_dir.join("sandbox.rs");
let sanbox_ttrpc_rs = out_dir.join("sandbox_ttrpc.rs");

std::fs::write(
out_dir.join("mod.rs"),
format!(
r#"
#[path = {sanbox_rs:?}] pub mod sandbox;
#[path = {sanbox_ttrpc_rs:?}] pub mod sandbox_ttrpc;
"#,
),
)
.expect("failed to generate module");
}
3 changes: 1 addition & 2 deletions crates/containerd-shim-wasm/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
// do not run clippy on generated files
#![allow(clippy::all)]

pub mod sandbox;
pub mod sandbox_ttrpc;
include!(concat!(env!("OUT_DIR"), "/mod.rs"));
Loading

0 comments on commit c4535cc

Please sign in to comment.