Skip to content

Commit

Permalink
add next-build-test binary / library
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed May 22, 2024
1 parent 7e34b4c commit a0a7918
Show file tree
Hide file tree
Showing 9 changed files with 773 additions and 17 deletions.
247 changes: 230 additions & 17 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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" }
Expand All @@ -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-240521.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240521.2" }
turbo-tasks-malloc = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240521.2" }

# General Deps

Expand Down
47 changes: 47 additions & 0 deletions packages/next-swc/crates/next-build-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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, features = ["small_rng"] }
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"
32 changes: 32 additions & 0 deletions packages/next-swc/crates/next-build-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# next-build-test

This binary lets you sidestep all of the node bundling and run a turbo build
against a raw rust binary. It does _not_ do everything nextjs does, but it
is an ok approximation.

## Getting started

You will need a project_options file that points to some nextjs repo that has
its dependencies installed. The easiest way to do that is to run a nextjs
build using a modified binary that spits one out for you or to run the
`generate` command and tweak it manually. We cannot bundle one in the repo,
since it needs fs-specific paths and env vars.

You can run the binary with the `generate` flag to build one for you.

```sh
cargo run -- generate /path/to/project > project_options.json
cargo run -- run
```

## Flags

The `run` command supports 4 flags:

- `strategy` can be one of sequential, concurrent, or parallel. defines how
work is structured
- `factor` defined how many pages should be built at once. defaults to num_cpus
- `limit` defines the highest number of pages to build. the pages are
shuffled deterministically. defaults to 1 page
- `pages` a comma separated list of routes to run. queues that precise set in
the order specified
3 changes: 3 additions & 0 deletions packages/next-swc/crates/next-build-test/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
turbopack_binding::turbo::tasks_build::generate_register();
}
35 changes: 35 additions & 0 deletions packages/next-swc/crates/next-build-test/jsConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"compilerOptions": {
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": false,
"skipLibCheck": true,
"strict": true,
"lib": ["lib.dom.d.ts", "lib.dom.iterable.d.ts", "lib.esnext.d.ts"],
"module": 99,
"target": 8,
"moduleResolution": 2,
"incremental": true,
"noEmit": true,
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": 1,
"plugins": [
{
"name": "typescript-plugin-css-modules",
"options": {
"goToDefinition": true
}
},
{
"name": "next"
}
],
"allowJs": true,
"paths": {},
"tsBuildInfoFile": "/tmp/ignore",
"strictNullChecks": true,
"pathsBasePath": "/tmp/ignore"
}
}
147 changes: 147 additions & 0 deletions packages/next-swc/crates/next-build-test/nextConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"env": {},
"webpack": {},
"eslint": {
"ignoreDuringBuilds": false
},
"typescript": {
"ignoreBuildErrors": false,
"tsconfigPath": "tsconfig.json"
},
"distDir": ".next",
"cleanDistDir": true,
"assetPrefix": "",
"cacheMaxMemorySize": 52428800,
"configOrigin": "next.config.mjs",
"useFileSystemPublicRoutes": true,
"generateBuildId": null,
"generateEtags": true,
"pageExtensions": ["jsx", "js", "tsx", "ts", "mdx", "md"],
"poweredByHeader": true,
"compress": true,
"analyticsId": "",
"images": {
"deviceSizes": [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
"imageSizes": [16, 32, 48, 64, 96, 128, 256, 384],
"path": "/_next/image",
"loader": "default",
"loaderFile": "",
"domains": [],
"disableStaticImages": false,
"minimumCacheTTL": 60,
"formats": ["image/avif", "image/webp"],
"dangerouslyAllowSVG": false,
"contentSecurityPolicy": "script-src 'none'; frame-src 'none'; sandbox;",
"contentDispositionType": "inline",
"remotePatterns": [],
"unoptimized": false
},
"devIndicators": {
"buildActivity": true,
"buildActivityPosition": "bottom-right"
},
"onDemandEntries": {
"maxInactiveAge": 60000,
"pagesBufferLength": 5
},
"amp": {
"canonicalBase": ""
},
"basePath": "",
"sassOptions": {},
"trailingSlash": false,
"i18n": null,
"productionBrowserSourceMaps": false,
"optimizeFonts": true,
"excludeDefaultMomentLocales": true,
"serverRuntimeConfig": {},
"publicRuntimeConfig": {},
"reactProductionProfiling": false,
"reactStrictMode": true,
"httpAgentOptions": {
"keepAlive": true
},
"outputFileTracing": true,
"staticPageGenerationTimeout": 60,
"swcMinify": true,
"modularizeImports": {},
"experimental": {
"prerenderEarlyExit": false,
"serverMinification": true,
"serverSourceMaps": false,
"linkNoTouchStart": false,
"caseSensitiveRoutes": false,
"clientRouterFilter": true,
"clientRouterFilterRedirects": false,
"fetchCacheKeyPrefix": "",
"middlewarePrefetch": "flexible",
"optimisticClientCache": true,
"manualClientBasePath": false,
"cpus": 2,
"memoryBasedWorkersCount": false,
"isrFlushToDisk": true,
"workerThreads": false,
"optimizeCss": false,
"nextScriptWorkers": false,
"scrollRestoration": false,
"externalDir": false,
"disableOptimizedLoading": false,
"gzipSize": true,
"craCompat": false,
"esmExternals": true,
"fullySpecified": false,
"outputFileTracingRoot": "/tmp/ignore",
"swcTraceProfiling": false,
"forceSwcTransforms": false,
"largePageDataBytes": 128000,
"adjustFontFallbacks": false,
"adjustFontFallbacksWithSizeAdjust": false,
"turbo": {
"rules": {
"*.mdx": {
"loaders": ["turbopack-mdx-loader"],
"as": "*.tsx"
}
},
"resolveAlias": {
"fs": {
"browser": "./turbopack/empty.js"
},
"cookie": {
"browser": "./turbopack/empty.js"
},
"http": {
"browser": "./turbopack/empty.js"
},
"https": {
"browser": "./turbopack/empty.js"
},
"node-fetch": {
"browser": "./turbopack/empty.js"
}
}
},
"typedRoutes": false,
"instrumentationHook": true,
"bundlePagesExternals": false,
"parallelServerCompiles": false,
"parallelServerBuildTraces": false,
"ppr": false,
"missingSuspenseWithCSRBailout": true,
"optimizeServerReact": true,
"useEarlyImport": false,
"serverComponentsExternalPackages": [],
"useLightningcss": true,
"optimizePackageImports": []
},
"configFile": "/tmp/ignore",
"configFileName": "next.config.mjs",
"transpilePackages": [],
"_originalRewrites": {
"beforeFiles": [],
"afterFiles": [],
"fallback": []
},
"_originalRedirects": [],
"exportPathMap": {}
}
Loading

0 comments on commit a0a7918

Please sign in to comment.