mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-06 08:07:49 +00:00
31 lines
1.1 KiB
Bash
Executable File
31 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Builds Rust plugins into WebAssembly components (wasm32-wasip2 emits a
|
|
# component directly; no cargo-component / wasm-tools needed).
|
|
#
|
|
# plugins/build.sh # all plugins with a Cargo.toml
|
|
# plugins/build.sh hello # one plugin
|
|
#
|
|
# Output: <plugin>/dist/plugin.wasm (referenced by `wasm = ...` in plugin.toml).
|
|
set -euo pipefail
|
|
here="$(cd "$(dirname "$0")" && pwd)"
|
|
rustup target list --installed | grep -qx wasm32-wasip2 || rustup target add wasm32-wasip2
|
|
|
|
build() {
|
|
local dir="$1"
|
|
local name
|
|
name="$(sed -n 's/^name *= *"\(.*\)"/\1/p' "$dir/Cargo.toml" | head -1)"
|
|
echo "building $name ($dir)"
|
|
CARGO_TARGET_DIR="$dir/target" cargo build --manifest-path "$dir/Cargo.toml" --release --target wasm32-wasip2
|
|
mkdir -p "$dir/dist"
|
|
cp "$dir/target/wasm32-wasip2/release/${name//-/_}.wasm" "$dir/dist/plugin.wasm"
|
|
echo " -> $dir/dist/plugin.wasm ($(wc -c < "$dir/dist/plugin.wasm" | tr -d " ") bytes)"
|
|
}
|
|
|
|
if [ $# -gt 0 ]; then
|
|
for p in "$@"; do
|
|
case "$p" in /*) build "$p" ;; *) build "$here/$p" ;; esac
|
|
done
|
|
else
|
|
for manifest in "$here"/*/Cargo.toml; do build "$(dirname "$manifest")"; done
|
|
fi
|