Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
refactor(scripts): delegate build-cap-muxer to build-desktop-binaries
Richie McIlroyb1403f849b51
diff --git a/apps/desktop/package.json b/apps/desktop/package.jsonindex 9306e4370..77e04d9d8 100644--- a/apps/desktop/package.json+++ b/apps/desktop/package.json@@ -4,7 +4,7 @@"scripts": {"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",+ "build:sidecar": "node ../../scripts/build-desktop-binaries.mjs","preparescript": "node scripts/prepare.js","localdev": "dotenv -e ../../.env -- vinxi dev --port 3002","build": "vinxi build",diff --git a/package.json b/package.jsonindex 8ae22dd6d..4d4458d4d 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": "node scripts/build-cap-muxer.mjs && dotenv -e .env -- pnpm --dir apps/desktop run preparescript && dotenv -e .env -- pnpm --dir apps/desktop tauri build --verbose",+ "tauri:build": "node scripts/build-desktop-binaries.mjs && dotenv -e .env -- pnpm --dir apps/desktop run preparescript && dotenv -e .env -- pnpm --dir apps/desktop tauri build --verbose","typecheck": "pnpm --dir apps/web exec next typegen && 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.mjsindex ef01f5a7d..9864d64ae 100644--- a/scripts/build-cap-muxer.mjs+++ b/scripts/build-cap-muxer.mjs@@ -1,140 +1 @@-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] || process.env.RUST_TARGET_TRIPLE || detectHostTriple();- const ext = target.includes("windows") ? ".exe" : "";-- await fs.mkdir(binariesDir, { recursive: true });-- for (const sidecar of [- {- packageName: "cap-muxer",- sourceBinary: "cap-muxer",- destBinary: "cap-muxer",- watchPaths: [- path.join(repoRoot, "crates", "cap-muxer"),- path.join(repoRoot, "crates", "cap-muxer-protocol"),- path.join(repoRoot, "Cargo.lock"),- ],- },- {- packageName: "cap",- sourceBinary: "cap",- destBinary: "cap-exporter",- watchPaths: [- path.join(repoRoot, "apps", "cli"),- path.join(repoRoot, "crates", "editor"),- path.join(repoRoot, "crates", "enc-ffmpeg"),- path.join(repoRoot, "crates", "export"),- path.join(repoRoot, "crates", "media"),- path.join(repoRoot, "crates", "media-info"),- path.join(repoRoot, "crates", "project"),- path.join(repoRoot, "crates", "rendering"),- path.join(repoRoot, "Cargo.lock"),- ],- },- ]) {- await buildSidecar(sidecar, target, ext);- }-}--async function buildSidecar(sidecar, target, ext) {- const src = path.join(- repoRoot,- "target",- target,- "release",- `${sidecar.sourceBinary}${ext}`,- );- const dest = path.join(binariesDir, `${sidecar.destBinary}-${target}${ext}`);-- if (await isUpToDate(dest, sidecar.watchPaths)) {- console.log(`${sidecar.destBinary} sidecar up to date: ${dest}`);- return;- }-- console.log(`Building ${sidecar.destBinary} sidecar for ${target}...`);- const cargo = spawnSync(- "cargo",- ["build", "--release", "-p", sidecar.packageName, "--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.copyFile(src, dest);- console.log(`Copied ${src} -> ${dest}`);-}--main().catch((err) => {- console.error(err);- process.exit(1);-});+import "./build-desktop-binaries.mjs";diff --git a/scripts/build-cap-muxer.sh b/scripts/build-cap-muxer.shindex 2fdd9bfb6..b01b5fc56 100755--- a/scripts/build-cap-muxer.sh+++ b/scripts/build-cap-muxer.sh@@ -1,52 +1,4 @@#!/usr/bin/env bashset -euo pipefail-# Build desktop sidecar binaries with the target-triple suffix Tauri's-# externalBin expects, and copy them into apps/desktop/src-tauri/binaries.-#-# Usage:-# scripts/build-cap-muxer.sh # uses host triple-# scripts/build-cap-muxer.sh <target-triple> # uses given triple-#-# Example target triples:-# aarch64-apple-darwin-# x86_64-apple-darwin-# x86_64-pc-windows-msvc--TARGET="${1:-}"-if [[ -z "$TARGET" ]]; then- TARGET="$(rustc -vV | sed -n 's|host: ||p')"-fi--REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"-BINARIES_DIR="$REPO_ROOT/apps/desktop/src-tauri/binaries"--EXT=""-case "$TARGET" in- *windows*) EXT=".exe" ;;-esac--mkdir -p "$BINARIES_DIR"--build_sidecar() {- local package_name="$1"- local source_binary="$2"- local dest_binary="$3"-- echo "Building $dest_binary for $TARGET..."- cargo build --release -p "$package_name" --target "$TARGET"-- local src="$REPO_ROOT/target/$TARGET/release/$source_binary$EXT"- local dest="$BINARIES_DIR/$dest_binary-$TARGET$EXT"-- if [[ ! -f "$src" ]]; then- echo "error: built binary not found at $src" >&2- exit 1- fi-- cp "$src" "$dest"- echo "Copied $(realpath "$src" 2>/dev/null || echo "$src") -> $dest"-}--build_sidecar "cap-muxer" "cap-muxer" "cap-muxer"-build_sidecar "cap" "cap" "cap-exporter"+exec "$(dirname "$0")/build-desktop-binaries.sh" "$@"