diff --git a/BUILD b/BUILD index 65bbdbc21f9..dada619bea1 100644 --- a/BUILD +++ b/BUILD @@ -29,7 +29,7 @@ exports_files(["LICENSE"]) # These files are built via cargo outside of Bazel. exports_files(srcs = glob(["target/x86_64-unknown-linux-musl/release/*oak_loader"])) -exports_files(srcs = glob(["target/wasm32-unknown-unknown/release/*.wasm"])) +exports_files(srcs = glob(["examples/target/wasm32-unknown-unknown/release/*.wasm"])) # These files are necessary for the backend server in the Aggregator example application. exports_files(srcs = glob(["target/release/aggregator_*"])) diff --git a/Cargo.lock b/Cargo.lock index 7e8185880da..e7693ee5913 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -328,17 +328,6 @@ dependencies = [ "serde_json 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "cargo_metadata" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "cc" version = "1.0.52" @@ -1376,7 +1365,6 @@ name = "oak_tests" version = "0.1.0" dependencies = [ "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cargo_metadata 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "oak 0.1.0", @@ -3356,7 +3344,6 @@ dependencies = [ "checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" "checksum bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1" "checksum cargo_metadata 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "700b3731fd7d357223d0000f4dbf1808401b694609035c3c411fbc0cd375c426" -"checksum cargo_metadata 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "46e3374c604fb39d1a2f35ed5e4a4e30e60d01fab49446e08f1b3e9a90aef202" "checksum cc 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)" = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2" diff --git a/examples/aggregator/config/BUILD b/examples/aggregator/config/BUILD index d214400acc5..d9eee50822e 100644 --- a/examples/aggregator/config/BUILD +++ b/examples/aggregator/config/BUILD @@ -26,7 +26,7 @@ exports_files(srcs = glob(["*.textproto"])) serialized_config( name = "config", modules = { - "app": "//:target/wasm32-unknown-unknown/release/aggregator.wasm", + "app": "//:examples/target/wasm32-unknown-unknown/release/aggregator.wasm", }, textproto = ":config.textproto", ) diff --git a/examples/chat/config/BUILD b/examples/chat/config/BUILD index cebfcdb94da..64348733342 100644 --- a/examples/chat/config/BUILD +++ b/examples/chat/config/BUILD @@ -25,7 +25,7 @@ exports_files(srcs = glob(["*.textproto"])) serialized_config( name = "config", modules = { - "app": "//:target/wasm32-unknown-unknown/release/chat.wasm", + "app": "//:examples/target/wasm32-unknown-unknown/release/chat.wasm", }, textproto = ":config.textproto", ) diff --git a/examples/hello_world/config/BUILD b/examples/hello_world/config/BUILD index 845841a9a77..22703405dd6 100644 --- a/examples/hello_world/config/BUILD +++ b/examples/hello_world/config/BUILD @@ -26,8 +26,8 @@ exports_files(srcs = glob(["*.textproto"])) serialized_config( name = "config", modules = { - "app": "//:target/wasm32-unknown-unknown/release/hello_world.wasm", - "translator": "//:target/wasm32-unknown-unknown/release/translator.wasm", + "app": "//:examples/target/wasm32-unknown-unknown/release/hello_world.wasm", + "translator": "//:examples/target/wasm32-unknown-unknown/release/translator.wasm", }, textproto = ":config.textproto", ) diff --git a/examples/machine_learning/config/BUILD b/examples/machine_learning/config/BUILD index 7b890776472..c5e715d69d2 100644 --- a/examples/machine_learning/config/BUILD +++ b/examples/machine_learning/config/BUILD @@ -25,7 +25,7 @@ exports_files(srcs = glob(["*.textproto"])) serialized_config( name = "config", modules = { - "app": "//:target/wasm32-unknown-unknown/release/machine_learning.wasm", + "app": "//:examples/target/wasm32-unknown-unknown/release/machine_learning.wasm", }, textproto = ":config.textproto", ) diff --git a/examples/private_set_intersection/config/BUILD b/examples/private_set_intersection/config/BUILD index b69ea229bd5..c665b561027 100644 --- a/examples/private_set_intersection/config/BUILD +++ b/examples/private_set_intersection/config/BUILD @@ -25,7 +25,7 @@ exports_files(srcs = glob(["*.textproto"])) serialized_config( name = "config", modules = { - "app": "//:target/wasm32-unknown-unknown/release/private_set_intersection.wasm", + "app": "//:examples/target/wasm32-unknown-unknown/release/private_set_intersection.wasm", }, textproto = ":config.textproto", ) diff --git a/examples/running_average/config/BUILD b/examples/running_average/config/BUILD index 5912581d93e..c8c30d62937 100644 --- a/examples/running_average/config/BUILD +++ b/examples/running_average/config/BUILD @@ -25,7 +25,7 @@ exports_files(srcs = glob(["*.textproto"])) serialized_config( name = "config", modules = { - "app": "//:target/wasm32-unknown-unknown/release/running_average.wasm", + "app": "//:examples/target/wasm32-unknown-unknown/release/running_average.wasm", }, textproto = ":config.textproto", ) diff --git a/examples/rustfmt/config/BUILD b/examples/rustfmt/config/BUILD index ffb258200a1..1f3f84e74a4 100644 --- a/examples/rustfmt/config/BUILD +++ b/examples/rustfmt/config/BUILD @@ -25,7 +25,7 @@ exports_files(srcs = glob(["*.textproto"])) serialized_config( name = "config", modules = { - "app": "//:target/wasm32-unknown-unknown/release/rustfmt.wasm", + "app": "//:examples/target/wasm32-unknown-unknown/release/rustfmt.wasm", }, textproto = ":config.textproto", ) diff --git a/examples/translator/config/BUILD b/examples/translator/config/BUILD index 6dda7d84baf..641405c3638 100644 --- a/examples/translator/config/BUILD +++ b/examples/translator/config/BUILD @@ -25,7 +25,7 @@ exports_files(srcs = glob(["*.textproto"])) serialized_config( name = "config", modules = { - "app": "//:target/wasm32-unknown-unknown/release/translator.wasm", + "app": "//:examples/target/wasm32-unknown-unknown/release/translator.wasm", }, textproto = ":config.textproto", ) diff --git a/scripts/build_example b/scripts/build_example index 20622352bc9..6bcdc248e77 100755 --- a/scripts/build_example +++ b/scripts/build_example @@ -48,16 +48,18 @@ fi case "${language}" in rust) for module in examples/"${EXAMPLE}"/module*/rust/Cargo.toml; do - cargo build --release --target=wasm32-unknown-unknown --manifest-path="${module}" + # Use a separate target dir for Wasm build artifacts. The precise name is not relevant, but it + # should end with `target` so that it gets automatically ignored by our `.gitignore`. + cargo build --release --target-dir=examples/target --target=wasm32-unknown-unknown --manifest-path="${module}" done # Serialize application configuration for Rust module. if [[ "${EXAMPLE}" == "hello_world" ]]; then # `hello_world` example has an optional additional `translator` module. - cargo build --release --target=wasm32-unknown-unknown --manifest-path="examples/translator/module/rust/Cargo.toml" + cargo build --release --target-dir=examples/target --target=wasm32-unknown-unknown --manifest-path="examples/translator/module/rust/Cargo.toml" elif [[ "${EXAMPLE}" == "aggregator" ]]; then # `aggregator` example has an additional Backend Docker image - cargo build --release --package=aggregator_backend + cargo build --release --target=x86_64-unknown-linux-musl --package=aggregator_backend fi bazel --output_base="${CACHE_DIR}/client" build "${bazel_build_flags[@]}" "//examples/${EXAMPLE}/config:config";; cpp) diff --git a/sdk/rust/oak_tests/Cargo.toml b/sdk/rust/oak_tests/Cargo.toml index 3fcfc29a77d..25a4025adc6 100644 --- a/sdk/rust/oak_tests/Cargo.toml +++ b/sdk/rust/oak_tests/Cargo.toml @@ -7,7 +7,6 @@ license = "Apache-2.0" [dependencies] byteorder = "*" -cargo_metadata = "*" lazy_static = "*" log = { version = "*", features = ["std"] } oak = "=0.1.0" diff --git a/sdk/rust/oak_tests/src/lib.rs b/sdk/rust/oak_tests/src/lib.rs index e0ab27dec08..4401a18f9b6 100644 --- a/sdk/rust/oak_tests/src/lib.rs +++ b/sdk/rust/oak_tests/src/lib.rs @@ -22,20 +22,24 @@ use oak_abi::proto::oak::application::{ WebAssemblyConfiguration, }; use prost::Message; -use std::{collections::HashMap, process::Command}; +use std::{collections::HashMap, path::PathBuf, process::Command}; use tonic::transport::Certificate; // TODO(#544): re-enable unit tests of SDK functionality /// Uses cargo to compile a Rust manifest to Wasm bytes. pub fn compile_rust_wasm(cargo_path: &str, module_name: &str) -> std::io::Result> { - let mut cmd = cargo_metadata::MetadataCommand::new(); - cmd.manifest_path(cargo_path); - let metadata = cmd.exec().unwrap(); + // Use a separate target dir for Wasm build artifacts. The precise name is not relevant, but it + // should end with `target` so that it gets automatically ignored by our `.gitignore`. + let target_dir = PathBuf::from("oak_tests/target"); Command::new("cargo") .args(&[ "build", + &format!( + "--target-dir={}", + target_dir.to_str().expect("invalid target dir") + ), "--target=wasm32-unknown-unknown", &format!("--manifest-path={}", cargo_path), ]) @@ -43,11 +47,13 @@ pub fn compile_rust_wasm(cargo_path: &str, module_name: &str) -> std::io::Result .spawn()? .wait()?; - let mut path = metadata.target_directory; - path.push("wasm32-unknown-unknown/debug"); - path.push(module_name); + let mut module_path = target_dir; + module_path.push("wasm32-unknown-unknown/debug"); + module_path.push(module_name); - std::fs::read(path) + info!("compiled Wasm module path: {:?}", module_path); + + std::fs::read(module_path) } const DEFAULT_ENTRYPOINT_NAME: &str = "oak_main";