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

+184-157
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-2
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

+4-3
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

+8-44
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

+3
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

+21-6
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

+2-2
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

+3-2
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

+5-10
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

+3
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();

crates/next-api/src/project.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ use turbopack_nodejs::NodeJsChunkingContext;
6868

6969
use crate::{
7070
app::{AppProject, OptionAppProject, ECMASCRIPT_CLIENT_TRANSITION_NAME},
71+
build,
7172
empty::EmptyEndpoint,
7273
entrypoints::Entrypoints,
7374
instrumentation::InstrumentationEndpoint,
@@ -1068,7 +1069,7 @@ impl Project {
10681069
// First, emit an event for the binary target triple.
10691070
// This is different to webpack-config; when this is being called,
10701071
// it is always using SWC so we don't check swc here.
1071-
emit_event(env!("VERGEN_CARGO_TARGET_TRIPLE"), true);
1072+
emit_event(build::BUILD_TARGET, true);
10721073

10731074
// Go over jsconfig and report enabled features.
10741075
let compiler_options = self.js_config().compiler_options().await?;

crates/next-build/Cargo.toml

+20
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,25 @@ workspace = true
1616
next-core = { workspace = true }
1717
turbopack-core = { workspace = true }
1818

19+
#turbopack-binding = { workspace = true, features = [
20+
# "__turbo_tasks",
21+
# "__turbo_tasks_memory",
22+
# "__turbo_tasks_env",
23+
# "__turbo_tasks_fs",
24+
# "__turbo_tasks_memory",
25+
# "__turbopack",
26+
# "__turbopack_nodejs",
27+
# "__turbopack_core",
28+
# "__turbopack_browser",
29+
# "__turbopack_ecmascript",
30+
# "__turbopack_ecmascript_runtime",
31+
# "__turbopack_env",
32+
# "__turbopack_node",
33+
#] }
34+
1935
[build-dependencies]
2036
turbo-tasks-build = { workspace = true }
37+
vergen = { version = "7.3.2", default-features = false, features = [
38+
"cargo",
39+
"build",
40+
] }

crates/next-build/build.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
use turbo_tasks_build::generate_register;
2+
use vergen::{vergen, Config};
23

34
fn main() {
45
generate_register();
6+
7+
// Attempt to collect some build time env values but will skip if there are any
8+
// errors.
9+
let _ = vergen(Config::default());
510
}

turbopack/crates/turbo-tasks-backend/src/database/db_versioning.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,24 @@ use std::{
77

88
use anyhow::Result;
99

10-
/// Information gathered by `vergen_git2` in the top-level binary crate and passed down. This
11-
/// information must be computed in the top-level crate for cargo incremental compilation to work
12-
/// correctly.
13-
///
14-
/// See `crates/napi/build.rs` for details.
15-
pub struct GitVersionInfo<'a> {
16-
/// Output of `git describe --match 'v[0-9]' --dirty`.
17-
pub describe: &'a str,
18-
/// Is the git repository dirty? Always forced to `false` when the `CI` environment variable is
19-
/// set and non-empty.
20-
pub dirty: bool,
21-
}
22-
2310
/// Specifies many databases that have a different version than the current one are retained.
2411
/// For example if MAX_OTHER_DB_VERSIONS is 2, there can be at most 3 databases in the directory,
2512
/// the current one and two older/newer ones.
2613
const MAX_OTHER_DB_VERSIONS: usize = 2;
2714

28-
pub fn handle_db_versioning(base_path: &Path, version_info: &GitVersionInfo) -> Result<PathBuf> {
15+
pub fn handle_db_versioning(base_path: &Path, version_info: &str) -> Result<PathBuf> {
2916
if let Ok(version) = env::var("TURBO_ENGINE_VERSION") {
3017
return Ok(base_path.join(version));
3118
}
3219
// Database versioning. Pass `TURBO_ENGINE_IGNORE_DIRTY` at runtime to ignore a
3320
// dirty git repository. Pass `TURBO_ENGINE_DISABLE_VERSIONING` at runtime to disable
3421
// versioning and always use the same database.
22+
let (version_info, git_dirty) = if let Some(version_info) = version_info.strip_suffix("-dirty")
23+
{
24+
(version_info, true)
25+
} else {
26+
(version_info, false)
27+
};
3528
let ignore_dirty = env::var("TURBO_ENGINE_IGNORE_DIRTY").ok().is_some();
3629
let disabled_versioning = env::var("TURBO_ENGINE_DISABLE_VERSIONING").ok().is_some();
3730
let version = if disabled_versioning {
@@ -40,14 +33,14 @@ pub fn handle_db_versioning(base_path: &Path, version_info: &GitVersionInfo) ->
4033
caching database might be required."
4134
);
4235
Some("unversioned")
43-
} else if !version_info.dirty {
44-
Some(version_info.describe)
36+
} else if !git_dirty {
37+
Some(version_info)
4538
} else if ignore_dirty {
4639
println!(
4740
"WARNING: The git repository is dirty, but Persistent Caching is still enabled. \
4841
Manual removal of the persistent caching database might be required."
4942
);
50-
Some(version_info.describe)
43+
Some(version_info)
5144
} else {
5245
println!(
5346
"WARNING: The git repository is dirty: Persistent Caching is disabled. Use \

turbopack/crates/turbo-tasks-backend/src/lib.rs

+8-21
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ use std::path::Path;
1515

1616
use anyhow::Result;
1717

18-
use crate::database::{
19-
db_versioning::handle_db_versioning, noop_kv::NoopKvDb, turbo::TurboKeyValueDatabase,
20-
};
21-
pub use crate::{
18+
pub use self::{
2219
backend::{BackendOptions, StorageMode, TurboTasksBackend},
23-
database::db_versioning::GitVersionInfo,
2420
kv_backing_storage::KeyValueDatabaseBackingStorage,
2521
};
22+
use crate::database::{
23+
db_versioning::handle_db_versioning, noop_kv::NoopKvDb, turbo::TurboKeyValueDatabase,
24+
};
2625

2726
#[cfg(feature = "lmdb")]
2827
pub type LmdbBackingStorage = KeyValueDatabaseBackingStorage<
@@ -36,10 +35,7 @@ pub type LmdbBackingStorage = KeyValueDatabaseBackingStorage<
3635
>;
3736

3837
#[cfg(feature = "lmdb")]
39-
pub fn lmdb_backing_storage(
40-
path: &Path,
41-
version_info: &GitVersionInfo,
42-
) -> Result<LmdbBackingStorage> {
38+
pub fn lmdb_backing_storage(path: &Path, version_info: &str) -> Result<LmdbBackingStorage> {
4339
use crate::database::{
4440
fresh_db_optimization::{is_fresh, FreshDbOptimization},
4541
read_transaction_cache::ReadTransactionCache,
@@ -57,10 +53,7 @@ pub fn lmdb_backing_storage(
5753

5854
pub type TurboBackingStorage = KeyValueDatabaseBackingStorage<TurboKeyValueDatabase>;
5955

60-
pub fn turbo_backing_storage(
61-
path: &Path,
62-
version_info: &GitVersionInfo,
63-
) -> Result<TurboBackingStorage> {
56+
pub fn turbo_backing_storage(path: &Path, version_info: &str) -> Result<TurboBackingStorage> {
6457
let path = handle_db_versioning(path, version_info)?;
6558
let database = TurboKeyValueDatabase::new(path)?;
6659
Ok(KeyValueDatabaseBackingStorage::new(database))
@@ -76,20 +69,14 @@ pub fn noop_backing_storage() -> NoopBackingStorage {
7669
pub type DefaultBackingStorage = LmdbBackingStorage;
7770

7871
#[cfg(feature = "lmdb")]
79-
pub fn default_backing_storage(
80-
path: &Path,
81-
version_info: &GitVersionInfo,
82-
) -> Result<DefaultBackingStorage> {
72+
pub fn default_backing_storage(path: &Path, version_info: &str) -> Result<DefaultBackingStorage> {
8373
lmdb_backing_storage(path, version_info)
8474
}
8575

8676
#[cfg(not(feature = "lmdb"))]
8777
pub type DefaultBackingStorage = TurboBackingStorage;
8878

8979
#[cfg(not(feature = "lmdb"))]
90-
pub fn default_backing_storage(
91-
path: &Path,
92-
version_info: &GitVersionInfo,
93-
) -> Result<DefaultBackingStorage> {
80+
pub fn default_backing_storage(path: &Path, version_info: &str) -> Result<DefaultBackingStorage> {
9481
turbo_backing_storage(path, version_info)
9582
}

0 commit comments

Comments
 (0)