fix web build
This commit is contained in:
+38
-17
@@ -11,7 +11,8 @@ echo -e "${GREEN}Building Coop Web...${NC}"
|
||||
|
||||
# Get the script directory
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
PROJECT_ROOT="$SCRIPT_DIR/.."
|
||||
PROJECT_ROOT="$SCRIPT_DIR/../.."
|
||||
WEB_ROOT="$SCRIPT_DIR/.."
|
||||
|
||||
# Parse arguments
|
||||
RELEASE_FLAG=""
|
||||
@@ -20,27 +21,47 @@ if [[ "$1" == "--release" ]]; then
|
||||
echo -e "${YELLOW}Building in release mode${NC}"
|
||||
fi
|
||||
|
||||
# macOS: ensure LLVM from Homebrew is available
|
||||
# wasm_thread requires a nightly compiler for its atomics features
|
||||
CARGO="cargo +nightly"
|
||||
|
||||
# Step 0: Toolchain prerequisites
|
||||
echo -e "${GREEN}Step 0: Checking toolchain...${NC}"
|
||||
rustup target add wasm32-unknown-unknown --toolchain nightly
|
||||
|
||||
if [[ "$(uname)" == "Darwin" ]]; then
|
||||
echo -e "${GREEN}Detected macOS, setting up LLVM...${NC}"
|
||||
if brew list llvm &>/dev/null; then
|
||||
echo -e "${GREEN}LLVM already installed, skipping install${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}LLVM not found, installing via Homebrew...${NC}"
|
||||
brew install llvm
|
||||
# secp256k1-sys compiles C for wasm; Apple clang has the wasm32 target and
|
||||
# llvm-ar for archives comes from the rustup llvm-tools component
|
||||
if ! xcrun --find clang &>/dev/null; then
|
||||
echo -e "${RED}Apple clang not found. Install the Xcode command line tools: xcode-select --install${NC}"
|
||||
exit 1
|
||||
fi
|
||||
LLVM_PATH=$(brew --prefix llvm)
|
||||
export AR="${LLVM_PATH}/bin/llvm-ar"
|
||||
export CC="${LLVM_PATH}/bin/clang"
|
||||
echo -e "${GREEN}LLVM path: ${LLVM_PATH}${NC}"
|
||||
rustup component add llvm-tools-preview --toolchain nightly
|
||||
|
||||
RUSTUP_HOME=$(rustup show home)
|
||||
if [[ "$(uname -m)" == "arm64" ]]; then
|
||||
HOST_ARCH="aarch64-apple-darwin"
|
||||
else
|
||||
HOST_ARCH="x86_64-apple-darwin"
|
||||
fi
|
||||
LLVM_BIN="$RUSTUP_HOME/toolchains/nightly-$HOST_ARCH/lib/rustlib/$HOST_ARCH/bin"
|
||||
|
||||
export CC_wasm32_unknown_unknown=clang
|
||||
export AR_wasm32_unknown_unknown="$LLVM_BIN/llvm-ar"
|
||||
echo -e "${GREEN}Using Apple clang + rustup llvm-ar for wasm32 C code${NC}"
|
||||
fi
|
||||
|
||||
# Match wasm-bindgen-cli to the version in Cargo.lock
|
||||
LOCKED_BINDGEN=$(grep -A1 '^name = "wasm-bindgen"$' "$PROJECT_ROOT/Cargo.lock" | grep version | cut -d'"' -f2)
|
||||
if [[ "$(wasm-bindgen --version 2>/dev/null | awk '{print $2}')" != "$LOCKED_BINDGEN" ]]; then
|
||||
echo -e "${YELLOW}Installing wasm-bindgen-cli $LOCKED_BINDGEN to match Cargo.lock...${NC}"
|
||||
cargo install -f wasm-bindgen-cli --version "$LOCKED_BINDGEN"
|
||||
fi
|
||||
|
||||
# Step 1: Build WASM
|
||||
echo -e "${GREEN}Step 1: Building WASM...${NC}"
|
||||
cd "$PROJECT_ROOT"
|
||||
export CARGO_TARGET_DIR="$PROJECT_ROOT/target"
|
||||
RUSTFLAGS='-C target-feature=+bulk-memory -C link-arg=--max-memory=4294967296' \
|
||||
cargo build --target wasm32-unknown-unknown $RELEASE_FLAG
|
||||
$CARGO build -p coop_web --target wasm32-unknown-unknown $RELEASE_FLAG
|
||||
|
||||
# Determine the build directory
|
||||
if [[ "$RELEASE_FLAG" == "--release" ]]; then
|
||||
@@ -61,12 +82,12 @@ fi
|
||||
# Step 2: Generate JavaScript bindings
|
||||
echo -e "${GREEN}Step 2: Generating JavaScript bindings...${NC}"
|
||||
wasm-bindgen "$WASM_PATH" \
|
||||
--out-dir "$PROJECT_ROOT/www/wasm" \
|
||||
--out-dir "$WEB_ROOT/www/wasm" \
|
||||
--target web \
|
||||
--no-typescript
|
||||
|
||||
echo -e "${GREEN}✓ Build completed successfully!${NC}"
|
||||
echo -e "${YELLOW}Next steps:${NC}"
|
||||
echo -e " cd www"
|
||||
echo -e " cd web/www"
|
||||
echo -e " deno install"
|
||||
echo -e " deno run dev"
|
||||
echo -e " deno task dev"
|
||||
|
||||
Reference in New Issue
Block a user