Skip to content

Commit 2da328e

Browse files
committed
build(core): split native packages publishing
1 parent 26bb5e4 commit 2da328e

36 files changed

Lines changed: 4514 additions & 1646 deletions

File tree

.cargo/config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[env]
2+
# Required by rolldown_workspace crate - points to the rolldown subproject root
3+
WORKSPACE_DIR = { value = "rolldown", relative = true }
4+
15
[build]
26
rustflags = ["--cfg", "tokio_unstable"] # also update .github/workflows/ci.yml
37
# fix sqlite build error on linux
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
name: cargo-workspace-merger
3+
description: "Use this agent when you need to merge one Cargo workspace into another, specifically when integrating a subproject's crates and dependencies into a root workspace. This includes tasks like: adding crate path references to workspace members, merging workspace dependency definitions while avoiding duplicates, and ensuring only production dependencies (not unnecessary dev dependencies) are included.\\n\\n<example>\\nContext: The user wants to integrate the rolldown project into their existing Cargo workspace.\\nuser: \"I need to merge the rolldown Cargo workspace into our root workspace\"\\nassistant: \"I'll use the cargo-workspace-merger agent to handle this integration. This involves analyzing both Cargo.toml files, identifying the crates to add, and merging the necessary dependencies.\"\\n<Task tool call to launch cargo-workspace-merger agent>\\n</example>\\n\\n<example>\\nContext: The user has cloned a Rust project as a subdirectory and wants to integrate it.\\nuser: \"Can you add all the crates from ./external-lib into our workspace?\"\\nassistant: \"I'll launch the cargo-workspace-merger agent to analyze the external library's workspace structure and merge it into your root Cargo.toml.\"\\n<Task tool call to launch cargo-workspace-merger agent>\\n</example>"
4+
model: opus
5+
color: yellow
6+
---
7+
8+
You are an expert Rust build system engineer specializing in Cargo workspace management and dependency resolution. You have deep knowledge of Cargo.toml structure, workspace inheritance, and dependency deduplication strategies.
9+
10+
## Your Primary Mission
11+
12+
Merge a child Cargo workspace (located in a subdirectory) into a parent root Cargo workspace. This involves two main tasks:
13+
14+
1. **Adding crate references**: Add all crates from the child workspace to the root workspace's `[workspace.dependencies]` section with proper path references.
15+
16+
2. **Merging workspace dependencies**: Combine the child workspace's `[workspace.dependencies]` with the root's dependencies, ensuring no duplicates and only including dependencies actually used by the crates being merged.
17+
18+
## Step-by-Step Process
19+
20+
### Step 1: Analyze the Child Workspace
21+
- Read the child workspace's `Cargo.toml` (e.g., `./rolldown/Cargo.toml`)
22+
- Identify all workspace members from the `[workspace.members]` section
23+
- Extract all `[workspace.dependencies]` definitions
24+
25+
### Step 2: Identify Crates to Add
26+
- For each workspace member, locate its `Cargo.toml`
27+
- Extract the crate name from `[package].name`
28+
- Build a list of path references in the format: `crate_name = { path = "./child/crates/crate_name" }`
29+
30+
### Step 3: Analyze Dependency Usage
31+
- For each crate in the child workspace, read its `Cargo.toml`
32+
- Collect all dependencies from `[dependencies]`, `[dev-dependencies]`, and `[build-dependencies]`
33+
- Focus on dependencies that reference `workspace = true` - these need the workspace-level definition
34+
- Create a set of actually-used workspace dependencies
35+
36+
### Step 4: Filter and Merge Dependencies
37+
- From the child's `[workspace.dependencies]`, only include those that are actually used by the crates
38+
- Check for conflicts with existing root workspace dependencies:
39+
- Same dependency, same version: Skip (already exists)
40+
- Same dependency, different version: Flag for manual resolution and suggest keeping the newer version
41+
- Exclude dev-only dependencies that aren't needed for the merged crates
42+
43+
### Step 5: Update Root Cargo.toml
44+
- Add all crate path references to `[workspace.dependencies]`
45+
- Add filtered workspace dependencies to `[workspace.dependencies]`
46+
- Maintain alphabetical ordering within sections for cleanliness
47+
- Preserve any existing comments and formatting
48+
49+
## Output Format
50+
51+
Provide:
52+
1. A summary of crates being added
53+
2. A summary of dependencies being merged
54+
3. Any conflicts or issues requiring manual attention
55+
4. The exact additions to make to the root `Cargo.toml`
56+
57+
## Quality Checks
58+
59+
- Verify all paths exist before adding references
60+
- Ensure no duplicate entries are created
61+
- Validate that merged dependencies don't break existing crates
62+
- After modifications, suggest running `cargo check --workspace` to verify the merge
63+
- Use highest compatible semver versions (if not pinned) and merge features in crates
64+
65+
## Important Considerations
66+
67+
- Use `vite_path` types for path operations as per project conventions
68+
- Dependencies with `path` references in the child workspace may need path adjustments
69+
- Feature flags on dependencies must be preserved
70+
- Optional dependencies must maintain their optional status
71+
- If a dependency exists in both workspaces with different features, merge the feature lists
72+
73+
### Workspace Package Inheritance
74+
75+
Child crates may inherit fields from `[workspace.package]` using `field.workspace = true`. Common inherited fields include:
76+
- `homepage`
77+
- `repository`
78+
- `license`
79+
- `edition`
80+
- `authors`
81+
- `rust-version`
82+
83+
**Important**: If the child workspace's `[workspace.package]` defines fields that the root workspace does not, you must add those fields to the root workspace's `[workspace.package]` section. Otherwise, crates that inherit these fields will fail to build with errors like:
84+
```
85+
error inheriting `homepage` from workspace root manifest's `workspace.package.homepage`
86+
Caused by: `workspace.package.homepage` was not defined
87+
```
88+
89+
**Steps to handle this**:
90+
1. Read the child workspace's `[workspace.package]` section
91+
2. Compare with the root workspace's `[workspace.package]` section
92+
3. Add any missing fields to the root workspace (use the root project's own values, not the child's)
93+
94+
## Error Handling
95+
96+
- If a crate path doesn't exist, report it clearly and skip
97+
- If Cargo.toml parsing fails, provide the specific error
98+
- If version conflicts exist, list all conflicts before proceeding and ask for guidance
99+
100+
### Crates with Compile-Time Environment Variables
101+
102+
Some crates use `env!()` macros that require compile-time environment variables set via `.cargo/config.toml`. These crates often have `relative = true` paths that only work when building from their original workspace root.
103+
104+
**Example**: `rolldown_workspace` uses `env!("WORKSPACE_DIR")` which is set in `rolldown/.cargo/config.toml`.
105+
106+
**How to handle**:
107+
1. Check child workspace's `.cargo/config.toml` for `[env]` section
108+
2. If crates use these env vars with `relative = true`, copy those env vars to root `.cargo/config.toml` with paths adjusted to point to the child workspace directory
109+
3. Example: If child has `WORKSPACE_DIR = { value = "", relative = true }`, root should have `WORKSPACE_DIR = { value = "child-dir", relative = true }`

