Repository navigation
Description
Optional split-module output mode
In addition to the default full-app mode and the minimal --no-app mode, support a split-module build that emits the application module and a separately loadable sketch side module:
fastled_js/
index.js
fastled.js
fastled.wasm
sketch.wasm
sketch_assets.json
In this mode:
fastled.wasmis the smaller main library/loader WASM module. It contains the broad, intentionally unstripped FastLED implementation and loads the sketch side module; the application itself isindex.js.sketch.wasmis the sketch side module, equivalent to a dynamically loaded DLL. It is loaded by thefastled.wasmmain library/loader module through the generated Emscripten runtime.fastled.jsis the JavaScript loader/API used byindex.jsto initialize the main module and its sketch side module.index.jsremains the default application built on that JavaScript API.
There should not be a separate fastled.library.wasm artifact in this output contract. The main module is named fastled.wasm; archive is an implementation/build-cache concept, not an appropriate public artifact name.
This mode must coexist with --no-app:
- default mode: app + normal linked
fastled.wasm --no-app:fastled.js+ normal minimal runtime output, noindex.js- split-module mode: app (
index.js) +fastled.js+ main library/loaderfastled.wasm+ side modulesketch.wasm
The split-module mode should have an explicit CLI flag, to be chosen during implementation, and must not change the default output behavior.
Additional acceptance criteria
- A split-module build emits
index.js,fastled.js,fastled.wasm,sketch.wasm, andsketch_assets.json. -
fastled.wasmsuccessfully loadssketch.wasmas its side module through the generated loader/runtime. - The library/loader
fastled.wasmmodule is intentionally unstripped and contains the documented broad FastLED implementation while remaining smaller than theindex.jsapplication layer. - The split-module artifacts work with the same sketch asset loading contract as the normal and
--no-appmodes. - The split-module mode has cache keys and tests distinct from the normal statically linked output.
- The output and loader documentation explain that
index.jsis the application,fastled.jsis the JavaScript loader,fastled.wasmis the main library/loader module, andsketch.wasmis a dynamically loaded side module.
Linking modes
The output contract should distinguish two valid linking modes:
- Statically linked mode ? the normal build links the sketch into the main
fastled.wasm. The resulting program isfastled.js+fastled.wasm; nosketch.wasmis emitted. - Split-module mode ?
fastled.wasmis the main FastLED library/application module andsketch.wasmis the dynamically loaded side module (DLL equivalent). The resulting program isfastled.js+fastled.wasm+sketch.wasm.
The exact Emscripten dynamic-linking flags still need to be selected. The intended responsibility boundary is:
fastled.jsperforms the JavaScript-side fetch/load/instantiate operation forsketch.wasmand supplies the module paths/configuration.fastled.wasmis the main module and contains the dynamic-linking runtime and broad unstripped FastLED implementation.sketch.wasmcontains the sketch-specific side-module code and resolves its imports against the main module.
The implementation must verify whether Emscripten requires the load operation to be initiated explicitly by fastled.js or whether generated main-module glue performs it automatically. The public contract should hide that detail from index.js and external JavaScript hosts.
Emscripten dynamic-linking clarification
The public model should follow Emscripten?s terminology:
- A statically linked build has one ordinary main module: generated
fastled.jsplusfastled.wasm. The sketch is linked intofastled.wasm; nosketch.wasmis emitted. - A split build has one Emscripten main module (
fastled.jsplusfastled.wasm) and one side module (sketch.wasm). The main module contains the dynamic-linking runtime and the FastLED library implementation; the side module contains sketch-specific code. fastled.wasmdoes not fetch files itself. The generatedfastled.jsloader performs the JavaScript-side fetch/instantiate/load operation and coordinates the side module with the main module.
The first split implementation should prefer Emscripten load-time dynamic linking: build the sketch as a side module and provide it when linking the main module, so generated fastled.js knows to load it during startup. Runtime loading through dlopen, emscripten_dlopen, or Emscripten?s loadDynamicLibrary should be treated as a separate design option, not assumed by the initial output contract.
The implementation should evaluate the appropriate Emscripten settings, likely MAIN_MODULE for the main module and SIDE_MODULE/-shared for the sketch module. The choice between mode 1 (broadly linkable/no normal dead-code elimination) and mode 2 (dead-code elimination with explicitly retained side-module dependencies) must be measured and documented. Emscripten also notes that dynamic linking with pthreads is experimental, which is a significant compatibility risk for FastLED?s current pthread-based runtime.
Proposed initial implementation decision
Implement the two modes as follows:
- Default/static: emit
fastled.js+fastled.wasm, with the sketch statically linked intofastled.wasm. - Split/load-time: emit
fastled.js+fastled.wasm+sketch.wasm, using Emscripten?s main-module/side-module model.fastled.wasmis the main FastLED library/runtime module;sketch.wasmis the sketch side module; generatedfastled.jsperforms the side-module load. --no-app: suppress only the defaultindex.jsapplication and its app assets; retain the JavaScript loader, WASM module(s), andsketch_assets.json.
Do not initially implement runtime dlopen/loadDynamicLibrary semantics unless load-time linking proves insufficient. The issue should be considered complete only after a real sketch is built and executed in both static and split modes, including the current pthread-based runtime configuration.
CLI spelling
Use a single explicit link-mode argument:
# Static linking (the default)
fastled <sketch>
fastled <sketch> --link-mode=static
# Load-time dynamic linking with sketch.wasm as a side module
fastled <sketch> --link-mode=dynamic
# Dynamic linking without the default app
fastled <sketch> --no-app --link-mode=dynamic
--link-mode accepts static or dynamic. static remains the default for backwards compatibility. dynamic means Emscripten load-time dynamic linking: the generated main module loads sketch.wasm as a side module at startup. It does not initially imply runtime dlopen/loadDynamicLibrary behavior.
Validation requirement
Both link modes are new and must be tested independently:
- Static mode (
--link-mode=static, including the default with no link-mode flag) builds and runs a representative sketch successfully. - Dynamic mode (
--link-mode=dynamic) builds the main module andsketch.wasm, loads the side module successfully, and runs the same representative sketch successfully. - Tests verify the expected output files for each mode and fail if a stale artifact from the other mode is reused.
- The test matrix covers both modes with and without
--no-appwhere supported.
Loader/API boundary decision
Keep the loader and low-level JavaScript API together as the single emitted fastled.js artifact. Do not add a separate public loader file in the initial implementation.
fastled.js is responsible for:
- loading
fastled.wasm - loading
sketch.wasmin dynamic mode - configuring Emscripten memory, workers, and pthreads
- owning the Emscripten
Moduleinstance - exposing the stable FastLED JavaScript API
The loader is tightly coupled to the generated WASM module, worker filename, exports, memory configuration, and dynamic-linking settings. Keeping it together avoids creating an unnecessary public compatibility boundary.
The source may still be separated internally, for example:
src/fastled/
wasm_loader.ts
fastled_api.ts
app/
Those pieces can be bundled into fastled.js. The default index.js application remains a separate consumer of that API.
The API should hide static versus dynamic linking from callers. Conceptually:
const fastled = await createFastLED({
moduleUrl: "./fastled.wasm",
sketchUrl: "./sketch.wasm" // dynamic mode only
});A separate public loader artifact should only be reconsidered if distinct browser, Node, Tauri, or Replit loading environments later require materially different implementations.
Activity
feat(cli): add no-app and dynamic link modes (#185)
zackees commentedon Jul 11, 2026
Implemented and merged in PR #185. This adds --no-app, --link-mode=static|dynamic, flat fastled.js/index.js outputs, Emscripten main/side-module dynamic linking, sketch_assets.json output, and legacy files.json loading fallback.
fix(cli): align dynamic module WASM ABI (#186)
zackees commentedon Jul 11, 2026
Follow-up runtime validation found and fixed an Emscripten dynamic-link ABI mismatch. fastled-wasm PR #186 and FastLED PR #3618 are now merged. �uild_flags.toml defines -sWASM_BIGINT=1 in [linking.base], with quick mode's -sWASM_BIGINT=0 as the explicit later override; the dynamic main and side modules now receive the same setting.