Skip to content

feat(cli): add --no-app mode for minimal JavaScript API output #184

Closed

Description

@zackees

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.wasm is the smaller main library/loader WASM module. It contains the broad, intentionally unstripped FastLED implementation and loads the sketch side module; the application itself is index.js.
  • sketch.wasm is the sketch side module, equivalent to a dynamically loaded DLL. It is loaded by the fastled.wasm main library/loader module through the generated Emscripten runtime.
  • fastled.js is the JavaScript loader/API used by index.js to initialize the main module and its sketch side module.
  • index.js remains 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, no index.js
  • split-module mode: app (index.js) + fastled.js + main library/loader fastled.wasm + side module sketch.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, and sketch_assets.json.
  • fastled.wasm successfully loads sketch.wasm as its side module through the generated loader/runtime.
  • The library/loader fastled.wasm module is intentionally unstripped and contains the documented broad FastLED implementation while remaining smaller than the index.js application layer.
  • The split-module artifacts work with the same sketch asset loading contract as the normal and --no-app modes.
  • The split-module mode has cache keys and tests distinct from the normal statically linked output.
  • The output and loader documentation explain that index.js is the application, fastled.js is the JavaScript loader, fastled.wasm is the main library/loader module, and sketch.wasm is a dynamically loaded side module.

Linking modes

The output contract should distinguish two valid linking modes:

  1. Statically linked mode ? the normal build links the sketch into the main fastled.wasm. The resulting program is fastled.js + fastled.wasm; no sketch.wasm is emitted.
  2. Split-module mode ? fastled.wasm is the main FastLED library/application module and sketch.wasm is the dynamically loaded side module (DLL equivalent). The resulting program is fastled.js + fastled.wasm + sketch.wasm.

The exact Emscripten dynamic-linking flags still need to be selected. The intended responsibility boundary is:

  • fastled.js performs the JavaScript-side fetch/load/instantiate operation for sketch.wasm and supplies the module paths/configuration.
  • fastled.wasm is the main module and contains the dynamic-linking runtime and broad unstripped FastLED implementation.
  • sketch.wasm contains 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.js plus fastled.wasm. The sketch is linked into fastled.wasm; no sketch.wasm is emitted.
  • A split build has one Emscripten main module (fastled.js plus fastled.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.wasm does not fetch files itself. The generated fastled.js loader 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 into fastled.wasm.
  • Split/load-time: emit fastled.js + fastled.wasm + sketch.wasm, using Emscripten?s main-module/side-module model. fastled.wasm is the main FastLED library/runtime module; sketch.wasm is the sketch side module; generated fastled.js performs the side-module load.
  • --no-app: suppress only the default index.js application and its app assets; retain the JavaScript loader, WASM module(s), and sketch_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 and sketch.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-app where 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.wasm in dynamic mode
  • configuring Emscripten memory, workers, and pthreads
  • owning the Emscripten Module instance
  • 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

  1. zackees commented on Jul 11, 2026

    @zackees
    MemberAuthor

    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.

  2. zackees commented on Jul 11, 2026

    @zackees
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions