cpp.js 0.6.1 → 1.0.0-alpha.3

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.
@@ -1,199 +1,68 @@
1
- import { execFileSync } from 'child_process';
2
- import glob from 'glob';
3
- import pullDockerImage, { getDockerImage } from '../utils/pullDockerImage.js';
4
- import getBaseInfo from '../utils/getBaseInfo.js';
1
+ import fs from 'fs';
2
+ import buildJS from './buildJS.js';
3
+ import run from './run.js';
4
+ import getCmakeParams from './getCmakeParams.js';
5
+ import getLibs from './getLibs.js';
6
+ import getData from './getData.js';
5
7
  import getPathInfo from '../utils/getPathInfo.js';
6
- import getOsUserAndGroupId from '../utils/getOsUserAndGroupId.js';
7
- import { getCliCMakeListsFile } from '../utils/findCMakeListsFile.js'
8
8
 
9
- export default function createWasm(compiler, options = {}) {
10
- const compiler2 = new CppjsCompiler(
11
- compiler.config,
12
- options,
13
- );
14
- return compiler2.compileToWasm();
15
- }
16
-
17
- export function getCmakeParams(compiler, options = {}) {
18
- const compiler2 = new CppjsCompiler(
19
- compiler.config,
20
- options,
21
- );
22
-
23
- compiler2.prepare();
24
- return compiler2.getCmakeParams(compiler.config.general.name, true, true);
25
- }
26
-
27
- function setPath(arr, dependency, type, filter = () => {}) {
28
- if (filter(dependency)) {
29
- if (type === 'this') {
30
- arr.push(dependency);
31
- } else if (Array.isArray(dependency.paths[type])) {
32
- arr.push(...dependency.paths[type]);
33
- } else {
34
- arr.push(dependency.paths[type]);
9
+ export default async function createWasm(compiler, options, buildAll = false) {
10
+ const output = `/tmp/cppjs/live/${getPathInfo(compiler.config.paths.temp, compiler.config.paths.base).relative}`;
11
+
12
+ let params = getCmakeParams(compiler.config, '/tmp/cppjs/live/', true, false);
13
+ run(compiler, 'emcmake', [
14
+ 'cmake', '/tmp/cppjs/cmake',
15
+ '-DCMAKE_BUILD_TYPE=Release', '-DBUILD_TYPE=STATIC',
16
+ `-DCMAKE_INSTALL_PREFIX=${output}`, `-DPROJECT_NAME=${compiler.config.general.name}`,
17
+ ...params,
18
+ ]);
19
+ run(compiler, 'emmake', ['make', 'install']);
20
+
21
+ params = getCmakeParams(compiler.config, '/tmp/cppjs/live/', false, true);
22
+ run(compiler, 'emcmake', [
23
+ 'cmake', '/tmp/cppjs/cmake',
24
+ '-DCMAKE_BUILD_TYPE=Release', '-DBUILD_TYPE=STATIC',
25
+ `-DCMAKE_INSTALL_PREFIX=${output}`, `-DPROJECT_NAME=${compiler.config.general.name}bridge`,
26
+ ...params,
27
+ ]);
28
+ run(compiler, 'emmake', ['make', 'install']);
29
+
30
+ const libs = getLibs(compiler.config, '/tmp/cppjs/live/');
31
+ const data = Object.entries(getData(compiler.config, 'data', '/tmp/cppjs/live/', 'Emscripten-x86_64', 'browser')).map(([key, value]) => ['--preload-file', `${key}@${value}`]).flat();
32
+ run(compiler, 'emcc', [
33
+ '-lembind', '-Wl,--whole-archive',
34
+ ...libs, ...(options.cc || []),
35
+ '-s', 'WASM=1', '-s', 'MODULARIZE=1',
36
+ '-s', 'RESERVED_FUNCTION_POINTERS=200', '-s', 'DISABLE_EXCEPTION_CATCHING=0', '-s', 'FORCE_FILESYSTEM=1',
37
+ '-s', 'TOTAL_MEMORY=512MB', '-s', 'ALLOW_MEMORY_GROWTH=1',
38
+ '-s', 'EXPORTED_RUNTIME_METHODS=["FS", "ENV"]',
39
+ '-o', `${output}/${compiler.config.general.name}.js`,
40
+ ...data,
41
+ ]);
42
+ await buildJS(compiler, `${output}/${compiler.config.general.name}.js`, 'browser');
43
+ run(compiler, 'emcc', [
44
+ '-lembind', '-Wl,--whole-archive', '-lnodefs.js',
45
+ ...libs, ...(options.cc || []),
46
+ '-s', 'WASM=1', '-s', 'MODULARIZE=1',
47
+ '-s', 'RESERVED_FUNCTION_POINTERS=200', '-s', 'DISABLE_EXCEPTION_CATCHING=0', '-s', 'FORCE_FILESYSTEM=1', '-s', 'NODERAWFS',
48
+ '-s', 'TOTAL_MEMORY=512MB', '-s', 'ALLOW_MEMORY_GROWTH=1',
49
+ '-s', 'EXPORTED_RUNTIME_METHODS=["FS", "ENV", "NODEFS"]',
50
+ '-o', `${output}/${compiler.config.general.name}.js`,
51
+ ]);
52
+ Object.entries(getData(compiler.config, 'data', null, 'Emscripten-x86_64', 'node')).forEach(([key, value]) => {
53
+ if (fs.existsSync(key)) {
54
+ const dAssetPath = `${output}/data/${value}`;
55
+ if (!fs.existsSync(dAssetPath)) {
56
+ fs.mkdirSync(dAssetPath, { recursive: true });
57
+ fs.cpSync(key, dAssetPath, { recursive: true });
58
+ }
35
59
  }
36
- }
37
-
38
- dependency.dependencies.forEach(dep => {
39
- setPath(arr, dep, type, filter);
40
60
  });
41
- }
42
-
43
- function getParentPath(path) {
44
- const pathArray = path.split('/');
45
- pathArray.pop();
46
- return pathArray.join('/');
47
- }
48
-
49
-
50
- class CppjsCompiler {
51
- constructor(config, options) {
52
- this.config = config;
53
- this.options = options;
54
- this.pathType = 'absolute';
55
- this.pathPrefix = '';
56
- }
57
-
58
- getPath(path) {
59
- if (this.pathType === 'absolute') {
60
- return getPathInfo(path, this.config.paths.base).absolute;
61
- } else if (this.pathType === 'relative') {
62
- return `${this.pathPrefix}${getPathInfo(path, this.config.paths.base).relative}`
63
- }
64
-
65
- return '';
66
- }
67
-
68
- compileToWasm() {
69
- pullDockerImage();
70
-
71
- this.pathType = 'relative';
72
- this.pathPrefix = '/live/';
73
-
74
- this.prepare();
75
- this.cmake(this.config.general.name, true, false);
76
- this.make();
77
- this.cmake(this.config.general.name+'bridge', false, true);
78
- this.make();
79
-
80
- const dependLibs = [
81
- ...glob.sync(`${this.config.paths.temp}/dependencies/**/*.a`, { absolute: true, cwd: this.config.paths.project }),
82
- ];
83
- this.cmakeDepends.forEach((d) => {
84
- dependLibs.push(...glob.sync(`${d.paths.output}/prebuilt/Emscripten-x86_64/**/*.a`, { absolute: true, cwd: d.paths.project }));
85
- });
86
-
87
- this.libs = [
88
- `${this.config.paths.temp}/lib${this.config.general.name}.a`,
89
- `${this.config.paths.temp}/lib${this.config.general.name}bridge.a`,
90
- ...dependLibs,
91
- ].filter(path => !!path.toString()).map(path => this.getPath(path));
92
-
93
- this.cc();
94
-
95
- return this.config.paths.temp;
96
- }
97
-
98
- prepare() {
99
- const sourceFilter = (d) => d === this.config || d.export.type === 'source';
100
- this.headerPathWithDepends = [];
101
- setPath(this.headerPathWithDepends, this.config, 'header', sourceFilter);
102
- this.headerPathWithDepends = this.headerPathWithDepends.map(p => this.getPath(p)).join(';');
103
-
104
- this.headerGlob = [];
105
- this.headerPathWithDepends.split(';').forEach(h => {
106
- this.config.ext.header.forEach(ext => {
107
- this.headerGlob.push(`${h}/*.${ext}`);
108
- });
109
- });
110
-
111
-
112
- this.nativePathWithDepends = [];
113
- setPath(this.nativePathWithDepends, this.config, 'native', sourceFilter);
114
- this.nativePathWithDepends = this.nativePathWithDepends.map(p => this.getPath(p)).join(';');
115
-
116
- this.nativeGlob = [];
117
- this.nativePathWithDepends.split(';').forEach(h => {
118
- this.config.ext.source.forEach(ext => {
119
- this.nativeGlob.push(`${h}/*.${ext}`);
120
- });
121
- });
122
-
123
- const cliCMakeListsFile = getCliCMakeListsFile();
124
- const cmakeFilter = (d) => d !== this.config && d.export.type === 'cmake' && d.paths.cmake !== cliCMakeListsFile;
125
- this.cmakeDepends = [];
126
- setPath(this.cmakeDepends, this.config, 'this', cmakeFilter);
127
-
128
- this.pathsOfCmakeDepends = this.cmakeDepends
129
- .map(d => getParentPath(d.paths.cmake))
130
- .map(p => this.getPath(p)).join(';');
131
- this.nameOfCmakeDepends = this.cmakeDepends.map(d => d.general.name).join(';');
61
+ await buildJS(compiler, `${output}/${compiler.config.general.name}.js`, 'node');
62
+ // await buildJS(compiler, `${output}/${compiler.config.general.name}.js`);
63
+ if (fs.existsSync(`${compiler.config.paths.temp}/${compiler.config.general.name}.data`)) {
64
+ fs.renameSync(`${compiler.config.paths.temp}/${compiler.config.general.name}.data`, `${compiler.config.paths.temp}/${compiler.config.general.name}.data.txt`);
132
65
  }
133
66
 
134
- getCmakeParams(name, isBuildSource, isBuildBridge) {
135
- const params = [];
136
- if (isBuildSource) params.push('-DBUILD_SOURCE=TRUE');
137
- if (isBuildBridge) params.push('-DBUILD_BRIDGE=TRUE');
138
-
139
- const output = this.getPath(this.config.paths.temp);
140
- const projectPath = this.getPath(process.cwd());
141
-
142
- params.push(...[
143
- `-DBASE_DIR=${projectPath}`,
144
- `-DNATIVE_GLOB=${this.nativeGlob.join(';')}`,
145
- `-DHEADER_GLOB=${this.headerGlob.join(';')}`,
146
- `-DHEADER_DIR=${this.headerPathWithDepends}`,
147
- `-DDEPENDS_CMAKE_PATHS=${this.pathsOfCmakeDepends}`,
148
- `-DDEPENDS_CMAKE_NAMES=${this.nameOfCmakeDepends}`,
149
- `-DBRIDGE_DIR=${output}/bridge`,
150
- ]);
151
-
152
- return params;
153
- }
154
-
155
- cmake(name, isBuildSource, isBuildBridge) {
156
- const params = this.getCmakeParams(name, isBuildSource, isBuildBridge);
157
-
158
- const output = this.getPath(this.config.paths.temp);
159
- const base = getBaseInfo(this.config.paths.base);
160
-
161
- const cMakeParentPath = getParentPath(this.config.paths.cmake);
162
-
163
- const args = [
164
- "run", "--user", getOsUserAndGroupId(), "-v", `${base.withoutSlash}:/live`, "-v", `${cMakeParentPath}:/cmake`, "--workdir", `${output}`, getDockerImage(),
165
- "emcmake", "cmake", "/cmake", '-DCMAKE_BUILD_TYPE=Release', '-DBUILD_TYPE=STATIC', `-DCMAKE_INSTALL_PREFIX=${output}`, `-DPROJECT_NAME=${name}`, ...params,
166
- ];
167
- const options = { cwd: this.config.paths.temp, stdio : 'pipe' };
168
- execFileSync("docker", args, options);
169
- return this.config.paths.temp;
170
- }
171
-
172
- make() {
173
- const output = this.getPath(this.config.paths.temp);
174
- const base = getBaseInfo(this.config.paths.base);
175
-
176
- let cMakeParentPath = this.config.paths.cmake.split('/');
177
- cMakeParentPath.pop();
178
- cMakeParentPath = cMakeParentPath.join('/');
179
- const args = [
180
- "run", "--user", getOsUserAndGroupId(), "-v", `${base.withoutSlash}:/live`, "-v", `${cMakeParentPath}:/cmake`, "--workdir", `${output}`, getDockerImage(),
181
- "emmake", "make", "install"
182
- ];
183
- const options = { cwd: this.config.paths.temp, stdio : 'pipe' };
184
- execFileSync("docker", args, options);
185
- return this.config.paths.temp;
186
- }
187
-
188
- cc() {
189
- const output = this.getPath(this.config.paths.temp);
190
- const base = getBaseInfo(this.config.paths.base);
191
- const args = [
192
- "run", "--user", getOsUserAndGroupId(), "-v", `${base.withoutSlash}:/live`, "-v", `${this.config.paths.cli}:/cli`, getDockerImage(),
193
- "emcc", "-lembind", "-Wl,--whole-archive", ...this.libs, ...(this.options.cc || []), "-s", "WASM=1", "-s", "MODULARIZE=1", '-o', `${output}/${this.config.general.name}.js`, '--extern-post-js', '/cli/assets/extern-post.js'
194
- ];
195
- const options = { cwd: this.config.paths.temp, stdio : 'pipe' };
196
- execFileSync("docker", args, options);
197
- return this.config.paths.temp;
198
- }
67
+ return compiler.config.paths.temp;
199
68
  }
@@ -1,28 +1,49 @@
1
+ /* eslint-disable prefer-destructuring */
1
2
  import fs from 'fs';
2
3
  import getBaseInfo from '../utils/getBaseInfo.js';
3
4
  import getPathInfo from '../utils/getPathInfo.js';
5
+ import { getDependencyParams } from './getCmakeParams.js';
4
6
 
5
7
  export default function findOrCreateInterfaceFile(compiler, filePath) {
8
+ const moduleRegex = new RegExp(`.(${compiler.config.ext.module.join('|')})$`);
9
+ if (moduleRegex.test(filePath) && fs.existsSync(filePath)) {
10
+ const newPath = `${compiler.config.paths.temp}/interface/${filePath.split('/').pop()}`;
11
+ fs.copyFileSync(filePath, newPath);
12
+ compiler.interfaces.push(newPath);
13
+ return filePath;
14
+ }
15
+
6
16
  const input = getPathInfo(filePath, compiler.config.paths.base);
7
- const output = getPathInfo(compiler.config.paths.temp+'/interface', compiler.config.paths.base);
17
+ const output = getPathInfo(`${compiler.config.paths.temp}/interface`, compiler.config.paths.base);
8
18
  const base = getBaseInfo(compiler.config.paths.base);
9
19
 
20
+ const headerPaths = (getDependencyParams(compiler.config)?.pathsOfCmakeDepends?.split(';') || [])
21
+ .filter((d) => d.startsWith(compiler.config.paths.base))
22
+ .map((d) => d.replace(`${compiler.config.paths.base}/`, ''));
23
+
24
+ const temp2 = headerPaths
25
+ .map((p) => input.relative.match(new RegExp(`^${p}/.*?/include/(.*?)$`, 'i')))
26
+ .filter((p) => p && p.length === 2);
27
+
10
28
  const temp = input.relative.match(/^(.*)\..+?$/);
11
29
  if (temp.length < 2) return null;
12
30
 
13
31
  const filePathWithoutExt = temp[1];
14
- const interfaceFile = filePathWithoutExt + '.i';
32
+ const interfaceFile = `${compiler.config.paths.base}/${filePathWithoutExt}.i`;
15
33
 
16
- if (fs.existsSync(interfaceFile)) return interfaceFile;
34
+ if (fs.existsSync(interfaceFile)) {
35
+ compiler.interfaces.push(interfaceFile);
36
+ return interfaceFile;
37
+ }
17
38
 
18
39
  const fileName = filePathWithoutExt.split('/').at(-1);
19
40
 
20
- let headerPath = compiler.config.paths.header.find(path => filePath.startsWith(path));
21
- if (headerPath) headerPath = filePath.substr(headerPath.length+1);
41
+ let headerPath = compiler.config.paths.header.find((path) => filePath.startsWith(path));
42
+ if (headerPath) headerPath = filePath.substr(headerPath.length + 1);
43
+ else if (temp2 && temp2.length > 0) headerPath = temp2[0][1];
22
44
  else headerPath = input.relative.split('/').at(-1);
23
45
 
24
- const content =
25
- `#ifndef _${fileName.toUpperCase()}_I
46
+ const content = `#ifndef _${fileName.toUpperCase()}_I
26
47
  #define _${fileName.toUpperCase()}_I
27
48
 
28
49
  %module ${fileName.toUpperCase()}
@@ -38,7 +59,7 @@ export default function findOrCreateInterfaceFile(compiler, filePath) {
38
59
 
39
60
  #endif
40
61
  `;
41
- const outputFilePath = base.withSlash + output.relative+'/'+fileName+'.i';
62
+ const outputFilePath = `${base.withSlash + output.relative}/${fileName}.i`;
42
63
  fs.writeFileSync(outputFilePath, content);
43
64
 
44
65
  compiler.interfaces.push(outputFilePath);
@@ -0,0 +1,43 @@
1
+ import fs from 'fs';
2
+ import { execFileSync } from 'child_process';
3
+ import getPathInfo from '../utils/getPathInfo.js';
4
+
5
+ export default function finishBuild(compiler) {
6
+ const output = getPathInfo(compiler.config.paths.output, compiler.config.paths.base);
7
+ if (
8
+ !fs.existsSync(`${output.absolute}/prebuilt/iOS-iphoneos/lib`)
9
+ || !fs.existsSync(`${output.absolute}/prebuilt/iOS-iphonesimulator/lib`)
10
+ ) return;
11
+
12
+ const options = {
13
+ cwd: `${output.absolute}/prebuilt`,
14
+ stdio: 'inherit',
15
+ };
16
+
17
+ compiler.config.export.libName.forEach((fileName) => {
18
+ if (!fs.existsSync(`${options.cwd}/${fileName}.xcframework`)) {
19
+ const params = [
20
+ '-create-xcframework',
21
+ '-library', `iOS-iphoneos/lib/lib${fileName}.a`,
22
+ '-headers', 'iOS-iphoneos/include',
23
+ '-library', `iOS-iphonesimulator/lib/lib${fileName}.a`,
24
+ '-headers', 'iOS-iphonesimulator/include',
25
+ '-output', `${fileName}.xcframework`,
26
+ ];
27
+ execFileSync('xcodebuild', params, options);
28
+ }
29
+
30
+ if (!fs.existsSync(`${options.cwd}/${fileName}.xcframework.zip`)) {
31
+ execFileSync('zip', ['-y', '-r', `./${fileName}.xcframework.zip`, `${fileName}.xcframework`], options);
32
+ }
33
+ if (!fs.existsSync(`${compiler.config.paths.project}/${fileName}.xcframework`)) {
34
+ fs.symlinkSync(`${options.cwd}/${fileName}.xcframework`, `${compiler.config.paths.project}/${fileName}.xcframework`);
35
+ }
36
+ });
37
+ /* if (fs.existsSync(`${output.absolute}/prebuilt/iOS-iphoneos`)) {
38
+ fs.rmSync(`${output.absolute}/prebuilt/iOS-iphoneos`, { recursive: true, force: true });
39
+ }
40
+ if (fs.existsSync(`${output.absolute}/prebuilt/iOS-iphonesimulator`)) {
41
+ fs.rmSync(`${output.absolute}/prebuilt/iOS-iphonesimulator`, { recursive: true, force: true });
42
+ } */
43
+ }
@@ -0,0 +1,106 @@
1
+ import getPathInfo from '../utils/getPathInfo.js';
2
+ import { getCliCMakeListsFile } from '../utils/findCMakeListsFile.js';
3
+
4
+ function setPath(arr, dependency, type, filter = () => {}) {
5
+ if (filter(dependency)) {
6
+ if (type === 'this') {
7
+ arr.push(dependency);
8
+ } else if (Array.isArray(dependency.paths[type])) {
9
+ arr.push(...dependency.paths[type]);
10
+ } else {
11
+ arr.push(dependency.paths[type]);
12
+ }
13
+ }
14
+
15
+ dependency.dependencies.forEach((dep) => {
16
+ setPath(arr, dep, type, filter);
17
+ });
18
+ }
19
+
20
+ function getParentPath(path) {
21
+ const pathArray = path.split('/');
22
+ pathArray.pop();
23
+ return pathArray.join('/');
24
+ }
25
+
26
+ function getPath(config, path, pathPrefix) {
27
+ if (!pathPrefix) {
28
+ return getPathInfo(path, config.paths.base).absolute;
29
+ }
30
+
31
+ return `${pathPrefix}${getPathInfo(path, config.paths.base).relative}`;
32
+ }
33
+
34
+ const dependencyParams = {};
35
+ export function getDependencyParams(config, pathPrefix) {
36
+ if (dependencyParams && dependencyParams[pathPrefix || 'empty']) {
37
+ return dependencyParams[pathPrefix || 'empty'];
38
+ }
39
+
40
+ const sourceFilter = (d) => d === config || d.export.type === 'source';
41
+ let headerPathWithDepends = [];
42
+ setPath(headerPathWithDepends, config, 'header', sourceFilter);
43
+ headerPathWithDepends = [...new Set(headerPathWithDepends.map((p) => getPath(config, p, pathPrefix)))].join(';');
44
+
45
+ const headerGlob = [];
46
+ headerPathWithDepends.split(';').forEach((h) => {
47
+ config.ext.header.forEach((ext) => {
48
+ headerGlob.push(`${h}/*.${ext}`);
49
+ });
50
+ });
51
+
52
+ let nativePathWithDepends = [];
53
+ setPath(nativePathWithDepends, config, 'native', sourceFilter);
54
+ nativePathWithDepends = [...new Set(nativePathWithDepends.map((p) => getPath(config, p, pathPrefix)))].join(';');
55
+
56
+ const nativeGlob = [];
57
+ nativePathWithDepends.split(';').forEach((h) => {
58
+ config.ext.source.forEach((ext) => {
59
+ nativeGlob.push(`${h}/*.${ext}`);
60
+ });
61
+ });
62
+
63
+ const cliCMakeListsFile = getCliCMakeListsFile();
64
+ const cmakeFilter = (d) => d !== config && d.export.type === 'cmake' && d.paths.cmake !== cliCMakeListsFile;
65
+ let cmakeDepends = [];
66
+ setPath(cmakeDepends, config, 'this', cmakeFilter);
67
+ cmakeDepends = [...new Set(cmakeDepends)];
68
+
69
+ const pathsOfCmakeDepends = [...new Set(cmakeDepends
70
+ .map((d) => getParentPath(d.paths.cmake))
71
+ .map((p) => getPath(config, p, pathPrefix)))].join(';');
72
+ const nameOfCmakeDepends = [...new Set(cmakeDepends.map((d) => d.general.name))].join(';');
73
+
74
+ dependencyParams[pathPrefix || 'empty'] = {
75
+ nativeGlob,
76
+ headerGlob,
77
+ headerPathWithDepends,
78
+ cmakeDepends,
79
+ pathsOfCmakeDepends,
80
+ nameOfCmakeDepends,
81
+ };
82
+ return dependencyParams[pathPrefix || 'empty'];
83
+ }
84
+
85
+ export default function getCmakeParams(config, pathPrefix, isBuildSource, isBuildBridge) {
86
+ const params = [];
87
+ if (isBuildSource) params.push('-DBUILD_SOURCE=TRUE');
88
+ if (isBuildBridge) params.push('-DBUILD_BRIDGE=TRUE');
89
+
90
+ const output = getPath(config, config.paths.temp, pathPrefix);
91
+ const projectPath = getPath(config, process.cwd(), pathPrefix);
92
+
93
+ const dependParams = getDependencyParams(config, pathPrefix);
94
+
95
+ params.push(...[
96
+ `-DBASE_DIR=${projectPath}`,
97
+ `-DNATIVE_GLOB=${dependParams.nativeGlob.join(';')}`,
98
+ `-DHEADER_GLOB=${dependParams.headerGlob.join(';')}`,
99
+ `-DHEADER_DIR=${dependParams.headerPathWithDepends}`,
100
+ `-DDEPENDS_CMAKE_PATHS=${dependParams.pathsOfCmakeDepends}`,
101
+ `-DDEPENDS_CMAKE_NAMES=${dependParams.nameOfCmakeDepends}`,
102
+ `-DBRIDGE_DIR=${output}/bridge`,
103
+ ]);
104
+
105
+ return params;
106
+ }
@@ -0,0 +1,37 @@
1
+ /* eslint-disable default-param-last */
2
+ /* eslint-disable no-param-reassign */
3
+ import getPathInfo from '../utils/getPathInfo.js';
4
+
5
+ function getPath(config, path, pathPrefix) {
6
+ if (!pathPrefix) {
7
+ return getPathInfo(path, config.paths.base).absolute;
8
+ }
9
+
10
+ return `${pathPrefix}${getPathInfo(path, config.paths.base).relative}`;
11
+ }
12
+
13
+ function getRecursiveData(obj, dependency, field, pathPrefix, platform, subPlatform) {
14
+ const platformName = subPlatform ? `${platform}-${subPlatform}` : platform;
15
+ if (dependency?.platform?.[platformName]?.[field]) {
16
+ Object.entries(dependency.platform[platformName][field]).forEach(([dKey, value]) => {
17
+ if (field === 'data') {
18
+ const a = `${dependency.paths.project}/dist/prebuilt/${platform}/${dKey}`;
19
+ const key = getPath(dependency, a, pathPrefix);
20
+ obj[key] = value;
21
+ } else {
22
+ obj[dKey] = value;
23
+ }
24
+ });
25
+ }
26
+
27
+ dependency.dependencies.forEach((dep) => {
28
+ getRecursiveData(obj, dep, field, pathPrefix, platform, subPlatform);
29
+ });
30
+ }
31
+
32
+ export default function getData(config, field, pathPrefix, platform = 'Emscripten-x86_64', subPlatform) {
33
+ const output = {};
34
+ getRecursiveData(output, config, field, pathPrefix, platform, subPlatform);
35
+
36
+ return output;
37
+ }
@@ -0,0 +1,33 @@
1
+ import glob from 'glob';
2
+ import getPathInfo from '../utils/getPathInfo.js';
3
+ import { getDependencyParams } from './getCmakeParams.js';
4
+
5
+ function getPath(config, path, pathPrefix) {
6
+ if (!pathPrefix) {
7
+ return getPathInfo(path, config.paths.base).absolute;
8
+ }
9
+
10
+ return `${pathPrefix}${getPathInfo(path, config.paths.base).relative}`;
11
+ }
12
+
13
+ export default function getLibs(config, pathPrefix) {
14
+ let dependLibs = [
15
+ ...glob.sync(`${config.paths.temp}/dependencies/**/*.a`, { absolute: true, cwd: config.paths.project }),
16
+ ];
17
+ getDependencyParams(config, pathPrefix).cmakeDepends.forEach((d) => {
18
+ if (d.export.libName) {
19
+ d.export.libName.forEach((fileName) => {
20
+ if (d.platform['Emscripten-x86_64'].ignoreLibName?.includes(fileName)) return;
21
+ dependLibs.push(...glob.sync(`${d.paths.output}/prebuilt/Emscripten-x86_64/lib/lib${fileName}.a`, { absolute: true, cwd: d.paths.project }));
22
+ });
23
+ }
24
+ });
25
+
26
+ dependLibs = [...new Set(dependLibs)];
27
+
28
+ return [...new Set([
29
+ `${config.paths.temp}/lib${config.general.name}.a`,
30
+ `${config.paths.temp}/lib${config.general.name}bridge.a`,
31
+ ...dependLibs,
32
+ ].filter((path) => !!path.toString()).map((path) => getPath(config, path, pathPrefix)))];
33
+ }