Skip to content
Open

v2 #53

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 10 additions & 2 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ on:
branches:
- main
paths:
- packages/**
- cppjs-core/**
- cppjs-extensions/**
- cppjs-packages/**
- cppjs-plugins/**
- cppjs-samples/**
- .github/workflows/build-linux.yml
pull_request:
branches:
- main
paths:
- packages/**
- cppjs-core/**
- cppjs-extensions/**
- cppjs-packages/**
- cppjs-plugins/**
- cppjs-samples/**
- .github/workflows/build-linux.yml

permissions: {}
Expand Down
18 changes: 11 additions & 7 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ on:
branches:
- main
paths:
- packages/**
- cppjs-core/**
- cppjs-extensions/**
- cppjs-packages/**
- cppjs-plugins/**
- cppjs-samples/**
- .github/workflows/build-macos.yml
pull_request:
branches:
- main
paths:
- packages/cpp.js/**
- packages/cppjs-plugin-*/**
- packages/cppjs-sample-lib-*/**
- packages/cppjs-sample-web-*/**
- packages/cppjs-sample-backend-*/**
- packages/cppjs-sample-cloud-*/**
- cppjs-core/cpp.js/**
- cppjs-plugins/**
- cppjs-samples/cppjs-sample-lib-*/**
- cppjs-samples/cppjs-sample-web-*/**
- cppjs-samples/cppjs-sample-backend-*/**
- cppjs-samples/cppjs-sample-cloud-*/**
- .github/workflows/build-macos.yml

permissions: {}
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ on:
branches:
- main
paths:
- packages/**
- cppjs-core/**
- cppjs-extensions/**
- cppjs-packages/**
- cppjs-plugins/**
- cppjs-samples/**
- .github/workflows/build-windows.yml
pull_request:
branches:
- main
paths:
- packages/cpp.js/**
- packages/cppjs-plugin-*/**
- cppjs-core/cpp.js/**
- cppjs-plugins/**
- .github/workflows/build-windows.yml

permissions: {}
Expand Down
32 changes: 18 additions & 14 deletions .github/workflows/test-android-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ on:
branches:
- main
paths:
- packages/**
- cppjs-core/**
- cppjs-extensions/**
- cppjs-packages/**
- cppjs-plugins/**
- cppjs-samples/**
- .github/workflows/test-android-sample.yml
pull_request:
branches:
- main
paths:
- packages/cpp.js/**
- packages/cppjs-plugin-metro/**
- packages/cppjs-plugin-react-native/**
- packages/cppjs-sample-lib-prebuilt-matrix/**
- packages/cppjs-sample-mobile-reactnative-cli/**
- cppjs-core/cpp.js/**
- cppjs-plugins/cppjs-plugin-metro/**
- cppjs-plugins/cppjs-plugin-react-native/**
- cppjs-samples/cppjs-sample-lib-prebuilt-matrix/**
- cppjs-samples/cppjs-sample-mobile-reactnative-cli/**
- .github/workflows/test-android-sample.yml

permissions: {}
Expand Down Expand Up @@ -52,25 +56,25 @@ jobs:
- name: Gradle cache
uses: gradle/actions/setup-gradle@0bdd871935719febd78681f197cd39af5b6e16a6 #v4
- name: create AVD
uses: reactivecircus/android-emulator-runner@62dbb605bba737720e10b196cb4220d374026a6d #v2
uses: reactivecircus/android-emulator-runner@b530d96654c385303d652368551fb075bc2f0b6b #v2
with:
api-level: 30
target: google_apis
api-level: 35
target: default
arch: x86_64
cmake: 3.31.1
ndk: 26.1.10909125
ndk: 27.3.13750724
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."
- name: E2E Android
uses: reactivecircus/android-emulator-runner@62dbb605bba737720e10b196cb4220d374026a6d #v2
uses: reactivecircus/android-emulator-runner@b530d96654c385303d652368551fb075bc2f0b6b #v2
with:
api-level: 30
target: google_apis
api-level: 35
target: default
arch: x86_64
cmake: 3.31.1
ndk: 26.1.10909125
ndk: 27.3.13750724
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
Expand Down
22 changes: 13 additions & 9 deletions .github/workflows/test-ios-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ on:
branches:
- main
paths:
- packages/**
- cppjs-core/**
- cppjs-extensions/**
- cppjs-packages/**
- cppjs-plugins/**
- cppjs-samples/**
- .github/workflows/test-ios-sample.yml
pull_request:
branches:
- main
paths:
- packages/cpp.js/**
- packages/cppjs-plugin-metro/**
- packages/cppjs-plugin-react-native/**
- packages/cppjs-plugin-react-native-ios-helper/**
- packages/cppjs-sample-lib-prebuilt-matrix/**
- packages/cppjs-sample-mobile-reactnative-cli/**
- cppjs-core/cpp.js/**
- cppjs-plugins/cppjs-plugin-metro/**
- cppjs-plugins/cppjs-plugin-react-native/**
- cppjs-plugins/cppjs-plugin-react-native-ios-helper/**
- cppjs-samples/cppjs-sample-lib-prebuilt-matrix/**
- cppjs-samples/cppjs-sample-mobile-reactnative-cli/**
- .github/workflows/test-ios-sample.yml

permissions: {}
Expand Down Expand Up @@ -70,10 +74,10 @@ jobs:
curl -fsSL "https://get.maestro.mobile.dev" | bash
echo "$HOME/.maestro/bin" >> $GITHUB_PATH
- name: Restore cached bridge files
run: cp -r ./packages/cppjs-sample-mobile-reactnative-cli/ci/.cppjs ./packages/cppjs-sample-mobile-reactnative-cli
run: cp -r ./cppjs-samples/cppjs-sample-mobile-reactnative-cli/ci/.cppjs ./cppjs-samples/cppjs-sample-mobile-reactnative-cli
- name: Build cppjs-sample-lib-prebuilt-matrix
run: pnpm --filter=@cpp.js/sample-lib-prebuilt-matrix run build:ios
- name: Pod install
run: cd packages/cppjs-sample-mobile-reactnative-cli/ios && pod install && cd ../../../
run: cd cppjs-samples/cppjs-sample-mobile-reactnative-cli/ios && pod install && cd ../../../
- name: E2E IOS
run: pnpm run e2e:ios
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const nodeLibs = {
buffer: 'export default {};',
crypto: 'export default {};',
stream: 'export default {};',
ws: 'export default {};',
};

const options = {
Expand Down Expand Up @@ -42,7 +43,8 @@ export default async function buildJS(input, type) {
env: ${env},
paths: {
wasm: '${state.config.general.name}.wasm',
data: '${state.config.general.name}.data.txt'
data: '${state.config.general.name}.data.txt',
worker: '${state.config.general.name}.js',
}
}`;
let file = input;
Expand Down
127 changes: 127 additions & 0 deletions cppjs-core/cpp.js/src/actions/buildWasm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import fs from 'node:fs';
import replace from 'replace';
import run from './run.js';
import getDependLibs from './getDependLibs.js';
import getData from './getData.js';
import buildJs from './buildJs.js';
import triggerExtensions from './extensions.js';
import state from '../state/index.js';

export default async function buildWasm(type, isProd = false) {
const buildType = isProd ? 'Release' : 'Debug';
const libs = [
...getDependLibs(),
`${state.config.paths.build}/Source-${buildType}/Emscripten-x86_64/lib${state.config.general.name}.a`,
`${state.config.paths.build}/Bridge-${buildType}/Emscripten-x86_64/lib${state.config.general.name}.a`,
];

const binary = getData('binary', 'Emscripten-x86_64');

if (type === 'browser') {
console.log('wasm compiling for browser...');
const t0 = performance.now();
const emccFlags = [
...(binary?.emccFlags || []),
...(getData('binary', 'Emscripten-x86_64', 'browser')?.emccFlags || []),
];

triggerExtensions('buildWasm', 'beforeBuildBrowser', [emccFlags]);

if (state.config.build.usePthread && !emccFlags.includes('-pthread')) {
emccFlags.push('-pthread');
emccFlags.push('-sPTHREAD_POOL_SIZE=4');
}

const data = Object.entries(getData('data', 'Emscripten-x86_64', 'browser')).map(([key, value]) => ['--preload-file', `${key.replaceAll('@', '@@')}@${value}`]).flat();
run('emcc', [
'-lembind', '-Wl,--whole-archive',
...emccFlags,
// '-lwebsocket.js', '-sPROXY_POSIX_SOCKETS', '-sWEBSOCKET_DEBUG=1', '-sJSPI', '-g', '-sWASMFS',
'-sWASM_BIGINT=1', '-s', 'FORCE_FILESYSTEM=1',
'-sEXPORT_NAME=Module2', // '-pthread', '-sPTHREAD_POOL_SIZE=5',
...libs, ...(isProd ? ['-O3'] : []),
'-s', 'WASM=1', '-s', 'MODULARIZE=1', '-s', 'DYNAMIC_EXECUTION=0',
/* '-s', 'RESERVED_FUNCTION_POINTERS=200',*/ // '-s', 'FORCE_FILESYSTEM=1',
// '-s', 'ALLOW_MEMORY_GROWTH=1',
'-s', 'EXPORTED_RUNTIME_METHODS=["FS", "ENV"]',
'-fwasm-exceptions',
'-o', `${state.config.paths.build}/${state.config.general.name}.js`,
...data,
]);
const t1 = performance.now();
console.log('wasm compiled for browser...', Math.round(t1 - t0));
console.log('js compiling for browser...');
replace({
regex: 'var _scriptName = ',
replacement: `var _scriptName = 'cpp.worker.js'; //`,
paths: [`${state.config.paths.build}/${state.config.general.name}.js`],
recursive: false,
silent: true,
});
/* replace({
regex: 'val === 10',
replacement: 'false',
paths: [`${state.config.paths.build}/${state.config.general.name}.js`],
recursive: false,
silent: true,
}); */
await buildJs(`${state.config.paths.build}/${state.config.general.name}.js`, 'browser');
// fs.rmSync(`${state.config.paths.build}/${state.config.general.name}.js`);
// fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.browser.js`, `${state.config.paths.build}/${state.config.general.name}.js`);
// fs.renameSync(`${state.config.paths.build}/${state.config.general.name}.js`, `${state.config.paths.build}/${state.config.general.name}.worker.browser.js`);
const t2 = performance.now();
console.log('js compiled for browser...', Math.round(t2 - t1));
}

