Skip to content

Commit

Permalink
[Turbopack] use new backend in next-build-test (vercel#75724)
Browse files Browse the repository at this point in the history
### What?

* use new backend in next-build-test
* apply effects in next-build-test
* fix Dockerfile
  • Loading branch information
sokra authored Feb 6, 2025
1 parent f37a454 commit 2da6259
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 15 deletions.
1 change: 0 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# RUN su node -c "npm install -g <your-package-list-here>"

# Enable pnpm
RUN npm i -g corepack@latest
RUN corepack enable pnpm
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/next-build-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ tracing = "0.1"
tracing-subscriber = "0.3"
turbo-rcstr = { workspace = true }
turbo-tasks = { workspace = true }
turbo-tasks-backend = { workspace = true }
turbo-tasks-env = { workspace = true }
turbo-tasks-fs = { workspace = true }
turbo-tasks-malloc = { workspace = true }
turbo-tasks-memory = { workspace = true }
turbopack = { workspace = true }
turbopack-browser = { workspace = true }
turbopack-cli-utils = { workspace = true }
Expand Down
40 changes: 30 additions & 10 deletions crates/next-build-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use anyhow::{Context, Result};
use futures_util::{StreamExt, TryStreamExt};
use next_api::{
project::{ProjectContainer, ProjectOptions},
route::{endpoint_write_to_disk, Route},
route::{endpoint_write_to_disk, Endpoint, EndpointOutputPaths, Route},
};
use turbo_rcstr::RcStr;
use turbo_tasks::{ReadConsistency, TransientInstance, TurboTasks, Vc};
use turbo_tasks::{get_effects, ReadConsistency, ResolvedVc, TransientInstance, TurboTasks, Vc};
use turbo_tasks_backend::{NoopBackingStorage, TurboTasksBackend};
use turbo_tasks_malloc::TurboMalloc;
use turbo_tasks_memory::MemoryBackend;

pub async fn main_inner(
tt: &TurboTasks<MemoryBackend>,
tt: &TurboTasks<TurboTasksBackend<NoopBackingStorage>>,
strat: Strategy,
factor: usize,
limit: usize,
Expand Down Expand Up @@ -158,7 +158,7 @@ pub fn shuffle<'a, T: 'a>(items: impl Iterator<Item = T>) -> impl Iterator<Item
}

pub async fn render_routes(
tt: &TurboTasks<MemoryBackend>,
tt: &TurboTasks<TurboTasksBackend<NoopBackingStorage>>,
routes: impl Iterator<Item = (RcStr, Route)>,
strategy: Strategy,
factor: usize,
Expand All @@ -185,21 +185,21 @@ pub async fn render_routes(
html_endpoint,
data_endpoint: _,
} => {
endpoint_write_to_disk(*html_endpoint).await?;
endpoint_write_to_disk_with_effects(*html_endpoint).await?;
}
Route::PageApi { endpoint } => {
endpoint_write_to_disk(*endpoint).await?;
endpoint_write_to_disk_with_effects(*endpoint).await?;
}
Route::AppPage(routes) => {
for route in routes {
endpoint_write_to_disk(*route.html_endpoint).await?;
endpoint_write_to_disk_with_effects(*route.html_endpoint).await?;
}
}
Route::AppRoute {
original_name: _,
endpoint,
} => {
endpoint_write_to_disk(*endpoint).await?;
endpoint_write_to_disk_with_effects(*endpoint).await?;
}
Route::Conflict => {
tracing::info!("WARN: conflict {}", name);
Expand Down Expand Up @@ -242,7 +242,27 @@ pub async fn render_routes(
Ok(stream.len())
}

async fn hmr(tt: &TurboTasks<MemoryBackend>, project: Vc<ProjectContainer>) -> Result<()> {
#[turbo_tasks::function]
async fn endpoint_write_to_disk_with_effects(
endpoint: ResolvedVc<Box<dyn Endpoint>>,
) -> Result<Vc<EndpointOutputPaths>> {
let op = endpoint_write_to_disk_operation(endpoint);
let result = op.resolve_strongly_consistent().await?;
get_effects(op).await?.apply().await?;
Ok(*result)
}

#[turbo_tasks::function(operation)]
pub fn endpoint_write_to_disk_operation(
endpoint: ResolvedVc<Box<dyn Endpoint>>,
) -> Vc<EndpointOutputPaths> {
endpoint_write_to_disk(*endpoint)
}

async fn hmr(
tt: &TurboTasks<TurboTasksBackend<NoopBackingStorage>>,
project: Vc<ProjectContainer>,
) -> Result<()> {
tracing::info!("HMR...");
let session = TransientInstance::new(());
let idents = tt
Expand Down
11 changes: 9 additions & 2 deletions crates/next-build-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use next_core::tracing_presets::{
};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, Registry};
use turbo_tasks::TurboTasks;
use turbo_tasks_backend::{noop_backing_storage, BackendOptions, TurboTasksBackend};
use turbo_tasks_malloc::TurboMalloc;
use turbo_tasks_memory::MemoryBackend;
use turbopack_trace_utils::{
exit::ExitGuard, filter_layer::FilterLayer, raw_trace::RawTraceLayer, trace_writer::TraceWriter,
};
Expand Down Expand Up @@ -118,7 +118,14 @@ fn main() {
None
};

let tt = TurboTasks::new(MemoryBackend::new(usize::MAX));
let tt = TurboTasks::new(TurboTasksBackend::new(
BackendOptions {
dependency_tracking: false,
storage_mode: None,
..Default::default()
},
noop_backing_storage(),
));
let result = main_inner(&tt, strat, factor, limit, files).await;
let memory = TurboMalloc::memory_usage();
tracing::info!("memory usage: {} MiB", memory / 1024 / 1024);
Expand Down

0 comments on commit 2da6259

Please sign in to comment.