From 5458f293e0c1cce2ecabe3f413ac60f3b5139705 Mon Sep 17 00:00:00 2001 From: hardfist Date: Fri, 14 Feb 2025 12:41:00 +0800 Subject: [PATCH] chore: use more semantic naming profile (#9288) * chore: use more semantic profile * chore: fix script * chore: use ci by default * chore: fix * chore: use debug for windows * chore: fix dep * chore: adjust params * chore: adjust production -> release --- .github/workflows/ci.yml | 4 +- .github/workflows/preview-commit.yml | 2 +- .github/workflows/release-canary.yml | 5 +- .github/workflows/release.yml | 2 +- .github/workflows/reusable-build.yml | 57 +++---------------- Cargo.toml | 34 +++++++---- crates/node_binding/package.json | 22 ++----- crates/node_binding/scripts/build.js | 23 ++++---- package.json | 11 ++-- .../en/contribute/development/debugging.mdx | 2 +- .../zh/contribute/development/debugging.mdx | 2 +- x.mjs | 2 +- 12 files changed, 59 insertions(+), 107 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index becdbabf1876..71263352a9b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,7 +97,7 @@ jobs: uses: ./.github/workflows/reusable-build.yml with: target: x86_64-pc-windows-msvc - profile: "debug" + profile: "dev" runner: ${{ needs.get-runner-labels.outputs.WINDOWS_RUNNER_LABELS }} skipable: ${{ needs.check-changed.outputs.changed != 'true' }} @@ -124,7 +124,7 @@ jobs: uses: ./.github/workflows/reusable-build.yml with: target: x86_64-apple-darwin - profile: "debug" + profile: "ci" runner: ${{ needs.get-runner-labels.outputs.MACOS_RUNNER_LABELS }} skipable: ${{ needs.check-changed.outputs.changed != 'true' }} diff --git a/.github/workflows/preview-commit.yml b/.github/workflows/preview-commit.yml index 27cfe6a94f7b..53e9bc14d123 100644 --- a/.github/workflows/preview-commit.yml +++ b/.github/workflows/preview-commit.yml @@ -60,7 +60,7 @@ jobs: with: target: ${{ matrix.array.target }} runner: ${{ matrix.array.runner }} - profile: "release-prod" + profile: "release" test: false publish: diff --git a/.github/workflows/release-canary.yml b/.github/workflows/release-canary.yml index 3b98caea10c8..05eb15c63cb4 100644 --- a/.github/workflows/release-canary.yml +++ b/.github/workflows/release-canary.yml @@ -13,8 +13,9 @@ on: default: release options: - release - - release-debug - description: "release-debug means release with debug info for profile" + - profiling + - ci + description: "profiling means release with debug info for profiling, ci means release with debug info and faster build time" permissions: # To publish packages with provenance diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 024ace4741e8..da3a8d267dd2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -66,7 +66,7 @@ jobs: with: target: ${{ matrix.array.target }} runner: ${{ matrix.array.runner }} - profile: "release-prod" + profile: "release" release: name: Release diff --git a/.github/workflows/reusable-build.yml b/.github/workflows/reusable-build.yml index 1244d4354dd9..938785487509 100644 --- a/.github/workflows/reusable-build.yml +++ b/.github/workflows/reusable-build.yml @@ -1,34 +1,5 @@ name: Reusable Release -# Example job: -#jobs -# build: -# strategy: -# matrix: -# array: -# - target: x86_64-unknown-linux-gnu -# runner: ubuntu-latest -# - target: aarch64-unknown-linux-gnu -# runner: ubuntu-latest -# - target: x86_64-unknown-linux-musl -# runner: ubuntu-latest -# - target: aarch64-unknown-linux-musl -# runner: ubuntu-latest -# - target: i686-pc-windows-msvc -# runner: windows-latest -# - target: x86_64-pc-windows-msvc -# runner: windows-latest -# - target: aarch64-pc-windows-msvc -# runner: windows-latest -# - target: x86_64-apple-darwin -# runner: macos-latest -# - target: aarch64-apple-darwin -# runner: macos-latest -# uses: ./.github/workflows/reusable-build.yml -# with: -# target: ${{ matrix.array.target }} -# runner: ${{ matrix.array.runner }} - on: workflow_call: inputs: @@ -42,8 +13,8 @@ on: runner: # Runner labels required: true type: string - profile: # Rust profile, "debug" or "release" - default: "release" + profile: # Rust profile, "ci" or "production" or "profiling" + default: "ci" required: false type: string test: # Run tests? @@ -85,10 +56,6 @@ jobs: with: target: ${{ inputs.target }} - - name: Setup tmate session - uses: mxschmitt/action-tmate@e5c7151931ca95bad1c6f4190c730ecf8c7dde48 # v3 - if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled && !inputs.skipable }} - - name: Pnpm Cache if: ${{ !inputs.skipable }} uses: ./.github/actions/pnpm-cache @@ -102,16 +69,6 @@ jobs: save-cache: ${{ github.ref_name == 'main' }} # This should be safe because we have nightly building the cache every day shared-key: build-${{ inputs.target }}-${{ inputs.profile }} - # Compile dependencies with optimization to make tests run faster - - name: Add optimization to debug profile - if: ${{ inputs.profile == 'debug' && !inputs.skipable }} - shell: bash - run: | - echo '[profile.release.package."*"]' >> Cargo.toml - echo 'opt-level = 3' >> Cargo.toml - echo 'codegen-units = 64' >> Cargo.toml - echo 'incremental = false' >> Cargo.toml - - name: Trim paths if: ${{ !inputs.skipable }} shell: bash @@ -122,7 +79,7 @@ jobs: - name: Check local cache id: check_cache - if: ${{ inputs.profile == 'debug' && !startsWith(runner.name, 'GitHub Actions') && !inputs.skipable }} + if: ${{ inputs.profile == 'ci' && !startsWith(runner.name, 'GitHub Actions') && !inputs.skipable }} shell: bash run: | set -e @@ -227,7 +184,7 @@ jobs: with: name: bindings-${{ inputs.target }} path: crates/node_binding/*.node - try-local-cache: ${{ inputs.profile == 'debug' }} + try-local-cache: ${{ inputs.profile == 'ci' }} mv-when-local: true e2e: @@ -253,7 +210,7 @@ jobs: with: name: bindings-${{ inputs.target }} path: crates/node_binding/ - try-local-cache: ${{ inputs.profile == 'debug' }} + try-local-cache: ${{ inputs.profile == 'ci' }} link-when-local: true - name: Setup Pnpm @@ -315,7 +272,7 @@ jobs: with: name: bindings-${{ inputs.target }} path: crates/node_binding/ - try-local-cache: ${{ inputs.profile == 'debug' }} + try-local-cache: ${{ inputs.profile == 'ci' }} link-when-local: true - name: Show restored binding @@ -414,7 +371,7 @@ jobs: with: name: bindings-${{ inputs.target }} path: crates/node_binding/ - try-local-cache: ${{ inputs.profile == 'debug' }} + try-local-cache: ${{ inputs.profile == 'ci' }} link-when-local: true - name: Show restored binding diff --git a/Cargo.toml b/Cargo.toml index 1791d82445ca..26ad18c54c5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -195,29 +195,39 @@ rspack_util = { version = "0.2.0", path = "crates/rsp [workspace.metadata.release] rate-limit = { existing-packages = 70, new-packages = 70 } + +# Follow servo's style https://github.com/servo/servo/blob/c95bd9d052d7eae378d31c5be0f92669cadb2c85/Cargo.toml#L175 + +# This is for local development [profile.dev] -codegen-units = 16 -debug = 2 # debug build will cause runtime panic if codegen-unints is default -incremental = true -panic = "abort" +debug = 2 # debug build will cause runtime panic if codegen-unints is default +incremental = true +panic = "abort" +# This is for release build for users [profile.release] codegen-units = 1 debug = false -# Performs “thin” LTO. This is similar to “fat”, but takes substantially less time to run while still achieving performance gains similar to “fat”. -lto = "thin" -opt-level = 3 +# Performs “fat” LTO which attempts to perform optimizations across all crates within the dependency graph. +lto = "fat" +opt-level = "s" panic = "abort" strip = true -[profile.release-prod] -inherits = "release" -# Performs “fat” LTO which attempts to perform optimizations across all crates within the dependency graph. -lto = "fat" +# This is for CI build based on release but with faster build time +[profile.ci] +codegen-units = 64 +inherits = "release" +## reduce little optimization to reduce build time +lto = "thin" +## reduce little optimization to reduce build time +opt-level = 2 -[profile.release-debug] +# This is for production for profiling production build +[profile.profiling] debug = true inherits = "release" +lto = "thin" strip = false # the following lints rules are from https://github.com/biomejs/biome/blob/4bd3d6f09642952ee14445ed56af81a73796cea1/Cargo.toml#L7C1-L75C1 diff --git a/crates/node_binding/package.json b/crates/node_binding/package.json index 3e44db2d7dcd..3157f5bbf3ab 100644 --- a/crates/node_binding/package.json +++ b/crates/node_binding/package.json @@ -14,24 +14,10 @@ "binding.d.ts" ], "scripts": { - "build:debug": "node scripts/build.js", - "watch:debug": "node scripts/build.js --watch", - "build:debug:x64": "cross-env RUST_TARGET=x86_64-apple-darwin node scripts/build.js", - "build:debug:linux": "cross-env RUST_TARGET=x86_64-unknown-linux-gnu node scripts/build.js", - "build:release": "node scripts/build.js --release", - "watch:release": "node scripts/build.js --release --watch", - "build:release:arm64": "cross-env RUST_TARGET=aarch64-apple-darwin node scripts/build.js --release", - "build:release:x64": "cross-env RUST_TARGET=x86_64-apple-darwin node scripts/build.js --release", - "build:release:linux": "cross-env RUST_TARGET=x86_64-unknown-linux-gnu node scripts/build.js --release", - "build:release:musl": "cross-env RUST_TARGET=aarch64-unknown-linux-musl node scripts/build.js --release", - "build:release:win": "cross-env RUST_TARGET=x86_64-pc-windows-msvc node scripts/build.js --release", - "build:release-prod": "node scripts/build.js --release-prod", - "watch:release-prod": "node scripts/build.js --release-prod --watch", - "build:release-prod:arm64": "cross-env RUST_TARGET=aarch64-apple-darwin node scripts/build.js --release-prod", - "build:release-prod:x64": "cross-env RUST_TARGET=x86_64-apple-darwin node scripts/build.js --release-prod", - "build:release-prod:linux": "cross-env RUST_TARGET=x86_64-unknown-linux-gnu node scripts/build.js --release-prod", - "build:release-prod:win": "cross-env RUST_TARGET=x86_64-pc-windows-msvc node scripts/build.js --release-prod", - "build:release-debug": "node scripts/build.js --release-debug", + "build:dev": "node scripts/build.js", + "build:ci": "node scripts/build.js --profile ci", + "build:production": "node scripts/build.js --profile production", + "build:release": "node scripts/build.js --profile release", "move-binding": "node scripts/move-binding", "test": "tsc -p tsconfig.type-test.json" }, diff --git a/crates/node_binding/scripts/build.js b/crates/node_binding/scripts/build.js index 618f82e2bd9a..a7468262de21 100644 --- a/crates/node_binding/scripts/build.js +++ b/crates/node_binding/scripts/build.js @@ -1,15 +1,18 @@ const path = require("path"); const { readFileSync, writeFileSync } = require("fs") +const { values } = require('util').parseArgs({ + args: process.argv.slice(2), + options: { + profile: { + type: 'string' + } + } +}) const { spawn } = require("child_process"); const CARGO_SAFELY_EXIT_CODE = 0; -// Faster release for CI & canary with `thin` LTO -let release = process.argv.includes("--release"); -// Slower release for production with `fat` LTO -let releaseProd = process.argv.includes("--release-prod"); -let releaseDebug = process.argv.includes("--release-debug"); let watch = process.argv.includes("--watch"); build().then((value) => { @@ -35,14 +38,8 @@ async function build() { "--pipe", `"node ./scripts/dts-header.js"` ]; - if (release) { - args.push("--release"); - } - if (releaseProd) { - args.push('--profile release-prod'); - } - if (releaseDebug) { - args.push('--profile release-debug'); + if (values.profile) { + args.push("--profile", values.profile) } if (watch) { args.push("--watch"); diff --git a/package.json b/package.json index c9e76f37249b..ad9d323a0efe 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "clean": "pnpm --filter @rspack/cli run clean", "check-dependency-version": "pnpx check-dependency-version-consistency@5 . --ignore-dep @napi-rs/cli --ignore-dep chalk --ignore-package webpack-test --ignore-package webpack-examples --ignore-package plugin-test", "build:js": "pnpm --filter \"@rspack/core\" build:force && pnpm --filter \"@rspack/*\" --filter \"create-rspack\" --filter \"!@rspack/core\" build", - "build:cli:debug": "npm run build:binding:debug && npm run build:js", + "build:cli:dev": "npm run build:binding:dev && npm run build:js", "build:cli:release": "npm run build:binding:release && npm run build:js", "build:cli:release:all": "pnpm --filter @rspack/binding build:release:all && npm run build:js", "build:cli:release:arm64": "pnpm --filter @rspack/binding build:release:arm64 && npm run build:js", @@ -28,10 +28,10 @@ "lint:js": "pnpm run lint-ci:js --write", "lint-ci:js": "biome check --diagnostic-level=warn --no-errors-on-unmatched --max-diagnostics=none", "lint:rs": "node ./scripts/check_rust_dependency.cjs", - "build:binding:debug": "pnpm --filter @rspack/binding run build:debug", + "build:binding:dev": "pnpm --filter @rspack/binding run build:dev", + "build:binding:ci": "pnpm --filter @rspack/binding run build:ci", "build:binding:release": "pnpm --filter @rspack/binding run build:release", - "build:binding:release-debug": "pnpm --filter @rspack/binding run build:release-debug", - "build:binding:release-prod": "pnpm --filter @rspack/binding run build:release-prod", + "build:binding:profiling": "pnpm --filter @rspack/binding run build:profiling", "prepare": "is-ci || husky", "test:diff": "pnpm --filter \"@rspack/*\" test:diff", "test:hot": "pnpm --filter \"@rspack/*\" test:hot", @@ -43,7 +43,8 @@ "doc-coverage": "pnpm --filter \"@rspack/core\" doc-coverage", "api-extractor:local": "pnpm --filter \"@rspack/*\" api-extractor --local", "api-extractor:ci": "pnpm --filter \"@rspack/*\" api-extractor:ci", - "bench:ci": "cargo codspeed run && pnpm --filter bench run bench" + "bench:ci:rust": "cargo codspeed run", + "bench:ci:js": "pnpm --filter bench run bench" }, "homepage": "https://rspack.dev", "bugs": "https://github.com/web-infra-dev/rspack/issues", diff --git a/website/docs/en/contribute/development/debugging.mdx b/website/docs/en/contribute/development/debugging.mdx index 4316f61e4eb6..f60d21348756 100644 --- a/website/docs/en/contribute/development/debugging.mdx +++ b/website/docs/en/contribute/development/debugging.mdx @@ -104,7 +104,7 @@ To illustrate this process, I'll use an example. Let's start by introduce the en Firstly, you need to build rspack in debug mode. To do this, execute the following commands in the project's root directory: ```bash -npm run build:binding:debug +npm run build:binding:dev npm run build:js ``` diff --git a/website/docs/zh/contribute/development/debugging.mdx b/website/docs/zh/contribute/development/debugging.mdx index d31b8b5363ff..3c196fa5ab4b 100644 --- a/website/docs/zh/contribute/development/debugging.mdx +++ b/website/docs/zh/contribute/development/debugging.mdx @@ -104,7 +104,7 @@ Target 0: (node) stopped. 首先,你需要在调试模式下构建 rspack。为此,请在项目的根目录中执行以下命令: ```bash -npm run build:binding:debug +npm run build:binding:dev npm run build:js ``` diff --git a/x.mjs b/x.mjs index 6f3da8ad2720..81ff97c665fa 100755 --- a/x.mjs +++ b/x.mjs @@ -107,7 +107,7 @@ buildCommand .command("binding") .description("build rust binding") .action(async () => { - await $`pnpm --filter @rspack/binding build:debug`; + await $`pnpm --filter @rspack/binding build:dev`; }); // x build js