.github/actions/build-upstream/action.yml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,58 @@ inputs:
44
target:
55
description: 'The target platform'
66
required: true
7-
build-rolldown-native:
8-
description: 'Build rolldown native'
9-
required: false
10-
default: 'false'
7+
118
runs:
129
using: 'composite'
1310
steps:
11+
- uses: ./.github/actions/download-rolldown-binaries
12+
with:
13+
github-token: ${{ github.token }}
14+
target: ${{ inputs.target }}
15+
upload: 'false'
16+
- name: Patch Vite
17+
shell: bash
18+
run: sed -i '' '123,124d' rolldown-vite/packages/vite/rolldown.dts.config.ts
1419
- name: Build
1520
shell: bash
1621
if: ${{ inputs.target == 'x86_64-unknown-linux-gnu' }}
1722
run: |
1823
pnpm --filter @rolldown/pluginutils build
19-
if [ "${{ inputs.build-rolldown-native }}" = "true" ] || [ "${{ github.head_ref || github.ref_name }}" = "deps/upstream-update" ]; then
20-
pnpm --filter rolldown build-binding:release --target ${{ inputs.target }} --use-napi-cross
21-
fi
2224
pnpm --filter rolldown build-node
23-
pnpm --filter vite build-types
25+
pnpm --filter vite build-types &
2426
pnpm --filter=@voidzero-dev/vite-plus-core build
2527
pnpm --filter=@voidzero-dev/vite-plus-test build
26-
CC=clang pnpm --filter=@voidzero-dev/vite-plus build --target ${{ inputs.target }} --use-napi-cross
27-
CC=clang pnpm --filter=@voidzero-dev/global build --target ${{ inputs.target }} --use-napi-cross
28+
pnpm --filter=@voidzero-dev/vite-plus build --target ${{ inputs.target }} --use-napi-cross
29+
pnpm --filter=@voidzero-dev/global build --target ${{ inputs.target }} --use-napi-cross
2830
env:
2931
TARGET_CC: clang
32+
DEBUG: napi:*
3033

