Skip to content

Commit

Permalink
Run checks per crate, not workspace. (project-oak#1900)
Browse files Browse the repository at this point in the history
  • Loading branch information
wildarch committed Mar 11, 2021
1 parent 5bb2c7e commit 7039625
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 48 deletions.
1 change: 0 additions & 1 deletion examples/Cargo.lock

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

1 change: 0 additions & 1 deletion examples/proxy_attestation/module/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
anyhow = "*"
base64 = "*"
log = "*"
oak = "=0.1.0"
oak_abi = "=0.1.0"
Expand Down
37 changes: 28 additions & 9 deletions examples/trusted_database/client/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,45 @@ authors = ["Ivan Petrov <ivanpetrov@google.com>"]
edition = "2018"
license = "Apache-2.0"

[features]
binary = [
"log",
"structopt",
"oak_abi",
"oak_client",
"oak_sign",
"anyhow",
"env_logger",
"tokio"
]

[lib]
name = "trusted_database_client"
path = "src/lib.rs"

[[bin]]
name = "trusted_database_client_bin"
path = "src/main.rs"
required-features = ["binary"]

[dependencies]
anyhow = "*"
env_logger = "*"
log = "*"
oak_abi = "=0.1.0"
oak_client = "=0.1.0"
oak_sign = "=0.1.0"
tonic = { version = "*", features = ["tls"] }
prost = "*"
structopt = "*"
# Dependencies for main, not required to build the library
log = { version = "*", optional = true }
structopt = { version = "*", optional = true }
oak_abi = { version = "=0.1.0", optional = true }
oak_client = { version = "=0.1.0", optional = true }
oak_sign = { version = "=0.1.0", optional = true }
anyhow = { version = "*", optional = true }
env_logger = { version = "*", optional = true }
# Pinned to 0.2 because of tonic: https://github.com/hyperium/tonic/blob/master/tonic/Cargo.toml
tokio = { version = "0.2", features = ["fs", "macros", "sync", "stream"] }
tonic = { version = "*", features = ["tls"] }
tokio = { version = "0.2", features = [
"fs",
"macros",
"sync",
"stream"
], optional = true }

[build-dependencies]
oak_utils = "*"
19 changes: 11 additions & 8 deletions examples/trusted_database/example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ additional_args = [
"--config-files=database=third_party/data/cycle-hire-availability/livecyclehireupdates.xml"
]

[clients]
rust = { Cargo = { cargo_manifest = "examples/trusted_database/client/rust/Cargo.toml" }, additional_args = [
"--root-tls-certificate=examples/certs/local/ca.pem",
"--latitude=0.0",
"--longitude=0.0"
[clients.rust]
Cargo = { cargo_manifest = "examples/trusted_database/client/rust/Cargo.toml", additional_build_args = [
"--features=binary"
] }
cpp = { Bazel = { bazel_target = "//examples/trusted_database/client/cpp:client" }, additional_args = [
additional_args = [
"--root-tls-certificate=examples/certs/local/ca.pem",
"--latitude=0.0",
"--longitude=0.0"
] }
"--longitude=0.0",
]

[clients.cpp]
Bazel = { bazel_target = "//examples/trusted_database/client/cpp:client" }
additional_args = ["--latitude=0.0", "--longitude=0.0"]
8 changes: 0 additions & 8 deletions experimental/Cargo.lock

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

2 changes: 1 addition & 1 deletion experimental/split_grpc/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "Apache-2.0"
env_logger = "*"
log = "*"
prost = "*"
tokio = { version = "*", features = ["fs", "macros"] }
tokio = { version = "*", features = ["fs", "macros", "rt-multi-thread"] }
tonic = { version = "*", features = ["tls"] }

[build-dependencies]
Expand Down
54 changes: 34 additions & 20 deletions runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,20 @@ fn run_examples(opt: &RunExamples) -> Step {

fn build_wasm_module(name: &str, target: &Target, example_name: &str) -> Step {
match target {
Target::Cargo { cargo_manifest } => Step::Single {
Target::Cargo {
cargo_manifest,
additional_build_args,
} => Step::Single {
name: format!("wasm:{}:{}", name, cargo_manifest.to_string()),
command: Cmd::new(
"cargo",
&[
spread![
// `--out-dir` is unstable and requires `-Zunstable-options`.
"-Zunstable-options",
"build",
"--release",
"--target=wasm32-unknown-unknown",
&format!("--manifest-path={}", cargo_manifest),
"-Zunstable-options".to_string(),
"build".to_string(),
"--release".to_string(),
"--target=wasm32-unknown-unknown".to_string(),
format!("--manifest-path={}", cargo_manifest),
// Use a fixed target directory, because `--target-dir` influences SHA256 hash
// of Wasm module. Target directory should also be synchronized with
// `--target-dir` used in [`oak_tests::compile_rust_wasm`] in order to have
Expand All @@ -201,13 +204,14 @@ fn build_wasm_module(name: &str, target: &Target, example_name: &str) -> Step {
// `cargo test`, which also executes [`oak_tests::compile_rust_wasm`] and thus
// runs `cargo build` inside it. It may lead to errors, since dependencies may
// be recompiled by `cargo build` and `cargo test` will fail to continue.
&format!("--target-dir={}", {
format!("--target-dir={}", {
let mut target_dir = PathBuf::from(cargo_manifest);
target_dir.pop();
target_dir.push("target");
target_dir.to_str().expect("Invalid target dir").to_string()
}),
&format!("--out-dir=examples/{}/bin", example_name),
format!("--out-dir=examples/{}/bin", example_name),
...additional_build_args
],
),
},
Expand Down Expand Up @@ -601,6 +605,8 @@ enum Target {
},
Cargo {
cargo_manifest: String,
#[serde(default)]
additional_build_args: Vec<String>,
},
Npm {
package_directory: String,
Expand Down Expand Up @@ -803,9 +809,12 @@ fn build_docker(example: &Example) -> Step {

fn build(target: &Target, opt: &BuildClient) -> Box<dyn Runnable> {
match target {
Target::Cargo { cargo_manifest } => Cmd::new(
Target::Cargo {
cargo_manifest,
additional_build_args,
} => Cmd::new(
"cargo",
vec![
spread![
"build".to_string(),
"--release".to_string(),
format!(
Expand All @@ -815,6 +824,7 @@ fn build(target: &Target, opt: &BuildClient) -> Box<dyn Runnable> {
.unwrap_or(DEFAULT_EXAMPLE_BACKEND_RUST_TARGET)
),
format!("--manifest-path={}", cargo_manifest),
...additional_build_args,
],
),
Target::Bazel {
Expand Down Expand Up @@ -846,13 +856,17 @@ fn run(
additional_args: Vec<String>,
) -> Box<dyn Runnable> {
match &executable.target {
Target::Cargo { cargo_manifest } => Cmd::new(
Target::Cargo {
cargo_manifest,
additional_build_args,
} => Cmd::new(
"cargo",
spread![
"run".to_string(),
"--release".to_string(),
format!("--target={}", opt.client_rust_target.as_deref().unwrap_or(DEFAULT_EXAMPLE_BACKEND_RUST_TARGET)),
format!("--manifest-path={}", cargo_manifest),
...additional_build_args,
"--".to_string(),
...executable.additional_args.clone(),
...additional_args,
Expand Down Expand Up @@ -954,11 +968,11 @@ fn source_files() -> impl Iterator<Item = PathBuf> {
.map(|e| e.into_path())
}

/// Return an iterator of all known Cargo Manifest files that define workspaces.
fn workspace_manifest_files() -> impl Iterator<Item = PathBuf> {
/// Return an iterator of all known Cargo Manifest files that define crates.
fn crate_manifest_files() -> impl Iterator<Item = PathBuf> {
source_files()
.filter(is_cargo_toml_file)
.filter(is_cargo_workspace_file)
.filter(|p| !is_cargo_workspace_file(p))
}

/// Return whether the provided path refers to a source file in a programming language.
Expand Down Expand Up @@ -1317,7 +1331,7 @@ fn run_check_todo() -> Step {
fn run_cargo_fmt(mode: FormatMode) -> Step {
Step::Multiple {
name: "cargo fmt".to_string(),
steps: workspace_manifest_files()
steps: crate_manifest_files()
.map(to_string)
.map(|entry| Step::Single {
name: entry.clone(),
Expand Down Expand Up @@ -1347,7 +1361,7 @@ fn run_cargo_fmt(mode: FormatMode) -> Step {
fn run_cargo_test() -> Step {
Step::Multiple {
name: "cargo test".to_string(),
steps: workspace_manifest_files()
steps: crate_manifest_files()
.map(to_string)
.map(|entry| Step::Single {
name: entry.clone(),
Expand Down Expand Up @@ -1397,7 +1411,7 @@ fn run_cargo_test_tsan() -> Step {
fn run_cargo_clippy() -> Step {
Step::Multiple {
name: "cargo clippy".to_string(),
steps: workspace_manifest_files()
steps: crate_manifest_files()
.map(to_string)
.map(|entry| Step::Single {
name: entry.clone(),
Expand Down Expand Up @@ -1427,7 +1441,7 @@ fn run_cargo_clippy() -> Step {
fn run_cargo_deny() -> Step {
Step::Multiple {
name: "cargo deny".to_string(),
steps: workspace_manifest_files()
steps: crate_manifest_files()
.map(to_string)
.map(|entry| Step::Single {
name: entry.clone(),
Expand All @@ -1443,7 +1457,7 @@ fn run_cargo_deny() -> Step {
fn run_cargo_udeps() -> Step {
Step::Multiple {
name: "cargo udeps".to_string(),
steps: workspace_manifest_files()
steps: crate_manifest_files()
.map(to_string)
.map(|entry| Step::Single {
name: entry.clone(),
Expand Down

0 comments on commit 7039625

Please sign in to comment.