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
fix(win): stop depending on the Visual C++ Redistributable
Etienne Lescot7f68e9a8fe22
diff --git a/.gitattributes b/.gitattributesindex 154f7c37f..d9dbbd32f 100644--- a/.gitattributes+++ b/.gitattributes@@ -7,3 +7,6 @@*.rs text eol=lf*.ts text eol=lf*.tsx text eol=lf+# Same drift, caught on the native helper's build file: an edit from Windows+# rewrote all 67 lines as CRLF and buried a 22-line change in a 156-line diff.+CMakeLists.txt text eol=lfdiff --git a/crates/.cargo/config.toml b/crates/.cargo/config.tomlindex ca5ccb6b6..29197773e 100644--- a/crates/.cargo/config.toml+++ b/crates/.cargo/config.toml@@ -12,6 +12,23 @@FFMPEG_DIR = { value = "thirdparty/ffmpeg-n8.1.2-win64-lgpl-shared", relative = true }LIBCLANG_PATH = "C:\\Program Files\\LLVM\\bin"+# CRT statique. Par défaut, un cdylib MSVC importe VCRUNTIME140.dll, qui ne fait PAS+# partie de Windows : elle vient du Redistribuable Visual C++. Toute machine ayant+# déjà compilé ce dépôt — ou installé à peu près n'importe quelle autre application+# de bureau — l'a dans System32, donc la dépendance est invisible en local comme en+# CI. Sur une image Windows propre, `require()` de compositor_view.node échoue et+# l'éditeur s'ouvre sans aperçu pendant que le son continue : le symptôme EXACT que+# la colocation avec les DLL ffmpeg (build-windows-compositor-addon.mjs) était+# censée corriger. Elle a bien corrigé sa cause à elle — MSIX qui ignore PATH — mais+# celle-ci restait, et aucune machine de dev ne peut la faire apparaître.+#+# Rien de partagé avec l'hôte ne traverse la frontière du CRT : napi-rs ne fait+# passer que des napi_value opaques, et les Buffer rendus à Node portent un+# finalizer qui libère côté addon ce que l'addon a alloué. Le CRT statique est donc+# sans effet de bord ici. scripts/before-pack.cjs échoue si l'import revient.+[target.x86_64-pc-windows-msvc]+rustflags = ["-C", "target-feature=+crt-static"]+# macOS : BtbN ne publie pas de build macOS (cf. scripts/fetch-ffmpeg.mjs), donc on# laisse `crates/compositor/build.rs` chercher MAC_FFMPEG_DIR (env var explicite posée# par la CI macOS ou par le dev local) ou un répertoire attendu sous `thirdparty/`.diff --git a/electron/native/wgc-capture/CMakeLists.txt b/electron/native/wgc-capture/CMakeLists.txtindex 32c5d6ef5..d1f55066b 100644--- a/electron/native/wgc-capture/CMakeLists.txt+++ b/electron/native/wgc-capture/CMakeLists.txt@@ -9,6 +9,28 @@ set(CMAKE_CXX_STANDARD_LIBRARIESproject(openscreen-wgc-capture LANGUAGES CXX)+# Static CRT (/MT), not CMake's default /MD. With /MD both helpers import+# VCRUNTIME140.dll, VCRUNTIME140_1.dll and MSVCP140.dll, which are NOT part of+# Windows — they come from the Visual C++ Redistributable. Every machine that has+# ever built this repo, or installed almost any other desktop app, already has+# them in System32, so the dependency is invisible in local testing and in CI.+#+# On a clean Windows image it is fatal: the loader kills the process before main()+# and the parent only sees an exit code. Store certification runs on exactly such+# an image and rejected 1.9.1 for it, reporting+#+# Error: Native Windows capture exited before recording started (code=3221225781)+#+# 3221225781 is 0xC0000135, STATUS_DLL_NOT_FOUND. Recording was impossible on the+# test device while the app itself started fine, because Electron already links+# the CRT statically.+#+# These are standalone processes that share no CRT state with anything, so /MT is+# free: it costs ~100 KB each and removes the dependency instead of obliging us to+# redistribute Microsoft's DLLs beside them. scripts/before-pack.cjs fails the+# build if it ever comes back.+set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")+set(CMAKE_CXX_STANDARD 20)set(CMAKE_CXX_STANDARD_REQUIRED ON)set(CMAKE_CXX_EXTENSIONS OFF)diff --git a/scripts/before-pack.cjs b/scripts/before-pack.cjsindex 264217960..e230f30c8 100644--- a/scripts/before-pack.cjs+++ b/scripts/before-pack.cjs@@ -242,14 +242,126 @@ const WIN_REQUIRED = [})),];+/**+ * DLLs that come from the Visual C++ Redistributable rather than from Windows itself.+ *+ * The `api-ms-win-crt-*` api-sets are deliberately absent: that is the UCRT, which IS+ * part of Windows 10 and later. These are not, and no machine is obliged to have them.+ */+const VC_REDIST_DLL = /^(msvcp|vcruntime|concrt)\d+/i;++/**+ * The DLL names a PE binary imports — just enough of the format to walk the import+ * directory, so this needs no dumpbin and therefore no Visual Studio on the runner.+ */+function importedDlls(file) {+ const b = fs.readFileSync(file);+ const pe = b.readUInt32LE(0x3c);+ if (b.readUInt32LE(pe) !== 0x00004550) throw new Error(`${file} is not a PE binary`);+ const opt = pe + 24;+ // The optional header's fixed part is 96 bytes for PE32 and 112 for PE32+ (five+ // fields widen to 8 bytes); the data directories follow it.+ const dirs = opt + (b.readUInt16LE(opt) === 0x20b ? 112 : 96);+ const importRva = b.readUInt32LE(dirs + 8); // directory 1 = imports+ if (!importRva) return [];++ const sections = [];+ for (let i = 0; i < b.readUInt16LE(pe + 6); i++) {+ const s = opt + b.readUInt16LE(pe + 20) + i * 40;+ sections.push({+ va: b.readUInt32LE(s + 12),+ size: b.readUInt32LE(s + 16),+ ptr: b.readUInt32LE(s + 20),+ });+ }+ const fileOffset = (rva) => {+ const s = sections.find((s) => rva >= s.va && rva < s.va + s.size);+ if (!s) throw new Error(`${file}: RVA 0x${rva.toString(16)} is in no section`);+ return s.ptr + (rva - s.va);+ };++ const names = [];+ // Array of 20-byte descriptors, terminated by an all-zero one.+ for (let entry = fileOffset(importRva); ; entry += 20) {+ const nameRva = b.readUInt32LE(entry + 12);+ if (!nameRva) return names;+ const at = fileOffset(nameRva);+ names.push(b.subarray(at, b.indexOf(0, at)).toString("latin1"));+ }+}++/**+ * Nothing we ship may depend on the Visual C++ Redistributable.+ *+ * This is the one failure this whole hook could not see. Every machine that builds this+ * repo, and most machines that have ever installed a desktop app, carry those DLLs in+ * System32 — so a binary that needs them works in local testing, in CI, and in every+ * package format, while being unloadable on a clean Windows image. There is no way to+ * reproduce it here; only the import table tells the truth.+ *+ * Store certification rejected 1.9.1 for exactly this: the WGC helper was built against+ * the dynamic CRT and died in the loader before main(), so the app reported+ * `Native Windows capture exited before recording started (code=3221225781)`+ * — 0xC0000135, STATUS_DLL_NOT_FOUND — and recording was impossible on the test device.+ * `compositor_view.node` had the same defect and would have failed certification a+ * second time, on the preview, right after the helper was fixed.+ *+ * The fix is per-toolchain, hence the two-part message: /MT for the CMake helpers+ * (electron/native/wgc-capture/CMakeLists.txt), `+crt-static` for the Rust addon+ * (crates/.cargo/config.toml).+ */+function checkWinNoRedistDependency(dir) {+ const scanned = fs+ .readdirSync(dir)+ .filter((name) => /\.(exe|dll|node)$/i.test(name))+ .map((name) => ({ name, imports: importedDlls(path.join(dir, name)) }));++ // A guard that silently stops looking is worse than no guard: it reports "clean" for+ // the rest of the project's life. Every native binary imports something — kernel32 at+ // the very least — so an empty result means the parser broke, not that the file is+ // self-contained. Asserted here against the real payload rather than a synthetic PE+ // fixture, which would only ever prove this parser agrees with itself.+ const unread = scanned.filter((entry) => entry.imports.length === 0);+ if (unread.length > 0) {+ throw new Error(+ `Refusing to package: read no imports at all from ${unread.map((e) => e.name).join(", ")}.\n\n` ++ "Every native binary imports at least kernel32, so this is a bug in importedDlls()\n" ++ "(scripts/before-pack.cjs), not a self-contained binary. Fix the parser — leaving it\n" ++ "is how the Visual C++ Redistributable dependency gets back into a shipped build.",+ );+ }++ const offenders = scanned+ .map((entry) => ({ name: entry.name, bad: entry.imports.filter((d) => VC_REDIST_DLL.test(d)) }))+ .filter((entry) => entry.bad.length > 0);+ if (offenders.length === 0) {+ return;+ }++ throw new Error(+ "Refusing to package binaries that need the Visual C++ Redistributable.\n\n" ++ ` looked in: ${path.relative(ROOT, dir)}\n\n` ++ `${offenders.map((o) => ` - ${o.name} imports ${o.bad.join(", ")}`).join("\n")}\n\n` ++ "Those DLLs are not part of Windows. On a clean image the loader kills the process\n" ++ "before main() (0xC0000135) or fails require(), and the app can only report an exit\n" ++ "code. It works on every developer machine, which is why this is checked here.\n\n" ++ "Build against the static CRT instead:\n" ++ " - CMake helpers: CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded (electron/native/wgc-capture)\n" ++ " - Rust addon: -C target-feature=+crt-static (crates/.cargo/config.toml)\n\n" ++ "For a third-party binary that cannot be rebuilt, ship the DLLs it needs beside it.",+ );+}+function checkWinNativePayload() {+ const dir = path.join(ROOT, "electron", "native", "bin", "win32-x64");checkNativePayload({- dir: path.join(ROOT, "electron", "native", "bin", "win32-x64"),+ dir,required: WIN_REQUIRED,osLabel: "Windows",bundleNoun: "the installer",emptyDirFix: `${FIX}\n\nThe STT helper and the capture helper are separate builds — see\ntechnical-documentation/engineering/build-and-packaging.md.`,});+ checkWinNoRedistDependency(dir);}function checkMacNativePayload(context) {diff --git a/technical-documentation/engineering/build-and-packaging.md b/technical-documentation/engineering/build-and-packaging.mdindex 9795be997..119eb8404 100644--- a/technical-documentation/engineering/build-and-packaging.md+++ b/technical-documentation/engineering/build-and-packaging.md@@ -64,6 +64,37 @@ This shipped: the 1.9.0 Store build loaded no compositor at all, so the editor o`electron/native/bin/`, local native build directories, the compositor build output, models, and caches are gitignored. Rebuilding from a source checkout therefore requires the complete platform toolchain and third-party SDKs; running the generic `npm run build` alone does not manufacture missing native artifacts. The Windows compositor's D3D11/FFmpeg prerequisites are described by the source POC in `crates/README.md`, while capture helper lookup and output conventions are documented in `electron/native/README.md`.+### Nothing Windows ships may need the Visual C++ Redistributable++`VCRUNTIME140.dll`, `VCRUNTIME140_1.dll` and `MSVCP140.dll` are **not part of Windows**. They come from the Visual C++ Redistributable, which arrives with Visual Studio, with the Rust MSVC toolchain, and with most desktop applications — so every machine that can build this repo already has them in `System32`, and so does almost every machine anyone would test on. A binary that depends on them therefore works locally, works in CI, and works in every packaging format, while being unloadable on a clean Windows image.++That is not a theoretical image. Store certification runs on one, and it rejected 1.9.1:++```+Error: Native Windows capture exited before recording started (code=3221225781)+```++`3221225781` is `0xC0000135`, `STATUS_DLL_NOT_FOUND`. The loader killed `wgc-capture.exe` before `main()`, so the parent only ever saw an exit code, and **screen recording was impossible on the test device** while the app itself started normally — Electron already links the CRT statically, which is why the window opened at all.++The import tables of the shipped 1.9.1 payload:++| Binary | Needed from the redistributable | Symptom on a clean machine |+|---|---|---|+| `wgc-capture.exe` | `VCRUNTIME140`, `VCRUNTIME140_1`, `MSVCP140` | recording fails instantly with an exit code |+| `cursor-sampler.exe` | `VCRUNTIME140`, `VCRUNTIME140_1`, `MSVCP140` | cursor capture unavailable |+| `compositor_view.node` | `VCRUNTIME140` | `require()` fails — blank preview, audio keeps playing |++The third row matters as much as the first. It is the *same visible symptom* as the MSIX/`PATH` bug documented above, from an unrelated cause, and colocation does nothing for it. Fixing only the helper would have failed certification a second time, on the preview, and looked like a regression of a fix that was actually correct.++The fix is to link the CRT statically, which removes the dependency instead of obliging us to redistribute Microsoft's DLLs beside our own:++- CMake helpers — `set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")` in `electron/native/wgc-capture/CMakeLists.txt`. These are standalone processes that share no CRT state with anything, so `/MT` costs about 100 KB each and nothing else.+- Rust addon — `-C target-feature=+crt-static` in `crates/.cargo/config.toml`. Safe for the napi cdylib: only opaque `napi_value`s cross the boundary, and Buffers handed to Node carry a finalizer that frees, in the addon, what the addon allocated.++`scripts/before-pack.cjs` now reads the import table of every `.exe`/`.dll`/`.node` in `electron/native/bin/win32-x64/` and refuses to package if any of them imports `msvcp*`/`vcruntime*`/`concrt*`. The `api-ms-win-crt-*` api-sets are deliberately not flagged: that is the UCRT, which does ship with Windows 10 and later.++**Local testing cannot confirm this class of fix.** This machine has the redistributable and always will, so a successful run here proves the build is not broken — it says nothing about the clean-machine behaviour. The import table is the only evidence for that half, which is why the guard reads it rather than running anything.+### Stale native artifacts**On Windows, always package with `npm run build:win`, not `npm run build`.**