Skip to content

Commit 3ba1900

Browse files
committed
feat(cpp.js): export.bundle flag to skip wasm bundle emit
New `export.bundle` boolean (default `true`) lets a package opt out of the final emcc link step. When `false`, the WASM target still produces its `.a` archives (consumed by other packages or by native iOS/Android builds via xcframework / .so) but the `.wasm` + `.js` glue and the Bridge-stage compile are skipped entirely. Useful for: - mobile-only apps that consume cpp.js via iOS/Android pipelines - library packages whose WASM output exists only to be linked into a downstream app's bundle Guarded in three layers: - `createWasmJs` (bin.js): short-circuits the whole WASM pipeline before bridge discovery / Bridge compile / emcc / copy - `buildWasm` (action): defence-in-depth for callers that bypass the CLI (rollup/vite plugins) - `loadConfig`: default `true`, `??` not `||` so explicit `false` survives Has no effect on iOS/Android pipelines, which never produce a bundle. Bumps cpp.js to beta.18.
1 parent 953c34e commit 3ba1900

4 files changed

Lines changed: 12 additions & 1 deletion

File tree

cppjs-core/cpp.js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cpp.js",
3-
"version": "2.0.0-beta.17",
3+
"version": "2.0.0-beta.18",
44
"license": "MIT",
55
"homepage": "https://cpp.js.org",
66
"repository": "https://github.com/bugra9/cpp.js.git",

cppjs-core/cpp.js/src/actions/buildWasm.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ export default async function buildWasm(target, options = {}) {
1212
const isProd = target.buildType === 'release';
1313
const buildType = isProd ? 'Release' : 'Debug';
1414

15+
// Caller can opt out of the final emcc link entirely (e.g. when the
16+
// package is consumed only as a static library by downstream builds).
17+
if (state.config.export.bundle === false) {
18+
logger.info(`[${target.path}] wasm+js skipped (export.bundle = false)`);
19+
return;
20+
}
21+
1522
if (!options.force && fs.existsSync(`${state.config.paths.build}/${target.jsName}`) && fs.existsSync(`${state.config.paths.build}/${target.wasmName}`)) {
1623
logger.cachedStep(target, 'wasm+js');
1724
return;

cppjs-core/cpp.js/src/bin.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ function buildLib(targetParams) {
325325
}
326326

327327
async function createWasmJs(targetParams) {
328+
if (state.config.export.bundle === false) {
329+
return;
330+
}
328331
const targets = getFilteredBuildTargets(targetParams, { platform: 'wasm' });
329332
if (targets.length === 0) {
330333
return;

cppjs-core/cpp.js/src/state/loadConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ function getFilledConfig(config, options = { isDepend: false }) {
9090
newConfig.export.libPath = getPath(newConfig.export.libPath || 'lib');
9191
newConfig.export.libName = newConfig.export.libName || [newConfig.general.name];
9292
newConfig.export.binHeaders = newConfig.export.binHeaders || [];
93+
newConfig.export.bundle = newConfig.export.bundle ?? true;
9394

9495
newConfig.allDependencies = (() => {
9596
const output = {};

0 commit comments

Comments
 (0)