Unverified Commit abee33ad authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Preserve WASI trace server with opt-in feature

Co-authored-by: 's avatarNiklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
parent 834267b8
...@@ -95,7 +95,7 @@ next-core = { workspace = true } ...@@ -95,7 +95,7 @@ next-core = { workspace = true }
turbopack-core = { workspace = true } turbopack-core = { workspace = true }
turbopack-ecmascript-hmr-protocol = { workspace = true } turbopack-ecmascript-hmr-protocol = { workspace = true }
turbopack-trace-utils = { workspace = true } turbopack-trace-utils = { workspace = true }
turbopack-trace-server = { workspace = true } turbopack-trace-server = { workspace = true, features = ["trace-server"] }
turbopack-node = { workspace = true, default-features = false, features = ["worker_pool"] } turbopack-node = { workspace = true, default-features = false, features = ["worker_pool"] }
mdxjs = { workspace = true, features = ["serializable"] } mdxjs = { workspace = true, features = ["serializable"] }
......
#[cfg(not(target_arch = "wasm32"))]
use std::thread;
use std::{ use std::{
borrow::Cow, borrow::Cow,
fs::{canonicalize, create_dir_all}, fs::{canonicalize, create_dir_all},
io::Write, io::Write,
path::{Path, PathBuf}, path::{Path, PathBuf},
sync::{Arc, LazyLock, Mutex}, sync::{Arc, LazyLock, Mutex},
thread,
time::{Duration, SystemTime}, time::{Duration, SystemTime},
}; };
...@@ -567,10 +566,8 @@ pub fn project_new<'env>( ...@@ -567,10 +566,8 @@ pub fn project_new<'env>(
.unwrap(); .unwrap();
}); });
// The file/WebSocket trace server is native-only; the WASI binding let trace_server = std::env::var("NEXT_TURBOPACK_TRACE_SERVER").ok();
// still supports writing traces, but cannot start a localhost server. if trace_server.is_some() {
#[cfg(not(target_arch = "wasm32"))]
if std::env::var("NEXT_TURBOPACK_TRACE_SERVER").is_ok() {
thread::spawn(move || { thread::spawn(move || {
turbopack_trace_server::start_turbopack_trace_server(trace_file, None); turbopack_trace_server::start_turbopack_trace_server(trace_file, None);
}); });
......
#[cfg(not(target_arch = "wasm32"))] use std::{path::PathBuf, sync::Arc};
use std::path::PathBuf;
use std::sync::Arc;
use napi_derive::napi; use napi_derive::napi;
#[cfg(not(target_arch = "wasm32"))]
use turbopack_trace_server::start_turbopack_trace_server;
use turbopack_trace_server::{ use turbopack_trace_server::{
QueryOptions, SortMode, query_spans, store_container::StoreContainer, QueryOptions, SortMode, query_spans, start_turbopack_trace_server,
store_container::StoreContainer,
}; };
/// An opaque handle to a running trace server instance. /// An opaque handle to a running trace server instance.
...@@ -90,7 +87,6 @@ pub struct TraceQueryResult { ...@@ -90,7 +87,6 @@ pub struct TraceQueryResult {
/// Starts the turbopack trace server on a background thread and returns a /// Starts the turbopack trace server on a background thread and returns a
/// handle immediately (non-blocking). The WebSocket server will be available /// handle immediately (non-blocking). The WebSocket server will be available
/// at `ws://127.0.0.1:<port>` (default port 5747). /// at `ws://127.0.0.1:<port>` (default port 5747).
#[cfg(not(target_arch = "wasm32"))]
#[napi] #[napi]
pub fn start_turbopack_trace_server_handle(path: String, port: Option<u16>) -> TraceServerHandle { pub fn start_turbopack_trace_server_handle(path: String, port: Option<u16>) -> TraceServerHandle {
let store = start_turbopack_trace_server(PathBuf::from(path), port); let store = start_turbopack_trace_server(PathBuf::from(path), port);
......
...@@ -9,6 +9,9 @@ autobenches = false ...@@ -9,6 +9,9 @@ autobenches = false
[features] [features]
default = ["custom_allocator"] default = ["custom_allocator"]
custom_allocator = ["turbo-tasks-malloc/custom_allocator"] custom_allocator = ["turbo-tasks-malloc/custom_allocator"]
# Native platforms always include the reader/server; the WASI next-swc binding
# opts in while the browser trace engine leaves file I/O and sockets out.
trace-server = ["dep:tungstenite", "dep:zstd"]
[[bin]] [[bin]]
name = "turbo-trace-server" name = "turbo-trace-server"
...@@ -36,3 +39,7 @@ turbopack-trace-utils = { workspace = true } ...@@ -36,3 +39,7 @@ turbopack-trace-utils = { workspace = true }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tungstenite = { version = "0.21.0" } tungstenite = { version = "0.21.0" }
zstd = { version = "0.13.0" } zstd = { version = "0.13.0" }
[target.'cfg(target_arch = "wasm32")'.dependencies]
tungstenite = { version = "0.21.0", optional = true }
zstd = { version = "0.13.0", optional = true }
#![feature(deref_patterns)] #![feature(deref_patterns)]
#![cfg_attr(not(target_arch = "wasm32"), feature(bufreader_peek))] #![cfg_attr(
any(not(target_arch = "wasm32"), feature = "trace-server"),
feature(bufreader_peek)
)]
#[cfg(not(target_arch = "wasm32"))] #[cfg(any(not(target_arch = "wasm32"), feature = "trace-server"))]
use std::path::PathBuf; use std::path::PathBuf;
use std::{ use std::{
hash::BuildHasherDefault, hash::BuildHasherDefault,
...@@ -14,7 +17,7 @@ use std::{ ...@@ -14,7 +17,7 @@ use std::{
use rustc_hash::FxHasher; use rustc_hash::FxHasher;
#[cfg(not(target_arch = "wasm32"))] #[cfg(any(not(target_arch = "wasm32"), feature = "trace-server"))]
use self::{reader::TraceReader, server::serve}; use self::{reader::TraceReader, server::serve};
use self::{span_graph_ref::SpanGraphEventRef, span_ref::SpanRef, store_container::StoreContainer}; use self::{span_graph_ref::SpanGraphEventRef, span_ref::SpanRef, store_container::StoreContainer};
...@@ -22,10 +25,10 @@ mod bottom_up; ...@@ -22,10 +25,10 @@ mod bottom_up;
mod chunked_vec; mod chunked_vec;
mod lazy_sorted_vec; mod lazy_sorted_vec;
pub mod protocol; pub mod protocol;
#[cfg(not(target_arch = "wasm32"))] #[cfg(any(not(target_arch = "wasm32"), feature = "trace-server"))]
mod reader; mod reader;
mod self_time_tree; mod self_time_tree;
#[cfg(not(target_arch = "wasm32"))] #[cfg(any(not(target_arch = "wasm32"), feature = "trace-server"))]
mod server; mod server;
mod span; mod span;
mod span_bottom_up_ref; mod span_bottom_up_ref;
...@@ -49,7 +52,7 @@ type FxIndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>; ...@@ -49,7 +52,7 @@ type FxIndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>;
/// Starts the trace server on a background thread and returns the store /// Starts the trace server on a background thread and returns the store
/// immediately. The WebSocket server runs non-blocking. /// immediately. The WebSocket server runs non-blocking.
#[cfg(not(target_arch = "wasm32"))] #[cfg(any(not(target_arch = "wasm32"), feature = "trace-server"))]
pub fn start_turbopack_trace_server(path: PathBuf, port: Option<u16>) -> Arc<StoreContainer> { pub fn start_turbopack_trace_server(path: PathBuf, port: Option<u16>) -> Arc<StoreContainer> {
let store = Arc::new(StoreContainer::new()); let store = Arc::new(StoreContainer::new());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment