Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
build(macos): package the compositor addon, and refuse an incomplete .app
Etienne Lescot6348791e8ce1
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex dc3249c91..923a5c435 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -169,6 +169,40 @@ jobs:env:OPENSCREEN_MAC_HELPER_ARCHS: ${{ matrix.arch }}+ # The two steps below are what `npm run build:mac` does and this job did not.+ # Windows gets them for free because its job just runs `npm run build:win`,+ # which chains fetch:ffmpeg + build:native:compositor; macOS spells its steps+ # out (it needs `--dir` plus a hand-rolled DMG and signing) and drifted. The+ # result was a .app with no compositor addon — preview and export dead in the+ # installed app, silently. `scripts/before-pack.cjs` now refuses to package+ # that, so this is also what keeps the job from failing at the pack step.+ - name: Cache LGPL ffmpeg tree+ uses: actions/cache@v4+ with:+ # fetch-ffmpeg-macos.mjs BUILDS ffmpeg from source (~5 min): BtbN ships no+ # macOS target and every circulating macOS build is GPL, which would+ # relicense this MIT app. The script pins the release and checksums it, so+ # keying on the script itself busts the cache when the pin moves.+ path: crates/thirdparty+ key: ffmpeg-macos-${{ matrix.arch }}-${{ hashFiles('scripts/fetch-ffmpeg-macos.mjs') }}++ - name: Vendor LGPL ffmpeg+ run: npm run fetch:ffmpeg:mac++ - name: Cache cargo + compositor build tree+ uses: actions/cache@v4+ with:+ path: |+ ~/.cargo/registry+ ~/.cargo/git+ crates/target+ key: cargo-macos-${{ matrix.arch }}-${{ hashFiles('crates/Cargo.lock') }}+ restore-keys: |+ cargo-macos-${{ matrix.arch }}-++ - name: Build Metal compositor addon+ run: npm run build:native:compositor:mac+- name: Package .app bundlerun: npx electron-builder --mac --${{ matrix.arch }} --dir --publish neverenv:diff --git a/scripts/before-pack.cjs b/scripts/before-pack.cjsindex e64ba780e..c38cea87f 100644--- a/scripts/before-pack.cjs+++ b/scripts/before-pack.cjs@@ -38,6 +38,99 @@ const SOURCE_PATHS = [const FIX ="Rebuild it with:\n\n npm run build:native:compositor\n\nor use `npm run build:win`, which does that for you.";+const FIX_MAC =+ "Rebuild it with:\n\n npm run build:native:compositor:mac\n\nor use `npm run build:mac`, which does that for you.";++/**+ * Everything that has to be inside `electron/native/bin/darwin-<arch>/` for the .app to+ * work, keyed by what breaks when it is absent.+ *+ * This list exists because the macOS deliverable had no guard at all: `beforePack`+ * returned early on any non-win32 platform, so a mac package built without the compositor+ * addon shipped silently — the preview and the export come up dead, with nothing in any+ * log to say why. That is precisely the failure mode the staleness check below was written+ * to prevent, and the platform guard was letting it through on the other OS.+ *+ * `mac.extraResources` ships this directory wholesale (`filter: ["darwin-*/*"]`), so+ * "present here" is the same thing as "present in the installed app".+ */+const MAC_REQUIRED = [+ {+ match: (name) => name === "compositor_view.node",+ what: "the Metal compositor addon",+ breaks: "the preview and every export render nothing",+ fix: FIX_MAC,+ },+ {+ match: (name) => /^libav(codec|format|util)\.\d+\.dylib$/.test(name),+ what: "the LGPL ffmpeg dylibs the compositor links",+ breaks: "the compositor addon cannot be loaded at all (dyld error at require())",+ fix: FIX_MAC,+ atLeast: 3,+ },+ {+ match: (name) => name === "whisper-stt-server",+ what: "the whisper.cpp STT helper",+ breaks: "transcription and captions fail with a developer error shown to end users",+ fix: "Build it with:\n\n npm run build:whisper-binaries\n\nor stage CI's with `bash scripts/stage-whisper-stt.sh darwin-<arch>`.",+ },+ {+ match: (name) => /^libggml.*\.dylib$/.test(name),+ what: "the ggml backend dylibs the STT helper links",+ breaks: "whisper-stt-server dies in dyld before main(), so STT times out with no diagnostic",+ fix: "Build it with:\n\n npm run build:whisper-binaries",+ atLeast: 1,+ },+ {+ match: (name) => name === "openscreen-screencapturekit-helper",+ what: "the ScreenCaptureKit capture helper",+ breaks: "native screen capture is unavailable",+ fix: "Build it with:\n\n npm run build:native:mac",+ },+];++/** electron-builder passes `context.arch` as a numeric enum; map it to our directory tag. */+function archTagFor(context) {+ const BY_INDEX = { 0: "ia32", 1: "x64", 2: "armv7l", 3: "arm64", 4: "universal" };+ const name = BY_INDEX[context?.arch];+ return name && name !== "universal" ? name : process.arch;+}++function checkMacNativePayload(context) {+ const tag = `darwin-${archTagFor(context)}`;+ const dir = path.join(ROOT, "electron", "native", "bin", tag);+ if (!fs.existsSync(dir)) {+ throw new Error(+ `Refusing to package: ${path.relative(ROOT, dir)} does not exist, so the .app would ` ++ "ship with no native modules at all.\n\n" ++ `${FIX_MAC}\n\nThe STT helper and the capture helper are separate builds — see\n` ++ "technical-documentation/engineering/build-and-packaging.md.",+ );+ }++ const present = fs.readdirSync(dir);+ const missing = MAC_REQUIRED.filter(+ (req) => present.filter((name) => req.match(name)).length < (req.atLeast ?? 1),+ );+ if (missing.length === 0) {+ return;+ }++ const detail = missing+ .map(+ (req) =>+ ` - ${req.what}\n without it: ${req.breaks}\n ${req.fix.replace(/\n+/g, " ")}`,+ )+ .join("\n");+ throw new Error(+ `Refusing to package an incomplete macOS payload.\n\n` ++ ` looked in: ${path.relative(ROOT, dir)}\n\n` ++ `Missing:\n${detail}\n\n` ++ "Every one of these fails silently or as an unactionable timeout in the installed\n" ++ "app, which is why this is a hard error at pack time rather than a warning.",+ );+}+/** Newest mtime under `target` (file or directory), or 0 if it does not exist. */function newestMtimeMs(target) {let stat;@@ -56,14 +149,14 @@ function newestMtimeMs(target) {return newest;}-function checkCompositorAddonFreshness() {- if (!fs.existsSync(ADDON)) {+function checkCompositorAddonFreshness(addon = ADDON, fix = FIX, label = "D3D11") {+ if (!fs.existsSync(addon)) {throw new Error(- `Refusing to package: the D3D11 compositor addon is missing.\n\n expected: ${ADDON}\n\n${FIX}`,+ `Refusing to package: the ${label} compositor addon is missing.\n\n expected: ${addon}\n\n${fix}`,);}- const addonMs = fs.statSync(ADDON).mtimeMs;+ const addonMs = fs.statSync(addon).mtimeMs;const stale = SOURCE_PATHS.map((source) => ({ source, ms: newestMtimeMs(source) })).filter((entry) => entry.ms > addonMs,);@@ -73,29 +166,51 @@ function checkCompositorAddonFreshness() {const newest = stale.reduce((a, b) => (a.ms > b.ms ? a : b));throw new Error(- "Refusing to package a stale D3D11 compositor addon.\n\n" ++ `Refusing to package a stale ${label} compositor addon.\n\n` ++ ` addon: ${path.relative(ROOT, addon)}\n` +` addon built: ${new Date(addonMs).toISOString()}\n` +` newer source: ${path.relative(ROOT, newest.source)} (${new Date(newest.ms).toISOString()})\n\n` +"Packaging this would silently ship an addon that ignores newer scene fields\n" +"(they are #[serde(default)], so it falls back instead of erroring).\n\n" +- FIX,+ fix,);}exports.default = async function beforePack(context) {- // The compositor addon is Windows-only; skip when packing any other target.const platform = context?.electronPlatformName ?? process.platform;- if (platform !== "win32") {+ if (platform === "win32") {+ checkCompositorAddonFreshness();return;}- checkCompositorAddonFreshness();+ if (platform === "darwin") {+ // The addon that actually ships is the arch-tagged copy under+ // electron/native/bin/ (mac.extraResources), not the dev copy this hook used to+ // be the sole guardian of — so that is the one whose freshness matters.+ const tag = `darwin-${archTagFor(context)}`;+ const shipped = path.join(ROOT, "electron", "native", "bin", tag, "compositor_view.node");+ checkMacNativePayload(context);+ checkCompositorAddonFreshness(shipped, FIX_MAC, "Metal");+ return;+ }+ // Linux ships no native addon of its own; nothing to assert.};// Runnable on its own for debugging: `node scripts/before-pack.cjs`if (require.main === module) {try {- checkCompositorAddonFreshness();- console.log("compositor addon is up to date with its Rust sources.");+ if (process.platform === "darwin") {+ checkMacNativePayload({ arch: undefined });+ const tag = `darwin-${process.arch}`;+ checkCompositorAddonFreshness(+ path.join(ROOT, "electron", "native", "bin", tag, "compositor_view.node"),+ FIX_MAC,+ "Metal",+ );+ console.log(`macOS native payload complete in electron/native/bin/${tag}, addon up to date.`);+ } else {+ checkCompositorAddonFreshness();+ console.log("compositor addon is up to date with its Rust sources.");+ }} catch (err) {console.error(err.message);process.exit(1);diff --git a/technical-documentation/engineering/build-and-packaging.md b/technical-documentation/engineering/build-and-packaging.mdindex fb45dc8be..c1e623ed5 100644--- a/technical-documentation/engineering/build-and-packaging.md+++ b/technical-documentation/engineering/build-and-packaging.md@@ -33,7 +33,8 @@ A usable full package depends on generated artifacts that are not committed:| macOS ScreenCaptureKit capture helper and cursor helper | `electron/native/bin/darwin-arm64/` or `darwin-x64/` | Full Xcode, Swift, SwiftPM; Command Line Tools alone may be insufficient || Whisper STT server and ggml/whisper backend libraries | `electron/native/bin/<platform>-<arch>/` | CMake plus host compiler; Metal on Apple Silicon, Vulkan SDK on supported Windows/Linux builds, CPU fallback, optional CUDA || Native D3D11 compositor addon | `electron/native/compositor-view/build/compositor_view.node` | Rust MSVC toolchain, Visual Studio/Windows SDK, LLVM/libclang, and the exact pinned shared FFmpeg SDK |-| FFmpeg runtime files | matching `electron/native/bin/<platform>-<arch>/` directory | Downloaded by `fetch:ffmpeg` for the Windows build path |+| Native Metal compositor addon | `electron/native/bin/darwin-<arch>/compositor_view.node` (plus a dev copy under `electron/native/compositor-view/build/`) | Rust, Xcode, and the LGPL FFmpeg tree from `fetch:ffmpeg:mac` |+| FFmpeg runtime files | matching `electron/native/bin/<platform>-<arch>/` directory | Downloaded by `fetch:ffmpeg` on Windows; **built from source** by `fetch:ffmpeg:mac` on macOS (~5 min) — BtbN publishes no macOS target and every circulating macOS build is GPL, which would relicense this MIT app |Electron-builder copies only the matching `electron/native/bin/<platform>-<arch>/` directory into each package. The compositor `.node` file is included by the Windows `files` rule and unpacked from ASAR because native addons cannot be loaded from inside the archive.@@ -50,13 +51,28 @@ Electron-builder copies only the matching `electron/native/bin/<platform>-<arch>A stale addon **fails silently rather than erroring**. Scene fields are `#[serde(default)]` on the Rust side, so an addon that predates a contract change does not reject the payload: it ignores the unknown key, takes the default, and falls back to older behaviour. Nothing appears in any log, and the symptom ("the feature does nothing") is indistinguishable from a TypeScript bug. This is not hypothetical — on 2026-07-27 a build shipped an addon three days older than the commit adding `cursorSprites`, custom cursor themes silently rendered as the built-in art, and the resulting investigation blamed the wrong layer entirely.-`scripts/before-pack.cjs` runs as electron-builder's `beforePack` hook and fails the build when the addon is older than `crates/compositor/src/`, `crates/compositor-view-napi/src/`, or either `Cargo.toml`. It only checks when packaging for Windows. The fix it prints is:+`scripts/before-pack.cjs` runs as electron-builder's `beforePack` hook and fails the build when the addon is older than `crates/compositor/src/`, `crates/compositor-view-napi/src/`, or either `Cargo.toml`. The fix it prints is:```bash-npm run build:native:compositor+npm run build:native:compositor # Windows+npm run build:native:compositor:mac # macOS```-CI is unaffected: `.github/workflows/build.yml` already uses `build:win`, which rebuilds before packaging.+**On macOS it also asserts the payload is complete**, which is a stronger check than freshness and exists because the hook used to return early on every non-Windows platform. That gap was not theoretical: the macOS CI job built the ScreenCaptureKit helper but never ran `fetch:ffmpeg:mac` or `build:native:compositor:mac`, so the `.app` it produced had no compositor addon — preview and export dead in the installed app, with nothing in any log. Nothing caught it, because the one guard that would have was Windows-only.++The hook now reads `electron/native/bin/darwin-<arch>/` — the directory `mac.extraResources` ships wholesale, so "present here" means "present in the installed app" — and refuses to package unless it holds all of:++| Required | Without it |+|---|---|+| `compositor_view.node` | preview and every export render nothing |+| `libavcodec/libavformat/libavutil.*.dylib` | the addon cannot load at all (dyld error at `require()`) |+| `whisper-stt-server` | transcription and captions fail with a developer error shown to end users |+| `libggml*.dylib` | the helper dies in dyld before `main()`; STT times out with no diagnostic |+| `openscreen-screencapturekit-helper` | native screen capture unavailable |++It then applies the same staleness comparison to the **shipped** addon (the arch-tagged copy), not the dev copy under `electron/native/compositor-view/build/`, since the arch-tagged one is what electron-builder actually packages.++CI: the Windows job runs `build:win`, which rebuilds before packaging. The macOS job spells its steps out — it needs `--dir` plus a hand-rolled DMG and signing — and had drifted from the `build:mac` recipe; it now vendors the LGPL ffmpeg tree and builds the Metal addon before packing, both cached.The check compares modification times, so `git checkout` (which restamps source files) can occasionally flag an addon that is genuinely fine. That trade is deliberate — a false alarm costs one rebuild, whereas a missed stale addon ships a broken installer. Run `node scripts/before-pack.cjs` on its own to see the verdict without packaging.@@ -70,6 +86,8 @@ The default electron-builder target is NSIS, with an assisted installer that all### macOS+> **The macOS job is currently disabled** (`if: false` in `build.yml`) because 1.8.0 ships Windows-only. That flag is release-branch-only and must not reach `main` when promoting, or every later release becomes Windows-only too. Until it is lifted, the macOS packaging path — including the compositor and ffmpeg steps described above — is exercised only by `npm run build:mac` locally.+Electron-builder targets DMG for both `arm64` and `x64`, enables hardened runtime, and applies `macos.entitlements` to the app and inherited code. The entitlements allow Electron JIT/native library loading and audio, camera, and screen capture. The configuration itself sets `notarize: false`; release CI packages the `.app`, creates and signs the DMG manually, submits stable tags to `notarytool`, staples the ticket, and validates Gatekeeper. Pre-release tags skip DMG signing/notarization, and missing Apple credentials produce an unsigned artifact.### Linux and Nix