@crossbind/plugin-rollup 2.0.0-beta.64 → 2.0.0-beta.65
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 +2 -0
- package/index.js +40 -6
- package/package.json +3 -3
package/AGENTS.md
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
| `buildStart` | Iterate `state.config.paths.native` array; `addWatchFile` every entry. Watch mode now sees `.cpp`/`.h` edits |
|
|
16
16
|
| `generateBundle` | Run `createLib + createXCFramework + buildWasm` with `force = isSourceNewer(...)`; emit `crossbind.js`, `crossbind.wasm`, `crossbind.data.txt` as bundle assets |
|
|
17
17
|
|
|
18
|
+
In app mode (`target.runtimeEnv: 'app'`, macOS, Linux, Windows, iOS and Android for now) `generateBundle` builds the app host for this machine with `buildProjectApp` instead, or with `CROSSBIND_APP_PLATFORM`, which `crossbind app -p` sets, one for each iOS SDK, Android ABI or Linux or Windows arch (`appTargetParams`), and emits its page runtime as `crossbind.js`; `writeBundle` then puts the written page into each app beside it with `publishApp`: `<name>.app`, `<name>-linux-<arch>/`, `<name>-win32-<arch>/`, the Xcode project `<name>-ios/` or the Gradle project `<name>-android/` and its APK. See `docs/api/app.md`.
|
|
19
|
+
|
|
18
20
|
## Invariants
|
|
19
21
|
|
|
20
22
|
- **`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.
|
package/index.js
CHANGED
|
@@ -2,16 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
state, createLib, createBridgeFile, buildWasm, getCrossbindScript, getRustJsScript, buildDependencies,
|
|
5
|
-
getDependFilePath, getTargetParams, getFilteredBuildTargets, isSourceNewer, appSourceFiles,
|
|
5
|
+
getDependFilePath, getTargetParams, getFilteredBuildTargets, isSourceNewer, appSourceFiles, buildProjectApp, publishApp,
|
|
6
|
+
appOutputName, appTargetParams,
|
|
6
7
|
} from 'crossbind';
|
|
7
8
|
|
|
8
9
|
import fs from 'node:fs';
|
|
9
10
|
import p from 'node:path';
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
// An app's page reaches the module in the host the app runs, so its build makes the host, not wasm: this machine's, or
|
|
13
|
+
// with CROSSBIND_APP_PLATFORM one per iOS SDK, Android ABI or Linux or Windows arch.
|
|
14
|
+
const isApp = state.config.target.runtimeEnv === 'app';
|
|
15
|
+
const targetParams = isApp
|
|
16
|
+
? appTargetParams()
|
|
17
|
+
: getTargetParams({ platform: ['wasm'], arch: ['wasm32'], runtime: ['st'], runtimeEnv: ['browser'] }, true);
|
|
18
|
+
// iOS and Android keep targets without a runtime environment for React Native, which every filter of runtimeEnv lets
|
|
19
|
+
// through.
|
|
20
|
+
const appOnly = isApp ? { runtimeEnv: 'app' } : {};
|
|
21
|
+
let buildTargetRelease = getFilteredBuildTargets(targetParams, { buildType: 'release', ...appOnly })?.[0];
|
|
22
|
+
let buildTargetDebug = getFilteredBuildTargets(targetParams, { buildType: 'debug', ...appOnly })?.[0];
|
|
23
|
+
const appTargets = isApp ? getFilteredBuildTargets(targetParams, { buildType: 'release', ...appOnly }) : [];
|
|
24
|
+
|
|
25
|
+
if (isApp && !buildTargetRelease) {
|
|
26
|
+
throw new Error(`crossbind: desktop apps build on macOS, Linux and Windows so far, and this machine runs ${process.platform}-${process.arch}.`);
|
|
27
|
+
}
|
|
15
28
|
if (!buildTargetRelease && !buildTargetDebug) {
|
|
16
29
|
throw new Error('No build targets found');
|
|
17
30
|
}
|
|
@@ -25,11 +38,13 @@ const rollupCrossbindPlugin = (options, bridges = []) => {
|
|
|
25
38
|
const moduleRegex = new RegExp(`\\.(${state.config.ext.module.join('|')})$`);
|
|
26
39
|
// Vite gives the base it serves the app from; plain Rollup has none.
|
|
27
40
|
let base = '/';
|
|
41
|
+
let isServe = false;
|
|
28
42
|
|
|
29
43
|
return {
|
|
30
44
|
name: 'rollup-plugin-crossbind',
|
|
31
45
|
configResolved(config) {
|
|
32
46
|
base = config.base;
|
|
47
|
+
isServe = config.command === 'serve';
|
|
33
48
|
},
|
|
34
49
|
resolveId(source) {
|
|
35
50
|
if (source === '/crossbind.js') {
|
|
@@ -57,7 +72,9 @@ const rollupCrossbindPlugin = (options, bridges = []) => {
|
|
|
57
72
|
// A header transforms again after each source edit; a repeated entry would change the bridge lib's fingerprint.
|
|
58
73
|
if (!bridges.includes(bridgeFile)) bridges.push(bridgeFile);
|
|
59
74
|
// The names the app imports decide what a header binds, so watch mode transforms it again after any source edit.
|
|
60
|
-
|
|
75
|
+
// Vite's dev server rebinds them itself: there, Vite would take the sources for imports of the header and, the
|
|
76
|
+
// page importing the header, update nothing after an edit to the page.
|
|
77
|
+
if (!isServe) appSourceFiles(state.config.paths.project).forEach((file) => this.addWatchFile(file));
|
|
61
78
|
|
|
62
79
|
return getCrossbindScript(buildTargetRelease, bridgeFile, { base });
|
|
63
80
|
},
|
|
@@ -89,6 +106,15 @@ const rollupCrossbindPlugin = (options, bridges = []) => {
|
|
|
89
106
|
});
|
|
90
107
|
},
|
|
91
108
|
async generateBundle() {
|
|
109
|
+
if (isApp) {
|
|
110
|
+
for (const target of appTargets) await buildProjectApp(target);
|
|
111
|
+
this.emitFile({
|
|
112
|
+
type: 'asset',
|
|
113
|
+
source: fs.readFileSync(`${state.config.paths.build}/${buildTargetRelease.appJsName}`),
|
|
114
|
+
fileName: 'crossbind.js',
|
|
115
|
+
});
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
92
118
|
const force = isSourceNewer(buildTargetRelease);
|
|
93
119
|
const sourceBuilt = createLib(buildTargetRelease, 'Source', { force, buildSource: true });
|
|
94
120
|
// Bridge cache is keyed on the nativeGlob fingerprint: adding or
|
|
@@ -125,6 +151,14 @@ const rollupCrossbindPlugin = (options, bridges = []) => {
|
|
|
125
151
|
});
|
|
126
152
|
} */
|
|
127
153
|
},
|
|
154
|
+
// The page, once written, goes into the app beside it: one project of every SDK or ABI for iOS and Android, one
|
|
155
|
+
// app per arch for a desktop.
|
|
156
|
+
writeBundle(outputOptions) {
|
|
157
|
+
if (!isApp) return;
|
|
158
|
+
const dir = outputOptions.dir ?? p.dirname(outputOptions.file);
|
|
159
|
+
const apps = ['ios', 'android'].includes(buildTargetRelease.platform) ? [buildTargetRelease] : appTargets;
|
|
160
|
+
apps.forEach((target) => publishApp(target, { to: `${dir}/${appOutputName(target)}`, page: dir }));
|
|
161
|
+
},
|
|
128
162
|
};
|
|
129
163
|
};
|
|
130
164
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crossbind/plugin-rollup",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.65",
|
|
4
4
|
"description": "crossbind Rollup plugin: A tool for seamless C++ integration with the Rollup bundler.",
|
|
5
5
|
"homepage": "https://github.com/crossbind/crossbind/tree/main/plugins/rollup#readme",
|
|
6
6
|
"repository": {
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"type": "module",
|
|
12
12
|
"main": "index.js",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"crossbind": "^2.0.0-beta.
|
|
15
|
-
"@crossbind/core-embind-rust": "^2.0.0-beta.
|
|
14
|
+
"crossbind": "^2.0.0-beta.65",
|
|
15
|
+
"@crossbind/core-embind-rust": "^2.0.0-beta.65"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"rollup": ">=2.0.0"
|