MCPcopy Create free account
hub / github.com/FastLED/FastLED / compile_wasm

Function compile_wasm

ci/wasm_compile_native.py:227–385  ·  view source on GitHub ↗

Compile a FastLED sketch to WebAssembly using incremental compilation. Build phases: 1. Ensure PCH is up-to-date (via wasm_build_library.py dependency) 2. Ensure library is up-to-date (calls wasm_build_library.py) 3. Compile sketch wrapper to object file (always rebuild)

(
    source_file: Path,
    output_file: Path,
    build_mode: str = "quick",
    verbose: bool = False,
    force: bool = False,
    unity_chunks: int = 0,
)

Source from the content-addressed store, hash-verified

225
226
227def compile_wasm(
228 source_file: Path,
229 output_file: Path,
230 build_mode: str = "quick",
231 verbose: bool = False,
232 force: bool = False,
233 unity_chunks: int = 0,
234) -> int:
235 """
236 Compile a FastLED sketch to WebAssembly using incremental compilation.
237
238 Build phases:
239 1. Ensure PCH is up-to-date (via wasm_build_library.py dependency)
240 2. Ensure library is up-to-date (calls wasm_build_library.py)
241 3. Compile sketch wrapper to object file (always rebuild)
242 4. Compile entry_point.cpp to object file (always rebuild)
243 5. Link sketch.o + entry_point.o + libfastled.a -> wasm
244
245 Args:
246 source_file: Path to wrapper .cpp file or example name
247 output_file: Output .js file path
248 build_mode: Build mode (debug, fast_debug, quick, release)
249 verbose: Enable verbose output
250 force: Force rebuild of all components
251 unity_chunks: Number of unity build chunks (0 = disabled)
252
253 Returns:
254 Exit code (0 = success)
255 """
256 try:
257 start_time = time.time()
258 print(f"Building FastLED sketch to WASM (mode: {build_mode})...")
259
260 # Get tool command
261 emcc = get_emcc()
262 if verbose:
263 print(f"Using emscripten: {emcc}")
264
265 # Create build directories
266 BUILD_DIR.mkdir(parents=True, exist_ok=True)
267 LTO_CACHE_DIR.mkdir(parents=True, exist_ok=True)
268
269 # Phase 1 & 2: Ensure library is up-to-date (also ensures PCH is up-to-date)
270 phase2_start = time.time()
271 if not ensure_library_built(build_mode, verbose, force, unity_chunks):
272 print("✗ Library build failed")
273 return 1
274 phase2_time = time.time() - phase2_start
275 if verbose:
276 print(f"Library build phase: {phase2_time:.2f}s")
277
278 # Load build flags for sketch compilation
279 flags = get_sketch_compile_flags_dict(build_mode)
280 if verbose:
281 print(
282 f"Loaded {len(flags['defines'])} defines, {len(flags['compiler_flags'])} compiler flags, {len(flags['link_flags'])} link flags"
283 )
284

Callers 1

mainFunction · 0.85

Calls 10

get_emccFunction · 0.90
ensure_library_builtFunction · 0.85
needs_compilationFunction · 0.85
needs_linkingFunction · 0.85
timeMethod · 0.80
compile_objectFunction · 0.70
printFunction · 0.50
runMethod · 0.45

Tested by

no test coverage detected