Skip to content

Commit 998bb1b

Browse files
committed
v2
1 parent c1fc11e commit 998bb1b

File tree

1,664 files changed

+174973
-998
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,664 files changed

+174973
-998
lines changed

.github/workflows/build-linux.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@ on:
55
branches:
66
- main
77
paths:
8-
- packages/**
8+
- cppjs-core/**
9+
- cppjs-extensions/**
10+
- cppjs-packages/**
11+
- cppjs-plugins/**
12+
- cppjs-samples/**
913
- .github/workflows/build-linux.yml
1014
pull_request:
1115
branches:
1216
- main
1317
paths:
14-
- packages/**
18+
- cppjs-core/**
19+
- cppjs-extensions/**
20+
- cppjs-packages/**
21+
- cppjs-plugins/**
22+
- cppjs-samples/**
1523
- .github/workflows/build-linux.yml
1624

1725
permissions: {}

.github/workflows/build-macos.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ on:
55
branches:
66
- main
77
paths:
8-
- packages/**
8+
- cppjs-core/**
9+
- cppjs-extensions/**
10+
- cppjs-packages/**
11+
- cppjs-plugins/**
12+
- cppjs-samples/**
913
- .github/workflows/build-macos.yml
1014
pull_request:
1115
branches:
1216
- main
1317
paths:
14-
- packages/cpp.js/**
15-
- packages/cppjs-plugin-*/**
16-
- packages/cppjs-sample-lib-*/**
17-
- packages/cppjs-sample-web-*/**
18-
- packages/cppjs-sample-backend-*/**
19-
- packages/cppjs-sample-cloud-*/**
18+
- cppjs-core/cpp.js/**
19+
- cppjs-plugins/**
20+
- cppjs-samples/cppjs-sample-lib-*/**
21+
- cppjs-samples/cppjs-sample-web-*/**
22+
- cppjs-samples/cppjs-sample-backend-*/**
23+
- cppjs-samples/cppjs-sample-cloud-*/**
2024
- .github/workflows/build-macos.yml
2125

2226
permissions: {}

.github/workflows/build-windows.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ on:
55
branches:
66
- main
77
paths:
8-
- packages/**
8+
- cppjs-core/**
9+
- cppjs-extensions/**
10+
- cppjs-packages/**
11+
- cppjs-plugins/**
12+
- cppjs-samples/**
913
- .github/workflows/build-windows.yml
1014
pull_request:
1115
branches:
1216
- main
1317
paths:
14-
- packages/cpp.js/**
15-
- packages/cppjs-plugin-*/**
18+
- cppjs-core/cpp.js/**
19+
- cppjs-plugins/**
1620
- .github/workflows/build-windows.yml
1721

1822
permissions: {}

.github/workflows/test-android-sample.yml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@ on:
55
branches:
66
- main
77
paths:
8-
- packages/**
8+
- cppjs-core/**
9+
- cppjs-extensions/**
10+
- cppjs-packages/**
11+
- cppjs-plugins/**
12+
- cppjs-samples/**
913
- .github/workflows/test-android-sample.yml
1014
pull_request:
1115
branches:
1216
- main
1317
paths:
14-
- packages/cpp.js/**
15-
- packages/cppjs-plugin-metro/**
16-
- packages/cppjs-plugin-react-native/**
17-
- packages/cppjs-sample-lib-prebuilt-matrix/**
18-
- packages/cppjs-sample-mobile-reactnative-cli/**
18+
- cppjs-core/cpp.js/**
19+
- cppjs-plugins/cppjs-plugin-metro/**
20+
- cppjs-plugins/cppjs-plugin-react-native/**
21+
- cppjs-samples/cppjs-sample-lib-prebuilt-matrix/**
22+
- cppjs-samples/cppjs-sample-mobile-reactnative-cli/**
1923
- .github/workflows/test-android-sample.yml
2024

2125
permissions: {}
@@ -52,25 +56,25 @@ jobs:
5256
- name: Gradle cache
5357
uses: gradle/actions/setup-gradle@0bdd871935719febd78681f197cd39af5b6e16a6 #v4
5458
- name: create AVD
55-
uses: reactivecircus/android-emulator-runner@62dbb605bba737720e10b196cb4220d374026a6d #v2
59+
uses: reactivecircus/android-emulator-runner@b530d96654c385303d652368551fb075bc2f0b6b #v2
5660
with:
57-
api-level: 30
58-
target: google_apis
61+
api-level: 35
62+
target: default
5963
arch: x86_64
6064
cmake: 3.31.1
61-
ndk: 26.1.10909125
65+
ndk: 27.3.13750724
6266
force-avd-creation: false
6367
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
6468
disable-animations: false
6569
script: echo "Generated AVD snapshot for caching."
6670
- name: E2E Android
67-
uses: reactivecircus/android-emulator-runner@62dbb605bba737720e10b196cb4220d374026a6d #v2
71+
uses: reactivecircus/android-emulator-runner@b530d96654c385303d652368551fb075bc2f0b6b #v2
6872
with:
69-
api-level: 30
70-
target: google_apis
73+
api-level: 35
74+
target: default
7175
arch: x86_64
7276
cmake: 3.31.1
73-
ndk: 26.1.10909125
77+
ndk: 27.3.13750724
7478
force-avd-creation: false
7579
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
7680
disable-animations: true

.github/workflows/test-ios-sample.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ on:
55
branches:
66
- main
77
paths:
8-
- packages/**
8+
- cppjs-core/**
9+
- cppjs-extensions/**
10+
- cppjs-packages/**
11+
- cppjs-plugins/**
12+
- cppjs-samples/**
913
- .github/workflows/test-ios-sample.yml
1014
pull_request:
1115
branches:
1216
- main
1317
paths:
14-
- packages/cpp.js/**
15-
- packages/cppjs-plugin-metro/**
16-
- packages/cppjs-plugin-react-native/**
17-
- packages/cppjs-plugin-react-native-ios-helper/**
18-
- packages/cppjs-sample-lib-prebuilt-matrix/**
19-
- packages/cppjs-sample-mobile-reactnative-cli/**
18+
- cppjs-core/cpp.js/**
19+
- cppjs-plugins/cppjs-plugin-metro/**
20+
- cppjs-plugins/cppjs-plugin-react-native/**
21+
- cppjs-plugins/cppjs-plugin-react-native-ios-helper/**
22+
- cppjs-samples/cppjs-sample-lib-prebuilt-matrix/**
23+
- cppjs-samples/cppjs-sample-mobile-reactnative-cli/**
2024
- .github/workflows/test-ios-sample.yml
2125

2226
permissions: {}
@@ -70,10 +74,10 @@ jobs:
7074
curl -fsSL "https://get.maestro.mobile.dev" | bash
7175
echo "$HOME/.maestro/bin" >> $GITHUB_PATH
7276
- name: Restore cached bridge files
73-
run: cp -r ./packages/cppjs-sample-mobile-reactnative-cli/ci/.cppjs ./packages/cppjs-sample-mobile-reactnative-cli
77+
run: cp -r ./cppjs-samples/cppjs-sample-mobile-reactnative-cli/ci/.cppjs ./cppjs-samples/cppjs-sample-mobile-reactnative-cli
7478
- name: Build cppjs-sample-lib-prebuilt-matrix
7579
run: pnpm --filter=@cpp.js/sample-lib-prebuilt-matrix run build:ios
7680
- name: Pod install
77-
run: cd packages/cppjs-sample-mobile-reactnative-cli/ios && pod install && cd ../../../
81+
run: cd cppjs-samples/cppjs-sample-mobile-reactnative-cli/ios && pod install && cd ../../../
7882
- name: E2E IOS
7983
run: pnpm run e2e:ios
File renamed without changes.
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cpp.js",
3-
"version": "1.0.4",
3+
"version": "2.0.0",
44
"license": "MIT",
55
"homepage": "https://cpp.js.org",
66
"repository": "https://github.com/bugra9/cpp.js.git",
@@ -36,4 +36,4 @@
3636
"ios",
3737
"mobile"
3838
]
39-
}
39+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const nodeLibs = {
1414
buffer: 'export default {};',
1515
crypto: 'export default {};',
1616
stream: 'export default {};',
17+
ws: 'export default {};',
1718
};
1819

1920
const options = {
@@ -42,7 +43,8 @@ export default async function buildJS(input, type) {
4243
env: ${env},
4344
paths: {
4445
wasm: '${state.config.general.name}.wasm',
45-
data: '${state.config.general.name}.data.txt'
46+
data: '${state.config.general.name}.data.txt',
47+
worker: '${state.config.general.name}.js',
4648
}
4749
}`;
4850
let file = input;
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import fs from 'node:fs';
2+
import replace from 'replace';
3+
import run from './run.js';
4+
import getDependLibs from './getDependLibs.js';
5+
import getData from './getData.js';
6+
import buildJs from './buildJs.js';
7+
import triggerExtensions from './extensions.js';
8+
import state from '../state/index.js';
9+
10+
export default async function buildWasm(type, isProd = false) {
11+
const buildType = isProd ? 'Release' : 'Debug';
12+
const libs = [
13+
...getDependLibs(),
14+
`${state.config.paths.build}/Source-${buildType}/Emscripten-x86_64/lib${state.config.general.name}.a`,
15+
`${state.config.paths.build}/Bridge-${buildType}/Emscripten-x86_64/lib${state.config.general.name}.a`,
16+
];
17+
18+
const binary = getData('binary', 'Emscripten-x86_64');
19+
20+
if (type === 'browser') {
21+
console.log('wasm compiling for browser...');
22+
const t0 = performance.now();
23+
const emccFlags = [
24+
...(binary?.emccFlags || []),
25+
...(getData('binary', 'Emscripten-x86_64', 'browser')?.emccFlags || []),
26+
];
27+
28+
triggerExtensions('buildWasm', 'beforeBuildBrowser', [emccFlags]);
29+
30+
if (state.config.build.usePthread && !emccFlags.includes('-pthread')) {
31+
emccFlags.push('-pthread');
32+
emccFlags.push('-sPTHREAD_POOL_SIZE=4');
33+
}
34+
35+
const data = Object.entries(getData('data', 'Emscripten-x86_64', 'browser')).map(([key, value]) => ['--preload-file', `${key.replaceAll('@', '@@')}@${value}`]).flat();
36+
run('emcc', [
37+
'-lembind', '-Wl,--whole-archive',
38+
...emccFlags,
39+
// '-lwebsocket.js', '-sPROXY_POSIX_SOCKETS', '-sWEBSOCKET_DEBUG=1', '-sJSPI', '-g', '-sWASMFS',
40+
'-sWASM_BIGINT=1', '-s', 'FORCE_FILESYSTEM=1',
41+
'-sEXPORT_NAME=Module2', // '-pthread', '-sPTHREAD_POOL_SIZE=5',
42+
...libs, ...(isProd ? ['-O3'] : []),
43+
'-s', 'WASM=1', '-s', 'MODULARIZE=1', '-s', 'DYNAMIC_EXECUTION=0',
44+
/* '-s', 'RESERVED_FUNCTION_POINTERS=200',*/ // '-s', 'FORCE_FILESYSTEM=1',
45+
// '-s', 'ALLOW_MEMORY_GROWTH=1',
46+
'-s', 'EXPORTED_RUNTIME_METHODS=["FS", "ENV"]',
47+
'-fwasm-exceptions',
48+
'-o', `${state.config.paths.build}/${state.config.general.name}.js`,
49+
...data,
50+
]);
51+
const t1 = performance.now();
52+
console.log('wasm compiled for browser...', Math.round(t1 - t0));
53+
console.log('js compiling for browser...');
54+
replace({
55+
regex: 'var _scriptName = ',
56+
replacement: `var _scriptName = 'cpp.worker.js'; //`,
57+
paths: [`${state.config.paths.build}/${state.config.general.name}.js`],
58+
recursive: false,
59+
silent: true,
60+
});
61+
/* replace({
62+
regex: 'val === 10',
63+
replacement: 'false',
64+
paths: [`${state.config.paths.build}/${state.config.general.name}.js`],
65+
recursive: false,
66+
silent: true,
67+
}); */
68+
await buildJs(`${state.config.paths.build}/${state.config.general.name}.js`, 'browser');
69+
// fs.rmSync(`${state.config.paths.build}/${state.config.general.name}.js`);
70+
// fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.browser.js`, `${state.config.paths.build}/${state.config.general.name}.js`);
71+
// fs.renameSync(`${state.config.paths.build}/${state.config.general.name}.js`, `${state.config.paths.build}/${state.config.general.name}.worker.browser.js`);
72+
const t2 = performance.now();
73+
console.log('js compiled for browser...', Math.round(t2 - t1));
74+
}
75+
76+
if (type === 'node') {
77+
console.log('wasm compiling for node...');
78+
const emccFlags = [
79+
...(binary?.emccFlags || []),
80+
...(getData('binary', 'Emscripten-x86_64', 'node')?.emccFlags || []),
81+
];
82+
83+
triggerExtensions('buildWasm', 'beforeBuildNodeJS', [emccFlags]);
84+
85+
if (state.config.build.usePthread && !emccFlags.includes('-pthread')) {
86+
emccFlags.push('-pthread');
87+
emccFlags.push('-sPTHREAD_POOL_SIZE=4');
88+
}
89+
90+
run('emcc', [
91+
'-lembind', '-Wl,--whole-archive', '-lnodefs.js',
92+
...emccFlags,
93+
// '-s', 'FETCH', '-sJSPI', '-sWASM_BIGINT=1', '-pthread', '-sPTHREAD_POOL_SIZE=5',
94+
'-sWASM_BIGINT=1', '-s', 'FORCE_FILESYSTEM=1',
95+
...libs, ...(isProd ? ['-O3'] : []),
96+
'-s', 'WASM=1', '-s', 'MODULARIZE=1', '-s', 'DYNAMIC_EXECUTION=0',
97+
// '-s', 'RESERVED_FUNCTION_POINTERS=200', '-s', 'DISABLE_EXCEPTION_CATCHING=0', '-s', 'FORCE_FILESYSTEM=1',
98+
// '-s', 'ALLOW_MEMORY_GROWTH=1',
99+
'-s', 'NODERAWFS',
100+
'-s', 'EXPORTED_RUNTIME_METHODS=["FS", "ENV", "NODEFS"]',
101+
'-fwasm-exceptions',
102+
'-o', `${state.config.paths.build}/${state.config.general.name}.js`,
103+
]);
104+
console.log('wasm compiled for node...');
105+
console.log('js compiling for node...');
106+
await buildJs(`${state.config.paths.build}/${state.config.general.name}.js`, 'node');
107+
if (emccFlags.includes('FETCH')) {
108+
fs.appendFileSync(`${state.config.paths.build}/${state.config.general.name}.node.js`, 'var XMLHttpRequest = require(\'xhr2\');\n');
109+
}
110+
// fs.renameSync(`${state.config.paths.build}/${state.config.general.name}.js`, `${state.config.paths.build}/${state.config.general.name}.worker.node.js`);
111+
console.log('js compiled for node...');
112+
113+
Object.entries(getData('data', 'Emscripten-x86_64', 'node')).forEach(([key, value]) => {
114+
if (fs.existsSync(key)) {
115+
const dAssetPath = `${state.config.paths.build}/data/${value}`;
116+
if (!fs.existsSync(dAssetPath)) {
117+
fs.mkdirSync(dAssetPath, { recursive: true });
118+
fs.cpSync(key, dAssetPath, { recursive: true });
119+
}
120+
}
121+
});
122+
}
123+
124+
if (fs.existsSync(`${state.config.paths.build}/${state.config.general.name}.data`)) {
125+
fs.renameSync(`${state.config.paths.build}/${state.config.general.name}.data`, `${state.config.paths.build}/${state.config.general.name}.data.txt`);
126+
}
127+
}

0 commit comments

Comments
 (0)