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

Function build_sketch_pch

ci/wasm_build.py:873–972  ·  view source on GitHub ↗

Build a C++20 header unit (.pcm) from wasm_pch.h for sketch compilation. Uses -fmodules-codegen to pre-compile inline function bodies into a companion object file. This reduces sketch backend work by ~63% (509 → 187 codegen functions for Blink) while keeping header unit import fast

(
    build_dir: Path,
    mode: str,
    lib_was_rebuilt: bool = False,
    verbose: bool = False,
)

Source from the content-addressed store, hash-verified

871
872
873def build_sketch_pch(
874 build_dir: Path,
875 mode: str,
876 lib_was_rebuilt: bool = False,
877 verbose: bool = False,
878) -> Path | None:
879 """
880 Build a C++20 header unit (.pcm) from wasm_pch.h for sketch compilation.
881
882 Uses -fmodules-codegen to pre-compile inline function bodies into a companion
883 object file. This reduces sketch backend work by ~63% (509 → 187 codegen
884 functions for Blink) while keeping header unit import fast (~6ms vs 34ms PCH).
885
886 The companion object is added to libfastled.a so the linker picks up symbols
887 naturally — no changes needed to link commands.
888
889 Args:
890 lib_was_rebuilt: If True, library sources changed — invalidate header unit
891 since included headers may have changed.
892
893 Returns path to the header unit BMI (.pcm), or None if build fails.
894 """
895 sketch_pcm_path = build_dir / "wasm_pch.h.pcm"
896 sketch_pch_hash_path = build_dir / "sketch_pch.hash"
897 pch_codegen_o = build_dir / "pch_codegen.o"
898
899 sketch_flags = get_sketch_compile_flags(mode)
900 # Combine flags + source fingerprint to detect both flag and header changes
901 src_fp = _compute_src_fingerprint()
902 combined = "\n".join(sketch_flags) + "\n" + src_fp
903 current_hash = hashlib.sha256(combined.encode()).hexdigest()
904
905 # Check if header unit BMI is up-to-date
906 if (
907 not lib_was_rebuilt
908 and sketch_pcm_path.exists()
909 and pch_codegen_o.exists()
910 and sketch_pch_hash_path.exists()
911 ):
912 stored_hash = sketch_pch_hash_path.read_text(encoding="utf-8").strip()
913 if stored_hash == current_hash:
914 if verbose:
915 print("[WASM] Sketch header unit is up-to-date")
916 return sketch_pcm_path
917
918 includes = [
919 f"-I{PROJECT_ROOT / 'src'}",
920 f"-I{PROJECT_ROOT / 'src' / 'platforms' / 'wasm' / 'compiler'}",
921 ]
922
923 # Meson-injected defaults that must match the compilation environment
924 meson_defaults = [
925 "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST",
926 "-D_FILE_OFFSET_BITS=64",
927 ]
928
929 emcc_args = (
930 ["-fmodule-header=user", str(WASM_PCH_HEADER), "-o", str(sketch_pcm_path)]

Callers 1

buildFunction · 0.85

Calls 7

get_sketch_compile_flagsFunction · 0.90
run_emccFunction · 0.90
get_emarFunction · 0.90
_compute_src_fingerprintFunction · 0.85
unlinkMethod · 0.80
printFunction · 0.50
runMethod · 0.45

Tested by

no test coverage detected