@crossbind/plugin-rollup 2.0.0-beta.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md ADDED
@@ -0,0 +1,57 @@
1
+ # AGENTS.md — @crossbind/plugin-rollup
2
+
3
+ > Standalone Rollup plugin **and** the inner kernel of `@crossbind/plugin-vite`. Bundler-agnostic logic lives here; bundler-specific glue (Vite dev server, etc.) lives one level up.
4
+
5
+ ## What lives here
6
+
7
+ - `index.js` — single file, exports `rollupCrossbindPlugin(options, bridges)` factory. The `bridges` array is shared by the Vite outer plugin so both can append to one accumulating list per project.
8
+
9
+ ## Hooks the plugin implements
10
+
11
+ | Rollup hook | What it does |
12
+ |-------------|--------------|
13
+ | `resolveId('crossbind')` | Mark the crossbind loader as `external: true` so consumers fetch it at runtime, not bundle it |
14
+ | `transform(code, '.h')` | Run SWIG bridge generation; emit JS bridge code for the header |
15
+ | `buildStart` | Iterate `state.config.paths.native` array; `addWatchFile` every entry. Watch mode now sees `.cpp`/`.h` edits |
16
+ | `generateBundle` | Run `createLib + createXCFramework + buildWasm` with `force = isSourceNewer(...)`; emit `crossbind.js`, `crossbind.wasm`, `crossbind.data.txt` as bundle assets |
17
+
18
+ ## Invariants
19
+
20
+ - **`paths.native` is an array.** The outer Vite plugin assumed this years ago; this plugin must too. `existsSync(array)` returns false silently — always iterate entries before testing each one.
21
+ - **`force = isSourceNewer(buildTargetRelease)`** in `generateBundle`. Skips rebuild when artifacts are newer than every native source; bypasses cache when not.
22
+ - **`bridges` accumulates across `transform` calls.** Don't reset; downstream `generateBundle` reads the union.
23
+
24
+ ## Common pitfalls
25
+
26
+ - **Forgetting to call `addWatchFile` per native dir.** Watch mode silently skips edits → users think `pnpm rollup -w` is broken.
27
+ - **Returning `external: true` for `crossbind` in some configs and `false` in others.** Inconsistency makes Vite's HMR vs prod build behave differently.
28
+ - **Emitting `crossbind.js`/`crossbind.wasm` to a custom path.** Consumers (including Vite) expect `crossbind.js`, `crossbind.wasm`, `crossbind.data.txt` at the bundle root. Don't rename without updating the loader.
29
+ - **Re-running `buildWasm` without `force` semantics.** Cache-shortcut bugs land here; always go through `isSourceNewer`.
30
+ - **Calling `state.config.paths.cli/...` directly with hardcoded sub-paths.** Use the public `crossbind` exports (`createLib`, `buildWasm`, `getCrossbindScript`, …); they survive asset reorgs.
31
+
32
+ ## Validation
33
+
34
+ Touching this plugin propagates to:
35
+
36
+ - `plugins/vite` (wraps it) — all Vite samples must keep working.
37
+ - Anyone using rollup standalone (rare).
38
+
39
+ Strict gate:
40
+
41
+ ```bash
42
+ pnpm run ci:linux:build && pnpm run e2e:dev && pnpm run e2e:prod
43
+ ```
44
+
45
+ Targeted Vite smoke (since this plugin's biggest consumer is `plugin-vite`):
46
+
47
+ ```bash
48
+ pnpm --filter=@crossbind/example-web-vue-vite run build
49
+ pnpm --filter=@crossbind/e2e-web-vite-multithread run build
50
+ ```
51
+
52
+ ## Reference
53
+
54
+ - Outer Vite wrapper: `plugins/vite/`
55
+ - Standalone integration recipe: `docs/playbooks/integration/rollup.md`
56
+ - Vite integration recipe: `docs/playbooks/integration/vite.md`
57
+ - Force-rebuild trigger: `core/crossbind/src/actions/isSourceNewer.js`
package/CHANGELOG.md ADDED
@@ -0,0 +1,35 @@
1
+ # @crossbind/plugin-rollup
2
+
3
+ ## 2.0.0-beta.50
4
+
5
+ ### Patch Changes
6
+
7
+ - A cargo dependency no longer has to be built by hand before the app. The dependency step this
8
+ plugin already awaits builds one whose target is missing, and refuses to link one it could not
9
+ build — on wasm that case used to pass silently and leave a module that died at init.
10
+
11
+ ## 1.0.2
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+ - crossbind@1.0.4
17
+
18
+ ## 1.0.0
19
+
20
+ ### Major Changes
21
+
22
+ - 🚀 first stable release
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies
27
+ - crossbind@1.0.0
28
+
29
+ ## 1.0.0-beta.9
30
+
31
+ ### Patch Changes
32
+
33
+ - chore: add initial version of CHANGELOGS files
34
+ - Updated dependencies
35
+ - crossbind@1.0.0-beta.33
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Buğra Sarı and crossbind contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @crossbind/plugin-rollup
2
+ **crossbind Rollup plugin**
3
+ A tool for seamless C++ integration with the Rollup bundler.
4
+
5
+ <a href="https://www.npmjs.com/package/@crossbind/plugin-rollup">
6
+ <img alt="NPM version" src="https://img.shields.io/npm/v/@crossbind/plugin-rollup?style=for-the-badge" />
7
+ </a>
8
+ <a href="https://github.com/crossbind/crossbind/blob/main/LICENSE">
9
+ <img alt="License" src="https://img.shields.io/github/license/crossbind/crossbind?style=for-the-badge" />
10
+ </a>
11
+ <a href="https://crossbind.dev/docs/guide/integrate-into-existing-project/rollup">
12
+ <img alt="Docs - React Native" src="https://img.shields.io/badge/Docs_-_Rollup-20B2AA?style=for-the-badge" />
13
+ </a>
14
+
15
+ ## Integration
16
+ To integrate crossbind into your project using Rollup as a bundler, you can utilize the @crossbind/plugin-rollup plugin. Start by installing these package with the following command:
17
+
18
+ ```sh
19
+ npm install @crossbind/plugin-rollup --save-dev
20
+ ```
21
+
22
+ To enable the plugin, modify the `vite.config.js` file as shown below.
23
+
24
+ ```diff
25
+ import { defineConfig } from 'vite'
26
+ import vue from '@vitejs/plugin-vue'
27
+ + import rollupCrossbindPlugin from '@crossbind/plugin-rollup'
28
+
29
+ // https://vitejs.dev/config/
30
+ export default defineConfig({
31
+ plugins: [
32
+ + rollupCrossbindPlugin(),
33
+ ]
34
+ });
35
+ ```
package/index.js ADDED
@@ -0,0 +1,121 @@
1
+
2
+
3
+ import {
4
+ state, createLib, createBridgeFile, buildWasm, getCrossbindScript, getRustJsScript, buildDependencies,
5
+ getDependFilePath, getTargetParams, getFilteredBuildTargets, isSourceNewer,
6
+ } from 'crossbind';
7
+
8
+ import fs from 'node:fs';
9
+ import p from 'node:path';
10
+
11
+ const targetParams = getTargetParams({ platform: ['wasm'], arch: ['wasm32'], runtime: ['st'], runtimeEnv: ['browser'] }, true);
12
+ let buildTargetRelease = getFilteredBuildTargets(targetParams, { buildType: 'release' })?.[0];
13
+ let buildTargetDebug = getFilteredBuildTargets(targetParams, { buildType: 'debug' })?.[0];
14
+
15
+ if (!buildTargetRelease && !buildTargetDebug) {
16
+ throw new Error('No build targets found');
17
+ }
18
+
19
+ if (!buildTargetRelease) {
20
+ buildTargetRelease = buildTargetDebug;
21
+ }
22
+
23
+ const rollupCrossbindPlugin = (options, bridges = []) => {
24
+ const headerRegex = new RegExp(`\\.(${state.config.ext.header.join('|')})$`);
25
+ const moduleRegex = new RegExp(`\\.(${state.config.ext.module.join('|')})$`);
26
+
27
+ return {
28
+ name: 'rollup-plugin-crossbind',
29
+ resolveId(source) {
30
+ if (source === '/crossbind.js') {
31
+ return { id: source, external: true };
32
+ }
33
+ const dependFilePath = getDependFilePath(source, buildTargetRelease);
34
+ if (dependFilePath) {
35
+ return dependFilePath;
36
+ }
37
+
38
+ return null;
39
+ },
40
+ async transform(code, path) {
41
+ // Rust surfaces need no bridge file here: the native bridge is the package's
42
+ // generated companion crate (or the app-local synthesized crate); this only emits
43
+ // the JS proxy module - the same shape as the .h flow.
44
+ if (path.endsWith('.rs')) {
45
+ return getRustJsScript(buildTargetRelease, path);
46
+ }
47
+ if (!headerRegex.test(path) && !moduleRegex.test(path)) {
48
+ return null;
49
+ }
50
+
51
+ const bridgeFile = createBridgeFile(path);
52
+ bridges.push(bridgeFile);
53
+
54
+ return getCrossbindScript(buildTargetRelease, bridgeFile);
55
+ },
56
+ buildStart() {
57
+ const watch = (dirs) => {
58
+ dirs.forEach((dir) => {
59
+ const filesToWatch = fs.readdirSync(dir);
60
+
61
+ for (const file of filesToWatch) {
62
+ const fullPath = p.join(dir, file);
63
+ const stats = fs.statSync(fullPath);
64
+
65
+ if (stats.isFile()) {
66
+ this.addWatchFile(fullPath);
67
+ } else if (stats.isDirectory()) {
68
+ watch([fullPath]);
69
+ }
70
+ }
71
+ });
72
+ };
73
+
74
+ state.config.paths.native.forEach((dir) => {
75
+ if (fs.existsSync(dir)) {
76
+ watch([dir]);
77
+ }
78
+ });
79
+ },
80
+ async generateBundle() {
81
+ await buildDependencies({ targetParams: { ...targetParams, buildType: [buildTargetRelease.buildType] } });
82
+ const force = isSourceNewer(buildTargetRelease);
83
+ const sourceBuilt = createLib(buildTargetRelease, 'Source', { force, buildSource: true });
84
+ // Bridge cache is keyed on the nativeGlob fingerprint: adding or
85
+ // removing a .h import rebuilds the bridge lib even when no source
86
+ // file changed, and a rebuilt lib must force the final link too.
87
+ const bridgeBuilt = createLib(buildTargetRelease, 'Bridge', { force, buildSource: false, nativeGlob: [`${state.config.paths.cli}/assets/cpp-runtime/commonBridges.cpp`, ...bridges] });
88
+ await buildWasm(buildTargetRelease, { force: force || Boolean(sourceBuilt) || Boolean(bridgeBuilt) });
89
+
90
+ this.emitFile({
91
+ type: 'asset',
92
+ source: fs.readFileSync(`${state.config.paths.build}/${buildTargetRelease.jsName}`),
93
+ fileName: 'crossbind.js',
94
+ });
95
+
96
+ this.emitFile({
97
+ type: 'asset',
98
+ source: fs.readFileSync(`${state.config.paths.build}/${buildTargetRelease.wasmName}`),
99
+ fileName: 'crossbind.wasm',
100
+ });
101
+ const dataFilePath = `${state.config.paths.build}/${buildTargetRelease.dataTxtName}`;
102
+ if (fs.existsSync(dataFilePath)) {
103
+ this.emitFile({
104
+ type: 'asset',
105
+ source: fs.readFileSync(dataFilePath),
106
+ fileName: 'crossbind.data.txt',
107
+ });
108
+ }
109
+ /* const workerFilePath = `${state.config.paths.build}/${state.config.general.name}.js`;
110
+ if (fs.existsSync(workerFilePath)) {
111
+ this.emitFile({
112
+ type: 'asset',
113
+ source: fs.readFileSync(workerFilePath),
114
+ fileName: `cpp.worker.js`,
115
+ });
116
+ } */
117
+ },
118
+ };
119
+ };
120
+
121
+ export default rollupCrossbindPlugin;
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@crossbind/plugin-rollup",
3
+ "version": "2.0.0-beta.50",
4
+ "description": "crossbind Rollup plugin: A tool for seamless C++ integration with the Rollup bundler.",
5
+ "homepage": "https://github.com/crossbind/crossbind/tree/main/plugins/rollup#readme",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/crossbind/crossbind.git"
9
+ },
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "main": "index.js",
13
+ "dependencies": {
14
+ "crossbind": "^2.0.0-beta.50",
15
+ "@crossbind/core-embind-rust": "^2.0.0-beta.50"
16
+ },
17
+ "peerDependencies": {
18
+ "rollup": ">=4.62.4"
19
+ },
20
+ "keywords": [
21
+ "crossbind-plugin",
22
+ "rollup",
23
+ "bind",
24
+ "c++"
25
+ ]
26
+ }