Skip to content

Commit

Permalink
documented js bindings build script
Browse files Browse the repository at this point in the history
  • Loading branch information
RicBent committed Jun 24, 2024
1 parent f1f36b8 commit c637a69
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 52 deletions.
55 changes: 49 additions & 6 deletions bindings/wasm/build.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,67 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

# Change to the script directory
cd "$(dirname "$0")"

# Get root directory
REPO_ROOT_DIR=$(git rev-parse --show-toplevel)

# Check if emscripten is installed
if ! command -v emcmake &> /dev/null; then
echo "Emscripten is not installed. Please install it and make sure it is in your PATH."
exit 1
fi

# Generate the package structure
mkdir -p package/src/build
mkdir -p package/dist

# Find core count for make. Prefer nproc, then sysctl, then default to 1
if command -v nproc &> /dev/null; then
CORE_COUNT=$(nproc)
elif command -v sysctl &> /dev/null; then
CORE_COUNT=$(sysctl -n hw.logicalcpu)
else
CORE_COUNT=1
fi

# Build the wasm module
mkdir -p build
cd build
emcmake cmake -DCMAKE_BUILD_TYPE=Release -DKIWI_USE_CPUINFO=OFF -DKIWI_BUILD_TEST=OFF -DKIWI_USE_MIMALLOC=OFF -DKIWI_BUILD_CLI=OFF -DKIWI_BUILD_EVALUATOR=OFF -DKIWI_BUILD_MODEL_BUILDER=OFF ../../../
make -j8
emcmake cmake \
-DCMAKE_BUILD_TYPE=Release \
-DKIWI_USE_CPUINFO=OFF \
-DKIWI_USE_MIMALLOC=OFF \
-DKIWI_BUILD_TEST=OFF \
-DKIWI_BUILD_CLI=OFF \
-DKIWI_BUILD_EVALUATOR=OFF \
-DKIWI_BUILD_MODEL_BUILDER=OFF \
$REPO_ROOT_DIR
make -j $CORE_COUNT
cd ..

# Copy the generated files to the package
cp bindings/wasm/kiwi-wasm.js ../package/src/build/kiwi-wasm.js
cp bindings/wasm/kiwi-wasm.wasm ../package/dist/kiwi-wasm.wasm
cp build/bindings/wasm/kiwi-wasm.js package/src/build/kiwi-wasm.js
cp build/bindings/wasm/kiwi-wasm.wasm package/dist/kiwi-wasm.wasm

# Build typescript wrapper package
cd ../package
cd package
npm install
npm run build
cd ..

# Build the demo package if --demo or --demo-dev is passed
# --demo with create a static build
# --demo-dev will start a development server
if [ "$1" == "--demo" ] || [ "$1" == "--demo-dev" ]; then
cd package-demo
npm install
if [ "$1" == "--demo-dev" ]; then
npm run dev
else
npm run build
fi
cd ..
fi
46 changes: 0 additions & 46 deletions bindings/wasm/test.html

This file was deleted.

0 comments on commit c637a69

Please sign in to comment.