cpp.js 2.0.0-beta.3 → 2.0.0-beta.4
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/package.json +1 -1
- package/src/actions/buildJs.js +12 -18
- package/src/actions/buildWasm.js +42 -37
- package/src/actions/createInterface.js +10 -10
- package/src/actions/createLib.js +56 -32
- package/src/actions/createXCFramework.js +39 -21
- package/src/actions/getCmakeParameters.js +12 -18
- package/src/actions/getData.js +21 -21
- package/src/actions/getDependLibs.js +11 -5
- package/src/actions/run.js +21 -22
- package/src/actions/target.js +53 -0
- package/src/assets/CMakeLists.txt +0 -12
- package/src/assets/browser.js +3 -4
- package/src/assets/cppjs-package.podspec +14 -0
- package/src/assets/dist.cmake +9 -34
- package/src/assets/node.js +4 -4
- package/src/bin.js +81 -41
- package/src/index.js +1 -0
- package/src/integration/getCppJsScript.js +5 -5
- package/src/integration/getDependFilePath.js +4 -4
- package/src/state/calculateDependencyParameters.js +21 -18
- package/src/state/index.js +192 -18
- package/src/state/loadConfig.js +14 -13
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import state from '../state/index.js';
|
|
3
3
|
|
|
4
|
-
export default function getDependFilePath(source,
|
|
4
|
+
export default function getDependFilePath(source, target) {
|
|
5
5
|
const headerRegex = new RegExp(`\\.(${state.config.ext.header.join('|')})$`);
|
|
6
6
|
const moduleRegex = new RegExp(`\\.(${state.config.ext.module.join('|')})$`);
|
|
7
7
|
|
|
@@ -13,11 +13,11 @@ export default function getDependFilePath(source, platform) {
|
|
|
13
13
|
|
|
14
14
|
let path;
|
|
15
15
|
if (headerRegex.test(source)) {
|
|
16
|
-
path = `${dependPackage.paths.output}/prebuilt/${
|
|
16
|
+
path = `${dependPackage.paths.output}/prebuilt/${target.path}/include`;
|
|
17
17
|
} else if (moduleRegex.test(source)) {
|
|
18
|
-
path = `${dependPackage.paths.output}/prebuilt/${
|
|
18
|
+
path = `${dependPackage.paths.output}/prebuilt/${target.path}/swig`;
|
|
19
19
|
} else {
|
|
20
|
-
path = `${dependPackage.paths.output}/prebuilt/${
|
|
20
|
+
path = `${dependPackage.paths.output}/prebuilt/${target.path}`;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
if (fs.existsSync(`${path}/${configName}/${filePath}`)) {
|
|
@@ -27,23 +27,32 @@ export default function calculateDependencyParameters(config) {
|
|
|
27
27
|
setPath(cmakeDepends, config, 'this', cmakeFilter);
|
|
28
28
|
cmakeDepends = [...new Set(cmakeDepends)];
|
|
29
29
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
const getCmakeDepends = (target, variants = []) => {
|
|
31
|
+
return cmakeDepends.filter(d => d.functions.isEnabled(target, variants));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const getCmakeDependsPathAndName = (target, variants = []) => {
|
|
35
|
+
const pathsOfCmakeDepends = [];
|
|
36
|
+
const nameOfCmakeDepends = [];
|
|
37
|
+
getCmakeDepends(target, variants).forEach((d) => {
|
|
38
|
+
const dependPath = d.paths.cmakeDir;
|
|
39
|
+
if (!pathsOfCmakeDepends.includes(dependPath)) {
|
|
40
|
+
pathsOfCmakeDepends.push(dependPath);
|
|
41
|
+
nameOfCmakeDepends.push(d.general.name);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
pathsOfCmakeDepends: pathsOfCmakeDepends,
|
|
46
|
+
nameOfCmakeDepends: nameOfCmakeDepends,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
39
49
|
|
|
40
50
|
return {
|
|
41
51
|
nativeGlob,
|
|
42
52
|
headerGlob,
|
|
43
53
|
headerPathWithDepends,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
nameOfCmakeDepends: nameOfCmakeDepends.join(';'),
|
|
54
|
+
getCmakeDepends,
|
|
55
|
+
getCmakeDependsPathAndName,
|
|
47
56
|
};
|
|
48
57
|
}
|
|
49
58
|
|
|
@@ -62,9 +71,3 @@ function setPath(arr, dependency, type, filter = () => { }) {
|
|
|
62
71
|
setPath(arr, dep, type, filter);
|
|
63
72
|
});
|
|
64
73
|
}
|
|
65
|
-
|
|
66
|
-
function getParentPath(path) {
|
|
67
|
-
const pathArray = path.split('/');
|
|
68
|
-
pathArray.pop();
|
|
69
|
-
return pathArray.join('/');
|
|
70
|
-
}
|
package/src/state/index.js
CHANGED
|
@@ -5,12 +5,168 @@ import loadConfig from './loadConfig.js';
|
|
|
5
5
|
const cacheDir = `${process.cwd()}/.cppjs`;
|
|
6
6
|
|
|
7
7
|
const state = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
targets: [
|
|
9
|
+
{
|
|
10
|
+
platform: 'wasm',
|
|
11
|
+
arch: 'wasm32',
|
|
12
|
+
runtime: 'st',
|
|
13
|
+
buildType: 'release',
|
|
14
|
+
runtimeEnv: 'browser',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
platform: 'wasm',
|
|
18
|
+
arch: 'wasm32',
|
|
19
|
+
runtime: 'st',
|
|
20
|
+
buildType: 'release',
|
|
21
|
+
runtimeEnv: 'node',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
platform: 'wasm',
|
|
25
|
+
arch: 'wasm32',
|
|
26
|
+
runtime: 'st',
|
|
27
|
+
buildType: 'debug',
|
|
28
|
+
runtimeEnv: 'browser',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
platform: 'wasm',
|
|
32
|
+
arch: 'wasm32',
|
|
33
|
+
runtime: 'st',
|
|
34
|
+
buildType: 'debug',
|
|
35
|
+
runtimeEnv: 'node',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
platform: 'wasm',
|
|
39
|
+
arch: 'wasm32',
|
|
40
|
+
runtime: 'mt',
|
|
41
|
+
buildType: 'release',
|
|
42
|
+
runtimeEnv: 'browser',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
platform: 'wasm',
|
|
46
|
+
arch: 'wasm32',
|
|
47
|
+
runtime: 'mt',
|
|
48
|
+
buildType: 'release',
|
|
49
|
+
runtimeEnv: 'node',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
platform: 'wasm',
|
|
53
|
+
arch: 'wasm32',
|
|
54
|
+
runtime: 'mt',
|
|
55
|
+
buildType: 'debug',
|
|
56
|
+
runtimeEnv: 'browser',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
platform: 'wasm',
|
|
60
|
+
arch: 'wasm32',
|
|
61
|
+
runtime: 'mt',
|
|
62
|
+
buildType: 'debug',
|
|
63
|
+
runtimeEnv: 'node',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
platform: 'wasm',
|
|
67
|
+
arch: 'wasm64',
|
|
68
|
+
runtime: 'st',
|
|
69
|
+
buildType: 'release',
|
|
70
|
+
runtimeEnv: 'browser',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
platform: 'wasm',
|
|
74
|
+
arch: 'wasm64',
|
|
75
|
+
runtime: 'st',
|
|
76
|
+
buildType: 'release',
|
|
77
|
+
runtimeEnv: 'node',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
platform: 'wasm',
|
|
81
|
+
arch: 'wasm64',
|
|
82
|
+
runtime: 'st',
|
|
83
|
+
buildType: 'debug',
|
|
84
|
+
runtimeEnv: 'browser',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
platform: 'wasm',
|
|
88
|
+
arch: 'wasm64',
|
|
89
|
+
runtime: 'st',
|
|
90
|
+
buildType: 'debug',
|
|
91
|
+
runtimeEnv: 'node',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
platform: 'wasm',
|
|
95
|
+
arch: 'wasm64',
|
|
96
|
+
runtime: 'mt',
|
|
97
|
+
buildType: 'release',
|
|
98
|
+
runtimeEnv: 'browser',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
platform: 'wasm',
|
|
102
|
+
arch: 'wasm64',
|
|
103
|
+
runtime: 'mt',
|
|
104
|
+
buildType: 'release',
|
|
105
|
+
runtimeEnv: 'node',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
platform: 'wasm',
|
|
109
|
+
arch: 'wasm64',
|
|
110
|
+
runtime: 'mt',
|
|
111
|
+
buildType: 'debug',
|
|
112
|
+
runtimeEnv: 'browser',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
platform: 'wasm',
|
|
116
|
+
arch: 'wasm64',
|
|
117
|
+
runtime: 'mt',
|
|
118
|
+
buildType: 'debug',
|
|
119
|
+
runtimeEnv: 'node',
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
platform: 'android',
|
|
123
|
+
arch: 'arm64-v8a',
|
|
124
|
+
runtime: 'mt',
|
|
125
|
+
buildType: 'release',
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
platform: 'android',
|
|
129
|
+
arch: 'arm64-v8a',
|
|
130
|
+
runtime: 'mt',
|
|
131
|
+
buildType: 'debug',
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
platform: 'android',
|
|
135
|
+
arch: 'x86_64',
|
|
136
|
+
runtime: 'mt',
|
|
137
|
+
buildType: 'release',
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
platform: 'android',
|
|
141
|
+
arch: 'x86_64',
|
|
142
|
+
runtime: 'mt',
|
|
143
|
+
buildType: 'debug',
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
platform: 'ios',
|
|
147
|
+
arch: 'iphoneos',
|
|
148
|
+
runtime: 'mt',
|
|
149
|
+
buildType: 'release',
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
platform: 'ios',
|
|
153
|
+
arch: 'iphoneos',
|
|
154
|
+
runtime: 'mt',
|
|
155
|
+
buildType: 'debug',
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
platform: 'ios',
|
|
159
|
+
arch: 'iphonesimulator',
|
|
160
|
+
runtime: 'mt',
|
|
161
|
+
buildType: 'release',
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
platform: 'ios',
|
|
165
|
+
arch: 'iphonesimulator',
|
|
166
|
+
runtime: 'mt',
|
|
167
|
+
buildType: 'debug',
|
|
168
|
+
},
|
|
169
|
+
],
|
|
14
170
|
config: null,
|
|
15
171
|
cache: {
|
|
16
172
|
hashes: {},
|
|
@@ -30,6 +186,19 @@ await initProcessState();
|
|
|
30
186
|
async function initProcessState() {
|
|
31
187
|
state.cache = loadCacheState();
|
|
32
188
|
state.config = await loadConfig();
|
|
189
|
+
|
|
190
|
+
state.targets.forEach((target) => {
|
|
191
|
+
target.path = `${target.platform}-${target.arch}-${target.runtime}-${target.buildType}`;
|
|
192
|
+
target.releasePath = `${target.platform}-${target.arch}-${target.runtime}-release`;
|
|
193
|
+
if (target.runtimeEnv && target.platform === 'wasm') {
|
|
194
|
+
target.rawJsName = `${state.config.general.name}-${target.path}.js`;
|
|
195
|
+
target.jsName = `${state.config.general.name}-${target.path}.${target.runtimeEnv}.js`;
|
|
196
|
+
target.wasmName = `${state.config.general.name}-${target.path}.wasm`;
|
|
197
|
+
target.dataName = `${state.config.general.name}-${target.path}.data`;
|
|
198
|
+
target.dataTxtName = `${state.config.general.name}-${target.path}.data.txt`;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
33
202
|
setAllDependecyPaths();
|
|
34
203
|
if (state.config.build?.setState) {
|
|
35
204
|
state.config.build.setState(state);
|
|
@@ -43,23 +212,28 @@ function loadCacheState() {
|
|
|
43
212
|
|
|
44
213
|
function setAllDependecyPaths() {
|
|
45
214
|
state.config.allDependencyPaths = {};
|
|
46
|
-
state.
|
|
47
|
-
|
|
48
|
-
state.config.allDependencyPaths[platform] = { cmake: {} };
|
|
215
|
+
state.targets.forEach((target) => {
|
|
216
|
+
state.config.allDependencyPaths[target.path] = { cmake: {} };
|
|
49
217
|
state.config.allDependencies.forEach((d) => {
|
|
50
|
-
state.config.allDependencyPaths[
|
|
218
|
+
state.config.allDependencyPaths[target.path].cmake[d.general.name] = `${d.paths.output}/prebuilt`;
|
|
51
219
|
d.export.libName.forEach((name) => {
|
|
52
|
-
state.config.allDependencyPaths[
|
|
53
|
-
root: `${d.paths.output}/prebuilt/${
|
|
220
|
+
state.config.allDependencyPaths[target.path][name] = {
|
|
221
|
+
root: `${d.paths.output}/prebuilt/${target.path}`,
|
|
54
222
|
};
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
223
|
+
const entryArray = d?.targetSpecs?.filter(t => (
|
|
224
|
+
(!t.platform || t.platform === target.platform)
|
|
225
|
+
&& (!t.arch || t.arch === target.arch)
|
|
226
|
+
&& (!t.runtime || t.runtime === target.runtime)
|
|
227
|
+
&& (!t.buildType || t.buildType === target.buildType)
|
|
228
|
+
)).map(t => t?.specs);
|
|
229
|
+
const platformConfig = Object.assign({}, ...entryArray);
|
|
230
|
+
const isDynamicLib = target.platform === 'android' && platformConfig.libType !== 'static';
|
|
231
|
+
const dep = state.config.allDependencyPaths[target.path][name];
|
|
232
|
+
if (target.platform === 'ios') {
|
|
59
233
|
let xcRoot;
|
|
60
|
-
if (
|
|
234
|
+
if (target.arch === 'iphoneos') {
|
|
61
235
|
xcRoot = `${d.paths.project}/${name}.xcframework/ios-arm64_arm64e`;
|
|
62
|
-
} else if (
|
|
236
|
+
} else if (target.arch === 'iphonesimulator') {
|
|
63
237
|
xcRoot = `${d.paths.project}/${name}.xcframework/ios-arm64_x86_64-simulator`;
|
|
64
238
|
}
|
|
65
239
|
dep.header = `${xcRoot}/Headers`;
|
package/src/state/loadConfig.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
|
+
import fs from 'node:fs';
|
|
2
3
|
import systemKeys from '../utils/systemKeys.js';
|
|
3
4
|
import loadJs from '../utils/loadJs.js';
|
|
4
5
|
import loadJson from '../utils/loadJson.js';
|
|
@@ -38,10 +39,12 @@ function getFilledConfig(config, options = { isDepend: false }) {
|
|
|
38
39
|
paths: config.paths || {},
|
|
39
40
|
ext: config.ext || {},
|
|
40
41
|
export: config.export || {},
|
|
41
|
-
|
|
42
|
+
targetSpecs: config.targetSpecs || [],
|
|
42
43
|
build: config.build || {},
|
|
44
|
+
target: config.target || {},
|
|
43
45
|
extensions: config.extensions || [],
|
|
44
46
|
package: null,
|
|
47
|
+
functions: config.functions || {},
|
|
45
48
|
};
|
|
46
49
|
|
|
47
50
|
if (newConfig.paths.config && !newConfig.paths.project) {
|
|
@@ -88,14 +91,6 @@ function getFilledConfig(config, options = { isDepend: false }) {
|
|
|
88
91
|
newConfig.export.libName = newConfig.export.libName || [newConfig.general.name];
|
|
89
92
|
newConfig.export.binHeaders = newConfig.export.binHeaders || [];
|
|
90
93
|
|
|
91
|
-
newConfig.platform['Emscripten-x86_64'] = newConfig.platform['Emscripten-x86_64'] || {};
|
|
92
|
-
newConfig.platform['Emscripten-x86_64-browser'] = newConfig.platform['Emscripten-x86_64-browser'] || {};
|
|
93
|
-
newConfig.platform['Emscripten-x86_64-node'] = newConfig.platform['Emscripten-x86_64-node'] || {};
|
|
94
|
-
newConfig.platform['Android-arm64-v8a'] = newConfig.platform['Android-arm64-v8a'] || {};
|
|
95
|
-
newConfig.platform['Android-x86_64'] = newConfig.platform['Android-x86_64'] || {};
|
|
96
|
-
newConfig.platform['iOS-iphoneos'] = newConfig.platform['iOS-iphoneos'] || {};
|
|
97
|
-
newConfig.platform['iOS-iphonesimulator'] = newConfig.platform['iOS-iphonesimulator'] || {};
|
|
98
|
-
|
|
99
94
|
newConfig.allDependencies = (() => {
|
|
100
95
|
const output = {};
|
|
101
96
|
[...newConfig.dependencies, ...newConfig.dependencies.map((d) => d.allDependencies).flat()].forEach((d) => {
|
|
@@ -108,12 +103,18 @@ function getFilledConfig(config, options = { isDepend: false }) {
|
|
|
108
103
|
e?.loadConfig?.after(newConfig);
|
|
109
104
|
});
|
|
110
105
|
|
|
111
|
-
newConfig.
|
|
112
|
-
|
|
113
|
-
if (!newConfig.build.usePthread) {
|
|
114
|
-
newConfig.build.usePthread = newConfig.allDependencies.some((d) => d?.build?.usePthread);
|
|
106
|
+
if (newConfig.target.runtime !== 'mt' && newConfig.allDependencies.some((d) => d?.target?.runtime === 'mt')) {
|
|
107
|
+
newConfig.target.runtime = 'mt';
|
|
115
108
|
}
|
|
116
109
|
|
|
110
|
+
newConfig.functions.isEnabled = newConfig.functions.isEnabled || ((target) => {
|
|
111
|
+
return (
|
|
112
|
+
fs.existsSync(`${newConfig.paths.cmakeDir}/${target.path}`)
|
|
113
|
+
|| fs.existsSync(`${newConfig.paths.cmakeDir}/${target.releasePath}`)
|
|
114
|
+
|| (target.platform === 'ios' && fs.existsSync(`${newConfig.paths.cmakeDir}/../../${newConfig.general.name}-${target.runtime}.xcframework`))
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
|
|
117
118
|
newConfig.dependencyParameters = calculateDependencyParameters(newConfig);
|
|
118
119
|
// newConfig.cmakeParameters = getCmakeParameters(newConfig);
|
|
119
120
|
|