build-env: MSVC C and C++ lose the build paths too (/d1trimfile in CL, /PDBALTPATH in LINK)
A library a build script compiles with MSVC (CMake, the cc crate) kept its absolute source paths through __FILE__: -ffile-prefix-map exists only on gcc and clang. cl.exe and link.exe read CL and LINK themselves, so the roots are trimmed whatever runs the compiler. Longest root first: the first match wins.
This commit is contained in:
parent
308d78920a
commit
7cc82a9f2a
4 changed files with 30 additions and 5 deletions
|
|
@ -114,7 +114,7 @@ const Shell = createShell({ ...site, panel: { id: 'app', title: 'wayBetter', com
|
|||
- `waybetter store sign [--init] --key <private key>` / `waybetter store verify --pub <key file>`: Ed25519 signature over the exact catalog bytes; any listed public key verifies (rotation). The private key is never printed or copied.
|
||||
- `waybetter i18n check [--write] [--verbose] [locale…]`: checks an app's catalogs (and the framework's in the same languages) with the `waybetter/i18n/check` rules, bundled plugins' inline English and the generated files; `--write` regenerates `languages.json` and the native localization files (macOS, Linux). `waybetter i18n extract [--missing]`: keys the code looks up that English lacks, and English keys without a literal lookup. Both read `waybetter.i18n.json` in the app's root (`locales`, `sources`, `nativeSources`, `bundledPlugins`, `runtimeKeys`, `supported`, `native`; schema: `i18n-config.schema.json`). `supported` lists the languages in the supported tier; every other catalog gets `tier: "community"` in the generated `languages.json` (`languages.schema.json`), and an app resolves its automatic language choices only to supported ones (`createLanguage({ supported })`).
|
||||
- `waybetter release windows|macos`: signed native releases and the update manifest (`waybetter.release.json`). The Windows build runs path-free (below) and every artifact must pass the privacy scan before anything is copied or signed.
|
||||
- `waybetter build-env -- <command>`: runs a build (`tauri build`, `cargo build`) so the binary holds none of the machine's paths: the home folder, the workspace, `CARGO_HOME`, `RUSTUP_HOME` and `CARGO_TARGET_DIR` become `/home`, `/src`, `/cargo`, `/rustup` and `/target` (`--remap-path-prefix` appended to the flags already in `RUSTFLAGS`/`CARGO_ENCODED_RUSTFLAGS`, `/PDBALTPATH` on MSVC, `-ffile-prefix-map` for C sources elsewhere). Without a command it prints that environment (`--json`).
|
||||
- `waybetter build-env -- <command>`: runs a build (`tauri build`, `cargo build`) so the binary holds none of the machine's paths: the home folder, the workspace, `CARGO_HOME`, `RUSTUP_HOME` and `CARGO_TARGET_DIR` become `/home`, `/src`, `/cargo`, `/rustup` and `/target` (`--remap-path-prefix` appended to the flags already in `RUSTFLAGS`/`CARGO_ENCODED_RUSTFLAGS`, `/PDBALTPATH` on MSVC; for C and C++ a build script compiles, `-ffile-prefix-map` on gcc and clang and, on MSVC, `/d1trimfile:<root>` in `CL` and `/PDBALTPATH` in `LINK`, which reach the cc crate, CMake and MSBuild alike). Without a command it prints that environment (`--json`).
|
||||
- `waybetter privacy-scan <paths…> [--terms <file>] [--tracked] [--history]`: searches files, binaries (UTF-8 and UTF-16), archives (zip, tar, gzip, zstd, .deb, DMG; NSIS installers, AppImages and xz with 7-Zip or the matching tool), git-tracked files and a repository's whole history for forbidden terms: the lines of a file kept outside every repository (`--terms`, `WAYBETTER_FORBIDDEN_TERMS`, or `"forbiddenTerms"` in `waybetter.release.json`) plus this machine's account name. A name is a hit as a whole word in any case; a name of three characters or fewer only in a path or as the capitalized word. Output shows file and line or offset with the term masked (`m***`); exit 1 on a hit, 2 when a container could not be opened. Reviewed false positives: `"privacyAllowlist"`, lines of `<file glob>: <regex over the context, the term written <term>>`.
|
||||
- `windows/languages/<Language>.nsh`: the Windows installer's messages for the languages Tauri does not ship, next to the installer template (`windows/installer.nsi`).
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,11 @@
|
|||
//
|
||||
// (`--remap-path-prefix`, added to CARGO_ENCODED_RUSTFLAGS after the flags RUSTFLAGS or
|
||||
// CARGO_ENCODED_RUSTFLAGS already hold), keeps the PDB's name but not its folder on MSVC
|
||||
// (`/PDBALTPATH:%_PDB%`) and gives C sources compiled by build scripts the same mapping
|
||||
// (`-ffile-prefix-map` in CFLAGS/CXXFLAGS on gcc and clang).
|
||||
// (`/PDBALTPATH:%_PDB%`) and gives C and C++ sources compiled by build scripts the same treatment:
|
||||
// `-ffile-prefix-map` in CFLAGS/CXXFLAGS on gcc and clang; on MSVC `/d1trimfile:<root>` in the CL
|
||||
// variable and `/PDBALTPATH:%_PDB%` in the LINK variable, which cl.exe and link.exe read themselves,
|
||||
// so the cc crate, CMake and MSBuild are all covered (`__FILE__` in a library a build script
|
||||
// compiles: there a root is cut off, not renamed, and the path stays relative).
|
||||
//
|
||||
// waybetter build-env -- tauri build run a command with that environment
|
||||
// waybetter build-env [--json] show it
|
||||
|
|
@ -26,6 +29,7 @@ export const BUILD_ENV_USAGE = `Usage:
|
|||
Runs the command (tauri build, cargo build, ...) so the binary holds no build path: the home
|
||||
folder, the workspace, CARGO_HOME, RUSTUP_HOME and CARGO_TARGET_DIR become /home, /src,
|
||||
/cargo, /rustup and /target. Flags already in RUSTFLAGS or CARGO_ENCODED_RUSTFLAGS are kept.
|
||||
C and C++ compiled by build scripts: -ffile-prefix-map (gcc, clang), /d1trimfile in CL (MSVC).
|
||||
waybetter build-env [--json] [--root <dir>]
|
||||
Prints that environment. The workspace root is --root, else the folder of the nearest
|
||||
waybetter.release.json, else the git work tree, else the working directory.`;
|
||||
|
|
@ -71,7 +75,14 @@ export function pathFreeBuildEnv({ root, env = process.env, platform = process.p
|
|||
if (msvc) add('-Clink-arg=/PDBALTPATH:%_PDB%');
|
||||
const out = { CARGO_ENCODED_RUSTFLAGS: flags.join(SEPARATOR) };
|
||||
|
||||
if (!msvc) {
|
||||
if (msvc) {
|
||||
// cl.exe takes the first /d1trimfile prefix that matches (any case, either slash), so the
|
||||
// longest root goes first. Quoted, and closed with a slash: a backslash would escape the quote.
|
||||
const trims = roots.map(([from]) => from).filter(from => !from.includes('"')).sort((a, b) => b.length - a.length).map(from => `"/d1trimfile:${from}/"`);
|
||||
out.CL = [...new Set([env.CL, ...trims])].filter(Boolean).join(' ');
|
||||
// C and C++ linked with debug info (a CMake RelWithDebInfo library) name their PDB the same way.
|
||||
out.LINK = [...new Set([env.LINK, '/PDBALTPATH:%_PDB%'])].filter(Boolean).join(' ');
|
||||
} else {
|
||||
// gcc and clang (cc crate: sqlite, ring and other bundled C). A flag cannot hold a space there.
|
||||
const prefixMaps = maps.filter(([from]) => !/\s/.test(from)).map(([from, to]) => `-ffile-prefix-map=${from}=${to}`);
|
||||
if (prefixMaps.length < maps.length) notes.push('a build path contains a space: C sources keep it (CFLAGS cannot express it)');
|
||||
|
|
|
|||
|
|
@ -241,12 +241,23 @@ test('build-env: roots remapped general to specific, existing flags kept, per pl
|
|||
assert.ok(flags.includes('--remap-path-prefix=\\\\?\\C:\\Users\\dev\\.rustup=/rustup'));
|
||||
assert.equal(flags.at(-1), '-Clink-arg=/PDBALTPATH:%_PDB%');
|
||||
assert.equal(windows.env.CFLAGS, undefined);
|
||||
// MSVC C and C++: cl.exe takes the first /d1trimfile that matches, so the longest root leads.
|
||||
assert.deepEqual(windows.env.CL.split(' '), ['C:/Users/dev/.rustup', 'C:/Users/dev/.cargo', 'C:/Users/dev/app', 'C:/Users/dev'].map(dir => `"/d1trimfile:${dir.replaceAll('/', '\\')}/"`));
|
||||
assert.equal(windows.env.LINK, '/PDBALTPATH:%_PDB%');
|
||||
const kept = pathFreeBuildEnv({ root: 'D:\\my apps\\app', home: 'C:\\Users\\dev', platform: 'win32', env: { CL: '/MP', LINK: '/DEBUG:NONE', CARGO_TARGET_DIR: 'D:\\t' } });
|
||||
assert.ok(kept.env.CL.startsWith('/MP "/d1trimfile:C:\\Users\\dev\\.rustup/" '));
|
||||
assert.ok(kept.env.CL.includes(' "/d1trimfile:D:\\my apps\\app/" ') && kept.env.CL.endsWith(' "/d1trimfile:D:\\t/"'));
|
||||
assert.equal(kept.env.LINK, '/DEBUG:NONE /PDBALTPATH:%_PDB%');
|
||||
const gnu = pathFreeBuildEnv({ root: 'C:\\Users\\dev\\app', home: 'C:\\Users\\dev', platform: 'win32', env: { CARGO_BUILD_TARGET: 'x86_64-pc-windows-gnu' } });
|
||||
assert.equal(gnu.env.CL, undefined);
|
||||
assert.equal(gnu.env.LINK, undefined);
|
||||
|
||||
const encoded = pathFreeBuildEnv({ root: '/home/dev/app', home: '/home/dev', platform: 'linux', env: { CARGO_ENCODED_RUSTFLAGS: '-Cfoo\x1f--remap-path-prefix=/home/dev=/home', CARGO_HOME: '/opt/cargo', CARGO_TARGET_DIR: '/tmp/t', CFLAGS: '-O2' } });
|
||||
assert.deepEqual(encoded.env.CARGO_ENCODED_RUSTFLAGS.split('\x1f'), ['-Cfoo', '--remap-path-prefix=/home/dev=/home', '--remap-path-prefix=/home/dev/app=/src',
|
||||
'--remap-path-prefix=/tmp/t=/target', '--remap-path-prefix=/opt/cargo=/cargo', '--remap-path-prefix=/home/dev/.rustup=/rustup']);
|
||||
assert.match(encoded.env.CFLAGS, /^-O2 -ffile-prefix-map=\/home\/dev=\/home .*-ffile-prefix-map=\/opt\/cargo=\/cargo/);
|
||||
assert.equal(encoded.env.CXXFLAGS.split(' ').length, 5);
|
||||
assert.equal(encoded.env.CL, undefined);
|
||||
});
|
||||
|
||||
test('release: an artifact holding a term stops the release before anything is written', async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue