cpp.js 1.0.0-alpha.4 → 1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cpp.js",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-beta.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "homepage": "https://cpp.js.org",
@@ -152,10 +152,23 @@ function initCppJs(userConfig = {}) {
152
152
  return vector;
153
153
  },
154
154
  };
155
+ if (config.getWasmFunction) {
156
+ m.instantiateWasm = function instantiateWasm(info, receive) {
157
+ const instance = new WebAssembly.Instance(config.getWasmFunction(), info);
158
+ receive(instance);
159
+ return instance.exports;
160
+ };
161
+ }
155
162
  Module(m).then(resolve).catch(reject);
156
163
  });
157
164
 
158
165
  return cppJsPromise;
159
166
  }
160
167
 
168
+ if (typeof globalThis === 'object') {
169
+ globalThis.CppJs = {
170
+ initCppJs,
171
+ };
172
+ }
173
+
161
174
  export default initCppJs;
@@ -121,10 +121,23 @@ function initCppJs(userConfig = {}) {
121
121
  return vector;
122
122
  },
123
123
  };
124
+ if (config.getWasmFunction) {
125
+ m.instantiateWasm = function instantiateWasm(info, receive) {
126
+ const instance = new WebAssembly.Instance(config.getWasmFunction(), info);
127
+ receive(instance);
128
+ return instance.exports;
129
+ };
130
+ }
124
131
  Module(m).then(resolve).catch(reject);
125
132
  });
126
133
 
127
134
  return cppJsPromise;
128
135
  }
129
136
 
137
+ if (typeof globalThis === 'object') {
138
+ globalThis.CppJs = {
139
+ initCppJs,
140
+ };
141
+ }
142
+
130
143
  export default initCppJs;
@@ -1,23 +1,28 @@
1
- import glob from 'glob';
2
1
  import getBaseInfo from '../utils/getBaseInfo.js';
3
2
  import getPathInfo from '../utils/getPathInfo.js';
3
+ import { getDependencyParams } from './getCmakeParams.js';
4
4
  import run from './run.js';
5
5
 
6
6
  const platform = 'Emscripten-x86_64';
7
7
 
8
8
  export default function createBridge(compiler) {
9
9
  const bridges = [];
10
+
11
+ const allHeaders = getDependencyParams(compiler.config).headerPathWithDepends.split(';');
12
+
13
+ let includePath = [
14
+ ...compiler.config.getAllDependencies().map((d) => `${d.paths.output}/prebuilt/${platform}/include`),
15
+ ...compiler.config.getAllDependencies().map((d) => `${d.paths.output}/prebuilt/${platform}/swig`),
16
+ ...compiler.config.paths.header,
17
+ ...allHeaders,
18
+ ].filter((path) => !!path.toString()).map((path) => `-I/tmp/cppjs/live/${getPathInfo(path, compiler.config.paths.base).relative}`);
19
+ includePath = [...new Set(includePath)];
20
+
10
21
  compiler.interfaces.forEach((filePath) => {
11
22
  const input = getPathInfo(filePath, compiler.config.paths.base);
12
23
  const output = getPathInfo(`${compiler.config.paths.temp}/bridge`, compiler.config.paths.base);
13
24
  const base = getBaseInfo(compiler.config.paths.base);
14
25
 
15
- const includePath = [
16
- ...compiler.config.getAllDependencies().map((d) => `${d.paths.output}/prebuilt/${platform}/include`),
17
- ...compiler.config.getAllDependencies().map((d) => `${d.paths.output}/prebuilt/${platform}/swig`),
18
- ...compiler.config.paths.header,
19
- ].filter((path) => !!path.toString()).map((path) => `-I/tmp/cppjs/live/${getPathInfo(path, compiler.config.paths.base).relative}`);
20
-
21
26
  run(compiler, 'swig', [
22
27
  '-c++',
23
28
  '-embind',
@@ -6,7 +6,7 @@ import getLibs from './getLibs.js';
6
6
  import getData from './getData.js';
7
7
  import getPathInfo from '../utils/getPathInfo.js';
8
8
 
9
- export default async function createWasm(compiler, options, buildAll = false) {
9
+ export default async function createWasm(compiler, options = {}, buildAll = false) {
10
10
  if (fs.existsSync('/tmp/cppjs/live')) fs.unlinkSync('/tmp/cppjs/live');
11
11
  fs.symlinkSync(compiler.config.paths.base, '/tmp/cppjs/live');
12
12
 
@@ -35,9 +35,9 @@ export default async function createWasm(compiler, options, buildAll = false) {
35
35
  run(compiler, 'emcc', [
36
36
  '-lembind', '-Wl,--whole-archive',
37
37
  ...libs, ...(options.cc || []),
38
- '-s', 'WASM=1', '-s', 'MODULARIZE=1',
38
+ '-s', 'WASM=1', '-s', 'MODULARIZE=1', '-s', 'DYNAMIC_EXECUTION=0',
39
39
  '-s', 'RESERVED_FUNCTION_POINTERS=200', '-s', 'DISABLE_EXCEPTION_CATCHING=0', '-s', 'FORCE_FILESYSTEM=1',
40
- '-s', 'TOTAL_MEMORY=512MB', '-s', 'ALLOW_MEMORY_GROWTH=1',
40
+ '-s', 'ALLOW_MEMORY_GROWTH=1',
41
41
  '-s', 'EXPORTED_RUNTIME_METHODS=["FS", "ENV"]',
42
42
  '-o', `${output}/${compiler.config.general.name}.js`,
43
43
  ...data,
@@ -46,9 +46,9 @@ export default async function createWasm(compiler, options, buildAll = false) {
46
46
  run(compiler, 'emcc', [
47
47
  '-lembind', '-Wl,--whole-archive', '-lnodefs.js',
48
48
  ...libs, ...(options.cc || []),
49
- '-s', 'WASM=1', '-s', 'MODULARIZE=1',
49
+ '-s', 'WASM=1', '-s', 'MODULARIZE=1', '-s', 'DYNAMIC_EXECUTION=0',
50
50
  '-s', 'RESERVED_FUNCTION_POINTERS=200', '-s', 'DISABLE_EXCEPTION_CATCHING=0', '-s', 'FORCE_FILESYSTEM=1', '-s', 'NODERAWFS',
51
- '-s', 'TOTAL_MEMORY=512MB', '-s', 'ALLOW_MEMORY_GROWTH=1',
51
+ '-s', 'ALLOW_MEMORY_GROWTH=1',
52
52
  '-s', 'EXPORTED_RUNTIME_METHODS=["FS", "ENV", "NODEFS"]',
53
53
  '-o', `${output}/${compiler.config.general.name}.js`,
54
54
  ]);