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 }
turbopack-core = { workspace = true }
turbopack-ecmascript-hmr-protocol = { 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"] }
mdxjs = { workspace = true, features = ["serializable"] }
......
#[cfg(not(target_arch = "wasm32"))]
use std::thread;
use std::{
borrow::Cow,
fs::{canonicalize, create_dir_all},
io::Write,
path::{Path, PathBuf},
sync::{Arc, LazyLock, Mutex},
thread,
time::{Duration, SystemTime},
};
......@@ -567,10 +566,8 @@ pub fn project_new<'env>(
.unwrap();
});
// The file/WebSocket trace server is native-only; the WASI binding
// still supports writing traces, but cannot start a localhost server.
#[cfg(not(target_arch = "wasm32"))]
if std::env::var("NEXT_TURBOPACK_TRACE_SERVER").is_ok() {
let trace_server = std::env::var("NEXT_TURBOPACK_TRACE_SERVER").ok();
if trace_server.is_some() {
thread::spawn(move || {
turbopack_trace_server::start_turbopack_trace_server(trace_file, None);
});
......
#[cfg(not(target_arch = "wasm32"))]
use std::path::PathBuf;
use std::sync::Arc;
use std::{path::PathBuf, sync::Arc};
use napi_derive::napi;
#[cfg(not(target_arch = "wasm32"))]
use turbopack_trace_server::start_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.
......@@ -90,7 +87,6 @@ pub struct TraceQueryResult {
/// Starts the turbopack trace server on a background thread and returns a
/// handle immediately (non-blocking). The WebSocket server will be available
/// at `ws://127.0.0.1:<port>` (default port 5747).
#[cfg(not(target_arch = "wasm32"))]
#[napi]
pub fn start_turbopack_trace_server_handle(path: String, port: Option<u16>) -> TraceServerHandle {
let store = start_turbopack_trace_server(PathBuf::from(path), port);
......
......@@ -9,6 +9,9 @@ autobenches = false
[features]
default = ["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]]
name = "turbo-trace-server"
......@@ -36,3 +39,7 @@ turbopack-trace-utils = { workspace = true }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tungstenite = { version = "0.21.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)]
#![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::{
hash::BuildHasherDefault,
......@@ -14,7 +17,7 @@ use std::{
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::{span_graph_ref::SpanGraphEventRef, span_ref::SpanRef, store_container::StoreContainer};
......@@ -22,10 +25,10 @@ mod bottom_up;
mod chunked_vec;
mod lazy_sorted_vec;
pub mod protocol;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "trace-server"))]
mod reader;
mod self_time_tree;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "trace-server"))]
mod server;
mod span;
mod span_bottom_up_ref;
......@@ -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
/// 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> {
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