Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WebAssembly version with JavaScript bindings #303

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/build_wasm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: Build WebAssembly

on: [push, pull_request]

jobs:
linux:
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
cd ..
make wasm

mac:
strategy:
fail-fast: false
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- run: |
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
cd ..
make wasm
14 changes: 13 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ jobs:
- name: Install Python dependencies
run: |
pip install sphinx sphinx-rtd-theme breathe docutils
- name: Build wasm
run: |
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
cd ..
make wasm
cp out/scs.js docs/src/_static/
cp out/scs.wasm docs/src/_static/
- name: Build docs
run: |
cd docs/src && make docs && touch ../.nojekyll
Expand All @@ -27,4 +38,5 @@ jobs:
with:
branch: gh-pages # The branch the action should deploy to.
folder: docs # The folder the action should deploy.



34 changes: 33 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SRC_FILES = $(wildcard src/*.c)
INC_FILES = $(wildcard include/*.h)

AMD_SOURCE = $(wildcard $(EXTSRC)/amd/*.c)
LDL_SOURCE = $(EXTSRC)/qdldl/qdldl.c
LDL_SOURCE = $(wildcard $(EXTSRC)/qdldl/qdldl.c)
AMD_OBJS = $(AMD_SOURCE:.c=.o)
LDL_OBJS = $(LDL_SOURCE:.c=.o)
TARGETS = $(OUT)/demo_socp_indirect $(OUT)/demo_socp_direct $(OUT)/run_from_file_indirect $(OUT)/run_from_file_direct
Expand All @@ -36,6 +36,13 @@ $(SCS_O): src/scs.c $(INC_FILES)
$(SCS_INDIR_O): src/scs.c $(INC_FILES)
$(CC) $(CFLAGS) -DINDIRECT=1 -c $< -o $@

$(EXTSRC)/amd/%.o: $(EXTSRC)/amd/%.c
$(CC) $(CFLAGS) -c $< -o $@

$(EXTSRC)/qdldl/%.o: $(EXTSRC)/qdldl/%.c
$(CC) $(CFLAGS) -c $< -o $@


%.o : src/%.c
$(CC) $(CFLAGS) -c $< -o $@

Expand Down Expand Up @@ -166,6 +173,31 @@ $(OUT)/libscsgpuindir.a: $(SCS_INDIR_O) $(SCS_OBJECTS) $(GPUINDIR)/private.o $(L
$(OUT)/demo_socp_gpu_indirect: test/random_socp_prob.c $(OUT)/libscsgpuindir.a
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(BLASLDFLAGS) $(CULDFLAGS)

# Add wasm targets
WASM_TARGETS = $(OUT)/scs.wasm $(OUT)/scs.js

WASM_SRC = src/scs.c src/util.c src/cones.c src/exp_cone.c src/aa.c src/rw.c \
src/linalg.c src/ctrlc.c src/scs_version.c src/normalize.c \
$(DIRSRC)/private.c $(AMD_OBJS) $(LDL_OBJS) $(LINSYS)/scs_matrix.c $(LINSYS)/csparse.c

WASM_SRC += bindings/embind/scs_bindings.cpp

.PHONY: wasm
wasm: CC = emcc
wasm: $(WASM_TARGETS)

$(OUT)/scs.wasm $(OUT)/scs.js: $(WASM_SRC)
mkdir -p $(OUT)
emcc $(CFLAGS) -o $(OUT)/scs.js $^ \
-s WASM=1 \
--bind \
-g0 \
-Os \
-s ALLOW_MEMORY_GROWTH=1 \
-s MODULARIZE \
-s 'EXPORT_NAME="createSCS"'
$(LDFLAGS)

.PHONY: clean purge
clean:
@rm -rf $(TARGETS) $(SCS_O) $(SCS_INDIR_O) $(SCS_OBJECTS) $(AMD_OBJS) $(LDL_OBJS) $(LINSYS)/*.o $(DIRSRC)/*.o $(INDIRSRC)/*.o $(MKLSRC)/*.o $(GPUDIR)/*.o $(GPUINDIR)/*.o $(LINSYS)/gpu/*.o
Expand Down
Loading
Loading