Skip to content
Merged
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
67 changes: 67 additions & 0 deletions .github/workflows/build_web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: build_web

on:
push:
pull_request:

concurrency:
group: build-web-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v5
with:
submodules: true
fetch-depth: 0

- name: install system deps
run: sudo apt-get update && sudo apt-get install -y ninja-build

- name: setup emsdk
uses: mymindstorm/setup-emsdk@v14
with:
version: 4.0.23
actions-cache-folder: emsdk-cache-4.0.23

- name: verify EMSDK env
run: |
echo "EMSDK=$EMSDK"
test -n "$EMSDK"
emcc --version

- name: pin global typescript for emscripten --emit-tsd
run: |
sudo npm i -g typescript@5.9
which tsc
tsc --version

- name: configure wasm
run: cmake --preset wasm-release

- name: build wasm
run: cmake --build --preset wasm-release -j

- name: setup node
uses: actions/setup-node@v5
with:
node-version: '22'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
cache-dependency-path: web/package-lock.json

# Use the npm version pinned via "packageManager" in web/package.json
# so contributors and CI produce identical lockfile shapes.
- name: enable corepack
run: corepack enable

- name: install js deps
working-directory: web
run: npm ci

- name: build js package
working-directory: web
run: npm run build
105 changes: 105 additions & 0 deletions .github/workflows/publish_web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: publish_web

on:
push:
tags:
- 'v*.*.*'

concurrency:
group: publish-web
cancel-in-progress: false

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: checkout
uses: actions/checkout@v5
with:
submodules: true
fetch-depth: 0

- name: install system deps
run: sudo apt-get update && sudo apt-get install -y ninja-build

- name: setup emsdk
uses: mymindstorm/setup-emsdk@v14
with:
version: 4.0.23
actions-cache-folder: emsdk-cache-4.0.23

- name: verify EMSDK env
run: |
echo "EMSDK=$EMSDK"
test -n "$EMSDK"
emcc --version

- name: pin global typescript for emscripten --emit-tsd
run: |
sudo npm i -g typescript@5.9
which tsc
tsc --version

- name: configure wasm
run: cmake --preset wasm-release

- name: build wasm
run: cmake --build --preset wasm-release -j

- name: setup node
uses: actions/setup-node@v5
with:
node-version: '22'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
cache-dependency-path: web/package-lock.json

# Use the npm version pinned via "packageManager" in web/package.json
# so contributors and CI produce identical lockfile shapes.
- name: enable corepack
run: corepack enable

- name: install js deps
working-directory: web
run: npm ci

- name: derive version + dist-tag
id: meta
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
if [[ "$version" == *-* ]]; then
tag="next"
else
tag="latest"
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "dist_tag=$tag" >> "$GITHUB_OUTPUT"
echo "Publishing $version under dist-tag $tag"

- name: stamp package version
working-directory: web
run: npm version "${{ steps.meta.outputs.version }}" --no-git-tag-version --allow-same-version

- name: build js package
working-directory: web
run: npm run build

- name: npm publish
working-directory: web
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --access public --provenance --tag "${{ steps.meta.outputs.dist_tag }}"

- name: summary
shell: bash
run: |
{
echo "### Anira Web published"
echo ""
echo "- **Version:** \`${{ steps.meta.outputs.version }}\`"
echo "- **dist-tag:** \`${{ steps.meta.outputs.dist_tag }}\`"
} >> "$GITHUB_STEP_SUMMARY"
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.idea*
*.DS_Store
/build/
/out/
/build*/
modules/libtorch*
modules/onnxruntime*
Expand All @@ -9,9 +11,16 @@ cmake-build*
logs/
results/
venv/
web/wasm/
web/dist/
**/node_modules/**
extras/models/stateful-rnn/stateful-lstm/
extras/models/hybrid-nn/GuitarLSTM/
extras/models/cnn/steerable-nafx/
extras/models/model-pool/example-models/
extras/models/third-party/ircam-acids/RAVE/
extras/**/*.json
extras/**/*.json

# Auto-generated TypeDoc artifacts for the Anira Web docs (consumed by sphinx-js).
docs/typedoc/node_modules/
docs/typedoc/package-lock.json
53 changes: 48 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,49 @@ option(ANIRA_WITH_LIBTORCH "Build with LibTorch backend" ON)
option(ANIRA_WITH_ONNXRUNTIME "Build with ONNX Runtime backend" ON)
option(ANIRA_WITH_TFLITE "Build with TensorFlow Lite backend" ON)

option(ANIRA_BUILD_WASM "Build WebAssembly module (requires Emscripten toolchain)" OFF)

option(ANIRA_WITH_LOGGING "Enable logging printouts" ON)
option(ANIRA_WITH_RTSAN "Enable RealtimeSanitizer (rtan) checks (requires clang 20)" OFF)

