File size: 2,296 Bytes
3374e90 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #!/usr/bin/env bash
# Build and pack all BEX plugins
#
# This script:
# 1. Compiles all plugins to WASM (wasm32-wasip1)
# 2. Converts them to WASM components (using wasm-tools)
# 3. Packs them into .bex packages
#
# Requirements: cargo, wasm-tools (cargo install wasm-tools-cli)
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
PLUGINS=(bex-gogoanime bex-kaianime bex-hianime bex-imdb bex-kisskh)
WASI_ADAPTER=""
# Find WASI adapter
for dir in ~/.cargo/registry/src/index.crates.io-*/wasi-preview1-component-adapter-provider-*/artefacts/; do
if [ -f "${dir}wasi_snapshot_preview1.reactor.wasm" ]; then
WASI_ADAPTER="${dir}wasi_snapshot_preview1.reactor.wasm"
break
fi
done
if [ -z "$WASI_ADAPTER" ]; then
echo "ERROR: WASI adapter not found. Run 'cargo build -p bex-gogoanime --target wasm32-wasip1' first to download it."
exit 1
fi
echo "=== Building WASM plugins ==="
cargo build --target wasm32-wasip1 --release ${PLUGINS[*]/#/-p }
echo ""
echo "=== Converting to components ==="
mkdir -p target/components
for plugin in "${PLUGINS[@]}"; do
# Convert underscore to hyphen for the WASM file name
wasm_name="${plugin/-/_}"
wasm_path="target/wasm32-wasip1/release/${wasm_name}.wasm"
component_path="target/components/${plugin}.component.wasm"
if [ ! -f "$wasm_path" ]; then
echo " SKIP: $plugin (WASM not found)"
continue
fi
echo " Converting: $plugin"
wasm-tools component new "$wasm_path" -o "$component_path" --adapt "$WASI_ADAPTER"
done
echo ""
echo "=== Packing .bex packages ==="
mkdir -p dist
for plugin in "${PLUGINS[@]}"; do
component_path="target/components/${plugin}.component.wasm"
manifest_path="dist/${plugin}.yaml"
output_path="dist/${plugin}.bex"
if [ ! -f "$component_path" ]; then
echo " SKIP: $plugin (component not found)"
continue
fi
if [ ! -f "$manifest_path" ]; then
echo " SKIP: $plugin (manifest not found at $manifest_path)"
continue
fi
echo " Packing: $plugin"
./target/release/bex pack "$manifest_path" "$component_path" "$output_path"
done
echo ""
echo "=== Done! ==="
echo "Packages in dist/:"
ls -la dist/*.bex 2>/dev/null || echo " (no .bex files)"
|