Skip to content

feat: add Linux musl target support for NAPI bindings#995

Draft
fengmk2 wants to merge 5 commits intomainfrom
support-musl
Draft

feat: add Linux musl target support for NAPI bindings#995
fengmk2 wants to merge 5 commits intomainfrom
support-musl

Conversation

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Mar 17, 2026

Add build and publish support for x86_64-unknown-linux-musl and
aarch64-unknown-linux-musl targets, enabling vite-plus to run in
Alpine/musl-based Docker containers.

Closes #992

@fengmk2 fengmk2 self-assigned this Mar 17, 2026
Copy link
Member Author

fengmk2 commented Mar 17, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label auto-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch 2 times, most recently from 475016b to 45e4691 Compare March 17, 2026 15:16
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch from 45e4691 to bc38b7a Compare March 18, 2026 01:50
@fengmk2 fengmk2 marked this pull request as ready for review March 18, 2026 01:51
@fengmk2 fengmk2 requested a review from Brooooooklyn March 18, 2026 01:51
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch from bc38b7a to 810d51c Compare March 18, 2026 02:16
- Tier 2
- Windows arm64 (`aarch64-pc-windows-msvc`)
- Experimental
- Linux x64 musl (`x86_64-unknown-linux-musl`)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@branchseer Does vite-task support musl?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downloaded ciborium-ll v0.2.2

