cpp.js 1.0.0-alpha.2 → 1.0.0-alpha.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cpp.js",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "homepage": "https://cpp.js.org",
package/src/bin.js CHANGED
@@ -84,11 +84,23 @@ function run(programName, params) {
84
84
  function generate(type, platform) {
85
85
  const compiler2 = new CppjsCompiler();
86
86
  if (type === 'lib') {
87
+ const modules = [];
88
+ compiler2.config.paths.module.forEach((modulePath) => {
89
+ modules.push(...glob.sync('**/*.i', { absolute: true, cwd: modulePath }));
90
+ modules.push(...glob.sync('*.i', { absolute: true, cwd: modulePath }));
91
+ });
92
+
87
93
  if (platform === 'all' || platform === 'wasm') {
88
94
  if (!fs.existsSync(`${compiler2.config.paths.output}/prebuilt/Emscripten-x86_64`)) {
89
95
  generateWasmLib();
96
+ modules.forEach((modulePath) => {
97
+ const fileName = modulePath.split('/').at(-1);
98
+ createDir('prebuilt/Emscripten-x86_64/swig', compiler2.config.paths.output);
99
+ fs.copyFileSync(modulePath, `${compiler2.config.paths.output}/prebuilt/Emscripten-x86_64/swig/${fileName}`);
100
+ });
90
101
  }
91
102
  }
103
+
92
104
  if (platform === 'wasm') return;
93
105
  const platforms = {
94
106
  all: ['Android-arm64-v8a', 'iOS-iphoneos', 'iOS-iphonesimulator'],
@@ -99,6 +111,11 @@ function generate(type, platform) {
99
111
  if (!fs.existsSync(`${compiler2.config.paths.output}/prebuilt/${p}`)) {
100
112
  const compiler = new CppjsCompiler(p);
101
113
  compiler.createLib();
114
+ modules.forEach((modulePath) => {
115
+ const fileName = modulePath.split('/').at(-1);
116
+ createDir(`prebuilt/${p}/swig`, compiler2.config.paths.output);
117
+ fs.copyFileSync(modulePath, `${compiler2.config.paths.output}/prebuilt/${p}/swig/${fileName}`);
118
+ });
102
119
  }
103
120
  });
104
121
  if (platform === 'all' || platform === 'ios') {
@@ -126,7 +143,16 @@ async function generateWasmLib() {
126
143
 
127
144
  compiler.createBridge();
128
145
  await compiler.createWasm({ cc: ['-O3'] });
129
- createDir('prebuilt/Emscripten-x86_64', compiler.config.paths.output);
146
+ createDir('prebuilt/Emscripten-x86_64/lib', compiler.config.paths.output);
147
+
148
+ fs.renameSync(`${compiler.config.paths.temp}/lib/lib${compiler.config.general.name}.a`, `${compiler.config.paths.output}/prebuilt/Emscripten-x86_64/lib/lib${compiler.config.general.name}.a`);
149
+ fs.renameSync(`${compiler.config.paths.temp}/include/`, `${compiler.config.paths.output}/prebuilt/Emscripten-x86_64/include`);
150
+
151
+ fs.rmSync(`${compiler.config.paths.output}/data`, { recursive: true, force: true });
152
+ if (fs.existsSync(`${compiler.config.paths.temp}/data`)) {
153
+ fs.renameSync(`${compiler.config.paths.temp}/data`, `${compiler.config.paths.output}/data`);
154
+ }
155
+
130
156
  fs.copyFileSync(`${compiler.config.paths.temp}/${compiler.config.general.name}.node.js`, `${compiler.config.paths.output}/${compiler.config.general.name}.node.js`);
131
157
  fs.copyFileSync(`${compiler.config.paths.temp}/${compiler.config.general.name}.browser.js`, `${compiler.config.paths.output}/${compiler.config.general.name}.browser.js`);
132
158
  fs.copyFileSync(`${compiler.config.paths.temp}/${compiler.config.general.name}.wasm`, `${compiler.config.paths.output}/${compiler.config.general.name}.wasm`);
@@ -134,10 +160,5 @@ async function generateWasmLib() {
134
160
  fs.copyFileSync(`${compiler.config.paths.temp}/${compiler.config.general.name}.data.txt`, `${compiler.config.paths.output}/${compiler.config.general.name}.data.txt`);
135
161
  }
136
162
 
137
- fs.renameSync(`${compiler.config.paths.temp}/lib/`, `${compiler.config.paths.output}/prebuilt/Emscripten-x86_64/lib`);
138
- fs.renameSync(`${compiler.config.paths.temp}/include/`, `${compiler.config.paths.output}/prebuilt/Emscripten-x86_64/include`);
139
-
140
- fs.rmSync(`${compiler.config.paths.output}/data`, { recursive: true, force: true });
141
- fs.renameSync(`${compiler.config.paths.temp}/data`, `${compiler.config.paths.output}/data`);
142
163
  fs.rmSync(compiler.config.paths.temp, { recursive: true, force: true });
143
164
  }
@@ -7,6 +7,9 @@ import getData from './getData.js';
7
7
  import getPathInfo from '../utils/getPathInfo.js';
8
8
 
9
9
  export default async function createWasm(compiler, options, buildAll = false) {
10
+ if (fs.existsSync('/tmp/cppjs/live')) fs.unlinkSync('/tmp/cppjs/live');
11
+ fs.symlinkSync(compiler.config.paths.base, '/tmp/cppjs/live');
12
+
10
13
  const output = `/tmp/cppjs/live/${getPathInfo(compiler.config.paths.temp, compiler.config.paths.base).relative}`;
11
14
 
12
15
  let params = getCmakeParams(compiler.config, '/tmp/cppjs/live/', true, false);
@@ -28,7 +31,7 @@ export default async function createWasm(compiler, options, buildAll = false) {
28
31
  run(compiler, 'emmake', ['make', 'install']);
29
32
 
30
33
  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();
34
+ const data = Object.entries(getData(compiler.config, 'data', '/tmp/cppjs/live/', 'Emscripten-x86_64', 'browser')).map(([key, value]) => ['--preload-file', `${key.replaceAll('@', '@@')}@${value}`]).flat();
32
35
  run(compiler, 'emcc', [
33
36
  '-lembind', '-Wl,--whole-archive',
34
37
  ...libs, ...(options.cc || []),
@@ -6,17 +6,16 @@ function getPath(config, path, pathPrefix) {
6
6
  if (!pathPrefix) {
7
7
  return getPathInfo(path, config.paths.base).absolute;
8
8
  }
9
-
10
9
  return `${pathPrefix}${getPathInfo(path, config.paths.base).relative}`;
11
10
  }
12
11
 
13
- function getRecursiveData(obj, dependency, field, pathPrefix, platform, subPlatform) {
12
+ function getRecursiveData(obj, config, dependency, field, pathPrefix, platform, subPlatform) {
14
13
  const platformName = subPlatform ? `${platform}-${subPlatform}` : platform;
15
14
  if (dependency?.platform?.[platformName]?.[field]) {
16
15
  Object.entries(dependency.platform[platformName][field]).forEach(([dKey, value]) => {
17
16
  if (field === 'data') {
18
17
  const a = `${dependency.paths.project}/dist/prebuilt/${platform}/${dKey}`;
19
- const key = getPath(dependency, a, pathPrefix);
18
+ const key = getPath(config, a, pathPrefix);
20
19
  obj[key] = value;
21
20
  } else {
22
21
  obj[dKey] = value;
@@ -25,13 +24,13 @@ function getRecursiveData(obj, dependency, field, pathPrefix, platform, subPlatf
25
24
  }
26
25
 
27
26
  dependency.dependencies.forEach((dep) => {
28
- getRecursiveData(obj, dep, field, pathPrefix, platform, subPlatform);
27
+ getRecursiveData(obj, config, dep, field, pathPrefix, platform, subPlatform);
29
28
  });
30
29
  }
31
30
 
32
31
  export default function getData(config, field, pathPrefix, platform = 'Emscripten-x86_64', subPlatform) {
33
32
  const output = {};
34
- getRecursiveData(output, config, field, pathPrefix, platform, subPlatform);
33
+ getRecursiveData(output, config, config, field, pathPrefix, platform, subPlatform);
35
34
 
36
35
  return output;
37
36
  }
Binary file