3134
- name: Build
3235
shell: bash
3336
if: ${{ inputs.target == 'aarch64-unknown-linux-gnu' }}
3437
run: |
3538
pnpm --filter @rolldown/pluginutils build
36-
if [ "${{ inputs.build-rolldown-native }}" = "true" ] || [ "${{ github.head_ref || github.ref_name }}" = "deps/upstream-update" ]; then
37-
pnpm --filter rolldown build-binding:release --target ${{ inputs.target }} --use-napi-cross
38-
fi
3939
pnpm --filter rolldown build-node
40-
pnpm --filter vite build-types
40+
pnpm --filter vite build-types &
4141
pnpm --filter=@voidzero-dev/vite-plus-core build
4242
pnpm --filter=@voidzero-dev/vite-plus-test build
4343
TARGET_CFLAGS="-D_BSD_SOURCE" pnpm --filter=@voidzero-dev/vite-plus build --target ${{ inputs.target }} --use-napi-cross
4444
TARGET_CFLAGS="-D_BSD_SOURCE" pnpm --filter=@voidzero-dev/global build --target ${{ inputs.target }} --use-napi-cross
4545
env:
4646
TARGET_CC: clang
47+
DEBUG: napi:*
4748

4849
- name: Build
4950
shell: bash
5051
if: ${{ !contains(inputs.target, 'linux') }}
5152
run: |
5253
pnpm --filter @rolldown/pluginutils build
53-
if [ "${{ inputs.build-rolldown-native }}" = "true" ] || [ "${{ github.head_ref || github.ref_name }}" = "deps/upstream-update" ]; then
54-
pnpm --filter rolldown build-binding:release --target ${{ inputs.target }}
55-
fi
5654
pnpm --filter rolldown build-node
57-
pnpm --filter vite build-types
55+
pnpm --filter vite build-types &
5856
pnpm --filter=@voidzero-dev/vite-plus-core build
5957
pnpm --filter=@voidzero-dev/vite-plus-test build
6058
pnpm --filter=@voidzero-dev/vite-plus build --target ${{ inputs.target }}
6159
pnpm --filter=@voidzero-dev/global build --target ${{ inputs.target }}
60+
env:
61+
DEBUG: napi:*

.github/actions/download-rolldown-binaries/action.yml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,41 @@ inputs:
55
github-token:
66
description: 'GitHub token for accessing GitHub Package Registry'
77
required: true
8+
target:
9+
description: 'The target platform'
10+
default: 'x86_64-unknown-linux-gnu'
11+
required: false
12+
upload:
13+
description: 'Upload the rolldown binaries as artifact'
14+
required: false
15+
default: 'true'
816

917
runs:
1018
using: 'composite'
1119
steps:
1220
- name: Install previous release
1321
shell: bash
1422
run: |
15-
echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" >> ~/.npmrc
16-
echo "@voidzero-dev:registry=https://npm.pkg.github.com/" >> ~/.npmrc
17-
export VERSION=$(npm view --json @voidzero-dev/vite-plus-core | jq -r '.version')
18-
npm pack "@voidzero-dev/vite-plus-core@${VERSION}"
19-
tar -xzf voidzero-dev-vite-plus-core-${VERSION}.tgz
23+
if ${{ runner.os == 'Windows' }}; then
24+
export TARGET="win32-x64-msvc"
25+
elif ${{ runner.os == 'Linux' }}; then
26+
export TARGET="linux-x64-gnu"
27+
elif ${{ runner.os == 'macOS' }}; then
28+
export TARGET="darwin-arm64"
29+
fi
30+
31+
export VERSION=$(npm view --json rolldown | jq -r '.version')
32+
npm pack "@rolldown/binding-${TARGET}@${VERSION}"
33+
tar -xzf "rolldown-binding-${TARGET}-${VERSION}.tgz"
34+
if [ -d "./rolldown/packages/rolldown/src" ]; then
35+
cp "./package/rolldown-binding.${TARGET}.node" ./rolldown/packages/rolldown/src
36+
ls ./rolldown/packages/rolldown/src
37+
fi
2038
env:
2139
GITHUB_TOKEN: ${{ inputs.github-token }}
2240
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
41+
if: ${{ inputs.upload == 'true' }}
2342
with:
2443
name: rolldown-binaries
25-
path: ./package/dist/rolldown/shared/rolldown-binding.*.node
44+
path: ./package/rolldown-binding.*.node
2645
if-no-files-found: error

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
env:
6868
RUSTFLAGS: '-D warnings --cfg tokio_unstable' # also update .cargo/config.toml
6969

70-
- run: cargo test
70+
- run: cargo test -p vite_command -p vite_install -p vite_migration
7171

7272
lint:
7373
name: Lint
@@ -90,7 +90,7 @@ jobs:
9090
cargo shear
9191
cargo fmt --check
9292
# cargo clippy --all-targets --all-features -- -D warnings
93-
RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --document-private-items
93+
# RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --document-private-items
9494
9595
- uses: crate-ci/typos@85f62a8a84f939ae994ab3763f01a0296d61a7ee # v1.36.2
9696
with:

.github/workflows/release.yml

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ permissions: {}
77

88
env:
99
RELEASE_BUILD: 'true'
10+
DEBUG: 'napi:*'
1011

