Unverified Commit e95129b5 authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

next-swc: rebuild native when embedded js/src files change (#99669)

## Summary

`pnpm build-all` decides whether to build the native binary with
`packages/next-swc/maybe-build-native.mjs`. That script `git diff`s
against the last version-bump commit, and only builds when `.rs`,
`.toml`, `.cargo/**`, `Cargo.lock` or `rust-toolchain` files changed.

Several crates compile a `js/src` directory into the binary with
`embed_directory!`: next-core, turbopack-ecmascript-runtime,
turbopack-ecmascript, turbopack-node, turbopack-wasm and turbopack-cli.
Editing only those files counted as "no Rust changes", so the script
skipped the build. It then deleted the local `native/*.node` in favor of
the prebuilt npm binary, so local runtime changes silently never took
effect.

This adds `crates/*/js/src/**` and `turbopack/crates/*/js/src/**` to the
pathspec.

## Verification

- With only `turbopack-ecmascript-runtime/js/src` files modified, the
`git diff --name-only` in `hasRustChanges` now lists them, so the build
runs. Before this change it printed nothing.

<!-- NEXT_JS_LLM -->
parent cdf6866a
...@@ -47,8 +47,9 @@ function hasRustChanges(sinceCommit) { ...@@ -47,8 +47,9 @@ function hasRustChanges(sinceCommit) {
try { try {
// Omit HEAD to compare against the working tree, which includes // Omit HEAD to compare against the working tree, which includes
// committed, staged, and unstaged changes. // committed, staged, and unstaged changes.
// `js/src` directories are compiled into the binary via `embed_directory!`.
const diff = execSync( const diff = execSync(
`git diff --name-only ${sinceCommit} -- ':(glob)**/*.rs' ':(glob)**/*.toml' ':(glob).cargo/**' Cargo.lock rust-toolchain`, `git diff --name-only ${sinceCommit} -- ':(glob)**/*.rs' ':(glob)**/*.toml' ':(glob).cargo/**' ':(glob)crates/*/js/src/**' ':(glob)turbopack/crates/*/js/src/**' Cargo.lock rust-toolchain`,
{ cwd: ROOT_DIR, encoding: 'utf8' } { cwd: ROOT_DIR, encoding: 'utf8' }
).trim() ).trim()
return diff.length > 0 return diff.length > 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment