Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

fix: keep abort for Windows and Linux release builds

Tw93d34e302c44b1
diff --git a/.claude/rules/tauri-runtime.md b/.claude/rules/tauri-runtime.md
index a0416015..45259290 100644
--- a/.claude/rules/tauri-runtime.md
+++ b/.claude/rules/tauri-runtime.md
@@ -39,4 +39,4 @@ paths:
- Download and toast paths must not hardcode `get_webview_window("pake")` when the action originates from a secondary window: IPC commands take the calling `WebviewWindow`, and `on_download` resolves toast by the event webview's label. Authenticated downloads should attach webview session cookies when available. Link-download heuristics prefer real file extensions, the `download` attribute, and `?download` / `?attachment` query hints; Cmd/Ctrl+click is navigation, not "save as"; do not re-add broad SPA roots such as `/assets/`, `/dist/`, `/files/`, or `/releases/` (see #1337, #1339).
- The shared download HTTP client pools connections without a cookie jar. Redirects must re-read the calling window's cookies for each HTTP(S) target, progressively narrow Referer, and never restore it after an HTTPS downgrade. Accept page context only from the calling window's actual origin, strip URL credentials, and flush asynchronous file writes before reporting success. Wry (through 0.57.2) misses macOS literal-IP cookies; only that branch reads the window's full cookie store, with exact IP, Path, Secure and expiry filtering. Keep normal hostnames and other platforms on `cookies_for_url`. Validate the real WebView's User-Agent, Referer, HttpOnly session cookie and wrong-Path exclusion in `tests/integration/ipc-security.mjs`.
- macOS menu navigation must keep working on blank error pages: Reload uses native `WebviewWindow::reload`, Go Home uses `navigate` + `resolve_home_url`, Back/Forward use the platform WKWebView history API rather than page `eval`. Copy URL reads `window.url()` so it does not depend on a live JS document.
-- The release profile is `panic = "unwind"` (2026-11-19), not `abort`: under abort an Objective-C exception that crosses a Rust frame ends the app, since Wry's `objc2::exception::catch` cannot hold, and WebKit raises one whenever an `ipc://` answer arrives for a request a closing or leaving page had out. Measured on macOS 26.7 with both mitigations off (no `deferWindowClose`, `CLOSE_GRACE` 0): the abort build died on the first sign-in popup with a crash report, the unwind build finished all three flows of `tests/integration/signin-popup-server.mjs` and stayed up. It costs about 1.9 MB per architecture (12.8 to 14.7 MB on arm64). Do not switch it back for size; `tests/unit/popup-close.test.ts` holds it. The close delay and the grace stay: they let the popup's last calls finish, which unwinding does not.
+- The release profile is `panic = "unwind"` (2026-11-19), not `abort`: under abort an Objective-C exception that crosses a Rust frame ends the app, since Wry's `objc2::exception::catch` cannot hold, and WebKit raises one whenever an `ipc://` answer arrives for a request a closing or leaving page had out. Measured on macOS 26.7 with both mitigations off (no `deferWindowClose`, `CLOSE_GRACE` 0): the abort build died on the first sign-in popup with a crash report, the unwind build finished all three flows of `tests/integration/signin-popup-server.mjs` and stayed up. It costs about 1.9 MB per architecture on macOS (12.8 to 14.7 MB on arm64). Windows and Linux have no such exception and pay more (the Windows x64 binary went from 11.9 to 16.4 MB), so the CLI passes `CARGO_PROFILE_RELEASE_PANIC=abort` to their release builds (`getPanicStrategyEnvironment` in `bin/builders/env.ts`), as any other builder of those platforms should; the profile's default stays unwind so that a builder that forgets is only larger, never back to the crash. Do not switch the profile back for size; `tests/unit/popup-close.test.ts` holds it. The close delay and the grace stay: they let the popup's last calls finish, which unwinding does not.
diff --git a/bin/builders/BaseBuilder.ts b/bin/builders/BaseBuilder.ts
index 0cdd695c..26c3e49c 100644
--- a/bin/builders/BaseBuilder.ts
+++ b/bin/builders/BaseBuilder.ts
@@ -30,6 +30,7 @@ import {
configureCargoRegistry,
detectPackageManager,
getBuildEnvironment,
+ getPanicStrategyEnvironment,
getBuildTimeout,
getInstallCommand,
getInstallTimeout,
@@ -291,6 +292,7 @@ export default abstract class BaseBuilder {
process.platform === 'win32' && this.options.windowsToolchain === 'gnu';
let buildEnv: Record<string, string> = {
...(baseEnv ?? {}),
+ ...getPanicStrategyEnvironment(),
...(isWindowsGnuBuild ? getWindowsGnuBuildEnvironment() : {}),
...(process.env.NO_STRIP ? { NO_STRIP: process.env.NO_STRIP } : {}),
};
diff --git a/bin/builders/env.ts b/bin/builders/env.ts
index 877d95f2..9bc1721f 100644
--- a/bin/builders/env.ts
+++ b/bin/builders/env.ts
@@ -31,6 +31,23 @@ export function getBuildEnvironment(): Record<string, string> | undefined {
};
}
+/**
+ * The release profile unwinds for macOS's sake: there Wry has to catch an
+ * exception WebKit raises for an answer to a request a closing or leaving page
+ * still had out, and it cannot under `panic = "abort"`, so the app quit.
+ * Windows and Linux have no such exception to hold, and unwinding made the
+ * Windows x64 binary 4.5 MB larger (11.9 to 16.4 MB), so their release builds
+ * keep abort. A value the user already set wins.
+ */
+export function getPanicStrategyEnvironment(
+ platform: NodeJS.Platform = process.platform,
+): Record<string, string> {
+ if (platform === 'darwin' || process.env.CARGO_PROFILE_RELEASE_PANIC) {
+ return {};
+ }
+ return { CARGO_PROFILE_RELEASE_PANIC: 'abort' };
+}
+
/**
* Build scripts and proc-macros compile for the rustup *host* toolchain, not
* the `--target` triple, even when cross-compiling. Pake's own
diff --git a/dist/cli.js b/dist/cli.js
index e20dc7c8..47bdc902 100644
--- a/dist/cli.js
+++ b/dist/cli.js
@@ -1673,6 +1673,20 @@ function getBuildEnvironment() {
PATH: buildPath,
};
}
+/**
+ * The release profile unwinds for macOS's sake: there Wry has to catch an
+ * exception WebKit raises for an answer to a request a closing or leaving page
+ * still had out, and it cannot under `panic = "abort"`, so the app quit.
+ * Windows and Linux have no such exception to hold, and unwinding made the
+ * Windows x64 binary 4.5 MB larger (11.9 to 16.4 MB), so their release builds
+ * keep abort. A value the user already set wins.
+ */
+function getPanicStrategyEnvironment(platform = process.platform) {
+ if (platform === 'darwin' || process.env.CARGO_PROFILE_RELEASE_PANIC) {
+ return {};
+ }
+ return { CARGO_PROFILE_RELEASE_PANIC: 'abort' };
+}
/**
* Build scripts and proc-macros compile for the rustup *host* toolchain, not
* the `--target` triple, even when cross-compiling. Pake's own
@@ -2031,6 +2045,7 @@ class BaseBuilder {
const isWindowsGnuBuild = process.platform === 'win32' && this.options.windowsToolchain === 'gnu';
let buildEnv = {
...(baseEnv ?? {}),
+ ...getPanicStrategyEnvironment(),
...(isWindowsGnuBuild ? getWindowsGnuBuildEnvironment() : {}),
...(process.env.NO_STRIP ? { NO_STRIP: process.env.NO_STRIP } : {}),
};
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index ba455f2f..4a6dd4a7 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -118,7 +118,11 @@ custom-protocol = ["tauri/custom-protocol"]
# an Objective-C exception that crosses a Rust frame ends the whole app. WebKit
# raises one when an answer arrives for a request a closing or leaving page had
# out, and a sign-in popup closing itself ended the app that way. Costs about
-# 1.9 MB per architecture (12.8 to 14.7 MB on arm64 macOS, 2026-11-19).
+# 1.9 MB per architecture on macOS (12.8 to 14.7 MB on arm64, 2026-11-19).
+# Windows and Linux have no such exception and pay more for it (4.5 MB on
+# Windows x64), so the CLI builds them with CARGO_PROFILE_RELEASE_PANIC=abort
+# (bin/builders/env.ts); a plain `tauri build` there unwinds, which is only
+# larger.
panic = "unwind"
codegen-units = 1
lto = "thin"
diff --git a/tests/unit/base-builder.test.ts b/tests/unit/base-builder.test.ts
index 4e4daf73..5d67821b 100644
--- a/tests/unit/base-builder.test.ts
+++ b/tests/unit/base-builder.test.ts
@@ -22,6 +22,7 @@ import {
detectPackageManager,
getBuildEnvironment,
getInstallCommand,
+ getPanicStrategyEnvironment,
} from '@/builders/env';
import logger from '@/options/logger';
import { CN_MIRROR_ENV, isCnMirrorEnabled } from '@/utils/mirror';
@@ -106,6 +107,27 @@ describe('BaseBuilder guards', () => {
await Promise.all(tempDirs.splice(0).map((dir) => fsExtra.remove(dir)));
});
+ it('keeps abort for Windows and Linux release builds, and unwind for macOS', () => {
+ const original = process.env.CARGO_PROFILE_RELEASE_PANIC;
+ delete process.env.CARGO_PROFILE_RELEASE_PANIC;
+ try {
+ // macOS needs the profile's unwind to hold an exception from WebKit.
+ expect(getPanicStrategyEnvironment('darwin')).toEqual({});
+ for (const platform of ['win32', 'linux'] as const) {
+ expect(getPanicStrategyEnvironment(platform)).toEqual({
+ CARGO_PROFILE_RELEASE_PANIC: 'abort',
+ });
+ }
+ // A value the user set is theirs to keep.
+ process.env.CARGO_PROFILE_RELEASE_PANIC = 'unwind';
+ expect(getPanicStrategyEnvironment('win32')).toEqual({});
+ } finally {
+ if (original === undefined)
+ delete process.env.CARGO_PROFILE_RELEASE_PANIC;
+ else process.env.CARGO_PROFILE_RELEASE_PANIC = original;
+ }
+ });
+
it('prepends /usr/bin to PATH for macOS build environment', () => {
const originalPath = process.env.PATH;
process.env.PATH = '/opt/homebrew/bin:/usr/local/bin';