1112
jobs:
1213
build-rust:
@@ -25,7 +26,6 @@ jobs:
2526
os: ubuntu-latest
2627
- target: x86_64-pc-windows-msvc
2728
os: windows-latest
28-
# - aarch64-pc-windows-msvc
2929
steps:
3030
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3131
- uses: ./.github/actions/clone
@@ -38,10 +38,6 @@ jobs:
3838
- name: Rustup Adds Target
3939
run: rustup target add ${{ matrix.settings.target }}
4040

41-
- name: Rustup Adds Target for rolldown
42-
working-directory: rolldown
43-
run: rustup target add ${{ matrix.settings.target }}
44-
4541
- name: Add musl target (x86_64)
4642
if: ${{ matrix.settings.target == 'x86_64-unknown-linux-gnu' }}
4743
run: rustup target add x86_64-unknown-linux-musl
@@ -50,17 +46,8 @@ jobs:
5046
if: ${{ matrix.settings.target == 'aarch64-unknown-linux-gnu' }}
5147
run: rustup target add aarch64-unknown-linux-musl
5248

53-
- name: Add rolldown host target
54-
if: ${{ matrix.settings.target == 'aarch64-unknown-linux-gnu' }}
55-
working-directory: rolldown
56-
run: rustup target add x86_64-unknown-linux-gnu
57-
5849
- uses: oxc-project/setup-node@fdbf0dfd334c4e6d56ceeb77d91c76339c2a0885 # v1.0.4
5950

60-
- name: Build host rolldown
61-
if: ${{ matrix.settings.target == 'aarch64-unknown-linux-gnu' }}
62-
run: pnpm --filter rolldown build-binding:release --target x86_64-unknown-linux-gnu
63-
6451
- name: Set binding version
6552
run: |
6653
pnpm exec tool replace-file-content packages/cli/binding/Cargo.toml 'version = "0.0.0"' 'version = "0.0.0-${{ github.sha }}"'
@@ -73,9 +60,8 @@ jobs:
7360
uses: ./.github/actions/build-upstream
7461
with:
7562
target: ${{ matrix.settings.target }}
76-
build-rolldown-native: 'true'
7763

78-
- name: Upload Vite+ cli binding artifact
64+
- name: Upload Vite+ native artifact
7965
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
8066
with:
8167
name: vite-plus-native-${{ matrix.settings.target }}
@@ -89,13 +75,6 @@ jobs:
8975
path: ./packages/global/binding/*.node
9076
if-no-files-found: error
9177

92-
- name: Upload rolldown artifact
93-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
94-
with:
95-
name: rolldown-native-${{ matrix.settings.target }}
96-
path: ./rolldown/packages/rolldown/src/*.node
97-
if-no-files-found: error
98-
9978
- name: Remove .node files before upload dist
10079
if: ${{ matrix.settings.target == 'x86_64-unknown-linux-gnu' }}
10180
run: |
@@ -150,9 +129,8 @@ jobs:
150129
- name: Download cli binding
151130
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
152131
with:
153-
path: packages/cli/binding
132+
path: packages/cli/artifacts
154133
pattern: vite-plus-native-*
155-
merge-multiple: true
156134

157135
- name: Download core dist
158136
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
@@ -161,18 +139,11 @@ jobs:
161139
pattern: core
162140
merge-multiple: true
163141

164-
- name: Download rolldown native
165-
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
166-
with:
167-
path: packages/core/dist/rolldown/shared
168-
pattern: rolldown-native-*
169-
merge-multiple: true
170-
171-
- name: Download rolldown native
172-
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
142+
- uses: ./.github/actions/download-rolldown-binaries
173143
with:
174-
path: rolldown/packages/rolldown/src
175-
name: rolldown-native-x86_64-unknown-linux-gnu
144+
github-token: ${{ github.token }}
145+
target: x86_64-unknown-linux-gnu
146+
upload: 'false'
176147

177148
- name: Download global dist
178149
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
@@ -208,6 +179,13 @@ jobs:
208179

209180
- run: npm install -g npm@latest # For trusted publishing support
210181

182+
- name: Publish native addons
183+
run: |
184+
echo '@voidzero-dev:registry=https://npm.pkg.github.com/' >> ~/.npmrc
185+
pnpm --filter=@voidzero-dev/vite-plus publish-native
186+
env:
187+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
188+
211189
- name: Publish
212190
run: |
213191
pnpm publish --filter=./packages/core --registry https://npm.pkg.github.com --no-git-checks

.github/workflows/upgrade-deps.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ jobs:
5252
uses: ./.github/actions/build-upstream
5353
with:
5454
target: x86_64-unknown-linux-gnu
55-
build-rolldown-native: 'true'
5655

5756
- name: Update lockfile
5857
run: |

0 commit comments

Comments
 (0)