Skip to content

Commit f90a9f2

Browse files
committed
build(core): split native packages publishing
1 parent 4240153 commit f90a9f2

33 files changed

Lines changed: 3884 additions & 904 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: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ 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'
1416
- name: Build
1517
shell: bash
1618
if: ${{ inputs.target == 'x86_64-unknown-linux-gnu' }}
1719
run: |
1820
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
2221
pnpm --filter rolldown build-node
2322
pnpm --filter vite build-types
2423
pnpm --filter=@voidzero-dev/vite-plus-core build
@@ -33,9 +32,6 @@ runs:
3332
if: ${{ inputs.target == 'aarch64-unknown-linux-gnu' }}
3433
run: |
3534
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
3935
pnpm --filter rolldown build-node
4036
pnpm --filter vite build-types
4137
pnpm --filter=@voidzero-dev/vite-plus-core build
@@ -50,9 +46,6 @@ runs:
5046
if: ${{ !contains(inputs.target, 'linux') }}
5147
run: |
5248
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
5649
pnpm --filter rolldown build-node
5750
pnpm --filter vite build-types
5851
pnpm --filter=@voidzero-dev/vite-plus-core build

.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: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ jobs:
2525
os: ubuntu-latest
2626
- target: x86_64-pc-windows-msvc
2727
os: windows-latest
28-
# - aarch64-pc-windows-msvc
2928
steps:
3029
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3130
- uses: ./.github/actions/clone
@@ -38,10 +37,6 @@ jobs:
3837
- name: Rustup Adds Target
3938
run: rustup target add ${{ matrix.settings.target }}
4039

41-
- name: Rustup Adds Target for rolldown
42-
working-directory: rolldown
43-
run: rustup target add ${{ matrix.settings.target }}
44-
4540
- name: Add musl target (x86_64)
4641
if: ${{ matrix.settings.target == 'x86_64-unknown-linux-gnu' }}
4742
run: rustup target add x86_64-unknown-linux-musl
@@ -50,17 +45,8 @@ jobs:
5045
if: ${{ matrix.settings.target == 'aarch64-unknown-linux-gnu' }}
5146
run: rustup target add aarch64-unknown-linux-musl
5247

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-
5848
- uses: oxc-project/setup-node@fdbf0dfd334c4e6d56ceeb77d91c76339c2a0885 # v1.0.4
5949

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-
6450
- name: Set binding version
6551
run: |
6652
pnpm exec tool replace-file-content packages/cli/binding/Cargo.toml 'version = "0.0.0"' 'version = "0.0.0-${{ github.sha }}"'
@@ -73,9 +59,8 @@ jobs:
7359
uses: ./.github/actions/build-upstream
7460
with:
7561
target: ${{ matrix.settings.target }}
76-
build-rolldown-native: 'true'
7762

78-
- name: Upload Vite+ cli binding artifact
63+
- name: Upload Vite+ native artifact
7964
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
8065
with:
8166
name: vite-plus-native-${{ matrix.settings.target }}
@@ -89,13 +74,6 @@ jobs:
8974
path: ./packages/global/binding/*.node
9075
if-no-files-found: error
9176

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-
9977
- name: Remove .node files before upload dist
10078
if: ${{ matrix.settings.target == 'x86_64-unknown-linux-gnu' }}
10179
run: |
@@ -150,9 +128,8 @@ jobs:
150128
- name: Download cli binding
151129
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
152130
with:
153-
path: packages/cli/binding
131+
path: packages/cli/artifacts
154132
pattern: vite-plus-native-*
155-
merge-multiple: true
156133

157134
- name: Download core dist
158135
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
@@ -161,18 +138,11 @@ jobs:
161138
pattern: core
162139
merge-multiple: true
163140

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
141+
- uses: ./.github/actions/download-rolldown-binaries
173142
with:
174-
path: rolldown/packages/rolldown/src
175-
name: rolldown-native-x86_64-unknown-linux-gnu
143+
github-token: ${{ github.token }}
144+
target: x86_64-unknown-linux-gnu
145+
upload: 'false'
176146

177147
- name: Download global dist
178148
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
@@ -208,6 +178,9 @@ jobs:
208178

209179
- run: npm install -g npm@latest # For trusted publishing support
210180

181+
- name: Publish native addons
182+
run: pnpm --filter=@voidzero-dev/vite-plus publish-native-addons
183+
211184
- name: Publish
212185
run: |
213186
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)