Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Add cap-muxer build script and integrate sidecar

Richie McIlroyc2fc54bdff11
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index 49eb8f37a..3e32c06fb 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -2,8 +2,9 @@
"name": "@cap/desktop",
"type": "module",
"scripts": {
- "dev": "pnpm -w cap-setup && dotenv -e ../../.env -- pnpm run preparescript && dotenv -e ../../.env -- pnpm tauri dev",
- "build:tauri": "dotenv -e ../../.env -- pnpm run preparescript && dotenv -e ../../.env -- pnpm tauri build",
+ "dev": "pnpm -w cap-setup && pnpm build:sidecar && dotenv -e ../../.env -- pnpm run preparescript && dotenv -e ../../.env -- pnpm tauri dev",
+ "build:tauri": "pnpm build:sidecar && dotenv -e ../../.env -- pnpm run preparescript && dotenv -e ../../.env -- pnpm tauri build",
+ "build:sidecar": "node ../../scripts/build-cap-muxer.mjs",
"preparescript": "node scripts/prepare.js",
"localdev": "dotenv -e ../../.env -- vinxi dev --port 3002",
"build": "vinxi build",
diff --git a/apps/web/package.json b/apps/web/package.json
index f26557a0b..0d21caf3b 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -3,11 +3,11 @@
"version": "0.3.1",
"private": true,
"scripts": {
- "dev": "NODE_OPTIONS='--disable-warning=DEP0169' dotenv -e ../../.env -- next dev",
+ "dev": "cross-env NODE_OPTIONS=--disable-warning=DEP0169 dotenv -e ../../.env -- next dev",
"build": "next build --turbopack",
"build:web": "next build --turbopack",
"build:docker": "cd ../.. && docker build -t cap-web-docker . --no-cache --progress=plain",
- "start": "NODE_OPTIONS='--disable-warning=DEP0169' next start",
+ "start": "cross-env NODE_OPTIONS=--disable-warning=DEP0169 next start",
"compress-images": "bash tools/compress-images.sh",
"test": "vitest run",
"test:watch": "vitest",
@@ -161,6 +161,7 @@
"@vitest/coverage-v8": "^3.2.0",
"@vitest/ui": "^3.2.0",
"autoprefixer": "^10.4.14",
+ "cross-env": "^7.0.3",
"eslint": "^9.30.1",
"eslint-config-next": "16.2.1",
"postcss": "^8.4.23",
diff --git a/package.json b/package.json
index 6bbc2b536..6d96a8c7e 100644
--- a/package.json
+++ b/package.json
@@ -25,7 +25,7 @@
"docker:up": "turbo run docker:up",
"format": "pnpm exec biome check --write",
"lint": "pnpm exec biome lint",
- "tauri:build": "dotenv -e .env -- pnpm --dir apps/desktop tauri build --verbose",
+ "tauri:build": "node scripts/build-cap-muxer.mjs && dotenv -e .env -- pnpm --dir apps/desktop tauri build --verbose",
"typecheck": "pnpm tsc -b",
"test": "turbo run test",
"test:web": "pnpm --filter=@cap/web test",
diff --git a/scripts/build-cap-muxer.mjs b/scripts/build-cap-muxer.mjs
new file mode 100644
index 000000000..55f08b827
--- /dev/null
+++ b/scripts/build-cap-muxer.mjs
@@ -0,0 +1,109 @@
+import { spawnSync } from "node:child_process";
+import * as fs from "node:fs/promises";
+import * as path from "node:path";
+import { fileURLToPath } from "node:url";
+
+const __dirname = path.dirname(fileURLToPath(import.meta.url));
+const repoRoot = path.resolve(__dirname, "..");
+const binariesDir = path.join(
+ repoRoot,
+ "apps",
+ "desktop",
+ "src-tauri",
+ "binaries",
+);
+
+function detectHostTriple() {
+ const result = spawnSync("rustc", ["-vV"], { encoding: "utf8" });
+ if (result.status !== 0) {
+ const reason =
+ result.stderr || result.error?.message || `exit ${result.status}`;
+ throw new Error(`rustc -vV failed: ${reason}`);
+ }
+ const match = result.stdout.match(/^host:\s*(.+)$/m);
+ if (!match) throw new Error("Could not parse host triple from rustc -vV");
+ return match[1].trim();
+}
+
+async function fileExists(p) {
+ return await fs
+ .access(p)
+ .then(() => true)
+ .catch(() => false);
+}
+
+async function newestMtimeMs(targetPath) {
+ let max = 0;
+ const stack = [targetPath];
+ while (stack.length > 0) {
+ const current = stack.pop();
+ const stat = await fs.stat(current).catch(() => null);
+ if (!stat) continue;
+ if (stat.isFile()) {
+ if (stat.mtimeMs > max) max = stat.mtimeMs;
+ continue;
+ }
+ if (stat.isDirectory()) {
+ const entries = await fs.readdir(current);
+ for (const name of entries) stack.push(path.join(current, name));
+ }
+ }
+ return max;
+}
+
+async function isUpToDate(destPath, sourcePaths) {
+ if (!(await fileExists(destPath))) return false;
+ const destStat = await fs.stat(destPath);
+ for (const src of sourcePaths) {
+ const newest = await newestMtimeMs(src);
+ if (newest > destStat.mtimeMs) return false;
+ }
+ return true;
+}
+
+async function main() {
+ const target = process.argv[2] || detectHostTriple();
+ const ext = target.includes("windows") ? ".exe" : "";
+ const src = path.join(
+ repoRoot,
+ "target",
+ target,
+ "release",
+ `cap-muxer${ext}`,
+ );
+ const dest = path.join(binariesDir, `cap-muxer-${target}${ext}`);
+ const watchPaths = [
+ path.join(repoRoot, "crates", "cap-muxer"),
+ path.join(repoRoot, "crates", "cap-muxer-protocol"),
+ path.join(repoRoot, "Cargo.lock"),
+ ];
+
+ if (await isUpToDate(dest, watchPaths)) {
+ console.log(`cap-muxer sidecar up to date: ${dest}`);
+ return;
+ }
+
+ console.log(`Building cap-muxer sidecar for ${target}...`);
+ const cargo = spawnSync(
+ "cargo",
+ ["build", "--release", "-p", "cap-muxer", "--target", target],
+ { stdio: "inherit", cwd: repoRoot },
+ );
+ if (cargo.status !== 0) {
+ process.exit(cargo.status ?? 1);
+ }
+
+ if (!(await fileExists(src))) {
+ console.error(`error: built binary not found at ${src}`);
+ process.exit(1);
+ }
+
+ await fs.mkdir(binariesDir, { recursive: true });
+ await fs.copyFile(src, dest);
+ console.log(`Copied ${src} -> ${dest}`);
+}
+
+main().catch((err) => {
+ console.error(err);
+ process.exit(1);
+});
diff --git a/scripts/setup.js b/scripts/setup.js
index 0a2b3b2ca..ca372d31e 100644
--- a/scripts/setup.js
+++ b/scripts/setup.js
@@ -114,6 +114,8 @@ async function main() {
onnxRuntimePath,
)}" }\n`;
} else if (process.platform === "win32") {
+ await ensureMsvcVersion();
+
const FFMPEG_VERSION = "7.1";
const FFMPEG_ZIP_NAME = `ffmpeg-${FFMPEG_VERSION}-full_build-shared`;
const FFMPEG_ZIP_URL = `https://github.com/GyanD/codexffmpeg/releases/download/${FFMPEG_VERSION}/${FFMPEG_ZIP_NAME}.zip`;
@@ -351,6 +353,68 @@ async function missingFiles(dir, names) {
return names.filter((name) => !present.has(name));
}
+const MIN_MSVC_VERSION = [17, 12];
+
+async function ensureMsvcVersion() {
+ const programFilesX86 =
+ process.env["ProgramFiles(x86)"] || "C:\\Program Files (x86)";
+ const vswherePath = path.join(
+ programFilesX86,
+ "Microsoft Visual Studio",
+ "Installer",
+ "vswhere.exe",
+ );
+
+ if (!(await fileExists(vswherePath))) {
+ throw new Error(
+ `Visual Studio Installer not found at ${vswherePath}. ` +
+ `Install "Visual Studio 2022 Build Tools" ${MIN_MSVC_VERSION[0]}.${MIN_MSVC_VERSION[1]} ` +
+ `or newer with the "MSVC v143 - VS 2022 C++ x64/x86 build tools" component, ` +
+ `then re-run pnpm dev.`,
+ );
+ }
+
+ const { stdout } = await execFile(vswherePath, [
+ "-latest",
+ "-products",
+ "*",
+ "-requires",
+ "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
+ "-property",
+ "installationVersion",
+ ]);
+
+ const raw = stdout.trim();
+ if (!raw) {
+ throw new Error(
+ `No Visual Studio 2022 installation with MSVC v143 was found. ` +
+ `Install "Visual Studio 2022 Build Tools" ${MIN_MSVC_VERSION[0]}.${MIN_MSVC_VERSION[1]} ` +
+ `or newer with the "MSVC v143 - VS 2022 C++ x64/x86 build tools" component, ` +
+ `then re-run pnpm dev.`,
+ );
+ }
+
+ const parts = raw.split(".").map((n) => Number.parseInt(n, 10) || 0);
+ const [major, minor] = parts;
+ const isAtLeast =
+ major > MIN_MSVC_VERSION[0] ||
+ (major === MIN_MSVC_VERSION[0] && minor >= MIN_MSVC_VERSION[1]);
+
+ if (!isAtLeast) {
+ throw new Error(
+ `Visual Studio 2022 Build Tools ${major}.${minor} is too old (full: ${raw}).\n` +
+ `Cap requires ${MIN_MSVC_VERSION[0]}.${MIN_MSVC_VERSION[1]} or newer because the prebuilt ONNX Runtime ` +
+ `shipped by the 'ort' crate references vectorized-algorithm symbols ` +
+ `(e.g. __std_find_last_of_trivial_pos_*, __std_remove_8) that only exist in vcruntime140_1.lib from MSVC 14.42+.\n` +
+ `\nUpdate via the Visual Studio Installer, or from an elevated PowerShell:\n` +
+ ` winget upgrade --id Microsoft.VisualStudio.2022.BuildTools\n` +
+ `After updating, run: cargo clean -p cap-desktop && pnpm dev:windows\n`,
+ );
+ }
+
+ console.log(`MSVC toolchain ${major}.${minor} OK (full: ${raw})`);
+}
+
async function findExecutable(name) {
const command = process.platform === "win32" ? "where.exe" : "which";