From b8bd9e1fe168495f4e0aceebd3f1e77d5e3795ad Mon Sep 17 00:00:00 2001 From: Akira Moroo Date: Sat, 21 Jun 2025 18:44:55 +0900 Subject: [PATCH] Add WebAssembly build to CI Signed-off-by: Akira Moroo --- .github/workflows/ci.yml | 4 +++- .gitignore | 4 ++++ Makefile | 14 ++++++++++++++ README.md | 11 +++++++++++ docs/AGENT_PROMPTS.md | 1 + main.cpp | 6 ++++++ web/index.html | 24 ++++++++++++++++++++++++ 7 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 web/index.html diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20ad38a..5941684 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: wget https://packages.apache.org/artifactory/arrow/$(lsb_release --id --short | tr 'A-Z' 'a-z')/apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb sudo apt install -y ./apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb sudo apt-get update - sudo apt-get install -y g++ make clang-tidy clang-format python3 python3-pip libarrow-dev libparquet-dev + sudo apt-get install -y g++ make clang-tidy clang-format python3 python3-pip libarrow-dev libparquet-dev emscripten pip3 install pandas pyarrow pytest - name: Build run: make USE_ARROW=${{ matrix.arrow }} @@ -32,3 +32,5 @@ jobs: run: make tidy - name: Run test run: make USE_ARROW=${{ matrix.arrow }} test + - name: Build WebAssembly + run: make web diff --git a/.gitignore b/.gitignore index c6795f1..865bdef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ main spikes.bin +web/main.js +web/main.wasm +web/main.data +test/__pycache__/ diff --git a/Makefile b/Makefile index c4064d9..6cf2337 100644 --- a/Makefile +++ b/Makefile @@ -35,3 +35,17 @@ submodule: git submodule update --init --recursive .PHONY: clean format tidy test submodule bench + +WEB_DIR = web +WEB_TARGET = $(WEB_DIR)/main.js + +$(WEB_TARGET): main.cpp + mkdir -p $(WEB_DIR) + em++ $< -O3 -std=c++20 -s WASM=1 -s MODULARIZE=1 \ + -s EXPORTED_FUNCTIONS="['_run_simulation_c']" \ + -s EXPORTED_RUNTIME_METHODS="['cwrap','FS']" \ + --preload-file test -o $(WEB_TARGET) + +web: $(WEB_TARGET) + +.PHONY: web diff --git a/README.md b/README.md index db47317..7bb3805 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,17 @@ make This produces an executable named `main`. To enable Apache Arrow support pass `USE_ARROW=1` (requires Arrow C++ libraries with `pkg-config` files). +### WebAssembly + +Emscripten can build the simulator to WebAssembly. Install `em++` and run: + +```bash +make web +``` + +The generated `web/` directory contains `main.js`, `main.wasm`, and a small +`index.html` that runs the example dataset in your browser. + ## Running Run the simulator by providing a connectome CSV file and lists of active and silent neurons. When built with Arrow support you may provide a Parquet file instead: diff --git a/docs/AGENT_PROMPTS.md b/docs/AGENT_PROMPTS.md index 85375ec..9acd849 100644 --- a/docs/AGENT_PROMPTS.md +++ b/docs/AGENT_PROMPTS.md @@ -9,6 +9,7 @@ The project simulates spikes in a Drosophila connectome using a leaky integrate- - Keep the simulator self contained in `main.cpp` unless new modules are justified. - Unit tests live under `test/` and should be expanded when new features are added. - Large datasets are provided via the optional `Drosophila_brain_model` submodule and should not be committed directly to the repository. Support for loading Parquet files via Apache Arrow is optional and can be enabled by building with `USE_ARROW=1`. +- WebAssembly builds can be generated with `make web` when Emscripten is available. ## Pull Request Guidance diff --git a/main.cpp b/main.cpp index b862152..00506d2 100644 --- a/main.cpp +++ b/main.cpp @@ -284,6 +284,12 @@ size_t run_simulation(const string &csv, const string &pq, const string &act, return S.spikes.size(); } +extern "C" size_t run_simulation_c(const char *csv, const char *pq, + const char *act, const char *sil, size_t T) { + return run_simulation(csv ? string(csv) : "", pq ? string(pq) : "", + act ? string(act) : "", sil ? string(sil) : "", T); +} + #ifndef BENCH_LIB int main(int argc, char **argv) { string csv, pq, act, sil; diff --git a/web/index.html b/web/index.html new file mode 100644 index 0000000..6371dc0 --- /dev/null +++ b/web/index.html @@ -0,0 +1,24 @@ + + + + + Drosophila WASM Demo + + +

Drosophila WebAssembly Demo

+ +

+    
+
+