Skip to content

Commit f412c8a

Browse files
authored
Remove wasm target (vercel#57437)
This PR removes the wasm target for the next-swc build for the next major version. The main motivation is that Turbopack does not support targeting wasm yet, and it would be a significant amount of work to add. We plan to make Turbopack the default zero-config experience in a minor version, possibly before we are able to support a wasm target, so we need to make this breaking change now. We also plan to make more improvements to the webpack experience with shared Rust code, which we have so far been blocked from implementing because of the current wasm restrictions. We would like to support a wasm target again in the future, but cannot say at this time when that would be. Closes WEB-1865
1 parent 6b18f39 commit f412c8a

File tree

5 files changed

+14
-130
lines changed

5 files changed

+14
-130
lines changed

.github/workflows/build_and_deploy.yml

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -340,65 +340,12 @@ jobs:
340340
name: turbo run summary
341341
path: .turbo/runs
342342

343-
build-wasm:
344-
strategy:
345-
matrix:
346-
target: [web, nodejs]
347-
348-
runs-on:
349-
- 'self-hosted'
350-
- 'linux'
351-
- 'x64'
352-
- 'metal'
353-
354-
steps:
355-
- uses: actions/checkout@v3
356-
357-
- name: Setup node
358-
uses: actions/setup-node@v3
359-
with:
360-
node-version: ${{ env.NODE_LTS_VERSION }}
361-
check-latest: true
362-
- run: corepack enable
363-
364-
- name: Install Rust
365-
uses: ./.github/actions/setup-rust
366-
with:
367-
targets: wasm32-unknown-unknown
368-
369-
- run: npm i -g turbo@${{ env.TURBO_VERSION }}
370-
371-
- name: Install wasm-pack
372-
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
373-
374-
- name: normalize versions
375-
run: node scripts/normalize-version-bump.js
376-
377-
- name: Build
378-
run: turbo run build-wasm -vvv --remote-cache-timeout 90 --summarize -- --target ${{ matrix.target }} --features tracing/release_max_level_info
379-
380-
- name: Add target to folder name
381-
run: '[[ -d "packages/next-swc/crates/wasm/pkg" ]] && mv packages/next-swc/crates/wasm/pkg packages/next-swc/crates/wasm/pkg-${{ matrix.target }} || ls packages/next-swc/crates/wasm'
382-
383-
- name: Upload turbo summary artifact
384-
uses: actions/upload-artifact@v3
385-
with:
386-
name: turbo run summary
387-
path: .turbo/runs
388-
389-
- name: Upload swc artifact
390-
uses: actions/upload-artifact@v3
391-
with:
392-
name: wasm-binaries
393-
path: packages/next-swc/crates/wasm/pkg-*
394-
395343
publishRelease:
396344
if: ${{ needs.build.outputs.isRelease == 'true' }}
397345
name: Potentially publish release
398346
runs-on: ubuntu-latest
399347
needs:
400348
- build
401-
- build-wasm
402349
- build-native
403350
permissions:
404351
contents: write
@@ -429,11 +376,6 @@ jobs:
429376
name: next-swc-binaries
430377
path: packages/next-swc/native
431378

432-
- uses: actions/download-artifact@v3
433-
with:
434-
name: wasm-binaries
435-
path: packages/next-swc/crates/wasm
436-
437379
- run: npm i -g npm@9.6.7 # need latest version for provenance (pinning to avoid bugs)
438380
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
439381
- run: ./scripts/publish-native.js

.github/workflows/build_and_test.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ jobs:
151151
afterBuild: RUST_BACKTRACE=0 NEXT_EXTERNAL_TESTS_FILTERS="$(pwd)/test/turbopack-tests-manifest.json" TURBOPACK=1 node run-tests.js --timings -g ${{ matrix.group }}/5 -c ${TEST_CONCURRENCY} --type integration
152152
secrets: inherit
153153

154-
test-next-swc-wasm:
155-
name: test next-swc wasm
156-
needs: ['build-native', 'build-next']
157-
uses: ./.github/workflows/build_reusable.yml
158-
with:
159-
skipForDocsOnly: 'yes'
160-
afterBuild: rustup target add wasm32-unknown-unknown && curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh && node ./scripts/normalize-version-bump.js && turbo run build-wasm -- --target nodejs --features tracing/release_max_level_info && git checkout . && mv packages/next-swc/crates/wasm/pkg packages/next-swc/crates/wasm/pkg-nodejs && node ./scripts/setup-wasm.mjs && NEXT_TEST_MODE=start TEST_WASM=true node run-tests.js test/production/pages-dir/production/test/index.test.ts test/e2e/streaming-ssr/index.test.ts
161-
secrets: inherit
154+
# test-next-swc-wasm:
155+
# name: test next-swc wasm
156+
# needs: ['build-native', 'build-next']
157+
# uses: ./.github/workflows/build_reusable.yml
158+
# with:
159+
# skipForDocsOnly: 'yes'
160+
# afterBuild: rustup target add wasm32-unknown-unknown && curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh && node ./scripts/normalize-version-bump.js && turbo run build-wasm -- --target nodejs --features tracing/release_max_level_info && git checkout . && mv packages/next-swc/crates/wasm/pkg packages/next-swc/crates/wasm/pkg-nodejs && node ./scripts/setup-wasm.mjs && NEXT_TEST_MODE=start TEST_WASM=true node run-tests.js test/production/pages-dir/production/test/index.test.ts test/e2e/streaming-ssr/index.test.ts
161+
# secrets: inherit
162162

163163
test-unit:
164164
name: test unit
@@ -258,7 +258,6 @@ jobs:
258258
'test-cargo-integration',
259259
'test-cargo-bench',
260260
'rust-check',
261-
'test-next-swc-wasm',
262261
'test-turbopack-dev',
263262
'test-turbopack-integration',
264263
]

