small fixes to kv; build.rs working much better now

This commit is contained in:
dr-frmr 2023-10-24 17:26:33 -04:00
parent 41ba7ed7ea
commit 8e36d7776a
No known key found for this signature in database
4 changed files with 21 additions and 89 deletions

View File

@ -1,37 +0,0 @@
#!/bin/bash
debug_flag="--release"
# Grab the full path to the target
target_path="$1"
name=$(basename "$target_path")
if [[ "$2" == "--debug" ]]; then
debug_flag=""
fi
pwd=$(pwd)
rm -rf "$target_path/wit" || { echo "Command failed"; exit 1; }
cp -r wit "$target_path" || { echo "Command failed"; exit 1; }
mkdir -p "$target_path/target/bindings/$name" || { echo "Command failed"; exit 1; }
cp target.wasm "$target_path/target/bindings/$name/" || { echo "Command failed"; exit 1; }
cp world "$target_path/target/bindings/$name/" || { echo "Command failed"; exit 1; }
mkdir -p "$target_path/target/wasm32-unknown-unknown/release" || { echo "Command failed"; exit 1; }
# Build the module using Cargo
cargo +nightly build \
$debug_flag \
--no-default-features \
--manifest-path="$target_path/Cargo.toml" \
--target "wasm32-wasi" || {
echo "Command failed"; exit 1;
}
# Adapt the module using wasm-tools
wasm-tools component new "$target_path/target/wasm32-wasi/release/$name.wasm" -o "$target_path/target/wasm32-wasi/release/${name}_adapted.wasm" --adapt "$pwd/wasi_snapshot_preview1.wasm" || { echo "Command failed"; exit 1; }
# Embed "wit" into the component and place it in the expected location
wasm-tools component embed wit --world uq-process "$target_path/target/wasm32-wasi/release/${name}_adapted.wasm" -o "$target_path/target/wasm32-unknown-unknown/release/$name.wasm" || { echo "Command failed"; exit 1; }

View File

@ -36,16 +36,17 @@ where
fn build_app(target_path: &str, name: &str, parent_pkg_path: Option<&str>) {
let pwd = std::env::current_dir().unwrap();
println!("cargo:warning=building {}", target_path);
let start = std::time::Instant::now();
// Copy in newly-made wit IF old one is outdated
// if and only if module's wit is outdated, re-set-up build environment
if file_outdated(
format!("{}/wit/", pwd.display()),
format!("{}/modules/{}/wit/", target_path, name),
format!("{}/wit/uqbar.wit", pwd.display()),
format!("{}/wit/uqbar.wit", target_path),
)
.unwrap_or(true)
{
run_command(Command::new("cp").args(&["-r", "wit", target_path])).unwrap();
println!("cargo:warning=wit outdated, rebuilding");
run_command(Command::new("cp").args(&["wit/uqbar.wit", &format!("{}/wit", target_path)])).unwrap();
// create target/bindings directory
fs::create_dir_all(&format!("{}/target/bindings/{}", target_path, name,)).unwrap();
// copy newly-made target.wasm into target/bindings
@ -63,6 +64,7 @@ fn build_app(target_path: &str, name: &str, parent_pkg_path: Option<&str>) {
}
// Build the module targeting wasm32-wasi
run_command(Command::new("cargo").args(&[
"+nightly",
"build",
"--release",
"--no-default-features",
@ -71,6 +73,7 @@ fn build_app(target_path: &str, name: &str, parent_pkg_path: Option<&str>) {
"wasm32-wasi",
]))
.unwrap();
// Adapt module to component with adapter based on wasi_snapshot_preview1.wasm
run_command(Command::new("wasm-tools").args(&[
"component",
@ -110,6 +113,13 @@ fn build_app(target_path: &str, name: &str, parent_pkg_path: Option<&str>) {
&wasm_dest_path,
]))
.unwrap();
let end = std::time::Instant::now();
println!(
"cargo:warning=building {} took {:?}",
target_path,
end.duration_since(start)
);
}
fn main() {
@ -117,47 +127,6 @@ fn main() {
println!("Skipping build script");
return;
}
let build_enabled = std::env::var("BUILD_APPS")
.map(|v| v == "true")
.unwrap_or(true); // run by default
if !build_enabled {
return;
}
// only execute if one of the modules has source code changes
const WASI_APPS: [&str; 7] = [
"app_store",
"chess",
"homepage",
"http_proxy",
"orgs",
"qns_indexer",
"terminal",
];
// NOT YET building KV, waiting for deps to be ready
const NESTED_WASI_APPS: [(&str, &str); 2] = [
("key_value", "key_value"),
("key_value", "key_value_worker"),
];
if std::env::var("REBUILD_ALL").is_ok() {
} else {
for name in &WASI_APPS {
println!("cargo:rerun-if-changed=modules/{}/src", name);
println!("cargo:rerun-if-changed=modules/{}/Cargo.toml", name);
println!("cargo:rerun-if-changed=modules/{}/pkg/manifest.json", name);
println!("cargo:rerun-if-changed=modules/{}/pkg/metadata.json", name);
}
for (outer, inner) in &NESTED_WASI_APPS {
println!("cargo:rerun-if-changed=modules/{}/{}/src", outer, inner);
println!(
"cargo:rerun-if-changed=modules/{}/{}/Cargo.toml",
outer, inner
);
println!("cargo:rerun-if-changed=modules/{}/pkg/manifest.json", outer);
println!("cargo:rerun-if-changed=modules/{}/pkg/metadata.json", outer);
}
}
let pwd = std::env::current_dir().unwrap();
// Create target.wasm (compiled .wit) & world
@ -178,11 +147,6 @@ fn main() {
let entry_path = entry.unwrap().path();
let package_name = entry_path.file_name().unwrap().to_str().unwrap();
// NOT YET building KV, waiting for deps to be ready
if package_name == "key_value" {
continue;
}
// If Cargo.toml is present, build the app
let parent_pkg_path = format!("{}/pkg", entry_path.display());
if entry_path.join("Cargo.toml").exists() {

View File

@ -191,6 +191,7 @@ impl Guest for Component {
if let Some(e) = e.downcast_ref::<kv::KeyValueError>() {
send_response(
&Response {
inherit: false,
ipc: Some(serde_json::to_string(&e).unwrap()),
metadata: None,
},

View File

@ -42,7 +42,7 @@ fn send_and_await_response_wrapped(
};
let (
_,
Message::Response((Response { ipc, metadata }, _)),
Message::Response((Response { ipc, metadata, .. }, _)),
) = send_and_await_response(
&Address {
node: target_node,
@ -118,6 +118,7 @@ fn handle_message (
send_response(
&Response {
inherit: false,
ipc,
metadata: None,
},
@ -137,6 +138,7 @@ fn handle_message (
None => {
send_response(
&Response {
inherit: false,
ipc,
metadata: None,
},
@ -155,6 +157,7 @@ fn handle_message (
);
send_response(
&Response {
inherit: false,
ipc,
metadata: None,
},
@ -193,6 +196,7 @@ impl Guest for Component {
if let Some(e) = e.downcast_ref::<kv::KeyValueError>() {
send_response(
&Response {
inherit: false,
ipc: Some(serde_json::to_string(&e).unwrap()),
metadata: None,
},