Skip to content

Commit

Permalink
Add an empty next-build
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Mar 16, 2023
1 parent f84e9ea commit c2855f2
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 6 deletions.
24 changes: 24 additions & 0 deletions packages/next-swc/Cargo.lock

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

1 change: 1 addition & 0 deletions packages/next-swc/Cargo.toml
Expand Up @@ -5,6 +5,7 @@ members = [
"crates/napi",
"crates/wasm",
"crates/next-binding",
"crates/next-build",
"crates/next-core",
"crates/next-dev",
"crates/next-dev-tests",
Expand Down
1 change: 1 addition & 0 deletions packages/next-swc/crates/napi/Cargo.toml
Expand Up @@ -44,6 +44,7 @@ turbo-tasks = { workspace = true }
turbo-tasks-memory = { workspace = true }
next-binding = { path = "../next-binding", features = [
"__swc_core_binding_napi",
"__turbo_next_build",
"__turbo_next_dev_server",
"__turbo_node_file_trace",
"__feature_mdx_rs",
Expand Down
19 changes: 16 additions & 3 deletions packages/next-swc/crates/napi/src/turbopack.rs
Expand Up @@ -2,7 +2,10 @@ use std::convert::TryFrom;

use crate::util::MapErr;
use napi::bindgen_prelude::*;
use next_binding::turbo::next_dev::{devserver_options::DevServerOptions, start_server};
use next_binding::turbo::{
next_build::{next_build as turbo_next_build, NextBuildOptions},
next_dev::{devserver_options::DevServerOptions, start_server},
};

#[napi]
pub async fn start_turbo_dev(options: Buffer) -> napi::Result<()> {
Expand Down Expand Up @@ -91,8 +94,18 @@ impl FromNapiValue for RouteHas {
}
}

impl From<NextBuildContext> for NextBuildOptions {
fn from(value: NextBuildContext) -> Self {
Self {
dir: value.dir,
app_dir: value.app_dir,
memory_limit: None,
full_stats: None,
}
}
}

#[napi]
pub async fn next_build(ctx: NextBuildContext) -> napi::Result<()> {
println!("ctx: {:?}", ctx);
Ok(())
turbo_next_build(ctx.into()).await.convert_err()
}
4 changes: 4 additions & 0 deletions packages/next-swc/crates/next-binding/Cargo.toml
Expand Up @@ -74,6 +74,7 @@ __swc_core_binding_wasm_plugin = ["swc_core/plugin_transform_host_js"]
__swc_core_testing_transform = ["swc_core/testing_transform"]

__turbo = []
__turbo_next_build = ["__turbo", "next-build/rustls-tls"]
__turbo_next_dev_server = ["__turbo", "next-dev/serializable"]
__turbo_node_file_trace = ["__turbo", "node-file-trace/node-api"]

Expand Down Expand Up @@ -102,6 +103,9 @@ __swc_testing = ["__swc", "testing"]
[dependencies]
mdxjs = { optional = true, workspace = true }
modularize_imports = { optional = true, workspace = true }
next-build = { optional = true, path = "../next-build", default-features = false, features = [
"custom_allocator",
] }
# TODO: Not sure what's going on, but using `workspace = true` noops `default-features = false`?
next-dev = { optional = true, path = "../next-dev", default-features = false, features = [
"custom_allocator",
Expand Down
2 changes: 2 additions & 0 deletions packages/next-swc/crates/next-binding/src/lib.rs
Expand Up @@ -21,6 +21,8 @@ pub mod swc {

#[cfg(feature = "__turbo")]
pub mod turbo {
#[cfg(feature = "__turbo_next_build")]
pub use next_build;
#[cfg(feature = "__turbo_next_dev_server")]
pub use next_dev;
#[cfg(feature = "__turbo_node_file_trace")]
Expand Down
37 changes: 37 additions & 0 deletions packages/next-swc/crates/next-build/Cargo.toml
@@ -0,0 +1,37 @@
[package]
name = "next-build"
version = "0.1.0"
description = "TBD"
license = "MPL-2.0"
edition = "2021"
autobenches = false

[features]
next-font-local = ["next-core/next-font-local"]
native-tls = ["next-core/native-tls"]
rustls-tls = ["next-core/rustls-tls"]
custom_allocator = ["turbo-malloc/custom_allocator"]

[dependencies]
anyhow = "1.0.47"
clap = { version = "4.0.18", features = ["derive", "env"], optional = true }
mime = "0.3.16"
next-core = { workspace = true }
owo-colors = "3"
serde = "1.0.136"
tokio = { version = "1.21.2", features = ["full"] }
turbo-malloc = { workspace = true, default-features = false }
turbo-tasks = { workspace = true }
turbo-tasks-fs = { workspace = true }
turbo-tasks-memory = { workspace = true }
turbopack-cli-utils = { workspace = true }
turbopack-core = { workspace = true }
turbopack-dev-server = { workspace = true }
turbopack-node = { workspace = true }

[build-dependencies]
turbo-tasks-build = { workspace = true }
vergen = { version = "7.3.2", default-features = false, features = [
"cargo",
"build",
] }
13 changes: 13 additions & 0 deletions packages/next-swc/crates/next-build/build.rs
@@ -0,0 +1,13 @@
use turbo_tasks_build::{generate_register, rerun_if_glob};

use vergen::{vergen, Config};

fn main() {
generate_register();

rerun_if_glob("tests/integration/*/*", "tests/integration");

// Attempt to collect some build time env values but will skip if there are any
// errors.
let _ = vergen(Config::default());
}
43 changes: 43 additions & 0 deletions packages/next-swc/crates/next-build/src/lib.rs
@@ -0,0 +1,43 @@
#![feature(future_join)]
#![feature(min_specialization)]

use turbo_tasks::{NothingVc, StatsType, TurboTasks, TurboTasksBackendApi};
use turbo_tasks_memory::MemoryBackend;

#[derive(Clone)]
pub enum EntryRequest {
Relative(String),
Module(String, String),
}

pub fn register() {
next_core::register();
include!(concat!(env!("OUT_DIR"), "/register.rs"));
}

pub struct NextBuildOptions {
pub dir: Option<String>,
pub app_dir: Option<String>,
pub memory_limit: Option<usize>,
pub full_stats: Option<bool>,
}

pub async fn next_build(options: NextBuildOptions) -> anyhow::Result<()> {
register();
let tt = TurboTasks::new(MemoryBackend::new(
options.memory_limit.map_or(usize::MAX, |l| l * 1024 * 1024),
));
let stats_type = match options.full_stats {
Some(true) => StatsType::Full,
_ => StatsType::Essential,
};
tt.set_stats_type(stats_type);
let task = tt.spawn_root_task(move || {
Box::pin(async move {
// run next build here
Ok(NothingVc::new().into())
})
});
tt.wait_task_completion(task, true).await?;
Ok(())
}
2 changes: 1 addition & 1 deletion packages/next/src/build/index.ts
Expand Up @@ -1015,7 +1015,7 @@ export default async function build(

async function runTurboBuild() {
const turboNextBuildStart = process.hrtime()
await binding.turbo.nextBuild()
await binding.turbo.nextBuild(NextBuildContext)
const [duration] = process.hrtime(turboNextBuildStart)
return { duration, turbotraceContext: null }
}
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/cli/next-build.ts
Expand Up @@ -17,7 +17,7 @@ const nextBuild: CliCommand = (argv) => {
'--no-lint': Boolean,
'--no-mangling': Boolean,
'--experimental-app-only': Boolean,
'--turbo': Boolean,
'--experimental-turbo': Boolean,
// Aliases
'-h': '--help',
'-d': '--debug',
Expand Down Expand Up @@ -78,7 +78,7 @@ const nextBuild: CliCommand = (argv) => {
!args['--no-lint'],
args['--no-mangling'],
args['--experimental-app-only'],
args['--turbo']
args['--experimental-turbo']
).catch((err) => {
console.error('')
if (
Expand Down

0 comments on commit c2855f2

Please sign in to comment.