cpp.js 1.0.2 → 2.0.0-beta.1
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/CHANGELOG.md +3 -3
- package/package.json +1 -1
- package/src/actions/buildJs.js +3 -1
- package/src/actions/buildWasm.js +63 -4
- package/src/actions/createLib.js +31 -10
- package/src/actions/createXCFramework.js +6 -0
- package/src/actions/extensions.js +7 -0
- package/src/actions/getCmakeParameters.js +18 -2
- package/src/actions/getData.js +7 -1
- package/src/actions/run.js +7 -6
- package/src/assets/CMakeLists.txt +4 -0
- package/src/assets/browser.js +25 -22
- package/src/assets/dist.cmake +45 -23
- package/src/assets/ios.toolchain.cmake +38 -7
- package/src/bin.js +30 -4
- package/src/integration/getCppJsScript.js +10 -11
- package/src/state/index.js +6 -3
- package/src/state/loadConfig.js +18 -1
- package/src/utils/downloadAndExtractFile.js +10 -1
- package/src/utils/findFiles.js +1 -1
- package/src/utils/pullDockerImage.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# cpp.js
|
|
2
2
|
|
|
3
|
-
## 1.0.
|
|
3
|
+
## 1.0.4
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- fix: workaround for race condition with turbomodule in android.
|
|
7
|
+
- fix: workaround for race condition with turbomodule in android.
|
|
8
8
|
|
|
9
9
|
## 1.0.1
|
|
10
10
|
|
|
11
11
|
### Patch Changes
|
|
12
12
|
|
|
13
|
-
- fix: include prebuilt/_/
|
|
13
|
+
- fix: include prebuilt/_/_config.general.name_/_.h in dependency header search paths
|
|
14
14
|
|
|
15
15
|
## 1.0.0
|
|
16
16
|
|
package/package.json
CHANGED
package/src/actions/buildJs.js
CHANGED
|
@@ -14,6 +14,7 @@ const nodeLibs = {
|
|
|
14
14
|
buffer: 'export default {};',
|
|
15
15
|
crypto: 'export default {};',
|
|
16
16
|
stream: 'export default {};',
|
|
17
|
+
ws: 'export default {};',
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
const options = {
|
|
@@ -42,7 +43,8 @@ export default async function buildJS(input, type) {
|
|
|
42
43
|
env: ${env},
|
|
43
44
|
paths: {
|
|
44
45
|
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',
|
|
46
48
|
}
|
|
47
49
|
}`;
|
|
48
50
|
let file = input;
|
package/src/actions/buildWasm.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
+
import replace from 'replace';
|
|
2
3
|
import run from './run.js';
|
|
3
4
|
import getDependLibs from './getDependLibs.js';
|
|
4
5
|
import getData from './getData.js';
|
|
5
6
|
import buildJs from './buildJs.js';
|
|
7
|
+
import triggerExtensions from './extensions.js';
|
|
6
8
|
import state from '../state/index.js';
|
|
7
9
|
|
|
8
10
|
export default async function buildWasm(type, isProd = false) {
|
|
@@ -13,42 +15,99 @@ export default async function buildWasm(type, isProd = false) {
|
|
|
13
15
|
`${state.config.paths.build}/Bridge-${buildType}/Emscripten-x86_64/lib${state.config.general.name}.a`,
|
|
14
16
|
];
|
|
15
17
|
|
|
18
|
+
const binary = getData('binary', 'Emscripten-x86_64');
|
|
19
|
+
|
|
16
20
|
if (type === 'browser') {
|
|
17
21
|
console.log('wasm compiling for browser...');
|
|
18
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
|
+
|
|
19
35
|
const data = Object.entries(getData('data', 'Emscripten-x86_64', 'browser')).map(([key, value]) => ['--preload-file', `${key.replaceAll('@', '@@')}@${value}`]).flat();
|
|
20
36
|
run('emcc', [
|
|
21
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',
|
|
22
42
|
...libs, ...(isProd ? ['-O3'] : []),
|
|
23
43
|
'-s', 'WASM=1', '-s', 'MODULARIZE=1', '-s', 'DYNAMIC_EXECUTION=0',
|
|
24
|
-
'-s', 'RESERVED_FUNCTION_POINTERS=200'
|
|
25
|
-
'-s', 'ALLOW_MEMORY_GROWTH=1',
|
|
44
|
+
/* '-s', 'RESERVED_FUNCTION_POINTERS=200',*/ // '-s', 'FORCE_FILESYSTEM=1',
|
|
45
|
+
// '-s', 'ALLOW_MEMORY_GROWTH=1',
|
|
26
46
|
'-s', 'EXPORTED_RUNTIME_METHODS=["FS", "ENV"]',
|
|
47
|
+
'-fwasm-exceptions',
|
|
27
48
|
'-o', `${state.config.paths.build}/${state.config.general.name}.js`,
|
|
28
49
|
...data,
|
|
29
50
|
]);
|
|
30
51
|
const t1 = performance.now();
|
|
31
52
|
console.log('wasm compiled for browser...', Math.round(t1 - t0));
|
|
32
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
|
+
}); */
|
|
33
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`);
|
|
34
72
|
const t2 = performance.now();
|
|
35
73
|
console.log('js compiled for browser...', Math.round(t2 - t1));
|
|
36
74
|
}
|
|
37
75
|
|
|
38
76
|
if (type === 'node') {
|
|
39
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
|
+
|
|
40
90
|
run('emcc', [
|
|
41
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',
|
|
42
95
|
...libs, ...(isProd ? ['-O3'] : []),
|
|
43
96
|
'-s', 'WASM=1', '-s', 'MODULARIZE=1', '-s', 'DYNAMIC_EXECUTION=0',
|
|
44
|
-
'-s', 'RESERVED_FUNCTION_POINTERS=200', '-s', 'DISABLE_EXCEPTION_CATCHING=0', '-s', 'FORCE_FILESYSTEM=1',
|
|
45
|
-
'-s', 'ALLOW_MEMORY_GROWTH=1',
|
|
97
|
+
// '-s', 'RESERVED_FUNCTION_POINTERS=200', '-s', 'DISABLE_EXCEPTION_CATCHING=0', '-s', 'FORCE_FILESYSTEM=1',
|
|
98
|
+
// '-s', 'ALLOW_MEMORY_GROWTH=1',
|
|
99
|
+
'-s', 'NODERAWFS',
|
|
46
100
|
'-s', 'EXPORTED_RUNTIME_METHODS=["FS", "ENV", "NODEFS"]',
|
|
101
|
+
'-fwasm-exceptions',
|
|
47
102
|
'-o', `${state.config.paths.build}/${state.config.general.name}.js`,
|
|
48
103
|
]);
|
|
49
104
|
console.log('wasm compiled for node...');
|
|
50
105
|
console.log('js compiling for node...');
|
|
51
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`);
|
|
52
111
|
console.log('js compiled for node...');
|
|
53
112
|
|
|
54
113
|
Object.entries(getData('data', 'Emscripten-x86_64', 'node')).forEach(([key, value]) => {
|
package/src/actions/createLib.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import replace from 'replace';
|
|
4
|
+
import getData from './getData.js';
|
|
4
5
|
import run from './run.js';
|
|
5
6
|
import getCmakeParameters from './getCmakeParameters.js';
|
|
7
|
+
import triggerExtensions from './extensions.js';
|
|
6
8
|
import state from '../state/index.js';
|
|
7
9
|
|
|
8
10
|
const cpuCount = os.cpus().length - 1;
|
|
@@ -26,8 +28,8 @@ export default function createLib(platform, fileType, options = {}) {
|
|
|
26
28
|
const buildEnv = { params: [] };
|
|
27
29
|
let buildParams;
|
|
28
30
|
const depPaths = state.config.allDependencyPaths[platform];
|
|
29
|
-
if (state.config.build) {
|
|
30
|
-
const { getBuildParams, getExtraLibs } = state.config.build;
|
|
31
|
+
if (state.config.build.withBuildConfig) {
|
|
32
|
+
const { getBuildParams, getExtraLibs, usePthread } = state.config.build;
|
|
31
33
|
buildEnv.console = true;
|
|
32
34
|
const ext = sharedPlatforms.includes(basePlatform) ? 'so' : 'a';
|
|
33
35
|
buildParams = getBuildParams ? getBuildParams(platform, depPaths, ext, buildPath) : [];
|
|
@@ -36,30 +38,49 @@ export default function createLib(platform, fileType, options = {}) {
|
|
|
36
38
|
buildParams.push(`-DCMAKE_PREFIX_PATH=${libdir}`, `-DCMAKE_FIND_ROOT_PATH=${libdir}`, `-DBUILD_TYPE=${cmakeBuildType}`);
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
const cFlags = Object.values(depPaths).map((d) => `-I${d.header}`)
|
|
40
|
-
const ldFlags = Object.values(depPaths).map((d) => `-L${d.libPath}`)
|
|
41
|
+
const cFlags = Object.values(depPaths).filter(d => d.header).map((d) => `-I${d.header}`);
|
|
42
|
+
const ldFlags = Object.values(depPaths).filter(d => d.libPath).map((d) => `-L${d.libPath}`);
|
|
41
43
|
let dependLibs = '';
|
|
42
44
|
if (state.config.build?.buildType === 'configure') {
|
|
43
|
-
dependLibs = Object.keys(depPaths).map((d) => `-l${d}`).join(' ');
|
|
45
|
+
dependLibs = Object.keys(depPaths).filter(d => d).map((d) => `-l${d}`).join(' ');
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
const extraLibs = getExtraLibs ? getExtraLibs(platform) : [];
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
triggerExtensions('createLib', 'setFlagWithBuildConfig', [buildEnv, cFlags, ldFlags]);
|
|
51
|
+
|
|
52
|
+
if (usePthread) {
|
|
53
|
+
cFlags.push('-pthread');
|
|
54
|
+
ldFlags.push('-pthread');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
buildEnv.params.push('-e', `CFLAGS=${cFlags.join(' ')}`);
|
|
58
|
+
buildEnv.params.push('-e', `CXXFLAGS=${cFlags.join(' ')}`);
|
|
59
|
+
buildEnv.params.push('-e', `LDFLAGS=${ldFlags.join(' ')} ${extraLibs.join(' ')}`);
|
|
51
60
|
// buildEnv.params.push('-e', `LIBS=${dependLibs} ${extraLibs.join(' ')}`);
|
|
52
61
|
|
|
53
|
-
state.config.build.env
|
|
62
|
+
let configBuildEnv = state.config.build.env;
|
|
63
|
+
if (configBuildEnv && typeof configBuildEnv === 'function') {
|
|
64
|
+
configBuildEnv = configBuildEnv(platform);
|
|
65
|
+
}
|
|
66
|
+
configBuildEnv?.forEach((e) => {
|
|
54
67
|
buildEnv.params.push('-e', e);
|
|
55
68
|
});
|
|
56
69
|
} else {
|
|
57
70
|
buildParams = getCmakeParameters(platform, options);
|
|
71
|
+
|
|
72
|
+
triggerExtensions('createLib', 'setFlagWithoutBuildConfig', [buildEnv]);
|
|
73
|
+
|
|
74
|
+
if (state.config.build.usePthread) {
|
|
75
|
+
buildEnv.params.push('-e', `CFLAGS=-pthread`);
|
|
76
|
+
buildEnv.params.push('-e', `CXXFLAGS=-pthread`);
|
|
77
|
+
buildEnv.params.push('-e', `LDFLAGS=-pthread`);
|
|
78
|
+
}
|
|
58
79
|
}
|
|
59
80
|
|
|
60
81
|
console.log(`${platform} is compiling...`);
|
|
61
82
|
const t0 = performance.now();
|
|
62
|
-
const cmakeDir = state.config.build ? `${state.config.paths.build}/source` : state.config.paths.cmakeDir;
|
|
83
|
+
const cmakeDir = state.config.build.withBuildConfig ? `${state.config.paths.build}/source` : state.config.paths.cmakeDir;
|
|
63
84
|
|
|
64
85
|
if (state.config.build?.beforeRun) {
|
|
65
86
|
const dataList = state.config.build?.beforeRun(cmakeDir);
|
|
@@ -3,6 +3,10 @@ import upath from 'upath';
|
|
|
3
3
|
import { execFileSync } from 'node:child_process';
|
|
4
4
|
import state from '../state/index.js';
|
|
5
5
|
|
|
6
|
+
const iOSDevPath = '/Applications/Xcode.app/Contents/Developer';
|
|
7
|
+
const iosBinPath = `${iOSDevPath}/Toolchains/XcodeDefault.xctoolchain/usr/bin`;
|
|
8
|
+
const iosRanLibBin = `${iosBinPath}/ranlib`;
|
|
9
|
+
|
|
6
10
|
export default function createXCFramework(overrideConfig = null) {
|
|
7
11
|
if (process.platform !== 'darwin') {
|
|
8
12
|
return;
|
|
@@ -26,6 +30,8 @@ export default function createXCFramework(overrideConfig = null) {
|
|
|
26
30
|
|
|
27
31
|
libName.forEach((fileName) => {
|
|
28
32
|
if (!fs.existsSync(`${projectPath}/${fileName}.xcframework`)) {
|
|
33
|
+
execFileSync(iosRanLibBin, [`${relativeOutput}/prebuilt/iOS-iphoneos/lib/lib${fileName}.a`], options);
|
|
34
|
+
execFileSync(iosRanLibBin, [`${relativeOutput}/prebuilt/iOS-iphonesimulator/lib/lib${fileName}.a`], options);
|
|
29
35
|
const params = [
|
|
30
36
|
'-create-xcframework',
|
|
31
37
|
'-library', `${relativeOutput}/prebuilt/iOS-iphoneos/lib/lib${fileName}.a`,
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
1
2
|
import state from '../state/index.js';
|
|
3
|
+
import getData from './getData.js';
|
|
2
4
|
|
|
3
5
|
export default function getCmakeParameters(platform, options = {}) {
|
|
4
6
|
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
|
@@ -35,6 +37,19 @@ export default function getCmakeParameters(platform, options = {}) {
|
|
|
35
37
|
const buildType = sharedPlatforms.includes(basePlatform) ? 'SHARED' : 'STATIC';
|
|
36
38
|
const otherBuildType = buildType === 'STATIC' ? 'SHARED' : 'STATIC';
|
|
37
39
|
|
|
40
|
+
const cmakeCompileOptions = [...new Set(getData('cmake', platform)?.compileOptions || [])];
|
|
41
|
+
|
|
42
|
+
const pathsOfCmakeDepends = dependParams.pathsOfCmakeDepends.split(';');
|
|
43
|
+
const nameOfCmakeDepends = dependParams.nameOfCmakeDepends.split(';');
|
|
44
|
+
const pathsOfCmakeDependsFilteredByPlatform = [];
|
|
45
|
+
const nameOfCmakeDependsFilteredByPlatform = nameOfCmakeDepends;
|
|
46
|
+
pathsOfCmakeDepends.forEach((d, i) => {
|
|
47
|
+
if (fs.existsSync(`${d}/${platform}`)) {
|
|
48
|
+
pathsOfCmakeDependsFilteredByPlatform.push(d);
|
|
49
|
+
// nameOfCmakeDependsFilteredByPlatform.push(nameOfCmakeDepends[i]);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
38
53
|
params.push(...[
|
|
39
54
|
`-DPROJECT_NAME=${options.name || state.config.general.name}`,
|
|
40
55
|
`-DBASE_DIR=${state.config.paths.project}`,
|
|
@@ -43,11 +58,12 @@ export default function getCmakeParameters(platform, options = {}) {
|
|
|
43
58
|
`-DNATIVE_GLOB=${nativeGlob.join(';')}`,
|
|
44
59
|
`-DHEADER_GLOB=${headerGlob.join(';')}`,
|
|
45
60
|
`-DHEADER_DIR=${headerDirs.join(';')}`,
|
|
46
|
-
`-DDEPENDS_CMAKE_PATHS=${
|
|
47
|
-
`-DDEPENDS_CMAKE_NAMES=${
|
|
61
|
+
`-DDEPENDS_CMAKE_PATHS=${pathsOfCmakeDependsFilteredByPlatform.join(';')}`,
|
|
62
|
+
`-DDEPENDS_CMAKE_NAMES=${nameOfCmakeDependsFilteredByPlatform.join(';')}`,
|
|
48
63
|
`-DBRIDGE_DIR=${state.config.paths.build}/bridge`,
|
|
49
64
|
`-DBUILD_TYPE=${buildType}`,
|
|
50
65
|
`-DBUILD_${otherBuildType}_LIBS=OFF`,
|
|
66
|
+
`-DCOMPILE_OPTIONS=${cmakeCompileOptions.join(';')}`,
|
|
51
67
|
// '-DCMAKE_CXX_COMPILER_LAUNCHER=ccache',
|
|
52
68
|
...(options.buildSource !== false ? ['-DBUILD_SOURCE=TRUE'] : []),
|
|
53
69
|
]);
|
package/src/actions/getData.js
CHANGED
|
@@ -10,7 +10,13 @@ function getRecursiveData(obj, config, dependency, field, platform, subPlatform)
|
|
|
10
10
|
const key = `${dependency.paths.project}/dist/prebuilt/${platform}/${dKey}`;
|
|
11
11
|
obj[key] = value;
|
|
12
12
|
} else {
|
|
13
|
-
|
|
13
|
+
if (typeof value === 'object' && Array.isArray(value)) {
|
|
14
|
+
obj[dKey] = [...(obj[dKey] || []), ...value];
|
|
15
|
+
} else if (typeof value === 'object') {
|
|
16
|
+
obj[dKey] = {...(obj[dKey] || {}), ...value};
|
|
17
|
+
} else {
|
|
18
|
+
obj[dKey] = value;
|
|
19
|
+
}
|
|
14
20
|
}
|
|
15
21
|
});
|
|
16
22
|
}
|
package/src/actions/run.js
CHANGED
|
@@ -7,7 +7,7 @@ import state from '../state/index.js';
|
|
|
7
7
|
|
|
8
8
|
const CROSSCOMPILER_ARM64 = 'aarch64-linux-android33';
|
|
9
9
|
const CROSSCOMPILER_x86_64 = 'x86_64-linux-android33';
|
|
10
|
-
const ANDROID_NDK = '/opt/android-sdk/ndk/
|
|
10
|
+
const ANDROID_NDK = '/opt/android-sdk/ndk/27.3.13750724';
|
|
11
11
|
const t = `${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin`;
|
|
12
12
|
const t2 = `${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64`;
|
|
13
13
|
|
|
@@ -41,7 +41,7 @@ const androidParamsX86_64 = [
|
|
|
41
41
|
];
|
|
42
42
|
|
|
43
43
|
const IOS_HOST_FLAGS = `-arch arm64 -arch arm64e -isysroot ${iosSdkPath} -fembed-bitcode`;
|
|
44
|
-
const IOS_SIM_HOST_FLAGS = `-arch x86_64 -arch arm64 -
|
|
44
|
+
const IOS_SIM_HOST_FLAGS = `-arch x86_64 -arch arm64 -isysroot ${iosSimSdkPath} -fembed-bitcode`;
|
|
45
45
|
const IOS_IPHONE_PARAMS = [
|
|
46
46
|
'-e', `CFLAGS="${IOS_HOST_FLAGS}"`,
|
|
47
47
|
'-e', `CXXFLAGS="${IOS_HOST_FLAGS}"`,
|
|
@@ -96,7 +96,7 @@ export default function run(program, params = [], platformPrefix = null, platfor
|
|
|
96
96
|
if (program === null) {
|
|
97
97
|
switch (basePlatform) {
|
|
98
98
|
case 'Emscripten':
|
|
99
|
-
platformParams = ['-e', 'CXXFLAGS=-
|
|
99
|
+
platformParams = ['-e', 'CXXFLAGS=-fwasm-exceptions', '-e', 'CFLAGS=-fwasm-exceptions'];
|
|
100
100
|
if (params[0].includes('configure')) dProgram = 'emconfigure';
|
|
101
101
|
else if (params[0] === 'make') dProgram = 'emmake';
|
|
102
102
|
else if (params[0] === 'cmake') dProgram = 'emcmake';
|
|
@@ -111,6 +111,7 @@ export default function run(program, params = [], platformPrefix = null, platfor
|
|
|
111
111
|
'-DCMAKE_SYSTEM_NAME=Android', '-DCMAKE_SYSTEM_VERSION=33',
|
|
112
112
|
`-DCMAKE_ANDROID_ARCH_ABI=${arch[0] === 'x86_64' ? 'x86_64' : 'arm64-v8a'}`,
|
|
113
113
|
`-DCMAKE_ANDROID_NDK=${ANDROID_NDK}`,
|
|
114
|
+
`-DANDROID_NDK=${ANDROID_NDK}`,
|
|
114
115
|
];
|
|
115
116
|
}
|
|
116
117
|
break;
|
|
@@ -130,7 +131,7 @@ export default function run(program, params = [], platformPrefix = null, platfor
|
|
|
130
131
|
`-DMACOSX_FRAMEWORK_IDENTIFIER=org.js.cpp.${state.config.general.name}`,
|
|
131
132
|
`-DCMAKE_XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER=org.js.cpp.${state.config.general.name}`,
|
|
132
133
|
`-DCMAKE_OSX_SYSROOT='${arch[0] === 'iphoneos' ? iosSdkPath : iosSimSdkPath}'`,
|
|
133
|
-
`-DCMAKE_OSX_ARCHITECTURES=${arch[0] === 'iphoneos' ? 'arm64;arm64e' : 'arm64;
|
|
134
|
+
`-DCMAKE_OSX_ARCHITECTURES=${arch[0] === 'iphoneos' ? 'arm64;arm64e' : 'arm64;x86_64'}`,
|
|
134
135
|
`-DCMAKE_C_FLAGS=${arch[0] === 'iphoneos' ? '-fembed-bitcode' : '-fembed-bitcode-marker'}`,
|
|
135
136
|
`-DCMAKE_CXX_FLAGS=${arch[0] === 'iphoneos' ? '-fembed-bitcode' : '-fembed-bitcode-marker'}`,
|
|
136
137
|
'-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY=\'iPhone Developer\'',
|
|
@@ -145,7 +146,7 @@ export default function run(program, params = [], platformPrefix = null, platfor
|
|
|
145
146
|
...dParams,
|
|
146
147
|
`-DCMAKE_TOOLCHAIN_FILE='${state.config.paths.cli}/assets/ios.toolchain.cmake'`,
|
|
147
148
|
`-DPLATFORM=${arch[0] === 'iphoneos' ? 'OS64' : 'SIMULATORARM64'}`,
|
|
148
|
-
`-DARCHS=${arch[0] === 'iphoneos' ? 'arm64;arm64e' : 'arm64;
|
|
149
|
+
`-DARCHS=${arch[0] === 'iphoneos' ? 'arm64;arm64e' : 'arm64;x86_64'}`,
|
|
149
150
|
'-DENABLE_BITCODE=TRUE',
|
|
150
151
|
'-DBUILD_SHARED_LIBS=OFF',
|
|
151
152
|
'-DFRAMEWORK=TRUE',
|
|
@@ -154,7 +155,7 @@ export default function run(program, params = [], platformPrefix = null, platfor
|
|
|
154
155
|
`-DMACOSX_FRAMEWORK_IDENTIFIER=org.js.cpp.${state.config.general.name}`,
|
|
155
156
|
`-DCMAKE_XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER=org.js.cpp.${state.config.general.name}`,
|
|
156
157
|
`-DCMAKE_OSX_SYSROOT='${arch[0] === 'iphoneos' ? iosSdkPath : iosSimSdkPath}'`,
|
|
157
|
-
`-DCMAKE_OSX_ARCHITECTURES=${arch[0] === 'iphoneos' ? 'arm64;arm64e' : 'arm64;
|
|
158
|
+
`-DCMAKE_OSX_ARCHITECTURES=${arch[0] === 'iphoneos' ? 'arm64;arm64e' : 'arm64;x86_64'}`,
|
|
158
159
|
`-DCMAKE_C_FLAGS=${arch[0] === 'iphoneos' ? '-fembed-bitcode' : '-fembed-bitcode-marker'}`,
|
|
159
160
|
`-DCMAKE_CXX_FLAGS=${arch[0] === 'iphoneos' ? '-fembed-bitcode' : '-fembed-bitcode-marker'}`,
|
|
160
161
|
'-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY=\'iPhone Developer\'',
|
|
@@ -39,6 +39,10 @@ if(ANDROID)
|
|
|
39
39
|
set(EXTRA_LINK_LIBRARIES "log")
|
|
40
40
|
endif()
|
|
41
41
|
|
|
42
|
+
if (NOT ${COMPILE_OPTIONS} STREQUAL "")
|
|
43
|
+
target_compile_options("${PROJECT_NAME}" PUBLIC "${COMPILE_OPTIONS}")
|
|
44
|
+
endif()
|
|
45
|
+
|
|
42
46
|
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "")
|
|
43
47
|
target_link_libraries("${PROJECT_NAME}" "${DEPENDS_CMAKE_NAMES}" "${EXTRA_LINK_LIBRARIES}")
|
|
44
48
|
endif()
|
package/src/assets/browser.js
CHANGED
|
@@ -36,6 +36,27 @@ function initCppJs(userConfig = {}) {
|
|
|
36
36
|
|
|
37
37
|
const config = mergeDeep(systemConfig, userConfig);
|
|
38
38
|
|
|
39
|
+
const locateFile = (fileName) => {
|
|
40
|
+
let path = fileName;
|
|
41
|
+
if (config.paths && config.paths.wasm && fileName.endsWith('.wasm')) {
|
|
42
|
+
path = config.paths.wasm;
|
|
43
|
+
} else if (config.paths && config.paths.data && (fileName.endsWith('.data.txt') || fileName.endsWith('.data'))) {
|
|
44
|
+
path = config.paths.data;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let prefix = '';
|
|
48
|
+
if (config.path) {
|
|
49
|
+
prefix = config.path;
|
|
50
|
+
if (prefix.slice(-1) !== '/') prefix += '/';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let output = prefix + path;
|
|
54
|
+
if (output.endsWith('.data')) output += '.txt';
|
|
55
|
+
if (output.substring(0, 4) !== 'http' && output[0] !== '/') output = `/${output}`;
|
|
56
|
+
|
|
57
|
+
return output;
|
|
58
|
+
};
|
|
59
|
+
|
|
39
60
|
cppJsPromise = new Promise((resolve, reject) => {
|
|
40
61
|
const m = {
|
|
41
62
|
print(text) {
|
|
@@ -52,26 +73,8 @@ function initCppJs(userConfig = {}) {
|
|
|
52
73
|
console.error(`wasm stderr: ${text}`);
|
|
53
74
|
}
|
|
54
75
|
},
|
|
55
|
-
locateFile(
|
|
56
|
-
|
|
57
|
-
if (config.paths && config.paths.wasm && fileName.endsWith('.wasm')) {
|
|
58
|
-
path = config.paths.wasm;
|
|
59
|
-
} else if (config.paths && config.paths.data && (fileName.endsWith('.data.txt') || fileName.endsWith('.data'))) {
|
|
60
|
-
path = config.paths.data;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let prefix = '';
|
|
64
|
-
if (config.path) {
|
|
65
|
-
prefix = config.path;
|
|
66
|
-
if (prefix.slice(-1) !== '/') prefix += '/';
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
let output = prefix + path;
|
|
70
|
-
if (output.endsWith('.data')) output += '.txt';
|
|
71
|
-
if (output.substring(0, 4) !== 'http' && output[0] !== '/') output = `/${output}`;
|
|
72
|
-
return output;
|
|
73
|
-
},
|
|
74
|
-
|
|
76
|
+
mainScriptUrlOrBlob: locateFile(config.paths.worker === 'cpp.js' ? 'cpp.js' : config.paths.worker.replace('.js', '.browser.js')),
|
|
77
|
+
locateFile,
|
|
75
78
|
preRun: [
|
|
76
79
|
({ ENV }) => {
|
|
77
80
|
if (ENV && config && config.env) {
|
|
@@ -83,8 +86,8 @@ function initCppJs(userConfig = {}) {
|
|
|
83
86
|
},
|
|
84
87
|
],
|
|
85
88
|
onRuntimeInitialized() {
|
|
86
|
-
m.FS.mkdir(VIRTUAL_PATH);
|
|
87
|
-
m.FS.mkdir(AUTO_MOUNTED_PATH);
|
|
89
|
+
// m.FS.mkdir(VIRTUAL_PATH);
|
|
90
|
+
// m.FS.mkdir(AUTO_MOUNTED_PATH);
|
|
88
91
|
if (config.onRuntimeInitialized) config.onRuntimeInitialized(m);
|
|
89
92
|
},
|
|
90
93
|
generateVirtualPath() {
|
package/src/assets/dist.cmake
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
cmake_minimum_required(VERSION 3.28)
|
|
2
|
-
set(CMAKE_CXX_STANDARD 11)
|
|
3
|
-
set(PROJECT_NAME "___PROJECT_NAME___")
|
|
4
|
-
set(PROJECT_LIBS "___PROJECT_LIBS___")
|
|
5
|
-
project("${PROJECT_NAME}")
|
|
6
|
-
|
|
7
1
|
if(ANDROID)
|
|
8
2
|
set(PACKAGE_HOST "${CMAKE_SYSTEM_NAME}-${CMAKE_ANDROID_ARCH_ABI}")
|
|
9
3
|
set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/${PACKAGE_HOST}/lib")
|
|
@@ -22,23 +16,51 @@ else()
|
|
|
22
16
|
set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/${PACKAGE_HOST}/lib")
|
|
23
17
|
endif()
|
|
24
18
|
|
|
25
|
-
set(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
NO_CMAKE_FIND_ROOT_PATH
|
|
34
|
-
REQUIRED
|
|
35
|
-
)
|
|
36
|
-
LIST(APPEND PROJECT_LIBS_DIR ${FOUND_LIB})
|
|
37
|
-
endforeach()
|
|
19
|
+
set(MY_LIST "___PROJECT_HOST___")
|
|
20
|
+
LIST(FIND MY_LIST "${PACKAGE_HOST}" PACKAGE_HOST_INDEX)
|
|
21
|
+
if(NOT PACKAGE_HOST_INDEX EQUAL -1)
|
|
22
|
+
cmake_minimum_required(VERSION 3.28)
|
|
23
|
+
set(CMAKE_CXX_STANDARD 11)
|
|
24
|
+
set(PROJECT_NAME "___PROJECT_NAME___")
|
|
25
|
+
set(PROJECT_LIBS "___PROJECT_LIBS___")
|
|
26
|
+
project("${PROJECT_NAME}")
|
|
38
27
|
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
if(ANDROID)
|
|
29
|
+
set(PACKAGE_HOST "${CMAKE_SYSTEM_NAME}-${CMAKE_ANDROID_ARCH_ABI}")
|
|
30
|
+
set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/${PACKAGE_HOST}/lib")
|
|
31
|
+
elseif(APPLE)
|
|
32
|
+
if (CMAKE_SYSTEM_NAME STREQUAL "iOS")
|
|
33
|
+
set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/../..")
|
|
34
|
+
else()
|
|
35
|
+
set(PACKAGE_HOST "${CMAKE_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}")
|
|
36
|
+
set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/${PACKAGE_HOST}/lib")
|
|
37
|
+
endif()
|
|
38
|
+
elseif(UNIX)
|
|
39
|
+
set(PACKAGE_HOST "${CMAKE_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}")
|
|
40
|
+
set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/${PACKAGE_HOST}/lib")
|
|
41
|
+
else()
|
|
42
|
+
set(PACKAGE_HOST "${CMAKE_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}")
|
|
43
|
+
set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/${PACKAGE_HOST}/lib")
|
|
44
|
+
endif()
|
|
45
|
+
|
|
46
|
+
set(PROJECT_LIBS_DIR)
|
|
47
|
+
foreach(L IN LISTS PROJECT_LIBS)
|
|
48
|
+
SET(FOUND_LIB "FOUND_LIB-NOTFOUND")
|
|
49
|
+
find_library(FOUND_LIB
|
|
50
|
+
NAMES "${L}"
|
|
51
|
+
PATHS "${PACKAGE_DIR}"
|
|
52
|
+
NO_CACHE
|
|
53
|
+
NO_DEFAULT_PATH
|
|
54
|
+
NO_CMAKE_FIND_ROOT_PATH
|
|
55
|
+
REQUIRED
|
|
56
|
+
)
|
|
57
|
+
LIST(APPEND PROJECT_LIBS_DIR ${FOUND_LIB})
|
|
58
|
+
endforeach()
|
|
41
59
|
|
|
42
|
-
|
|
43
|
-
|
|
60
|
+
add_library("${PROJECT_NAME}" INTERFACE)
|
|
61
|
+
target_link_libraries("${PROJECT_NAME}" INTERFACE "${PROJECT_LIBS_DIR}")
|
|
62
|
+
|
|
63
|
+
if(NOT APPLE)
|
|
64
|
+
target_include_directories("${PROJECT_NAME}" INTERFACE "${PROJECT_SOURCE_DIR}/${PACKAGE_HOST}/include")
|
|
65
|
+
endif()
|
|
44
66
|
endif()
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
# WATCHOSCOMBINED = Build for armv7k arm64_32 x86_64 watchOS + watchOS Simulator. Combined into FAT STATIC lib (only supported on 3.14+ of CMake with "-G Xcode" argument in combination with the "cmake --install" CMake build step)
|
|
75
75
|
# SIMULATOR_WATCHOS = Build for x86_64 for watchOS Simulator.
|
|
76
76
|
# SIMULATORARM64_WATCHOS = Build for arm64 for watchOS Simulator.
|
|
77
|
+
# SIMULATOR_WATCHOSCOMBINED = Build for arm64 x86_64 for watchOS Simulator. Combined into FAT STATIC lib (supported on 3.14+ of CMakewith "-G Xcode" argument ONLY)
|
|
77
78
|
# MAC = Build for x86_64 macOS.
|
|
78
79
|
# MAC_ARM64 = Build for Apple Silicon macOS.
|
|
79
80
|
# MAC_UNIVERSAL = Combined build for x86_64 and Apple Silicon on macOS.
|
|
@@ -166,7 +167,7 @@ set(ENV{_IOS_TOOLCHAIN_HAS_RUN} true)
|
|
|
166
167
|
list(APPEND _supported_platforms
|
|
167
168
|
"OS" "OS64" "OS64COMBINED" "SIMULATOR" "SIMULATOR64" "SIMULATORARM64" "SIMULATOR64COMBINED"
|
|
168
169
|
"TVOS" "TVOSCOMBINED" "SIMULATOR_TVOS" "SIMULATORARM64_TVOS"
|
|
169
|
-
"WATCHOS" "WATCHOSCOMBINED" "SIMULATOR_WATCHOS" "SIMULATORARM64_WATCHOS"
|
|
170
|
+
"WATCHOS" "WATCHOSCOMBINED" "SIMULATOR_WATCHOS" "SIMULATORARM64_WATCHOS" "SIMULATOR_WATCHOSCOMBINED"
|
|
170
171
|
"MAC" "MAC_ARM64" "MAC_UNIVERSAL"
|
|
171
172
|
"VISIONOS" "SIMULATOR_VISIONOS" "VISIONOSCOMBINED"
|
|
172
173
|
"MAC_CATALYST" "MAC_CATALYST_ARM64" "MAC_CATALYST_UNIVERSAL")
|
|
@@ -461,12 +462,12 @@ elseif(PLATFORM_INT STREQUAL "WATCHOSCOMBINED")
|
|
|
461
462
|
if(MODERN_CMAKE)
|
|
462
463
|
if(NOT ARCHS)
|
|
463
464
|
if (XCODE_VERSION_INT VERSION_GREATER 10.0)
|
|
464
|
-
set(ARCHS armv7k arm64_32
|
|
465
|
-
set(APPLE_TARGET_TRIPLE_INT arm64_32-
|
|
465
|
+
set(ARCHS armv7k arm64_32 x86_64)
|
|
466
|
+
set(APPLE_TARGET_TRIPLE_INT arm64_32-x86_64-apple-watchos${DEPLOYMENT_TARGET})
|
|
466
467
|
set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=watchos*] "armv7k arm64_32")
|
|
467
|
-
set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=watchsimulator*] "
|
|
468
|
+
set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=watchsimulator*] "x86_64")
|
|
468
469
|
set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=watchos*] "armv7k arm64_32")
|
|
469
|
-
set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=watchsimulator*] "
|
|
470
|
+
set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=watchsimulator*] "x86_64")
|
|
470
471
|
else()
|
|
471
472
|
set(ARCHS armv7k i386)
|
|
472
473
|
set(APPLE_TARGET_TRIPLE_INT arm-i386-apple-watchos${DEPLOYMENT_TARGET})
|
|
@@ -484,8 +485,13 @@ elseif(PLATFORM_INT STREQUAL "WATCHOSCOMBINED")
|
|
|
484
485
|
elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS")
|
|
485
486
|
set(SDK_NAME watchsimulator)
|
|
486
487
|
if(NOT ARCHS)
|
|
487
|
-
|
|
488
|
-
|
|
488
|
+
if (XCODE_VERSION_INT VERSION_GREATER 10.0)
|
|
489
|
+
set(ARCHS x86_64)
|
|
490
|
+
set(APPLE_TARGET_TRIPLE_INT x86_64-apple-watchos${DEPLOYMENT_TARGET}-simulator)
|
|
491
|
+
else()
|
|
492
|
+
set(ARCHS i386)
|
|
493
|
+
set(APPLE_TARGET_TRIPLE_INT i386-apple-watchos${DEPLOYMENT_TARGET}-simulator)
|
|
494
|
+
endif()
|
|
489
495
|
else()
|
|
490
496
|
set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-watchos${DEPLOYMENT_TARGET}-simulator)
|
|
491
497
|
endif()
|
|
@@ -497,6 +503,31 @@ elseif(PLATFORM_INT STREQUAL "SIMULATORARM64_WATCHOS")
|
|
|
497
503
|
else()
|
|
498
504
|
set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-watchos${DEPLOYMENT_TARGET}-simulator)
|
|
499
505
|
endif()
|
|
506
|
+
elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOSCOMBINED")
|
|
507
|
+
set(SDK_NAME watchsimulator)
|
|
508
|
+
if(MODERN_CMAKE)
|
|
509
|
+
if(NOT ARCHS)
|
|
510
|
+
if (XCODE_VERSION_INT VERSION_GREATER 12.0)
|
|
511
|
+
set(ARCHS arm64 x86_64)
|
|
512
|
+
set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=watchos*] "")
|
|
513
|
+
set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=watchsimulator*] "arm64 x86_64")
|
|
514
|
+
set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=watchos*] "")
|
|
515
|
+
set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=watchsimulator*] "arm64 x86_64")
|
|
516
|
+
set(APPLE_TARGET_TRIPLE_INT arm64_x86_64-apple-watchos${DEPLOYMENT_TARGET}-simulator)
|
|
517
|
+
else()
|
|
518
|
+
set(ARCHS arm64 i386)
|
|
519
|
+
set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=watchos*] "")
|
|
520
|
+
set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=watchsimulator*] "i386")
|
|
521
|
+
set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=watchos*] "")
|
|
522
|
+
set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=watchsimulator*] "i386")
|
|
523
|
+
set(APPLE_TARGET_TRIPLE_INT arm64_i386-apple-watchos${DEPLOYMENT_TARGET}-simulator)
|
|
524
|
+
endif()
|
|
525
|
+
else()
|
|
526
|
+
set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-watchos${DEPLOYMENT_TARGET}-simulator)
|
|
527
|
+
endif()
|
|
528
|
+
else()
|
|
529
|
+
message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the SIMULATOR_WATCHOSCOMBINED setting work")
|
|
530
|
+
endif()
|
|
500
531
|
elseif(PLATFORM_INT STREQUAL "SIMULATOR_VISIONOS")
|
|
501
532
|
set(SDK_NAME xrsimulator)
|
|
502
533
|
if(NOT ARCHS)
|
package/src/bin.js
CHANGED
|
@@ -55,7 +55,7 @@ program.parse(process.argv);
|
|
|
55
55
|
switch (program.args[0]) {
|
|
56
56
|
case 'build': {
|
|
57
57
|
const { platform } = commandBuild.opts();
|
|
58
|
-
if (state.config.build) {
|
|
58
|
+
if (state.config.build.withBuildConfig) {
|
|
59
59
|
buildExternal(platform);
|
|
60
60
|
} else {
|
|
61
61
|
build(platform);
|
|
@@ -228,7 +228,7 @@ async function buildExternal(platform) {
|
|
|
228
228
|
return;
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
const { getURL, replaceList, copyToSource } = state.config.build;
|
|
231
|
+
const { getURL, replaceList, copyToSource, copyToDist } = state.config.build;
|
|
232
232
|
const isNewlyCreated = await downloadAndExtractFile(getURL(version), state.config.paths.build);
|
|
233
233
|
const sourcePath = `${state.config.paths.build}/source`;
|
|
234
234
|
if (isNewlyCreated && replaceList) {
|
|
@@ -246,6 +246,23 @@ async function buildExternal(platform) {
|
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
buildLib(platform);
|
|
249
|
+
|
|
250
|
+
if (copyToDist) {
|
|
251
|
+
Object.entries(copyToDist).forEach(([key, value]) => {
|
|
252
|
+
const values = [];
|
|
253
|
+
if (Array.isArray(value)) {
|
|
254
|
+
values.push(...value);
|
|
255
|
+
} else {
|
|
256
|
+
values.push(value);
|
|
257
|
+
}
|
|
258
|
+
values.forEach(v => {
|
|
259
|
+
const targetPath = `${state.config.paths.output}/prebuilt/${v}`;
|
|
260
|
+
if (!fs.existsSync(targetPath)) {
|
|
261
|
+
fs.copyFileSync(`${state.config.paths.project}/${key}`, targetPath);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
}
|
|
249
266
|
}
|
|
250
267
|
|
|
251
268
|
async function build(platform) {
|
|
@@ -256,6 +273,7 @@ async function build(platform) {
|
|
|
256
273
|
}
|
|
257
274
|
|
|
258
275
|
function buildLib(platform) {
|
|
276
|
+
let isChanged = false;
|
|
259
277
|
state.platforms[platform].forEach((p) => {
|
|
260
278
|
if (!fs.existsSync(`${state.config.paths.output}/prebuilt/${p}/lib`)) {
|
|
261
279
|
createLib(p, 'Source', { isProd: true, buildSource: true });
|
|
@@ -272,17 +290,22 @@ function buildLib(platform) {
|
|
|
272
290
|
const fileName = modulePath.split('/').at(-1);
|
|
273
291
|
fs.copyFileSync(modulePath, `${state.config.paths.output}/prebuilt/${p}/swig/${fileName}`);
|
|
274
292
|
});
|
|
293
|
+
isChanged = true;
|
|
275
294
|
} else {
|
|
276
295
|
console.log(`${state.config.general.name} is already compiled to ${p} architecture.`);
|
|
277
296
|
}
|
|
278
297
|
});
|
|
279
298
|
|
|
280
|
-
fs.
|
|
299
|
+
if (isChanged && fs.existsSync(`${state.config.paths.build}/Source-Release/prebuilt`)) {
|
|
300
|
+
fs.cpSync(`${state.config.paths.build}/Source-Release/prebuilt`, `${state.config.paths.output}/prebuilt`, { recursive: true, dereference: true });
|
|
301
|
+
}
|
|
281
302
|
|
|
282
303
|
createXCFramework();
|
|
283
304
|
|
|
284
305
|
const distCmakeContent = fs.readFileSync(`${state.config.paths.cli}/assets/dist.cmake`, { encoding: 'utf8', flag: 'r' })
|
|
285
|
-
.replace('___PROJECT_NAME___', state.config.general.name)
|
|
306
|
+
.replace('___PROJECT_NAME___', state.config.general.name)
|
|
307
|
+
.replace('___PROJECT_HOST___', state.platforms[platform].join(';'))
|
|
308
|
+
.replace('___PROJECT_LIBS___', state.config.export.libName.join(';'));
|
|
286
309
|
fs.writeFileSync(`${state.config.paths.output}/prebuilt/CMakeLists.txt`, distCmakeContent);
|
|
287
310
|
}
|
|
288
311
|
|
|
@@ -323,4 +346,7 @@ async function createWasmJs() {
|
|
|
323
346
|
if (fs.existsSync(`${state.config.paths.build}/${state.config.general.name}.data.txt`)) {
|
|
324
347
|
fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.data.txt`, `${state.config.paths.output}/${state.config.general.name}.data.txt`);
|
|
325
348
|
}
|
|
349
|
+
/* if (fs.existsSync(`${state.config.paths.build}/${state.config.general.name}.js`)) {
|
|
350
|
+
fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.js`, `${state.config.paths.output}/${state.config.general.name}.js`);
|
|
351
|
+
} */
|
|
326
352
|
}
|
|
@@ -36,7 +36,7 @@ export default function getCppJsScript(platform, bridgePath = null) {
|
|
|
36
36
|
|
|
37
37
|
function getReactNativeScript(env, modulePrefix) {
|
|
38
38
|
return `
|
|
39
|
-
import { NativeModules
|
|
39
|
+
import { NativeModules } from 'react-native';
|
|
40
40
|
import Module from '@cpp.js/core-embind-jsi';
|
|
41
41
|
|
|
42
42
|
const { RNJsiLib } = NativeModules;
|
|
@@ -46,20 +46,18 @@ function getReactNativeScript(env, modulePrefix) {
|
|
|
46
46
|
const CPPJS_DATA_PATH = Module.CppJS.getEnv('CPPJS_DATA_PATH');
|
|
47
47
|
|
|
48
48
|
Object.entries(env).forEach(([key, value]) => {
|
|
49
|
-
Module.CppJS.setEnv(key, value.replace('_CPPJS_DATA_PATH_', CPPJS_DATA_PATH),
|
|
49
|
+
Module.CppJS.setEnv(key, value.replace('_CPPJS_DATA_PATH_', CPPJS_DATA_PATH), false);
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export function initCppJs(config = {}) {
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
54
|
+
return new Promise(async (resolve, reject) => {
|
|
55
55
|
if (RNJsiLib && RNJsiLib.start) {
|
|
56
|
-
RNJsiLib.start();
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
resolve(Module);
|
|
62
|
-
}, Platform.OS === 'android' ? 2000 : 0);
|
|
56
|
+
await RNJsiLib.start();
|
|
57
|
+
setEnv();
|
|
58
|
+
const m = Module;
|
|
59
|
+
${modulePrefix}
|
|
60
|
+
resolve(Module);
|
|
63
61
|
} else {
|
|
64
62
|
reject('Module failed to initialise.');
|
|
65
63
|
}
|
|
@@ -74,7 +72,8 @@ function getWebScript(env, modulePrefix) {
|
|
|
74
72
|
env: {...${env}, ...config.env},
|
|
75
73
|
paths: {
|
|
76
74
|
wasm: 'cpp.wasm',
|
|
77
|
-
data: 'cpp.data.txt'
|
|
75
|
+
data: 'cpp.data.txt',
|
|
76
|
+
worker: 'cpp.js'
|
|
78
77
|
}
|
|
79
78
|
}`;
|
|
80
79
|
|
package/src/state/index.js
CHANGED
|
@@ -45,19 +45,22 @@ function setAllDependecyPaths() {
|
|
|
45
45
|
state.config.allDependencyPaths = {};
|
|
46
46
|
state.platforms.All.forEach((platform) => {
|
|
47
47
|
const basePlatform = platform.split('-', 1)[0];
|
|
48
|
-
state.config.allDependencyPaths[platform] = {};
|
|
48
|
+
state.config.allDependencyPaths[platform] = { cmake: {} };
|
|
49
49
|
state.config.allDependencies.forEach((d) => {
|
|
50
|
+
state.config.allDependencyPaths[platform].cmake[d.general.name] = `${d.paths.output}/prebuilt`;
|
|
50
51
|
d.export.libName.forEach((name) => {
|
|
51
52
|
state.config.allDependencyPaths[platform][name] = {
|
|
52
53
|
root: `${d.paths.output}/prebuilt/${platform}`,
|
|
53
54
|
};
|
|
55
|
+
const platformConfig = d.platform[platform] || {};
|
|
56
|
+
const isDynamicLib = basePlatform === 'Android' && platformConfig.libType !== 'static';
|
|
54
57
|
const dep = state.config.allDependencyPaths[platform][name];
|
|
55
58
|
if (basePlatform === 'iOS') {
|
|
56
59
|
let xcRoot;
|
|
57
60
|
if (platform === 'iOS-iphoneos') {
|
|
58
61
|
xcRoot = `${d.paths.project}/${name}.xcframework/ios-arm64_arm64e`;
|
|
59
62
|
} else if (platform === 'iOS-iphonesimulator') {
|
|
60
|
-
xcRoot = `${d.paths.project}/${name}.xcframework/ios-
|
|
63
|
+
xcRoot = `${d.paths.project}/${name}.xcframework/ios-arm64_x86_64-simulator`;
|
|
61
64
|
}
|
|
62
65
|
dep.header = `${xcRoot}/Headers`;
|
|
63
66
|
dep.libPath = xcRoot;
|
|
@@ -66,7 +69,7 @@ function setAllDependecyPaths() {
|
|
|
66
69
|
} else {
|
|
67
70
|
dep.header = `${dep.root}/include`;
|
|
68
71
|
dep.libPath = `${dep.root}/lib`;
|
|
69
|
-
dep.lib = `${dep.libPath}/lib${name}.${
|
|
72
|
+
dep.lib = `${dep.libPath}/lib${name}.${isDynamicLib ? 'so' : 'a'}`;
|
|
70
73
|
dep.bin = `${dep.root}/bin`;
|
|
71
74
|
}
|
|
72
75
|
});
|
package/src/state/loadConfig.js
CHANGED
|
@@ -12,7 +12,12 @@ import calculateDependencyParameters from './calculateDependencyParameters.js';
|
|
|
12
12
|
export default async function loadConfig(configDir = process.cwd(), configName = 'cppjs.config') {
|
|
13
13
|
const config = await loadJs(configDir, configName) || {};
|
|
14
14
|
const output = getFilledConfig(config);
|
|
15
|
-
|
|
15
|
+
const build = await loadJs(configDir, 'cppjs.build');
|
|
16
|
+
|
|
17
|
+
if (build) {
|
|
18
|
+
build.withBuildConfig = true;
|
|
19
|
+
}
|
|
20
|
+
output.build = { ...build, ...output.build };
|
|
16
21
|
|
|
17
22
|
output.paths.systemConfig = `${os.homedir()}/.cppjs.json`;
|
|
18
23
|
output.system = loadJson(output.paths.systemConfig) || {};
|
|
@@ -34,6 +39,8 @@ function getFilledConfig(config, options = { isDepend: false }) {
|
|
|
34
39
|
ext: config.ext || {},
|
|
35
40
|
export: config.export || {},
|
|
36
41
|
platform: config.platform || {},
|
|
42
|
+
build: config.build || {},
|
|
43
|
+
extensions: config.extensions || [],
|
|
37
44
|
package: null,
|
|
38
45
|
};
|
|
39
46
|
|
|
@@ -97,6 +104,16 @@ function getFilledConfig(config, options = { isDepend: false }) {
|
|
|
97
104
|
return Object.values(output);
|
|
98
105
|
})();
|
|
99
106
|
|
|
107
|
+
newConfig.extensions?.forEach(e => {
|
|
108
|
+
e?.loadConfig?.after(newConfig);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
newConfig.build.usePthread = newConfig.build.usePthread || false;
|
|
112
|
+
|
|
113
|
+
if (!newConfig.build.usePthread) {
|
|
114
|
+
newConfig.build.usePthread = newConfig.allDependencies.some((d) => d?.build?.usePthread);
|
|
115
|
+
}
|
|
116
|
+
|
|
100
117
|
newConfig.dependencyParameters = calculateDependencyParameters(newConfig);
|
|
101
118
|
// newConfig.cmakeParameters = getCmakeParameters(newConfig);
|
|
102
119
|
|
|
@@ -23,7 +23,16 @@ function downloadFile(url, folder) {
|
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
const parsedUrl = new URL(url);
|
|
27
|
+
const options = {
|
|
28
|
+
hostname: parsedUrl.hostname,
|
|
29
|
+
path: parsedUrl.pathname + parsedUrl.search,
|
|
30
|
+
headers: {
|
|
31
|
+
'User-Agent': 'curl/8.7.1',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
fr.https.get(options, (res) => {
|
|
27
36
|
const fileStream = fs.createWriteStream(`${folder}/${filename}`);
|
|
28
37
|
res.pipe(fileStream);
|
|
29
38
|
|
package/src/utils/findFiles.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { glob } from 'glob';
|
|
2
2
|
|
|
3
3
|
export default function findFiles(regex, options = {}) {
|
|
4
|
-
return glob.sync(regex, { absolute: true, posix: true, ...options }).map(p => p.replace('//?/', ''));
|
|
4
|
+
return glob.sync(regex, { absolute: true, posix: true, follow: true, ...options }).map(p => p.replace('//?/', ''));
|
|
5
5
|
}
|