88 description : ' Print the output after the build'
99 required : false
1010 default : ' false'
11+ skip-native :
12+ description : >-
13+ Skip the NAPI binding cache and all native cargo/napi build steps; the
14+ native binaries must already be in place (e.g. downloaded from the
15+ windows-cli-binaries artifact produced by the build-windows-cli job).
16+ required : false
17+ default : ' false'
1118
1219runs :
1320 using : ' composite'
@@ -18,14 +25,17 @@ runs:
1825 target : ${{ inputs.target }}
1926 upload : ' false'
2027
21- # Compute cache key once before any builds modify files
22- # (packages/cli/package.json is modified by syncTestPackageExports during build-ts)
23- # Include env vars (RELEASE_BUILD, DEBUG, VERSION) to ensure cache miss on release builds
28+ # Compute the shared input hash before builds modify files
29+ # (packages/cli/package.json is modified by syncTestPackageExports during build-ts).
30+ - uses : ./.github/actions/compute-native-cache-input-hash
31+ id : native-cache-inputs
32+
33+ # Include env vars (RELEASE_BUILD, DEBUG, VERSION) to ensure cache miss on release builds.
2434 - name : Compute NAPI binding cache key
2535 id : cache-key
2636 shell : bash
2737 run : |
28- echo "key=napi-binding-v3-${INPUTS_TARGET}-${RELEASE_BUILD}-${DEBUG}-${VERSION}-${NPM_TAG}-${{ hashFiles('packages/tools/.upstream-versions.json', 'rust-toolchain.toml', 'Cargo.lock', 'crates/**/*.rs', 'crates/*/Cargo.toml', 'packages/cli/binding/**/*.rs', 'packages/cli/binding/Cargo.toml', 'Cargo.toml', '.cargo/config.toml', 'packages/cli/package.json', 'packages/cli/build.ts', 'packages/cli/tsdown.config.ts') }}" >> $GITHUB_OUTPUT
38+ echo "key=napi-binding-v3-${INPUTS_TARGET}-${RELEASE_BUILD}-${DEBUG}-${VERSION}-${NPM_TAG}-${{ steps.native-cache-inputs.outputs.hash }}" >> " $GITHUB_OUTPUT"
2939 env :
3040 INPUTS_TARGET : ${{ inputs.target }}
3141
3848 # Cache NAPI bindings and Rust CLI binary (the slow parts, especially on Windows)
3949 - name : Restore NAPI binding cache
4050 id : cache-restore
51+ if : inputs.skip-native != 'true'
4152 uses : actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
4253 with :
4354 path : |
5263 ${{ steps.rust-target.outputs.dir }}/${{ inputs.target }}/release/vp-setup.exe
5364 key : ${{ steps.cache-key.outputs.key }}
5465
66+ # Single source of truth for "build the native binaries in this job":
67+ # false when the caller supplied prebuilt ones (skip-native) or the cache
68+ # already has them. Every native build step (and the cache save) gates on
69+ # this one flag instead of repeating the two-part condition.
70+ - name : Decide native build
71+ id : native
72+ shell : bash
73+ run : echo "build=${{ inputs.skip-native != 'true' && steps.cache-restore.outputs.cache-hit != 'true' }}" >> "$GITHUB_OUTPUT"
74+
5575 # Apply Vite+ branding patches to vite source (CI checks out
5676 # upstream vite which doesn't have branding patches)
5777 - name : Brand vite
@@ -69,14 +89,14 @@ runs:
6989
7090 # Install zig + cargo-zigbuild for musl cross-compilation (napi-cross only supports gnu)
7191 - name : Add musl Rust target
72- if : steps.cache-restore .outputs.cache-hit ! = 'true' && contains(inputs.target, 'musl')
92+ if : steps.native .outputs.build = = 'true' && contains(inputs.target, 'musl')
7393 shell : bash
7494 run : rustup target add ${INPUTS_TARGET}
7595 env :
7696 INPUTS_TARGET : ${{ inputs.target }}
7797
7898 - name : Setup zig (musl)
79- if : steps.cache-restore .outputs.cache-hit ! = 'true' && contains(inputs.target, 'musl')
99+ if : steps.native .outputs.build = = 'true' && contains(inputs.target, 'musl')
80100 uses : mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2.2.1
81101 with :
82102 version : 0.15.2
@@ -87,15 +107,15 @@ runs:
87107 # the pinned git commit. TODO: revert to taiki-e/install-action once
88108 # cargo-zigbuild > 0.22.3 is released.
89109 - name : Install cargo-zigbuild (musl)
90- if : steps.cache-restore .outputs.cache-hit ! = 'true' && contains(inputs.target, 'musl')
110+ if : steps.native .outputs.build = = 'true' && contains(inputs.target, 'musl')
91111 shell : bash
92112 run : cargo install --locked --git https://github.com/rust-cross/cargo-zigbuild --rev 7e791b4be71b9870e0abccedf7885486803cd923 cargo-zigbuild
93113
94114 # NAPI builds - only run on cache miss (slow, especially on Windows)
95115 # Must run before vite-plus TypeScript builds which depend on the bindings
96116 - name : Build NAPI bindings (Linux gnu)
97117 shell : bash
98- if : steps.cache-restore .outputs.cache-hit ! = 'true' && contains(inputs.target, 'linux') && !contains(inputs.target, 'musl')
118+ if : steps.native .outputs.build = = 'true' && contains(inputs.target, 'linux') && !contains(inputs.target, 'musl')
99119 run : |
100120 pnpm --filter=vite-plus build-native --target ${INPUTS_TARGET} --use-napi-cross
101121 env :
@@ -106,7 +126,7 @@ runs:
106126
107127 - name : Build NAPI bindings (Linux musl)
108128 shell : bash
109- if : steps.cache-restore .outputs.cache-hit ! = 'true' && contains(inputs.target, 'musl')
129+ if : steps.native .outputs.build = = 'true' && contains(inputs.target, 'musl')
110130 run : |
111131 pnpm --filter=vite-plus build-native --target ${INPUTS_TARGET} -x
112132 env :
@@ -117,15 +137,15 @@ runs:
117137
118138 - name : Build NAPI bindings (non-Linux targets)
119139 shell : bash
120- if : steps.cache-restore .outputs.cache-hit ! = 'true' && !contains(inputs.target, 'linux')
140+ if : steps.native .outputs.build = = 'true' && !contains(inputs.target, 'linux')
121141 run : |
122142 pnpm --filter=vite-plus build-native --target ${INPUTS_TARGET}
123143 env :
124144 DEBUG : napi:*
125145 INPUTS_TARGET : ${{ inputs.target }}
126146
127147 - name : Build Rust CLI binary (Linux gnu)
128- if : steps.cache-restore .outputs.cache-hit ! = 'true' && contains(inputs.target, 'linux') && !contains(inputs.target, 'musl')
148+ if : steps.native .outputs.build = = 'true' && contains(inputs.target, 'linux') && !contains(inputs.target, 'musl')
129149 shell : bash
130150 run : |
131151 pnpm exec napi build --use-napi-cross --target ${INPUTS_TARGET} --release -p vite_global_cli
@@ -136,7 +156,7 @@ runs:
136156 INPUTS_TARGET : ${{ inputs.target }}
137157
138158 - name : Build Rust CLI binary (Linux musl)
139- if : steps.cache-restore .outputs.cache-hit ! = 'true' && contains(inputs.target, 'musl')
159+ if : steps.native .outputs.build = = 'true' && contains(inputs.target, 'musl')
140160 shell : bash
141161 run : |
142162 pnpm exec napi build -x --target ${INPUTS_TARGET} --release -p vite_global_cli
@@ -147,28 +167,28 @@ runs:
147167 INPUTS_TARGET : ${{ inputs.target }}
148168
149169 - name : Build Rust CLI binary (non-Linux targets)
150- if : steps.cache-restore .outputs.cache-hit ! = 'true' && !contains(inputs.target, 'linux')
170+ if : steps.native .outputs.build = = 'true' && !contains(inputs.target, 'linux')
151171 shell : bash
152172 run : cargo build --release --target ${INPUTS_TARGET} -p vite_global_cli
153173 env :
154174 INPUTS_TARGET : ${{ inputs.target }}
155175
156176 - name : Build trampoline shim binary (Windows only)
157- if : steps.cache-restore .outputs.cache-hit ! = 'true' && contains(inputs.target, 'windows')
177+ if : steps.native .outputs.build = = 'true' && contains(inputs.target, 'windows')
158178 shell : bash
159179 run : cargo build --release --target ${INPUTS_TARGET} -p vite_trampoline
160180 env :
161181 INPUTS_TARGET : ${{ inputs.target }}
162182
163183 - name : Build installer binary (Windows only)
164- if : steps.cache-restore .outputs.cache-hit ! = 'true' && contains(inputs.target, 'windows')
184+ if : steps.native .outputs.build = = 'true' && contains(inputs.target, 'windows')
165185 shell : bash
166186 run : cargo build --release --target ${INPUTS_TARGET} -p vite_installer
167187 env :
168188 INPUTS_TARGET : ${{ inputs.target }}
169189
170190 - name : Save NAPI binding cache
171- if : steps.cache-restore .outputs.cache-hit ! = 'true'
191+ if : steps.native .outputs.build = = 'true'
172192 uses : actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
173193 with :
174194 path : |
0 commit comments