Skip to content

Commit ee5c7d3

Browse files
authored
Revert "fix(turbopack): Use vergen-git2 instead of shadow-rs for napi and next-api crates to fix stale git lock files" (#76879)
Reverts #76773 > Looks like we broke compilation for our linux swc builds for musl/gnu
1 parent 190df61 commit ee5c7d3

File tree

16 files changed

+279
-269
lines changed

16 files changed

+279
-269
lines changed

Cargo.lock

Lines changed: 184 additions & 157 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,6 @@ unicode-segmentation = "1.10.1"
426426
unsize = "1.1.0"
427427
url = "2.2.2"
428428
urlencoding = "2.1.2"
429-
vergen = { version = "9.0.4", features = ["cargo"] }
430-
vergen-git2 = { version = "1.0.5", features = ["cargo"] }
431429
webbrowser = "0.8.7"
432430

433431
[patch.crates-io]

crates/napi/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ rand = { workspace = true }
6666
rustc-hash = { workspace = true }
6767
serde = "1"
6868
serde_json = "1"
69+
shadow-rs = { workspace = true }
6970
tracing = { workspace = true }
7071
tracing-subscriber = { workspace = true }
7172
tracing-chrome = "0.5.0"
7273
url = { workspace = true }
7374
urlencoding = { workspace = true }
7475
once_cell = { workspace = true }
75-
dashmap = { workspace = true }
76+
dashmap = "6.1.0"
7677

7778
swc_core = { workspace = true, features = [
7879
"base_concurrent",
@@ -138,11 +139,11 @@ turbo-tasks-malloc = { workspace = true, default-features = false }
138139
tokio = { workspace = true, features = ["full"] }
139140

140141
[build-dependencies]
141-
anyhow = { workspace = true }
142142
napi-build = "2"
143143
serde = { workspace = true }
144144
serde_json = { workspace = true }
145-
vergen-git2 = { workspace = true }
145+
# It is not a mistake this dependency is specified in dep / build-dep both.
146+
shadow-rs = { workspace = true }
146147

147148
# build-dependencies for the native, non-wasm32 build
148149
[target.'cfg(not(target_arch = "wasm32"))'.build-dependencies]

crates/napi/build.rs

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,18 @@
1-
use std::{env, process::Command, str};
1+
use std::fs;
22

33
extern crate napi_build;
44

5-
fn main() -> anyhow::Result<()> {
6-
println!("cargo:rerun-if-env-changed=CI");
7-
let is_ci = env::var("CI").is_ok_and(|value| !value.is_empty());
8-
5+
fn main() {
96
// Generates, stores build-time information as static values.
107
// There are some places relying on correct values for this (i.e telemetry),
118
// So failing build if this fails.
12-
let cargo = vergen_git2::CargoBuilder::default()
13-
.target_triple(true)
14-
.build()?;
15-
// We use the git dirty state to disable persistent caching (persistent caching relies on a
16-
// commit hash to be safe). One tradeoff of this is that we must invalidate the rust build more
17-
// often.
18-
//
19-
// This invalidates the build if any untracked files change. That's sufficient for the case
20-
// where we transition from dirty to clean.
21-
//
22-
// There's an edge-case here where the repository could be newly dirty, but we can't know
23-
// because our build hasn't been invalidated, since the untracked files weren't untracked last
24-
// time we ran. That will cause us to incorrectly report ourselves as clean.
25-
//
26-
// However, in practice that shouldn't be much of an issue: If no other dependency of this
27-
// top-level crate has changed (which would've triggered our rebuild), then the resulting binary
28-
// must be equivalent to a clean build anyways. Therefore, persistent caching using the HEAD
29-
// commit hash as a version is okay.
30-
let git = vergen_git2::Git2Builder::default()
31-
.dirty(/* include_untracked */ true)
32-
.describe(
33-
/* tags */ true,
34-
/* dirty */ !is_ci, // suppress the dirty suffix in CI
35-
/* matches */ Some("v[0-9]*"), // find the last version tag
36-
)
37-
.build()?;
38-
vergen_git2::Emitter::default()
39-
.add_instructions(&cargo)?
40-
.add_instructions(&git)?
41-
.fail_on_error()
42-
.emit()?;
9+
shadow_rs::ShadowBuilder::builder()
10+
.build()
11+
.expect("Should able to generate build time information");
4312

44-
match Command::new("git").args(["rev-parse", "HEAD"]).output() {
45-
Ok(out) if out.status.success() => println!(
46-
"cargo:warning=git HEAD: {}",
47-
str::from_utf8(&out.stdout).unwrap()
48-
),
49-
_ => println!("cargo:warning=`git rev-parse HEAD` failed"),
13+
let git_head = fs::read_to_string("../../.git/HEAD").unwrap_or_default();
14+
if !git_head.is_empty() && !git_head.starts_with("ref: ") {
15+
println!("cargo:warning=git version {}", git_head);
5016
}
5117

5218
#[cfg(not(all(target_os = "macos", target_arch = "aarch64")))]
@@ -70,6 +36,4 @@ fn main() -> anyhow::Result<()> {
7036

7137
#[cfg(not(target_arch = "wasm32"))]
7238
turbo_tasks_build::generate_register();
73-
74-
Ok(())
7539
}

crates/napi/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ pub mod turbo_trace_server;
6161
pub mod turbopack;
6262
pub mod util;
6363

64+
// Declare build-time information variables generated in build.rs
65+
shadow_rs::shadow!(build);
66+
6467
#[cfg(not(any(feature = "__internal_dhat-heap", feature = "__internal_dhat-ad-hoc")))]
6568
#[global_allocator]
6669
static ALLOC: turbo_tasks_malloc::TurboMalloc = turbo_tasks_malloc::TurboMalloc;

crates/napi/src/next_api/utils.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ use turbo_tasks::{
1313
TryJoinIterExt, TurboTasks, TurboTasksApi, UpdateInfo, Vc,
1414
};
1515
use turbo_tasks_backend::{
16-
default_backing_storage, noop_backing_storage, DefaultBackingStorage, GitVersionInfo,
17-
NoopBackingStorage,
16+
default_backing_storage, noop_backing_storage, DefaultBackingStorage, NoopBackingStorage,
1817
};
1918
use turbo_tasks_fs::FileContent;
2019
use turbopack_core::{
@@ -131,10 +130,26 @@ pub fn create_turbo_tasks(
131130
dependency_tracking: bool,
132131
) -> Result<NextTurboTasks> {
133132
Ok(if persistent_caching {
134-
let version_info = GitVersionInfo {
135-
describe: env!("VERGEN_GIT_DESCRIBE"),
136-
dirty: option_env!("CI").is_none_or(|value| value.is_empty())
137-
&& env!("VERGEN_GIT_DIRTY") == "true",
133+
let dirty_suffix = if crate::build::GIT_CLEAN
134+
|| option_env!("CI").is_some_and(|value| !value.is_empty())
135+
{
136+
""
137+
} else {
138+
"-dirty"
139+
};
140+
#[allow(
141+
clippy::const_is_empty,
142+
reason = "LAST_TAG might be empty if the tag can't be determined"
143+
)]
144+
let version_info = if crate::build::LAST_TAG.is_empty() {
145+
format!("{}{}", crate::build::SHORT_COMMIT, dirty_suffix)
146+
} else {
147+
format!(
148+
"{}-{}{}",
149+
crate::build::LAST_TAG,
150+
crate::build::SHORT_COMMIT,
151+
dirty_suffix
152+
)
138153
};
139154
NextTurboTasks::PersistentCaching(TurboTasks::new(
140155
turbo_tasks_backend::TurboTasksBackend::new(

crates/napi/src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ pub fn log_internal_error_and_inform(err_info: &str) {
127127
}
128128

129129
#[napi]
130-
pub fn get_target_triple() -> &'static str {
131-
env!("VERGEN_CARGO_TARGET_TRIPLE")
130+
pub fn get_target_triple() -> String {
131+
crate::build::BUILD_TARGET.to_string()
132132
}
133133

134134
pub trait MapErr<T>: Into<Result<T, anyhow::Error>> {

crates/next-api/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ regex = { workspace = true }
2424
rustc-hash = { workspace = true }
2525
serde = { workspace = true }
2626
serde_json = { workspace = true }
27+
shadow-rs = { workspace = true }
2728
swc_core = { workspace = true }
2829
tracing = { workspace = true }
2930
turbo-rcstr = { workspace = true }
@@ -42,6 +43,6 @@ turbopack-node = { workspace = true }
4243
turbopack-nodejs = { workspace = true }
4344

4445
[build-dependencies]
45-
anyhow = { workspace = true }
46+
# It is not a mistake this dependency is specified in dep / build-dep both.
47+
shadow-rs = { workspace = true }
4648
turbo-tasks-build = { workspace = true }
47-
vergen = { workspace = true }

crates/next-api/build.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
use turbo_tasks_build::generate_register;
22

3-
fn main() -> anyhow::Result<()> {
3+
fn main() {
44
// Generates, stores build-time information as static values.
55
// There are some places relying on correct values for this (i.e telemetry),
66
// So failing build if this fails.
7-
let cargo = vergen::CargoBuilder::default()
8-
.target_triple(true)
9-
.build()?;
10-
vergen::Emitter::default()
11-
.add_instructions(&cargo)?
12-
.fail_on_error()
13-
.emit()?;
7+
shadow_rs::ShadowBuilder::builder()
8+
.build_pattern(shadow_rs::BuildPattern::Lazy)
9+
.build()
10+
.expect("Should able to generate build time information");
1411

1512
generate_register();
16-
17-
Ok(())
1813
}

crates/next-api/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ mod server_actions;
2323
mod versioned_content_map;
2424
mod webpack_stats;
2525

26+
// Declare build-time information variables generated in build.rs
27+
shadow_rs::shadow!(build);
28+
2629
pub fn register() {
2730
next_core::register();
2831
turbopack_nodejs::register();

0 commit comments

Comments
 (0)