mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
## Summary Switch CI from self-hosted runners to GitHub-hosted runners and fix the follow-up issues that showed up once the hosted jobs were exercised. ## Changes - Move Linux workflows onto `ubuntu-latest-16-core-oss`, Windows workflows onto `windows-latest-8-core-oss`, and the native mac release lane onto `macos-15-intel`. - Update the reusable build workflow to work in hosted environments by relying on `runner.os` instead of label string matching, and by removing the hardcoded `/home/runner` `fnm` path. - Make Turbo/sccache configuration explicit for hosted runners: - unify on `vtest314-next-adapter-e2e-tests` - pass `TURBO_TOKEN` via workflow env/secrets instead of assuming runner-level env - switch Turbo cache mode to `local:rw,remote:rw` so jobs still have local cache behavior when remote cache is unavailable - Update the `sccache` action defaults/docs to use the hosted-runner secret setup (`TURBO_TOKEN`) instead of the old self-hosted token wiring. - Make Datadog reporting fail open so missing `DATA_DOG_API_KEY` does not block CI. - Fix the CLI reserved-port test so it asserts Next’s own `-p 1` validation instead of failing earlier on hosted Linux due to privileged-port binding. - Replace the live `musl.cc` dependency in `native-builder.Dockerfile` with musl sysroots imported from GHCR-hosted `rust-musl-cross` images, keeping the existing `/opt/*-cross` layout used by the Linux native build scripts. - Fix the macOS native build workaround s so it applies to all *-apple-darwin targets based on the Cargo target OS rather than the host architecture, which avoids napi-build injecting the unsupported -Wl linker arg when @next/swc is linked with rust-lld on hosted mac runners. Test Plan: - This PR's CI - This [build_and_deploy](https://github.com/vercel/next.js/actions/runs/24865715983/job/72801225722) job running on every arch
94 lines
3.8 KiB
Rust
94 lines
3.8 KiB
Rust
use std::{env, fs, path::Path, process::Command, str};
|
|
|
|
use serde_json::Value;
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
println!("cargo:rerun-if-env-changed=CI");
|
|
println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_OS");
|
|
let is_ci = env::var("CI").is_ok_and(|value| !value.is_empty());
|
|
let is_macos_target = env::var("CARGO_CFG_TARGET_OS").is_ok_and(|value| value == "macos");
|
|
|
|
let nextjs_version = {
|
|
let package_json_path = Path::new(env!("CARGO_MANIFEST_DIR"))
|
|
.join("../..")
|
|
.join("packages/next/package.json");
|
|
|
|
println!("cargo:rerun-if-changed={}", package_json_path.display());
|
|
|
|
let package_json_content = fs::read_to_string(&package_json_path)?;
|
|
let package_json: Value = serde_json::from_str(&package_json_content)?;
|
|
|
|
package_json["version"]
|
|
.as_str()
|
|
.expect("Expected a Next.js `version` string in its package.json")
|
|
.to_string()
|
|
};
|
|
|
|
// Make the Next.js version available as a build-time environment variable
|
|
println!("cargo:rustc-env=NEXTJS_VERSION={nextjs_version}");
|
|
|
|
// Generates, stores build-time information as static values.
|
|
// There are some places relying on correct values for this (i.e telemetry),
|
|
// So failing build if this fails.
|
|
let cargo = vergen_gitcl::CargoBuilder::default()
|
|
.target_triple(true)
|
|
.build()?;
|
|
// We use the git dirty state to disable filesystem cache (filesystem cache relies on a
|
|
// commit hash to be safe). One tradeoff of this is that we must invalidate the rust build more
|
|
// often.
|
|
//
|
|
// This invalidates the build if any untracked files change. That's sufficient for the case
|
|
// where we transition from dirty to clean.
|
|
//
|
|
// There's an edge-case here where the repository could be newly dirty, but we can't know
|
|
// because our build hasn't been invalidated, since the untracked files weren't untracked last
|
|
// time we ran. That will cause us to incorrectly report ourselves as clean.
|
|
//
|
|
// However, in practice that shouldn't be much of an issue: If no other dependency of this
|
|
// top-level crate has changed (which would've triggered our rebuild), then the resulting binary
|
|
// must be equivalent to a clean build anyways. Therefore, filesystem cache using the HEAD
|
|
// commit hash as a version is okay.
|
|
let git = vergen_gitcl::GitclBuilder::default()
|
|
.dirty(/* include_untracked */ true)
|
|
.describe(
|
|
/* tags */ true,
|
|
/* dirty */ !is_ci, // suppress the dirty suffix in CI
|
|
/* matches */ Some("v[0-9]*"), // find the last version tag
|
|
)
|
|
.build()?;
|
|
vergen_gitcl::Emitter::default()
|
|
.add_instructions(&cargo)?
|
|
.add_instructions(&git)?
|
|
.fail_on_error()
|
|
.emit()?;
|
|
|
|
match Command::new("git").args(["rev-parse", "HEAD"]).output() {
|
|
Ok(out) if out.status.success() => println!(
|
|
"cargo:warning=git HEAD: {}",
|
|
str::from_utf8(&out.stdout).unwrap()
|
|
),
|
|
_ => println!("cargo:warning=`git rev-parse HEAD` failed"),
|
|
}
|
|
|
|
if !is_macos_target {
|
|
napi_build::setup();
|
|
}
|
|
|
|
// This is a workaround for napi always including a GCC-specific flag on macOS.
|
|
if is_macos_target {
|
|
println!("cargo:rerun-if-env-changed=DEBUG_GENERATED_CODE");
|
|
println!("cargo:rerun-if-env-changed=TYPE_DEF_TMP_PATH");
|
|
println!("cargo:rerun-if-env-changed=CARGO_CFG_NAPI_RS_CLI_VERSION");
|
|
|
|
println!("cargo:rustc-cdylib-link-arg=-undefined");
|
|
println!("cargo:rustc-cdylib-link-arg=dynamic_lookup");
|
|
}
|
|
|
|
// Resolve a potential linker issue for unit tests on linux
|
|
// https://github.com/napi-rs/napi-rs/issues/1782
|
|
#[cfg(all(target_os = "linux", not(target_arch = "wasm32")))]
|
|
println!("cargo:rustc-link-arg=-Wl,--warn-unresolved-symbols");
|
|
|
|
Ok(())
|
|
}
|