From 19c0ef1c350d7bf52b6fc6b3ffad31968da8140a Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Fri, 5 Apr 2024 13:55:49 +0100 Subject: [PATCH] add next-build-test binary / library --- Cargo.lock | 258 ++++++++++++++++-- Cargo.toml | 7 + .../crates/next-build-test/Cargo.toml | 47 ++++ .../next-swc/crates/next-build-test/build.rs | 3 + .../crates/next-build-test/src/lib.rs | 140 ++++++++++ .../crates/next-build-test/src/main.rs | 46 ++++ 6 files changed, 474 insertions(+), 27 deletions(-) create mode 100644 packages/next-swc/crates/next-build-test/Cargo.toml create mode 100644 packages/next-swc/crates/next-build-test/build.rs create mode 100644 packages/next-swc/crates/next-build-test/src/lib.rs create mode 100644 packages/next-swc/crates/next-build-test/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index f1e0ab00bc2e00..9b0507a1f5223a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -444,6 +444,29 @@ dependencies = [ "serde", ] +[[package]] +name = "bindgen" +version = "0.69.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" +dependencies = [ + "bitflags 2.5.0", + "cexpr", + "clang-sys", + "itertools 0.12.0", + "lazy_static", + "lazycell", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.58", + "which", +] + [[package]] name = "binding_macros" version = "0.64.23" @@ -672,6 +695,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-expr" version = "0.15.4" @@ -703,6 +735,17 @@ dependencies = [ "windows-targets 0.48.1", ] +[[package]] +name = "clang-sys" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "clap" version = "4.5.2" @@ -1533,9 +1576,9 @@ checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" [[package]] name = "fastrand" -version = "2.0.0" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" [[package]] name = "fdeflate" @@ -1615,9 +1658,9 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ "percent-encoding", ] @@ -1648,6 +1691,12 @@ dependencies = [ "libc", ] +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + [[package]] name = "funty" version = "2.0.0" @@ -1972,6 +2021,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "hstr" version = "0.2.8" @@ -2083,6 +2141,41 @@ dependencies = [ "tungstenite", ] +[[package]] +name = "iai-callgrind" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e99bf26f496b13ac6273014f40afda46a233fbfb0289ce50fb4daaad2f2ffc80" +dependencies = [ + "bincode", + "bindgen", + "cc", + "iai-callgrind-macros", + "iai-callgrind-runner", + "regex", +] + +[[package]] +name = "iai-callgrind-macros" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2a4bb39225592c0a28cfca6f70af52ebd8da23f533c2cdd0a3329c1fa252d56" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "iai-callgrind-runner" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c23a951b9eccaa1e38556d27473d1462a9c247a27961812edcaac156af861282" +dependencies = [ + "serde", +] + [[package]] name = "iana-time-zone" version = "0.1.57" @@ -2120,9 +2213,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -2399,6 +2492,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "leb128" version = "0.2.5" @@ -3004,6 +3103,28 @@ dependencies = [ "vergen 7.5.1", ] +[[package]] +name = "next-build-test" +version = "0.1.0" +dependencies = [ + "anyhow", + "futures-util", + "iai-callgrind", + "next-api", + "next-core", + "num_cpus", + "rand 0.8.5", + "serde_json", + "tempdir", + "tokio", + "tokio-stream", + "tracing", + "tracing-subscriber", + "turbo-tasks", + "turbo-tasks-malloc", + "turbopack-binding", +] + [[package]] name = "next-core" version = "0.1.0" @@ -3499,9 +3620,9 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" @@ -3594,7 +3715,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" dependencies = [ "phf_shared 0.10.0", - "rand", + "rand 0.8.5", ] [[package]] @@ -3604,7 +3725,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" dependencies = [ "phf_shared 0.11.2", - "rand", + "rand 0.8.5", ] [[package]] @@ -3757,6 +3878,16 @@ dependencies = [ "yansi", ] +[[package]] +name = "prettyplease" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d3928fb5db768cb86f891ff014f0144589297e3c6a1aba6ed7cecfdace270c7" +dependencies = [ + "proc-macro2", + "syn 2.0.58", +] + [[package]] name = "priority-queue" version = "1.3.1" @@ -3886,6 +4017,19 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce082a9940a7ace2ad4a8b7d0b1eac6aa378895f18be598230c5f2284ac05426" +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +dependencies = [ + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "rdrand", + "winapi", +] + [[package]] name = "rand" version = "0.8.5" @@ -3894,7 +4038,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha", - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -3904,9 +4048,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", ] +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + [[package]] name = "rand_core" version = "0.6.4" @@ -3951,7 +4110,7 @@ dependencies = [ "num-traits", "once_cell", "paste", - "rand", + "rand 0.8.5", "rand_chacha", "rust_hawktracer", "rustc_version 0.4.0", @@ -4002,6 +4161,15 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + [[package]] name = "react_remove_properties" version = "0.24.7" @@ -4133,6 +4301,15 @@ dependencies = [ "swc_ecma_visit", ] +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + [[package]] name = "rend" version = "0.4.0" @@ -4713,6 +4890,12 @@ dependencies = [ "memmap2 0.6.2", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook" version = "0.3.17" @@ -6456,17 +6639,26 @@ version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ae9980cab1db3fceee2f6c6f643d5d8de2997c58ee8d25fb0cc8a9e9e7348e5" +[[package]] +name = "tempdir" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" +dependencies = [ + "rand 0.4.6", + "remove_dir_all", +] + [[package]] name = "tempfile" -version = "3.8.0" +version = "3.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", "fastrand", - "redox_syscall", "rustix", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -6700,9 +6892,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" dependencies = [ "futures-core", "pin-project-lite", @@ -6910,7 +7102,7 @@ dependencies = [ "http", "httparse", "log", - "rand", + "rand 0.8.5", "sha1", "thiserror", "url", @@ -7597,7 +7789,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if", - "rand", + "rand 0.8.5", "static_assertions", ] @@ -7736,9 +7928,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", "idna", @@ -8321,7 +8513,7 @@ dependencies = [ "once_cell", "petgraph", "pin-project", - "rand", + "rand 0.8.5", "rusty_pool", "semver 1.0.18", "serde", @@ -8452,7 +8644,7 @@ dependencies = [ "lexical-sort", "once_cell", "path-clean 1.0.1", - "rand", + "rand 0.8.5", "semver 1.0.18", "serde", "serde_cbor", @@ -8493,6 +8685,18 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + [[package]] name = "winapi" version = "0.3.9" @@ -8791,9 +8995,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.15" +version = "0.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index ffabdcc19f398a..d692e659a12196 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ members = [ "packages/next-swc/crates/napi", "packages/next-swc/crates/wasm", "packages/next-swc/crates/next-api", + "packages/next-swc/crates/next-build-test", "packages/next-swc/crates/next-build", "packages/next-swc/crates/next-core", "packages/next-swc/crates/next-custom-transforms", @@ -22,6 +23,11 @@ debug-assertions = false [profile.dev.build-override] opt-level = 3 +[profile.release-with-debug] +inherits = "release" +debug = true +lto = "thin" + [workspace.dependencies] # Workspace crates next-api = { path = "packages/next-swc/crates/next-api" } @@ -42,6 +48,7 @@ turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbop turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240416.1" } # [TODO]: need to refactor embed_directory! macro usage in next-core turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240416.1" } +turbo-tasks-malloc = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240416.1" } # General Deps diff --git a/packages/next-swc/crates/next-build-test/Cargo.toml b/packages/next-swc/crates/next-build-test/Cargo.toml new file mode 100644 index 00000000000000..208bda816ad13c --- /dev/null +++ b/packages/next-swc/crates/next-build-test/Cargo.toml @@ -0,0 +1,47 @@ +[package] +name = "next-build-test" +version = "0.1.0" +description = "TBD" +license = "MPL-2.0" +edition = "2021" +autobenches = false + +[lints] +workspace = true + +[dependencies] +next-core = { workspace = true, features = ["native-tls"] } +next-api = { workspace = true } +serde_json = { workspace = true } +anyhow = { workspace = true } +tokio = { workspace = true, features = ["full"] } +turbo-tasks-malloc = { workspace = true, default-features = false } +turbopack-binding = { workspace = true, features = [ + "__turbo_tasks", + "__turbo_tasks_memory", + "__turbo_tasks_env", + "__turbo_tasks_fs", + "__turbo_tasks_memory", + "__turbopack", + "__turbopack_nodejs", + "__turbopack_core", + "__turbopack_browser", + "__turbopack_ecmascript", + "__turbopack_ecmascript_runtime", + "__turbopack_env", + "__turbopack_node", +] } +turbo-tasks = { workspace = true } +rand.workspace = true +num_cpus = "1.16.0" +tokio-stream = "0.1.15" +tracing = "0.1" +tracing-subscriber = "0.3" +futures-util = "0.3.30" + +[build-dependencies] +turbopack-binding = { workspace = true, features = ["__turbo_tasks_build"] } + +[dev-dependencies] +iai-callgrind = "0.10.2" +tempdir = "0.3.7" diff --git a/packages/next-swc/crates/next-build-test/build.rs b/packages/next-swc/crates/next-build-test/build.rs new file mode 100644 index 00000000000000..f66b495c19d3bb --- /dev/null +++ b/packages/next-swc/crates/next-build-test/build.rs @@ -0,0 +1,3 @@ +fn main() { + turbopack_binding::turbo::tasks_build::generate_register(); +} diff --git a/packages/next-swc/crates/next-build-test/src/lib.rs b/packages/next-swc/crates/next-build-test/src/lib.rs new file mode 100644 index 00000000000000..a41ca399d88914 --- /dev/null +++ b/packages/next-swc/crates/next-build-test/src/lib.rs @@ -0,0 +1,140 @@ +#![feature(future_join)] +#![feature(min_specialization)] +#![feature(arbitrary_self_types)] + +use std::str::FromStr; + +use anyhow::{Context, Result}; +use futures_util::{StreamExt, TryStreamExt}; +use next_api::{ + project::{ProjectContainer, ProjectOptions}, + route::{Endpoint, Route}, +}; + +pub async fn main_inner(strat: Strategy, factor: usize, limit: usize) -> Result<()> { + register(); + + let mut file = std::fs::File::open("project_options.json").with_context(|| { + let path = std::env::current_dir() + .unwrap() + .join("project_options.json"); + format!("loading file at {}", path.display()) + })?; + + let options: ProjectOptions = serde_json::from_reader(&mut file).unwrap(); + let project = ProjectContainer::new(options); + + tracing::info!("collecting endpoints"); + let entrypoints = project.entrypoints().await?; + + let routes = shuffle(entrypoints.routes.clone().into_iter()); + let count = render_routes(routes, strat, factor, limit).await; + tracing::info!("rendered {} pages", count); + + Ok(()) +} + +pub fn register() { + next_api::register(); + include!(concat!(env!("OUT_DIR"), "/register.rs")); +} + +#[derive(PartialEq, Copy, Clone)] +pub enum Strategy { + Sequential, + Concurrent, + Parallel, +} + +impl std::fmt::Display for Strategy { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Strategy::Sequential => write!(f, "sequential"), + Strategy::Concurrent => write!(f, "concurrent"), + Strategy::Parallel => write!(f, "parallel"), + } + } +} + +impl FromStr for Strategy { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result { + match s { + "sequential" => Ok(Strategy::Sequential), + "concurrent" => Ok(Strategy::Concurrent), + "parallel" => Ok(Strategy::Parallel), + _ => Err(anyhow::anyhow!("invalid strategy")), + } + } +} + +pub fn shuffle<'a, T: 'a>(items: impl Iterator) -> impl Iterator { + use rand::{seq::SliceRandom, thread_rng}; + let mut rng = thread_rng(); + let mut input = items.collect::>(); + input.shuffle(&mut rng); + input.into_iter() +} + +pub async fn render_routes( + routes: impl Iterator, + strategy: Strategy, + factor: usize, + limit: usize, +) -> usize { + tracing::info!( + "rendering routes with {} parallel and strat {}", + factor, + strategy + ); + + let stream = tokio_stream::iter(routes) + .map(move |(name, route)| { + let fut = async move { + tracing::info!("{name}"); + + match route { + Route::Page { + html_endpoint, + data_endpoint: _, + } => { + html_endpoint.write_to_disk().await?; + } + Route::PageApi { endpoint } => { + endpoint.write_to_disk().await?; + } + Route::AppPage(routes) => { + for route in routes { + route.html_endpoint.write_to_disk().await?; + } + } + Route::AppRoute { + original_name: _, + endpoint, + } => { + endpoint.write_to_disk().await?; + } + Route::Conflict => { + tracing::info!("WARN: conflict {}", name); + } + } + + Ok::<_, anyhow::Error>(()) + }; + + async move { + match strategy { + Strategy::Parallel => tokio::task::spawn(fut).await.unwrap(), + _ => fut.await, + } + } + }) + .take(limit) + .buffer_unordered(factor) + .try_collect::>() + .await + .unwrap(); + + stream.len() +} diff --git a/packages/next-swc/crates/next-build-test/src/main.rs b/packages/next-swc/crates/next-build-test/src/main.rs new file mode 100644 index 00000000000000..2c9ed36888a3d7 --- /dev/null +++ b/packages/next-swc/crates/next-build-test/src/main.rs @@ -0,0 +1,46 @@ +use std::str::FromStr; + +use next_build_test::{main_inner, Strategy}; +use turbo_tasks::TurboTasks; +use turbo_tasks_malloc::TurboMalloc; +use turbopack_binding::turbo::tasks_memory::MemoryBackend; + +fn main() { + tracing_subscriber::fmt::init(); + + let mut factor = std::env::args() + .nth(2) + .map(|s| s.parse().unwrap()) + .unwrap_or(num_cpus::get()); + let strat = std::env::args() + .nth(1) + .map(|s| Strategy::from_str(&s)) + .transpose() + .unwrap() + .unwrap_or(Strategy::Sequential); + + let limit = std::env::args() + .nth(3) + .map(|s| s.parse().unwrap()) + .unwrap_or(1); + + if strat == Strategy::Sequential { + factor = 1; + } + + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .on_thread_stop(|| { + TurboMalloc::thread_stop(); + tracing::debug!("threads stopped"); + }) + .build() + .unwrap() + .block_on(async { + let tt = TurboTasks::new(MemoryBackend::new(usize::MAX)); + let x = tt.run_once(main_inner(strat, factor, limit)).await; + tracing::debug!("done"); + x + }) + .unwrap(); +}