if (type === 'node') {
console.log('wasm compiling for node...');
const emccFlags = [
...(binary?.emccFlags || []),
...(getData('binary', 'Emscripten-x86_64', 'node')?.emccFlags || []),
];

triggerExtensions('buildWasm', 'beforeBuildNodeJS', [emccFlags]);

if (state.config.build.usePthread && !emccFlags.includes('-pthread')) {
emccFlags.push('-pthread');
emccFlags.push('-sPTHREAD_POOL_SIZE=4');
}

run('emcc', [
'-lembind', '-Wl,--whole-archive', '-lnodefs.js',
...emccFlags,
// '-s', 'FETCH', '-sJSPI', '-sWASM_BIGINT=1', '-pthread', '-sPTHREAD_POOL_SIZE=5',
'-sWASM_BIGINT=1', '-s', 'FORCE_FILESYSTEM=1',
...libs, ...(isProd ? ['-O3'] : []),
'-s', 'WASM=1', '-s', 'MODULARIZE=1', '-s', 'DYNAMIC_EXECUTION=0',
// '-s', 'RESERVED_FUNCTION_POINTERS=200', '-s', 'DISABLE_EXCEPTION_CATCHING=0', '-s', 'FORCE_FILESYSTEM=1',
// '-s', 'ALLOW_MEMORY_GROWTH=1',
'-s', 'NODERAWFS',
'-s', 'EXPORTED_RUNTIME_METHODS=["FS", "ENV", "NODEFS"]',
'-fwasm-exceptions',
'-o', `${state.config.paths.build}/${state.config.general.name}.js`,
]);
console.log('wasm compiled for node...');
console.log('js compiling for node...');
await buildJs(`${state.config.paths.build}/${state.config.general.name}.js`, 'node');
if (emccFlags.includes('FETCH')) {
fs.appendFileSync(`${state.config.paths.build}/${state.config.general.name}.node.js`, 'var XMLHttpRequest = require(\'xhr2\');\n');
}
// fs.renameSync(`${state.config.paths.build}/${state.config.general.name}.js`, `${state.config.paths.build}/${state.config.general.name}.worker.node.js`);
console.log('js compiled for node...');

Object.entries(getData('data', 'Emscripten-x86_64', 'node')).forEach(([key, value]) => {
if (fs.existsSync(key)) {
const dAssetPath = `${state.config.paths.build}/data/${value}`;
if (!fs.existsSync(dAssetPath)) {
fs.mkdirSync(dAssetPath, { recursive: true });
fs.cpSync(key, dAssetPath, { recursive: true });
}
}
});
}

if (fs.existsSync(`${state.config.paths.build}/${state.config.general.name}.data`)) {
fs.renameSync(`${state.config.paths.build}/${state.config.general.name}.data`, `${state.config.paths.build}/${state.config.general.name}.data.txt`);
}
}
Loading
Loading