How Lakeport is built·/docs/compiler-and-runtime

Compiler pipeline and runtime internals

Build orchestration lives in packages/lakeport-cli/src/LakeportCli/Build/ and Pipeline.lean, implementing a Vite-style hookable pipeline across Web and all five native targets.

Build phases

1.
config & configResolved: Loads lakeport.json (falling back cleanly to lakefile.toml), .env* files with strict LAKEPORT_PUBLIC_* client isolation, path aliases, and define constants.
2.
.lp lowering & transform: LpTsx.lean lowers .lp markup to checked Lean StyledView definitions with line-preserving source maps; plugins can resolve virtual:* modules and ?url/?raw/?inline asset queries.
3.
cssTransform: Bundles recursive @import graphs, runs any project-configured CSS plugins (such as the built-in Tailwind integration or a PostCSS plugin) with content-addressed caching, validates static class references during lakeport check, and emits bundle.css (Web) + binary bundle.lpcss (native).
4.
Lean elaboration & proof stripping: Runs wave-parallel Lean 4.35 elaboration and kernel-checks every theorem across your .lean and .lp modules, erasing all Prop proofs and automatically excluding proof-only modules before C/Wasm code generation.
5.
Target linking & optimizeBundle: Reuses prebuilt cached runtime closures (WasmCache.lean, NativeOpt.lean) to eliminate multi-minute cold runtime compiles; in --release mode runs -Oz, LTO, dead-code section GC, and Binaryen wasm-opt.
6.
Native staging (NativeInputs.lean) & generateBundle: Resolves lakeport.native-deps/2 (Maven/AAR, SwiftPM/XCFramework, pkg-config), verifies lakeport.native.lock SHA-256 digests, merges AndroidManifest.xml / Info.plist / .entitlements, and for Web SSG pre-renders all ssgRoutes plus hydration-manifest.json.

Shared C runtime & binary wire protocol (LP2 / ABI5)

The compiled Lean core communicates with all six hosts through Lakeport's v2 C runtime (LP2, implemented in packages/lakeport-web/host/lakeport_runtime.c) and its versioned binary frame codecs (Wire2 / Schema 3 / ABI5 in element_value.c, semantic_props.c, and native_style_engine.c):

•
Web: Emits wasm/app_lp2.js + wasm/app_lp2.wasm paired with dom-renderer.mjs and SSG pre-hydration click replay.
•
Native: Emits native generation libraries linked against lpcss_native.c, layout_native.c, lp_gesture_spring.c, and the platform host shell (UIKit, AppKit, Android Views/Skia, GTK4, or Win32/Direct2D).

Development reload

lakeport dev dispatches file changes through handleHotUpdate:

•
CSS-only edits: Re-run CSS bundling (and any configured CSS build plugins) and push updated stylesheets to connected Web and native clients without recompiling Lean.
•
.lp / .lean edits: Rebuild changed modules and attempt a generation swap. State transfer depends on compatible app checkpoints and host support. Web has tests for deferring swaps during active text composition. Apple reload and device-level continuity have separate verification requirements.