From 9ef9c5a245bbb2c14b0257c9b2ce200bf068f4df Mon Sep 17 00:00:00 2001 From: Adrian Reber Date: Tue, 17 Jan 2023 13:01:23 +0000 Subject: [PATCH] Another try to make rust-criu work with crates.io Signed-off-by: Adrian Reber --- .github/workflows/test.yml | 3 +++ Cargo.toml | 4 +++- README.md | 16 +++++++++++++ build.rs | 23 +++++++++++++++---- {rust-criu-protobuf/proto => proto}/rpc.proto | 0 rust-criu-protobuf/Cargo.toml | 14 ----------- rust-criu-protobuf/build.rs | 11 --------- src/lib.rs | 2 ++ .../src => src/rust_criu_protobuf}/mod.rs | 0 .../src => src/rust_criu_protobuf}/rpc.rs | 0 10 files changed, 43 insertions(+), 30 deletions(-) rename {rust-criu-protobuf/proto => proto}/rpc.proto (100%) delete mode 100644 rust-criu-protobuf/Cargo.toml delete mode 100644 rust-criu-protobuf/build.rs rename {rust-criu-protobuf/src => src/rust_criu_protobuf}/mod.rs (100%) rename {rust-criu-protobuf/src => src/rust_criu_protobuf}/rpc.rs (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 80df6f7..aa4e5d9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,5 +28,8 @@ jobs: - name: Run fmt run: cargo fmt --all -- --check + - name: Build with generate enabled + run: GENERATE_PROTOBUF=1 GENERATE_TEST_PROCESS=1 cargo build --verbose + - name: Run tests run: sudo target/debug/rust-criu-test criu/criu/criu diff --git a/Cargo.toml b/Cargo.toml index 0e4d739..d985e09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,9 @@ license-file = "LICENSE" libc = "0.2" anyhow = "1.0.56" protobuf = "3.2.0" -rust-criu-protobuf = { path = "rust-criu-protobuf" } + +[build-dependencies] +protobuf-codegen = "3.2.0" [lib] name = "rust_criu" diff --git a/README.md b/README.md index eeba5c4..40d401e 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,19 @@ `rust-criu` provides an interface to use [CRIU](https://criu.org/) in the same way as [go-criu](https://github.com/checkpoint-restore/go-criu) does. + +## Generate protobuf bindings + +The CRIU RPC protobuf bindings are pre-generated and part of the rust-criu +repository. The bindings can be re-generated with +```shell +$ GENERATE_PROTOBUF=1 cargo build +``` + +## Run tests + +To run the included tests please use the following command to build `rust-criu`: +``` +$ GENERATE_TEST_PROCESS=1 cargo build +$ sudo target/debug/rust-criu-test /path/to/criu/binary +``` diff --git a/build.rs b/build.rs index a1f5df0..34ba9de 100644 --- a/build.rs +++ b/build.rs @@ -1,7 +1,22 @@ +extern crate protobuf_codegen; + fn main() { - std::process::Command::new("gcc") - .args(["test/piggie.c", "-o", "test/piggie"]) - .status() - .unwrap(); + if std::env::var_os("GENERATE_PROTOBUF").is_some() { + protobuf_codegen::Codegen::new() + .includes(["proto"]) + .input("proto/rpc.proto") + .out_dir("src/rust_criu_protobuf") + .run_from_script(); + } + + if std::env::var_os("GENERATE_TEST_PROCESS").is_some() { + std::process::Command::new("gcc") + .args(["test/piggie.c", "-o", "test/piggie"]) + .status() + .unwrap(); + } println!("cargo:rerun-if-changed=test/piggie.c"); + println!("cargo:rerun-if-changed=proto/rpc.proto"); + println!("cargo:rerun-if-env-changed=GENERATE_PROTOBUF"); + println!("cargo:rerun-if-env-changed=GENERATE_TEST_PROCESS"); } diff --git a/rust-criu-protobuf/proto/rpc.proto b/proto/rpc.proto similarity index 100% rename from rust-criu-protobuf/proto/rpc.proto rename to proto/rpc.proto diff --git a/rust-criu-protobuf/Cargo.toml b/rust-criu-protobuf/Cargo.toml deleted file mode 100644 index 9704a77..0000000 --- a/rust-criu-protobuf/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "rust-criu-protobuf" -version = "0.1.0" -edition = "2021" - -[dependencies] -protobuf = "3.2.0" - -[build-dependencies] -protobuf-codegen = "3.2.0" - -[lib] -name = "rust_criu_protobuf" -path = "src/mod.rs" diff --git a/rust-criu-protobuf/build.rs b/rust-criu-protobuf/build.rs deleted file mode 100644 index c48e3f5..0000000 --- a/rust-criu-protobuf/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate protobuf_codegen; - -fn main() { - protobuf_codegen::Codegen::new() - .includes(["proto"]) - .input("proto/rpc.proto") - .out_dir("src") - .run_from_script(); - - println!("cargo:rerun-if-changed=proto/rpc.proto"); -} diff --git a/src/lib.rs b/src/lib.rs index d13f5f9..a04a97e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +mod rust_criu_protobuf; + use anyhow::{Context, Result}; use protobuf::Message; use rust_criu_protobuf::rpc; diff --git a/rust-criu-protobuf/src/mod.rs b/src/rust_criu_protobuf/mod.rs similarity index 100% rename from rust-criu-protobuf/src/mod.rs rename to src/rust_criu_protobuf/mod.rs diff --git a/rust-criu-protobuf/src/rpc.rs b/src/rust_criu_protobuf/rpc.rs similarity index 100% rename from rust-criu-protobuf/src/rpc.rs rename to src/rust_criu_protobuf/rpc.rs