if(DEFINED EMSDK_VERSION)
set(DEFINED EMSDK_VERSION ON)
if(ANIRA_WITH_EXAMPLES)
message(FATAL_ERROR "WebAssembly support is not compatible with examples. Please disable ANIRA_WITH_EXAMPLES to build the library with WebAssembly support.")
elseif(ANIRA_WITH_TESTS)
message(FATAL_ERROR "WebAssembly support is not compatible with tests. Please disable ANIRA_WITH_TESTS to build the library with WebAssembly support.")
elseif(ANIRA_WITH_INSTALL)
message(FATAL_ERROR "WebAssembly support is not compatible with install targets. Please disable ANIRA_WITH_INSTALL to build the library with WebAssembly support.")
elseif(ANIRA_WITH_LIBTORCH)
message(FATAL_ERROR "Only the ONNX Runtime backend is supported for WebAssembly. Please set -DANIRA_WITH_LIBTORCH=OFF and enable ANIRA_WITH_ONNXRUNTIME to build the library with WebAssembly support.")
elseif(ANIRA_WITH_TFLITE)
message(FATAL_ERROR "Only the ONNX Runtime backend is supported for WebAssembly. Please set -DANIRA_WITH_TFLITE=OFF and enable ANIRA_WITH_ONNXRUNTIME to build the library with WebAssembly support.")
endif()
endif()
# ==============================================================================
# Get project version from git
# ==============================================================================

execute_process(COMMAND git describe --dirty
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE PROJECT_VERSION_FULL
OUTPUT_STRIP_TRAILING_WHITESPACE)
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE GIT_DESCRIBE_RESULT)

execute_process(COMMAND git describe --tags --abbrev=0
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE PROJECT_VERSION_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE)

# Retrive the v from the short version string
string(SUBSTRING ${PROJECT_VERSION_SHORT} 1 -1 PROJECT_VERSION_SHORT)
string(SUBSTRING ${PROJECT_VERSION_FULL} 1 -1 PROJECT_VERSION_FULL)
if(GIT_DESCRIBE_RESULT EQUAL 0 AND PROJECT_VERSION_SHORT)
# Retrieve the v from the short version string
string(SUBSTRING ${PROJECT_VERSION_SHORT} 1 -1 PROJECT_VERSION_SHORT)
string(SUBSTRING ${PROJECT_VERSION_FULL} 1 -1 PROJECT_VERSION_FULL)
else()
set(PROJECT_VERSION_SHORT "0.0.0")
set(PROJECT_VERSION_FULL "0.0.0-unknown")
message(WARNING "git describe failed - no tags found. Using fallback version ${PROJECT_VERSION_SHORT}")
endif()

# ==============================================================================
# Setup the project
Expand Down Expand Up @@ -93,6 +116,12 @@ endif ()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Detect Emscripten — must be after project() so CMAKE_CXX_COMPILER is set.
# EMSDK_VERSION is needed by SetupOnnxRuntime.cmake below.
if(ANIRA_BUILD_WASM)
include(cmake/DetectEmscripten.cmake)
endif()

# ==============================================================================
# Download and install the selected inference engines
# ==============================================================================
Expand Down Expand Up @@ -202,6 +231,7 @@ target_compile_definitions(${PROJECT_NAME}
# Backend-specific definitions
$<$<BOOL:${ANIRA_WITH_LIBTORCH}>:USE_LIBTORCH>
$<$<BOOL:${ANIRA_WITH_ONNXRUNTIME}>:USE_ONNXRUNTIME>
$<$<BOOL:EMSDK_VERSION>:USE_ANIRA_WEB>
$<$<BOOL:${ANIRA_WITH_TFLITE}>:USE_TFLITE>
$<$<BOOL:${ANIRA_WITH_LOGGING}>:ENABLE_LOGGING>
# Version number
Expand Down Expand Up @@ -239,7 +269,12 @@ endif()

# The onnxruntime library requires PUBLIC linking because otherwise "_OrtGetApiBase" symbol is not found
if(ANIRA_WITH_ONNXRUNTIME)
target_link_libraries(${PROJECT_NAME} PUBLIC onnxruntime)
if(EMSDK_VERSION)
target_include_directories(${PROJECT_NAME} PUBLIC ${ANIRA_ONNXRUNTIME_SHARED_LIB_PATH})
target_link_libraries(${PROJECT_NAME} PUBLIC ${ANIRA_ONNXRUNTIME_SHARED_LIB_PATH}/libonnxruntime_webassembly.a)
else()
target_link_libraries(${PROJECT_NAME} PUBLIC onnxruntime)
endif()
endif()

if(ANIRA_WITH_TFLITE)
Expand Down Expand Up @@ -291,3 +326,11 @@ endif()
if (ANIRA_WITH_DOCS)
add_subdirectory(docs)
endif()

# ==============================================================================
# Build WebAssembly module (optional, requires Emscripten)
# ==============================================================================

if(ANIRA_BUILD_WASM)
include(cmake/BuildWasm.cmake)
endif()
Loading
Loading