contributing/core/building.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@ pnpm build
88

99
By default, the latest canary of the `next-swc` binaries will be installed and used. If you are actively working on Rust code or you need to test out the most recent Rust code that hasn't been published as a canary yet, you can [install Rust](https://www.rust-lang.org/tools/install) and run `pnpm --filter=@next/swc build-native`.
1010

11-
If you want to test out the wasm build locally, you will need to [install wasm-pack](https://rustwasm.github.io/wasm-pack/installer/). Run `pnpm --filter=@next/swc build-wasm --target <wasm_target>` to build and `node ./scripts/setup-wasm.mjs` to copy it into your `node_modules`. Run next with `NODE_OPTIONS='--no-addons'` to force it to use the wasm binary.
12-
1311
If you need to clean the project for any reason, use `pnpm clean`.

docs/04-architecture/nextjs-compiler.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ We chose to build on SWC for a few reasons:
1717

1818
- **Extensibility:** SWC can be used as a Crate inside Next.js, without having to fork the library or workaround design constraints.
1919
- **Performance:** We were able to achieve ~3x faster Fast Refresh and ~5x faster builds in Next.js by switching to SWC, with more room for optimization still in progress.
20-
- **WebAssembly:** Rust's support for WASM is essential for supporting all possible platforms and taking Next.js development everywhere.
2120
- **Community:** The Rust community and ecosystem are amazing and still growing.
2221

2322
## Supported Features

packages/next/src/build/swc/index.ts

Lines changed: 6 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const infoLog = (...args: any[]) => {
3131
* Based on napi-rs's target triples, returns triples that have corresponding next-swc binaries.
3232
*/
3333
export const getSupportedArchTriples: () => Record<string, any> = () => {
34-
const { darwin, win32, linux, freebsd, android } = platformArchTriples
34+
const { darwin, win32, linux } = platformArchTriples
3535

3636
return {
3737
darwin,
@@ -48,16 +48,6 @@ export const getSupportedArchTriples: () => Record<string, any> = () => {
4848
(triple: { abi: string }) => triple.abi !== 'gnux32'
4949
),
5050
arm64: linux.arm64,
51-
// This target is being deprecated, however we keep it in `knownDefaultWasmFallbackTriples` for now
52-
arm: linux.arm,
53-
},
54-
// Below targets are being deprecated, however we keep it in `knownDefaultWasmFallbackTriples` for now
55-
freebsd: {
56-
x64: freebsd.x64,
57-
},
58-
android: {
59-
arm64: android.arm64,
60-
arm: android.arm,
6151
},
6252
}
6353
}
@@ -77,7 +67,7 @@ const triples = (() => {
7767

7868
if (rawTargetTriple) {
7969
Log.warn(
80-
`Trying to load next-swc for target triple ${rawTargetTriple}, but there next-swc does not have native bindings support`
70+
`Trying to load next-swc for target triple ${rawTargetTriple}, but this target is not supported`
8171
)
8272
} else {
8373
Log.warn(
@@ -107,21 +97,6 @@ function checkVersionMismatch(pkgData: any) {
10797
}
10898
}
10999

110-
// These are the platforms we'll try to load wasm bindings first,
111-
// only try to load native bindings if loading wasm binding somehow fails.
112-
// Fallback to native binding is for migration period only,
113-
// once we can verify loading-wasm-first won't cause visible regressions,
114-
// we'll not include native bindings for these platform at all.
115-
const knownDefaultWasmFallbackTriples = [
116-
'x86_64-unknown-freebsd',
117-
'aarch64-linux-android',
118-
'arm-linux-androideabi',
119-
'armv7-unknown-linux-gnueabihf',
120-
'i686-pc-windows-msvc',
121-
// WOA targets are TBD, while current userbase is small we may support it in the future
122-
//'aarch64-pc-windows-msvc',
123-
]
124-
125100
// The last attempt's error code returned when cjs require to native bindings fails.
126101
// If node.js throws an error without error code, this should be `unknown` instead of undefined.
127102
// For the wasm-first targets (`knownDefaultWasmFallbackTriples`) this will be `unsupported_target`.
@@ -201,21 +176,6 @@ export async function loadBindings(): Promise<Binding> {
201176
}
202177

203178
let attempts: any[] = []
204-
const disableWasmFallback = process.env.NEXT_DISABLE_SWC_WASM
205-
const shouldLoadWasmFallbackFirst =
206-
!disableWasmFallback &&
207-
triples.some(
208-
(triple: any) =>
209-
!!triple?.raw && knownDefaultWasmFallbackTriples.includes(triple.raw)
210-
)
211-
212-
if (shouldLoadWasmFallbackFirst) {
213-
lastNativeBindingsLoadErrorCode = 'unsupported_target'
214-
const fallbackBindings = await tryLoadWasmWithFallback(attempts)
215-
if (fallbackBindings) {
216-
return resolve(fallbackBindings)
217-
}
218-
}
219179

220180
// Trickle down loading `fallback` bindings:
221181
//
@@ -224,7 +184,6 @@ export async function loadBindings(): Promise<Binding> {
224184
// that host system where generated package lock is not matching to the guest system running on, try to manually
225185
// download corresponding target triple and load it. This won't be triggered if native bindings are failed to load
226186
// with other reasons than `ERR_MODULE_NOT_FOUND`.
227-
// - Lastly, falls back to wasm binding where possible.
228187
try {
229188
return resolve(loadNative())
230189
} catch (a) {
@@ -242,15 +201,7 @@ export async function loadBindings(): Promise<Binding> {
242201
attempts = attempts.concat(a)
243202
}
244203

245-
// For these platforms we already tried to load wasm and failed, skip reattempt
246-
if (!shouldLoadWasmFallbackFirst && !disableWasmFallback) {
247-
const fallbackBindings = await tryLoadWasmWithFallback(attempts)
248-
if (fallbackBindings) {
249-
return resolve(fallbackBindings)
250-
}
251-
}
252-
253-
logLoadFailure(attempts, true)
204+
logLoadFailure(attempts)
254205
})
255206
return pendingBindings
256207
}
@@ -279,6 +230,8 @@ async function tryLoadNativeWithFallback(attempts: Array<string>) {
279230
return undefined
280231
}
281232

233+
// We may end up using this function in the future if/when we support wasm builds again
234+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
282235
async function tryLoadWasmWithFallback(attempts: any) {
283236
try {
284237
let bindings = await loadWasm('')
@@ -331,18 +284,12 @@ function loadBindingsSync() {
331284
attempts = attempts.concat(a)
332285
}
333286

334-
// we can leverage the wasm bindings if they are already
335-
// loaded
336-
if (wasmBindings) {
337-
return wasmBindings
338-
}
339-
340287
logLoadFailure(attempts)
341288
}
342289

343290
let loggingLoadFailure = false
344291

345-
function logLoadFailure(attempts: any, triedWasm = false) {
292+
function logLoadFailure(attempts: any) {
346293
// make sure we only emit the event and log the failure once
347294
if (loggingLoadFailure) return
348295
loggingLoadFailure = true
@@ -353,7 +300,6 @@ function logLoadFailure(attempts: any, triedWasm = false) {
353300

354301
// @ts-expect-error TODO: this event has a wrong type.
355302
eventSwcLoadFailure({
356-
wasm: triedWasm ? 'failed' : undefined,
357303
nativeBindingsErrorCode: lastNativeBindingsLoadErrorCode,
358304
})
359305
.then(() => lockfilePatchPromise.cur || Promise.resolve())

0 commit comments

Comments
 (0)