Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions packages/next/build.ncl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
let { subsetOf, Attrs, BuildSpec, Local, Needs, OutputBin, OutputData, Source, Test, .. } = import "minimal.ncl" in
let { target, .. } = import "config.ncl" in
let base = import "../base/build.ncl" in
let coreutils = import "../coreutils/build.ncl" in
let glib = import "../glib/build.ncl" in
Expand All @@ -11,6 +12,19 @@ let python = import "../python/build.ncl" in
let toolchain = import "../toolchain/build.ncl" in

let version = "16.4.1" in
# The native SWC compiler Next loads at build/dev time. Upstream publishes it as a
# per-platform npm package (`@next/swc-linux-<arch>-gnu`) that `next` lists as an
# optionalDependency; the source build above does not produce it. Without it, every
# `next build` tries to download one into next's own tree, which is read-only here.
#
# PREBUILT, as an interim exception to AGENTS.md's build-from-source rule (Rust is
# packaged). Building it means upstream's `napi build -p next-napi-bindings` over
# the turbopack + swc Cargo workspace, and next.js pins its own Rust nightly
# (`rust-toolchain.toml`: nightly-2026-08-20), which pkgs doesn't package. Tracked
# in gominimal/pkgs#985; `binary_from` below records the exception.
# Bump these alongside `version`: the binary must match next exactly.
let swc_amd64_sha256 = "78a7aa9334cfcb3b15ae3bdd19944aa6d7754639dc534fb0123a3d8fd4f00f47" in
let swc_arm64_sha256 = "ea6ca74538e44799986dbea7ae0b7142b37abf5d6b16fcf34566221c3e7b86ea" in
{
name = "next",
build_deps = [
Expand All @@ -21,6 +35,18 @@ let version = "16.4.1" in
extract = true,
strip_prefix = "next.js-%{version}",
} | Source,
match {
{ arch = 'Amd64, .. } =>
{
url = "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-%{version}.tgz",
sha256 = swc_amd64_sha256,
} | Source,
{ arch = 'Arm64, .. } =>
{
url = "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-%{version}.tgz",
sha256 = swc_arm64_sha256,
} | Source,
} target,
base,
glib,
make,
Expand Down Expand Up @@ -63,6 +89,17 @@ let version = "16.4.1" in
["/bin/bash", "-c", "node -e \"const c = require('/usr/libexec/next/lib/node_modules/next/dist/shared/lib/constants.js'); if (c.PHASE_PRODUCTION_BUILD !== 'phase-production-build') process.exit(1);\""],
],
} | Test,
# The SWC addon loads and compiles. `loadBindingsSync` tries only the native
# addon (no download, no wasm fallback), and the loaded `.node` must be the one
# shipped under next's own node_modules.
swc_binary_ships =
{
class = 'Standalone,
test_deps = [base],
cmds = [
["/bin/bash", "-c", "node -e \"const swc = require('/usr/libexec/next/lib/node_modules/next/dist/build/swc/index.js'); const out = swc.transformSync('const a: number = 1; export default a;', { jsc: { parser: { syntax: 'typescript' } } }); if (!/a = 1;/.test(out.code) || /: number/.test(out.code)) { throw new Error('unexpected SWC output: ' + out.code); } const addon = Object.keys(require.cache).find((f) => f.endsWith('.node')); if (!addon || !/\\/node_modules\\/@next\\/swc-linux-(x64|arm64)-gnu\\/next-swc\\.linux-(x64|arm64)-gnu\\.node$/.test(addon)) { throw new Error('SWC loaded from an unexpected path: ' + addon); } console.log(addon);\""],
],
} | Test,
sharp_uses_system_libvips =
{
class = 'Standalone,
Expand All @@ -83,5 +120,12 @@ let version = "16.4.1" in
owner = "vercel",
repo = "next.js",
},
# next itself is built from source; only the SWC addon is prebuilt (see the
# comment at the top and gominimal/pkgs#985).
binary_from =
match {
{ arch = 'Amd64, .. } => "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-%{version}.tgz",
{ arch = 'Arm64, .. } => "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-%{version}.tgz",
} target,
} | Attrs,
} | BuildSpec
19 changes: 19 additions & 0 deletions packages/next/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash
set -euo pipefail

# Where the Sources land; the script cds around later (packages/next, a sharp staging dir).
BUILD_ROOT="$PWD"

# Sandbox doesn't have a cc symlink; point to gcc for native addon compilation
export CC=gcc
export CXX=g++
Expand Down Expand Up @@ -69,6 +72,22 @@ done

NEXT_DIR="$OUTPUT_DIR/usr/libexec/next/lib/node_modules/next"

# Ship the platform SWC compiler inside next's own node_modules, where next resolves
# `@next/swc-linux-<arch>-gnu` first. The source build does not produce this native
# addon; upstream publishes it as a per-platform npm package, fetched above as a
# sha256-pinned Source. Without it every `next build`/`next dev` attempts a download
# into next's tree, which is read-only when installed as a package.
case "$(uname -m)" in
x86_64) _swc_arch=x64 ;;
aarch64|arm64) _swc_arch=arm64 ;;
*) echo "next: no SWC binary for $(uname -m)" >&2; exit 1 ;;
esac
_swc_dir="$NEXT_DIR/node_modules/@next/swc-linux-$_swc_arch-gnu"
mkdir -p "$_swc_dir"
tar -xzf "$BUILD_ROOT/swc-linux-$_swc_arch-gnu-$MINIMAL_ARG_VERSION.tgz" -C "$_swc_dir" --strip-components=1
test -f "$_swc_dir/next-swc.linux-$_swc_arch-gnu.node" || { echo "next: SWC binary missing after extract" >&2; exit 1; }
chmod 0755 "$_swc_dir/next-swc.linux-$_swc_arch-gnu.node"

# Build sharp from source against our system libvips
SHARP_STAGING=$(mktemp -d)
cd "$SHARP_STAGING"
Expand Down
Loading