new plugin system

This commit is contained in:
KingKDot
2026-03-19 16:29:26 -05:00
parent 2aeac06b1a
commit cf314b5189
31 changed files with 1942 additions and 517 deletions
+46 -12
View File
@@ -3,31 +3,65 @@ set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PLUGIN_DIR="${1:-${ROOT_DIR}/plugin-sample-go}"
WASM_DIR="${PLUGIN_DIR}/wasm"
NATIVE_DIR="${PLUGIN_DIR}/native"
PLUGIN_NAME="sample"
WASM_OUT="${PLUGIN_DIR}/${PLUGIN_NAME}.wasm"
ZIP_OUT="${PLUGIN_DIR}/${PLUGIN_NAME}.zip"
if [[ ! -d "${WASM_DIR}" ]]; then
echo "[error] wasm folder not found: ${WASM_DIR}" >&2
if [[ ! -d "${NATIVE_DIR}" ]]; then
echo "[error] native folder not found: ${NATIVE_DIR}" >&2
exit 1
fi
pushd "${WASM_DIR}" >/dev/null
pushd "${NATIVE_DIR}" >/dev/null
echo "[build] go build -o ${WASM_OUT} (GOOS=wasip1 GOARCH=wasm)"
if ! GOOS=wasip1 GOARCH=wasm go build -o "${WASM_OUT}" .; then
echo "[warn] go build failed, trying tinygo"
echo "[build] tinygo build -o ${WASM_OUT} -target wasi -scheduler=none -gc=leaking ."
tinygo build -o "${WASM_OUT}" -target wasi -scheduler=none -gc=leaking .
fi
# Detect current OS/arch for default build
HOST_OS="$(go env GOOS)"
HOST_ARCH="$(go env GOARCH)"
# Build matrix - can be overridden with BUILD_TARGETS env var
# Format: "os-arch os-arch ..." e.g. "linux-amd64 linux-arm64 darwin-arm64"
DEFAULT_TARGETS="${HOST_OS}-${HOST_ARCH}"
BUILD_TARGETS="${BUILD_TARGETS:-${DEFAULT_TARGETS}}"
BUILT_FILES=()
for target in ${BUILD_TARGETS}; do
os="${target%%-*}"
arch="${target#*-}"
if [[ "${os}" == "windows" ]]; then
ext="dll"
elif [[ "${os}" == "darwin" ]]; then
ext="dylib"
else
ext="so"
fi
buildmode="c-shared"
outfile="${PLUGIN_DIR}/${PLUGIN_NAME}-${os}-${arch}.${ext}"
echo "[build] GOOS=${os} GOARCH=${arch} CGO_ENABLED=1 go build -buildmode=${buildmode} -o ${outfile}"
CGO_ENABLED=1 GOOS="${os}" GOARCH="${arch}" go build -buildmode="${buildmode}" -o "${outfile}" .
BUILT_FILES+=("${PLUGIN_NAME}-${os}-${arch}.${ext}")
done
popd >/dev/null
rm -f "${ZIP_OUT}"
# Collect files to zip
ZIP_FILES=()
for bf in "${BUILT_FILES[@]}"; do
ZIP_FILES+=("${bf}")
done
# Add web assets
for asset in "${PLUGIN_NAME}.html" "${PLUGIN_NAME}.css" "${PLUGIN_NAME}.js"; do
if [[ -f "${PLUGIN_DIR}/${asset}" ]]; then
ZIP_FILES+=("${asset}")
fi
done
if command -v zip >/dev/null 2>&1; then
(cd "${PLUGIN_DIR}" && zip -q "${ZIP_OUT}" "${PLUGIN_NAME}.wasm" "${PLUGIN_NAME}.html" "${PLUGIN_NAME}.css" "${PLUGIN_NAME}.js")
(cd "${PLUGIN_DIR}" && zip -q "${ZIP_OUT}" "${ZIP_FILES[@]}")
else
echo "[error] zip not found. Please install zip." >&2
exit 1