Skip to content

Commit 8ee79b8

Browse files
authored
change turbopack-cli to new backend (#75242)
### What? * change turbopack-cli to new backend * avoid transient tasks in turbopack-cli
1 parent 7aa6137 commit 8ee79b8

File tree

6 files changed

+43
-49
lines changed

6 files changed

+43
-49
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ tokio = { workspace = true, features = ["full"] }
4545
tracing-subscriber = { workspace = true, features = ["env-filter", "json"] }
4646
turbo-rcstr = { workspace = true }
4747
turbo-tasks = { workspace = true }
48+
turbo-tasks-backend = { workspace = true }
4849
turbo-tasks-env = { workspace = true }
4950
turbo-tasks-fetch = { workspace = true }
5051
turbo-tasks-fs = { workspace = true }
5152
turbo-tasks-malloc = { workspace = true, default-features = false }
52-
turbo-tasks-memory = { workspace = true }
5353
turbopack = { workspace = true }
5454
turbopack-browser = { workspace = true }
5555
turbopack-cli-utils = { workspace = true }

turbopack/crates/turbopack-cli/src/arguments.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,11 @@ pub struct CommonArguments {
7777
#[clap(long)]
7878
pub full_stats: bool,
7979

80-
/// Enable experimental garbage collection with the provided memory limit in
81-
/// MB.
82-
#[clap(long)]
83-
pub memory_limit: Option<usize>,
84-
85-
/// Target
80+
// Enable experimental garbage collection with the provided memory limit in
81+
// MB.
82+
// #[clap(long)]
83+
// pub memory_limit: Option<usize>,
84+
/// Whether to build for the `browser` or `node``
8685
#[clap(long)]
8786
pub target: Option<Target>,
8887
}

turbopack/crates/turbopack-cli/src/build/mod.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ use turbo_tasks::{
1111
apply_effects, ReadConsistency, ResolvedVc, TransientInstance, TryJoinIterExt, TurboTasks,
1212
Value, Vc,
1313
};
14+
use turbo_tasks_backend::{
15+
noop_backing_storage, BackendOptions, NoopBackingStorage, TurboTasksBackend,
16+
};
1417
use turbo_tasks_fs::FileSystem;
15-
use turbo_tasks_memory::MemoryBackend;
1618
use turbopack_browser::BrowserChunkingContext;
1719
use turbopack_cli_utils::issue::{ConsoleUi, LogOptions};
1820
use turbopack_core::{
@@ -43,8 +45,7 @@ use crate::{
4345
arguments::{BuildArguments, Target},
4446
contexts::{get_client_asset_context, get_client_compile_time_info, NodeEnv},
4547
util::{
46-
normalize_dirs, normalize_entries, output_fs, project_fs, EntryRequest, EntryRequests,
47-
NormalizedDirs,
48+
normalize_dirs, normalize_entries, output_fs, project_fs, EntryRequest, NormalizedDirs,
4849
},
4950
};
5051

@@ -53,8 +54,10 @@ pub fn register() {
5354
include!(concat!(env!("OUT_DIR"), "/register.rs"));
5455
}
5556

57+
type Backend = TurboTasksBackend<NoopBackingStorage>;
58+
5659
pub struct TurbopackBuildBuilder {
57-
turbo_tasks: Arc<TurboTasks<MemoryBackend>>,
60+
turbo_tasks: Arc<TurboTasks<Backend>>,
5861
project_dir: RcStr,
5962
root_dir: RcStr,
6063
entry_requests: Vec<EntryRequest>,
@@ -67,11 +70,7 @@ pub struct TurbopackBuildBuilder {
6770
}
6871

6972
impl TurbopackBuildBuilder {
70-
pub fn new(
71-
turbo_tasks: Arc<TurboTasks<MemoryBackend>>,
72-
project_dir: RcStr,
73-
root_dir: RcStr,
74-
) -> Self {
73+
pub fn new(turbo_tasks: Arc<TurboTasks<Backend>>, project_dir: RcStr, root_dir: RcStr) -> Self {
7574
TurbopackBuildBuilder {
7675
turbo_tasks,
7776
project_dir,
@@ -126,14 +125,7 @@ impl TurbopackBuildBuilder {
126125
let build_result_op = build_internal(
127126
self.project_dir.clone(),
128127
self.root_dir,
129-
EntryRequests(
130-
self.entry_requests
131-
.iter()
132-
.cloned()
133-
.map(EntryRequest::resolved_cell)
134-
.collect(),
135-
)
136-
.resolved_cell(),
128+
self.entry_requests.clone(),
137129
self.browserslist_query,
138130
self.minify_type,
139131
self.target,
@@ -177,7 +169,7 @@ impl TurbopackBuildBuilder {
177169
async fn build_internal(
178170
project_dir: RcStr,
179171
root_dir: RcStr,
180-
entry_requests: ResolvedVc<EntryRequests>,
172+
entry_requests: Vec<EntryRequest>,
181173
browserslist_query: RcStr,
182174
minify_type: MinifyType,
183175
target: Target,
@@ -285,11 +277,9 @@ async fn build_internal(
285277
);
286278

287279
let entry_requests = (*entry_requests
288-
.await?
289-
.iter()
290-
.cloned()
280+
.into_iter()
291281
.map(|r| async move {
292-
Ok(match &*r.await? {
282+
Ok(match r {
293283
EntryRequest::Relative(p) => Request::relative(
294284
Value::new(p.clone().into()),
295285
Default::default(),
@@ -421,10 +411,12 @@ pub async fn build(args: &BuildArguments) -> Result<()> {
421411
root_dir,
422412
} = normalize_dirs(&args.common.dir, &args.common.root)?;
423413

424-
let tt = TurboTasks::new(MemoryBackend::new(
425-
args.common
426-
.memory_limit
427-
.map_or(usize::MAX, |l| l * 1024 * 1024),
414+
let tt = TurboTasks::new(TurboTasksBackend::new(
415+
BackendOptions {
416+
storage_mode: None,
417+
..Default::default()
418+
},
419+
noop_backing_storage(),
428420
));
429421

430422
let mut builder = TurbopackBuildBuilder::new(tt, project_dir, root_dir)

turbopack/crates/turbopack-cli/src/dev/mod.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ use turbo_tasks::{
1616
util::{FormatBytes, FormatDuration},
1717
ResolvedVc, TransientInstance, TurboTasks, UpdateInfo, Value, Vc,
1818
};
19+
use turbo_tasks_backend::{
20+
noop_backing_storage, BackendOptions, NoopBackingStorage, TurboTasksBackend,
21+
};
1922
use turbo_tasks_fs::FileSystem;
2023
use turbo_tasks_malloc::TurboMalloc;
21-
use turbo_tasks_memory::MemoryBackend;
2224
use turbopack::evaluate_context::node_build_environment;
2325
use turbopack_cli_utils::issue::{ConsoleUi, LogOptions};
2426
use turbopack_core::{
@@ -50,8 +52,10 @@ use crate::{
5052

5153
pub(crate) mod web_entry_source;
5254

55+
type Backend = TurboTasksBackend<NoopBackingStorage>;
56+
5357
pub struct TurbopackDevServerBuilder {
54-
turbo_tasks: Arc<TurboTasks<MemoryBackend>>,
58+
turbo_tasks: Arc<TurboTasks<Backend>>,
5559
project_dir: RcStr,
5660
root_dir: RcStr,
5761
entry_requests: Vec<EntryRequest>,
@@ -68,7 +72,7 @@ pub struct TurbopackDevServerBuilder {
6872

6973
impl TurbopackDevServerBuilder {
7074
pub fn new(
71-
turbo_tasks: Arc<TurboTasks<MemoryBackend>>,
75+
turbo_tasks: Arc<TurboTasks<Backend>>,
7276
project_dir: RcStr,
7377
root_dir: RcStr,
7478
) -> TurbopackDevServerBuilder {
@@ -356,10 +360,12 @@ pub async fn start_server(args: &DevArguments) -> Result<()> {
356360
root_dir,
357361
} = normalize_dirs(&args.common.dir, &args.common.root)?;
358362

359-
let tt = TurboTasks::new(MemoryBackend::new(
360-
args.common
361-
.memory_limit
362-
.map_or(usize::MAX, |l| l * 1024 * 1024),
363+
let tt = TurboTasks::new(TurboTasksBackend::new(
364+
BackendOptions {
365+
storage_mode: None,
366+
..Default::default()
367+
},
368+
noop_backing_storage(),
363369
));
364370

365371
let tt_clone = tt.clone();
@@ -503,7 +509,7 @@ pub async fn start_server(args: &DevArguments) -> Result<()> {
503509
#[cfg(feature = "profile")]
504510
// When profiling, exits the process when no new updates have been received for
505511
// a given timeout and there are no more tasks in progress.
506-
async fn profile_timeout<T>(tt: &TurboTasks<MemoryBackend>, future: impl Future<Output = T>) -> T {
512+
async fn profile_timeout<T>(tt: &TurboTasks<Backend>, future: impl Future<Output = T>) -> T {
507513
/// How long to wait in between updates before force-exiting the process
508514
/// during profiling.
509515
const PROFILE_EXIT_TIMEOUT: Duration = Duration::from_secs(5);
@@ -523,7 +529,7 @@ async fn profile_timeout<T>(tt: &TurboTasks<MemoryBackend>, future: impl Future<
523529

524530
#[cfg(not(feature = "profile"))]
525531
fn profile_timeout<T>(
526-
_tt: &TurboTasks<MemoryBackend>,
532+
_tt: &TurboTasks<Backend>,
527533
future: impl Future<Output = T>,
528534
) -> impl Future<Output = T> {
529535
future

turbopack/crates/turbopack-cli/src/util.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ use std::{env::current_dir, path::PathBuf};
22

33
use anyhow::{Context, Result};
44
use dunce::canonicalize;
5+
use serde::{Deserialize, Serialize};
56
use turbo_rcstr::RcStr;
6-
use turbo_tasks::{ResolvedVc, Vc};
7+
use turbo_tasks::{NonLocalValue, TaskInput, Vc};
78
use turbo_tasks_fs::{DiskFileSystem, FileSystem};
89

9-
#[turbo_tasks::value(transparent)]
10-
pub struct EntryRequests(pub Vec<ResolvedVc<EntryRequest>>);
11-
12-
#[turbo_tasks::value(shared)]
13-
#[derive(Clone)]
10+
#[derive(Clone, Debug, TaskInput, Hash, PartialEq, Eq, NonLocalValue, Serialize, Deserialize)]
1411
pub enum EntryRequest {
1512
Relative(RcStr),
1613
Module(RcStr, RcStr),

0 commit comments

Comments
 (0)