2023-10-02 23:02:53 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-10-03 09:48:12 +03:00
|
|
|
debug_flag="--release"
|
2023-10-02 23:02:53 +03:00
|
|
|
|
2023-10-03 08:28:00 +03:00
|
|
|
# Grab the full path to the target
|
|
|
|
target_path="$1"
|
|
|
|
name=$(basename "$target_path")
|
2023-10-02 23:02:53 +03:00
|
|
|
|
2023-10-03 09:48:12 +03:00
|
|
|
if [[ "$2" == "--debug" ]]; then
|
|
|
|
debug_flag=""
|
2023-10-02 23:02:53 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
pwd=$(pwd)
|
|
|
|
|
2023-10-03 08:28:00 +03:00
|
|
|
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; }
|
2023-10-02 23:02:53 +03:00
|
|
|
|
2023-10-03 08:28:00 +03:00
|
|
|
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; }
|
2023-10-02 23:02:53 +03:00
|
|
|
|
2023-10-03 08:28:00 +03:00
|
|
|
mkdir -p "$target_path/target/wasm32-unknown-unknown/release" || { echo "Command failed"; exit 1; }
|
2023-10-02 23:02:53 +03:00
|
|
|
|
|
|
|
# Build the module using Cargo
|
2023-10-03 08:28:00 +03:00
|
|
|
cargo +nightly build \
|
2023-10-06 07:12:31 +03:00
|
|
|
$debug_flag \
|
2023-10-02 23:02:53 +03:00
|
|
|
--no-default-features \
|
2023-10-03 08:28:00 +03:00
|
|
|
--manifest-path="$target_path/Cargo.toml" \
|
2023-10-02 23:02:53 +03:00
|
|
|
--target "wasm32-wasi" || {
|
|
|
|
echo "Command failed"; exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Adapt the module using wasm-tools
|
2023-10-03 08:28:00 +03:00
|
|
|
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; }
|
2023-10-02 23:02:53 +03:00
|
|
|
|
|
|
|
# Embed "wit" into the component and place it in the expected location
|
2023-10-03 08:28:00 +03:00
|
|
|
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; }
|