Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.
Rust chatgptclaudeclidesktopdesktop-appelectron-alternativegeminilinuxmacosnativefierno-electronrusttauriweb-to-desktopwebsite-to-appwebviewwindowsyoutube
fix: preserve GNU linker flags with encoded Cargo flags
Tw93677fdadadd47
diff --git a/bin/builders/env.ts b/bin/builders/env.tsindex 3e011387..877d95f2 100644--- a/bin/builders/env.ts+++ b/bin/builders/env.ts@@ -35,7 +35,7 @@ export function getBuildEnvironment(): Record<string, string> | undefined {* Build scripts and proc-macros compile for the rustup *host* toolchain, not* the `--target` triple, even when cross-compiling. Pake's own* rust-toolchain.toml pins a bare channel (no host), which rustup resolves- * against the machine's configured default host — msvc on most Windows+ * against the machine's configured default host, msvc on most Windows* installs, regardless of whether MSVC is actually present. Without this,* a gnu `--target` build still shells out to the (possibly missing) MSVC* `link.exe` for every build script. RUSTUP_TOOLCHAIN is rustup's documented@@ -43,12 +43,26 @@ export function getBuildEnvironment(): Record<string, string> | undefined {* only affects this build subprocess. Left alone if the user already set it.*/export function getWindowsGnuBuildEnvironment(): Record<string, string> {- const excludeAllSymbols = '-C link-args=-Wl,--exclude-all-symbols';+ const excludeAllSymbols = ['-C', 'link-args=-Wl,--exclude-all-symbols'];const existingRustflags = process.env.RUSTFLAGS;+ const existingEncodedRustflags = process.env.CARGO_ENCODED_RUSTFLAGS;+ // Cargo prefers encoded flags over RUSTFLAGS, even when set to an empty value.+ const flags: Record<string, string> =+ existingEncodedRustflags !== undefined+ ? {+ CARGO_ENCODED_RUSTFLAGS: [+ ...(existingEncodedRustflags ? [existingEncodedRustflags] : []),+ ...excludeAllSymbols,+ ].join('\x1f'),+ }+ : {+ RUSTFLAGS: [+ ...(existingRustflags ? [existingRustflags] : []),+ ...excludeAllSymbols,+ ].join(' '),+ };return {- RUSTFLAGS: existingRustflags- ? `${existingRustflags} ${excludeAllSymbols}`- : excludeAllSymbols,+ ...flags,RUSTUP_TOOLCHAIN:process.env.RUSTUP_TOOLCHAIN || 'stable-x86_64-pc-windows-gnu',};diff --git a/dist/cli.js b/dist/cli.jsindex aa0297e8..e329ff25 100644--- a/dist/cli.js+++ b/dist/cli.js@@ -1408,7 +1408,7 @@ function getBuildEnvironment() {* Build scripts and proc-macros compile for the rustup *host* toolchain, not* the `--target` triple, even when cross-compiling. Pake's own* rust-toolchain.toml pins a bare channel (no host), which rustup resolves- * against the machine's configured default host — msvc on most Windows+ * against the machine's configured default host, msvc on most Windows* installs, regardless of whether MSVC is actually present. Without this,* a gnu `--target` build still shells out to the (possibly missing) MSVC* `link.exe` for every build script. RUSTUP_TOOLCHAIN is rustup's documented@@ -1416,12 +1416,25 @@ function getBuildEnvironment() {* only affects this build subprocess. Left alone if the user already set it.*/function getWindowsGnuBuildEnvironment() {- const excludeAllSymbols = '-C link-args=-Wl,--exclude-all-symbols';+ const excludeAllSymbols = ['-C', 'link-args=-Wl,--exclude-all-symbols'];const existingRustflags = process.env.RUSTFLAGS;+ const existingEncodedRustflags = process.env.CARGO_ENCODED_RUSTFLAGS;+ // Cargo prefers encoded flags over RUSTFLAGS, even when set to an empty value.+ const flags = existingEncodedRustflags !== undefined+ ? {+ CARGO_ENCODED_RUSTFLAGS: [+ ...(existingEncodedRustflags ? [existingEncodedRustflags] : []),+ ...excludeAllSymbols,+ ].join('\x1f'),+ }+ : {+ RUSTFLAGS: [+ ...(existingRustflags ? [existingRustflags] : []),+ ...excludeAllSymbols,+ ].join(' '),+ };return {- RUSTFLAGS: existingRustflags- ? `${existingRustflags} ${excludeAllSymbols}`- : excludeAllSymbols,+ ...flags,RUSTUP_TOOLCHAIN: process.env.RUSTUP_TOOLCHAIN || 'stable-x86_64-pc-windows-gnu',};}diff --git a/docs/cli-usage.md b/docs/cli-usage.mdindex ab123e2a..e9d4dbb0 100644--- a/docs/cli-usage.md+++ b/docs/cli-usage.md@@ -373,7 +373,7 @@ Select the Rust toolchain used for Windows builds. Windows only; ignored on othe--windows-toolchain gnu```-If no MSVC Build Tools are detected and a GNU toolchain is available, Pake logs a hint to retry with `--windows-toolchain gnu` rather than failing deep in the build with an unexplained linker error. Requesting `gnu` does not change your default Rust toolchain or any global `rustup`/environment settings — it only affects the current build subprocess.+If no MSVC Build Tools are detected and a GNU toolchain is available, Pake logs a hint to retry with `--windows-toolchain gnu` rather than failing deep in the build with an unexplained linker error. Requesting `gnu` does not change your default Rust toolchain or any global `rustup`/environment settings; it only affects the current build subprocess.#### [no-bundle]diff --git a/tests/unit/windows-toolchain.test.ts b/tests/unit/windows-toolchain.test.tsindex faf2012c..76a0c31d 100644--- a/tests/unit/windows-toolchain.test.ts+++ b/tests/unit/windows-toolchain.test.ts@@ -75,14 +75,24 @@ describe('WinBuilder toolchain target selection', () => {describe('getWindowsGnuBuildEnvironment', () => {const originalRustflags = process.env.RUSTFLAGS;+ const originalEncodedRustflags = process.env.CARGO_ENCODED_RUSTFLAGS;const originalRustupToolchain = process.env.RUSTUP_TOOLCHAIN;+ beforeEach(() => {+ delete process.env.CARGO_ENCODED_RUSTFLAGS;+ });+afterEach(() => {if (originalRustflags === undefined) {delete process.env.RUSTFLAGS;} else {process.env.RUSTFLAGS = originalRustflags;}+ if (originalEncodedRustflags === undefined) {+ delete process.env.CARGO_ENCODED_RUSTFLAGS;+ } else {+ process.env.CARGO_ENCODED_RUSTFLAGS = originalEncodedRustflags;+ }if (originalRustupToolchain === undefined) {delete process.env.RUSTUP_TOOLCHAIN;} else {@@ -116,6 +126,27 @@ describe('getWindowsGnuBuildEnvironment', () => {RUSTUP_TOOLCHAIN: '1.95.0-x86_64-pc-windows-gnu',});});++ it('appends to encoded flags without merging lower-priority RUSTFLAGS', () => {+ process.env.CARGO_ENCODED_RUSTFLAGS =+ '-C\x1flink-arg=C:/Path With Spaces/lib.a';+ process.env.RUSTFLAGS = '-C target-cpu=native';+ const env = getWindowsGnuBuildEnvironment();+ expect(env.CARGO_ENCODED_RUSTFLAGS).toBe(+ '-C\x1flink-arg=C:/Path With Spaces/lib.a\x1f-C\x1flink-args=-Wl,--exclude-all-symbols',+ );+ expect(env.RUSTFLAGS).toBeUndefined();+ });++ it('uses encoded flags even when the existing variable is empty', () => {+ process.env.CARGO_ENCODED_RUSTFLAGS = '';+ process.env.RUSTFLAGS = '-C target-cpu=native';+ const env = getWindowsGnuBuildEnvironment();+ expect(env.CARGO_ENCODED_RUSTFLAGS).toBe(+ '-C\x1flink-args=-Wl,--exclude-all-symbols',+ );+ expect(env.RUSTFLAGS).toBeUndefined();+ });});class TestBuilder extends BaseBuilder {