error: cannot produce cdylib for fspy_preload_unix v0.0.0 (https://github.com/voidzero-dev/vite-task.git?rev=398a147fd1ed42a88585d3a9481f200c3e56a2f4#398a147f) as the target x86_64-unknown-linux-musl does not support these crate types

Error: Process completed with exit code 101.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not supported. Needs extra work.

@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch from 810d51c to efc5c42 Compare March 18, 2026 02:28
@Brooooooklyn
Copy link
Member

@fengmk2 should also add musl target cargo tests and cli e2e tests

@fengmk2 fengmk2 force-pushed the support-musl branch 2 times, most recently from c63425a to 7ffe689 Compare March 18, 2026 03:51
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch from efc5c42 to d143fc6 Compare March 18, 2026 03:51
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch 2 times, most recently from 9db93c2 to cc73dcc Compare March 18, 2026 06:05
@fengmk2 fengmk2 force-pushed the support-musl branch 2 times, most recently from e49456f to 2572e70 Compare March 18, 2026 06:08
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch from cc73dcc to 000f043 Compare March 18, 2026 06:08
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch from 000f043 to 00ae674 Compare March 18, 2026 06:15
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch 2 times, most recently from cfccc29 to d64cba8 Compare March 18, 2026 07:42
@fengmk2 fengmk2 marked this pull request as draft March 18, 2026 08:17
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch from df57cf4 to 5534094 Compare March 18, 2026 11:38
@fengmk2 fengmk2 force-pushed the support-musl branch 3 times, most recently from 7e708ae to 996caf0 Compare March 18, 2026 11:57
@graphite-app graphite-app bot changed the base branch from trampoline-exe-for-shims to graphite-base/995 March 18, 2026 12:10
@fengmk2 fengmk2 force-pushed the graphite-base/995 branch from 04e854f to 641a5bc Compare March 18, 2026 12:26
@fengmk2 fengmk2 force-pushed the graphite-base/995 branch from 641a5bc to 1b89385 Compare March 18, 2026 12:44
permissions:
contents: read
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1

Check notice

Code scanning / zizmor

credential persistence through GitHub Actions artifacts Note test

credential persistence through GitHub Actions artifacts
permissions:
contents: read
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1

Check notice

Code scanning / zizmor

credential persistence through GitHub Actions artifacts Note test

credential persistence through GitHub Actions artifacts
fengmk2 added 4 commits March 18, 2026 13:18
## Summary

- Replace Windows `.cmd` shim wrappers with lightweight trampoline `.exe` binaries
- Eliminates the "Terminate batch job (Y/N)?" prompt on Ctrl+C
- The trampoline detects its tool name from its own filename, sets `VITE_PLUS_SHIM_TOOL` env var, spawns `vp.exe`, ignores Ctrl+C (child handles it), and propagates the exit code
- Thanks for the solution suggestion from @sunfkny

## Changes

- Add `crates/vite_trampoline/` — minimal Windows trampoline binary (~100-150KB)
- Update shim detection (`detect_shim_tool`) to check `VITE_PLUS_SHIM_TOOL` env var before `argv[0]`
- Replace `.cmd`/`.sh` wrapper creation with trampoline `.exe` copying in `setup.rs` and `global_install.rs`
- Add rename-before-copy pattern for refreshing `bin/vp.exe` while it's running
- Add legacy `.cmd`/`.sh` cleanup during `vp env setup --refresh`
- Update CI to build and distribute `vp-shim.exe` for Windows targets
- Update `install.ps1`, `install.sh`, `publish-native-addons.ts` for trampoline distribution
- Update `extract_platform_package` in upgrade path to also extract `vp-shim.exe`
- Update npm-link conflict detection to recognize `.exe` shims
- Add RFC document and update existing RFCs (`env-command`, `upgrade-command`, `vpx-command`)

## Manual testing (Windows)

### 1\. Fresh install via PowerShell

```powershell
Remove-Item -Recurse -Force "$env:USERPROFILE\.vite-plus" -ErrorAction SilentlyContinue
& ./packages/cli/install.ps1
dir "$env:USERPROFILE\.vite-plus\bin\*.exe"
dir "$env:USERPROFILE\.vite-plus\bin\*.cmd"
```

- [x] Trampoline `.exe` shims created for vp, node, npm, npx, vpx
- [x] No legacy `.cmd` wrappers for core tools (only `vp-use.cmd` if present)
- [x] `node --version` works
- [x] `npm --version` works
- [x] `vp --version` works

### 2\. Fresh install via Git Bash ([install.sh](http://install.sh))

```bash
rm -rf ~/.vite-plus
bash ./packages/cli/install.sh
ls -la ~/.vite-plus/current/bin/vp-shim.exe
```

- [x] `vp-shim.exe` copied alongside `vp.exe` in `current/bin/`
- [x] `node --version` works
- [x] `npm --version` works

### 3\. Ctrl+C behavior (the main fix)

```powershell
vp dev
# Press Ctrl+C in each shell
```

- [x] cmd.exe: clean exit, NO "Terminate batch job (Y/N)?" prompt
- [x] PowerShell: clean exit
- [x] Git Bash: clean exit

### 4\. Exit code propagation

```powershell
node -e "process.exit(42)"; echo $LASTEXITCODE
npm run nonexistent-script; echo $LASTEXITCODE
```

- [x] Exit code 42 propagated correctly
- [x] Non-zero exit code from failed npm command

### 5\. Nested shim invocations (recursion marker)

```powershell
npm --version
pnpm --version
```

- [x] `npm --version` prints version (npm spawns node internally)
- [x] `pnpm --version` prints version (pnpm spawns node internally)

### 6\. `vp env setup --refresh` (running exe overwrite)

```powershell
vp env setup --refresh
node --version
dir "$env:USERPROFILE\.vite-plus\bin\*.old"
```

- [x] Refresh succeeds without "sharing violation" error
- [x] Shims still work after refresh
- [x] `.old` files cleaned up (or only one recent if vp.exe was still running)

### 7\. `vp install -g` / `vp remove -g` (managed package shims)

```powershell
vp install -g typescript
where.exe tsc
tsc --version
vp remove -g typescript
dir "$env:USERPROFILE\.vite-plus\bin\tsc*"
```

- [x] `tsc.exe` created (NOT `tsc.cmd`)
- [x] `tsc --version` works
- [x] After remove: no `tsc.exe`, `tsc.cmd`, or extensionless `tsc` left behind

### 8\. `npm install -g` auto-link (npm-managed packages)

```powershell
npm install -g cowsay
where.exe cowsay
cowsay hello
npm uninstall -g cowsay
```

- [x] npm packages use `.cmd` wrapper (NOT trampoline)
- [x] `cowsay` works
- [x] Uninstall removes the `.cmd` wrapper

### 9\. `vp upgrade` and rollback

```powershell
vp --version
vp upgrade <version>
node --version
vp upgrade --rollback
vp --version
```

- [x] Upgrade succeeds, shims still work
- [x] Rollback succeeds, shims still work

### 10\. Install a pre-trampoline version (downgrade compatibility)

```powershell
$env:VITE_PLUS_VERSION = "<pre-trampoline-version>"
& ./packages/cli/install.ps1
Remove-Item Env:VITE_PLUS_VERSION
dir "$env:USERPROFILE\.vite-plus\bin\*.exe"
dir "$env:USERPROFILE\.vite-plus\bin\*.cmd"
```

- [x] Falls back to `.cmd` wrappers
- [x] Stale trampoline `.exe` shims removed (`node.exe`, `npm.exe`, etc.)
- [x] `vp --version` works via `.cmd` wrapper

### 11\. `vp env doctor`

```powershell
vp env doctor
```

- [x] Shows shims as working, no errors about missing files

### 12\. Cross-shell verification

- [x] cmd.exe: `node --version`, `npm --version`, `vp --version` all work
- [x] PowerShell: `node --version`, `npm --version`, `vp --version` all work
- [x] Git Bash: `node --version`, `npm --version`, `vp --version` all work

Closes #835
Add build and publish support for x86_64-unknown-linux-musl and
aarch64-unknown-linux-musl targets, enabling vite-plus to run in
Alpine/musl-based Docker containers.

Closes #992
Collapse 8 per-target Linux build steps into 2 using
contains(inputs.target, 'linux') with conditional TARGET_CFLAGS.
Add a default case to the musl target detection to fail fast on
unknown architectures.
Add cli-e2e-test-musl job that builds with musl target and runs
directly on ubuntu-latest (musl binaries are statically linked).
Includes full test parity with the glibc variant: vp check, global
package install, CLI snapshot tests, upgrade, and implode.
@graphite-app graphite-app bot force-pushed the graphite-base/995 branch from 86fda74 to ae93e93 Compare March 18, 2026 13:19
@graphite-app graphite-app bot changed the base branch from graphite-base/995 to trampoline-exe-for-shims March 18, 2026 13:19
The rolldown binding is loaded by Node.js on the host runner to run
JS build steps (rolldown build-node, vite build-types, etc.), not
cross-compiled into the output. Downloading a musl binding on a glibc
runner would cause binding.cjs to fail to load.
Base automatically changed from trampoline-exe-for-shims to main March 18, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants