fix: publish sidecar with native libs alongside exe, optimize prebuild

- Keep native DLLs outside single-file bundle (IncludeNativeLibrariesForSelfExtract=false)
- Prebuild script copies all output to Tauri bin (skips .pdb and .metal)
- Only copy runtimes for the target platform (e.g. win-x64), strip all others
- Clean stale runtimes on each rebuild

Co-Authored-By: Oz <oz-agent@warp.dev>
This commit is contained in:
Jacob Schmidt 2026-03-02 22:41:38 -06:00
parent 0d77300c22
commit d6523c6876
2 changed files with 40 additions and 10 deletions

View File

@ -1,5 +1,5 @@
import { spawnSync } from "node:child_process"; import { spawnSync } from "node:child_process";
import { copyFileSync, existsSync, mkdirSync } from "node:fs"; import { copyFileSync, cpSync, existsSync, mkdirSync, readdirSync, rmSync, statSync } from "node:fs";
import path from "node:path"; import path from "node:path";
import { fileURLToPath } from "node:url"; import { fileURLToPath } from "node:url";
@ -51,10 +51,10 @@ function publishProject(projectPath, runtime) {
runtime, runtime,
"--self-contained", "--self-contained",
"-p:PublishSingleFile=true", "-p:PublishSingleFile=true",
"-p:IncludeNativeLibrariesForSelfExtract=true", "-p:IncludeNativeLibrariesForSelfExtract=false",
"-p:IncludeAllContentForSelfExtract=true",
"-p:RestoreIgnoreFailedSources=true", "-p:RestoreIgnoreFailedSources=true",
"-p:NuGetAudit=false", "-p:NuGetAudit=false",
"-p:ErrorOnDuplicatePublishOutputFiles=false",
"-o", "-o",
publishOutputDir, publishOutputDir,
]; ];
@ -72,17 +72,47 @@ function publishProject(projectPath, runtime) {
} }
} }
function stageBinary(fileName) { function stageOutput(fileName) {
const publishedBinary = path.join(publishOutputDir, fileName); const publishedBinary = path.join(publishOutputDir, fileName);
const bundledBinary = path.join(tauriBinDir, fileName);
if (!existsSync(publishedBinary)) { if (!existsSync(publishedBinary)) {
throw new Error(`Published binary not found: ${publishedBinary}`); throw new Error(`Published binary not found: ${publishedBinary}`);
} }
mkdirSync(tauriBinDir, { recursive: true }); mkdirSync(tauriBinDir, { recursive: true });
copyFileSync(publishedBinary, bundledBinary);
console.log(`Staged binary for Tauri: ${bundledBinary}`); const skipExts = new Set([".pdb", ".metal"]);
for (const entry of readdirSync(publishOutputDir)) {
const ext = path.extname(entry).toLowerCase();
if (skipExts.has(ext)) continue;
const src = path.join(publishOutputDir, entry);
const dest = path.join(tauriBinDir, entry);
if (entry === "runtimes") {
// Only copy the runtimes subdirectory matching the target platform
stageRuntimes(src, dest, runtime);
} else if (statSync(src).isDirectory()) {
cpSync(src, dest, { recursive: true, force: true });
} else {
copyFileSync(src, dest);
}
}
console.log(`Staged sidecar + native libs to: ${tauriBinDir}`);
}
function stageRuntimes(runtimesDir, destDir, rid) {
// Only copy the subdirectory that matches our runtime identifier (e.g. win-x64)
const ridDir = path.join(runtimesDir, rid);
if (!existsSync(ridDir)) {
console.warn(`No runtimes found for ${rid}, skipping runtimes/`);
return;
}
// Remove stale runtimes from previous builds
if (existsSync(destDir)) {
rmSync(destDir, { recursive: true, force: true });
}
const destRidDir = path.join(destDir, rid);
cpSync(ridDir, destRidDir, { recursive: true, force: true });
console.log(`Copied runtimes/${rid} (skipped ${readdirSync(runtimesDir).length - 1} other platform(s))`);
} }
const runtime = runtimeForCurrentPlatform(); const runtime = runtimeForCurrentPlatform();
@ -94,4 +124,4 @@ console.log(
console.log("Publishing Journal.Sidecar..."); console.log("Publishing Journal.Sidecar...");
publishProject(sidecarProject, runtime); publishProject(sidecarProject, runtime);
stageBinary(sidecarName); stageOutput(sidecarName);

View File

@ -2,8 +2,8 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract> <IncludeNativeLibrariesForSelfExtract>false</IncludeNativeLibrariesForSelfExtract>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract> <ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>