cpp.js 0.6.0 → 0.6.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 +1 -1
- package/src/assets/CMakeLists.txt +2 -1
- package/src/functions/createWasm.js +58 -24
- package/src/index.js +5 -1
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
cmake_minimum_required(VERSION 3.25)
|
|
2
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
2
3
|
project("${PROJECT_NAME}")
|
|
3
4
|
set(PACKAGE_HOST "${CMAKE_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}")
|
|
4
5
|
|
|
@@ -18,7 +19,7 @@ if (BUILD_BRIDGE)
|
|
|
18
19
|
endif(BUILD_BRIDGE)
|
|
19
20
|
|
|
20
21
|
set(SRC_FILES "${BUILD_SRC_FILES}" "${BRIDGE_SRC_FILES}")
|
|
21
|
-
add_library("${PROJECT_NAME}"
|
|
22
|
+
add_library("${PROJECT_NAME}" "${BUILD_TYPE}" ${SRC_FILES})
|
|
22
23
|
|
|
23
24
|
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "")
|
|
24
25
|
target_link_libraries("${PROJECT_NAME}" "${DEPENDS_CMAKE_NAMES}")
|
|
@@ -11,7 +11,17 @@ export default function createWasm(compiler, options = {}) {
|
|
|
11
11
|
compiler.config,
|
|
12
12
|
options,
|
|
13
13
|
);
|
|
14
|
-
return compiler2.
|
|
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);
|
|
15
25
|
}
|
|
16
26
|
|
|
17
27
|
function setPath(arr, dependency, type, filter = () => {}) {
|
|
@@ -41,11 +51,26 @@ class CppjsCompiler {
|
|
|
41
51
|
constructor(config, options) {
|
|
42
52
|
this.config = config;
|
|
43
53
|
this.options = options;
|
|
54
|
+
this.pathType = 'absolute';
|
|
55
|
+
this.pathPrefix = '';
|
|
44
56
|
}
|
|
45
57
|
|
|
46
|
-
|
|
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() {
|
|
47
69
|
pullDockerImage();
|
|
48
70
|
|
|
71
|
+
this.pathType = 'relative';
|
|
72
|
+
this.pathPrefix = '/live/';
|
|
73
|
+
|
|
49
74
|
this.prepare();
|
|
50
75
|
this.cmake(this.config.general.name, true, false);
|
|
51
76
|
this.make();
|
|
@@ -63,7 +88,7 @@ class CppjsCompiler {
|
|
|
63
88
|
`${this.config.paths.temp}/lib${this.config.general.name}.a`,
|
|
64
89
|
`${this.config.paths.temp}/lib${this.config.general.name}bridge.a`,
|
|
65
90
|
...dependLibs,
|
|
66
|
-
].filter(path => !!path.toString()).map(path =>
|
|
91
|
+
].filter(path => !!path.toString()).map(path => this.getPath(path));
|
|
67
92
|
|
|
68
93
|
this.cc();
|
|
69
94
|
|
|
@@ -74,7 +99,7 @@ class CppjsCompiler {
|
|
|
74
99
|
const sourceFilter = (d) => d === this.config || d.export.type === 'source';
|
|
75
100
|
this.headerPathWithDepends = [];
|
|
76
101
|
setPath(this.headerPathWithDepends, this.config, 'header', sourceFilter);
|
|
77
|
-
this.headerPathWithDepends = this.headerPathWithDepends.map(p =>
|
|
102
|
+
this.headerPathWithDepends = this.headerPathWithDepends.map(p => this.getPath(p)).join(';');
|
|
78
103
|
|
|
79
104
|
this.headerGlob = [];
|
|
80
105
|
this.headerPathWithDepends.split(';').forEach(h => {
|
|
@@ -86,7 +111,7 @@ class CppjsCompiler {
|
|
|
86
111
|
|
|
87
112
|
this.nativePathWithDepends = [];
|
|
88
113
|
setPath(this.nativePathWithDepends, this.config, 'native', sourceFilter);
|
|
89
|
-
this.nativePathWithDepends = this.nativePathWithDepends.map(p =>
|
|
114
|
+
this.nativePathWithDepends = this.nativePathWithDepends.map(p => this.getPath(p)).join(';');
|
|
90
115
|
|
|
91
116
|
this.nativeGlob = [];
|
|
92
117
|
this.nativePathWithDepends.split(';').forEach(h => {
|
|
@@ -102,47 +127,57 @@ class CppjsCompiler {
|
|
|
102
127
|
|
|
103
128
|
this.pathsOfCmakeDepends = this.cmakeDepends
|
|
104
129
|
.map(d => getParentPath(d.paths.cmake))
|
|
105
|
-
.map(p =>
|
|
130
|
+
.map(p => this.getPath(p)).join(';');
|
|
106
131
|
this.nameOfCmakeDepends = this.cmakeDepends.map(d => d.general.name).join(';');
|
|
107
132
|
}
|
|
108
133
|
|
|
109
|
-
|
|
134
|
+
getCmakeParams(name, isBuildSource, isBuildBridge) {
|
|
110
135
|
const params = [];
|
|
111
136
|
if (isBuildSource) params.push('-DBUILD_SOURCE=TRUE');
|
|
112
137
|
if (isBuildBridge) params.push('-DBUILD_BRIDGE=TRUE');
|
|
113
138
|
|
|
114
|
-
const output =
|
|
115
|
-
const projectPath =
|
|
116
|
-
const base = getBaseInfo(this.config.paths.base);
|
|
117
|
-
|
|
118
|
-
const cMakeParentPath = getParentPath(this.config.paths.cmake);
|
|
139
|
+
const output = this.getPath(this.config.paths.temp);
|
|
140
|
+
const projectPath = this.getPath(process.cwd());
|
|
119
141
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
"emcmake", "cmake", "/cmake", '-DCMAKE_BUILD_TYPE=Release',
|
|
123
|
-
`-DBASE_DIR=/live/${projectPath.relative}`,
|
|
142
|
+
params.push(...[
|
|
143
|
+
`-DBASE_DIR=${projectPath}`,
|
|
124
144
|
`-DNATIVE_GLOB=${this.nativeGlob.join(';')}`,
|
|
125
|
-
`-DHEADER_GLOB=${this.headerGlob.join(';')}
|
|
145
|
+
`-DHEADER_GLOB=${this.headerGlob.join(';')}`,
|
|
126
146
|
`-DHEADER_DIR=${this.headerPathWithDepends}`,
|
|
127
147
|
`-DDEPENDS_CMAKE_PATHS=${this.pathsOfCmakeDepends}`,
|
|
128
148
|
`-DDEPENDS_CMAKE_NAMES=${this.nameOfCmakeDepends}`,
|
|
129
|
-
`-
|
|
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,
|
|
130
166
|
];
|
|
131
167
|
const options = { cwd: this.config.paths.temp, stdio : 'pipe' };
|
|
132
168
|
execFileSync("docker", args, options);
|
|
133
169
|
return this.config.paths.temp;
|
|
134
170
|
}
|
|
135
171
|
|
|
136
|
-
|
|
137
172
|
make() {
|
|
138
|
-
const output =
|
|
173
|
+
const output = this.getPath(this.config.paths.temp);
|
|
139
174
|
const base = getBaseInfo(this.config.paths.base);
|
|
140
175
|
|
|
141
176
|
let cMakeParentPath = this.config.paths.cmake.split('/');
|
|
142
177
|
cMakeParentPath.pop();
|
|
143
178
|
cMakeParentPath = cMakeParentPath.join('/');
|
|
144
179
|
const args = [
|
|
145
|
-
"run", "--user", getOsUserAndGroupId(), "-v", `${base.withoutSlash}:/live`, "-v", `${cMakeParentPath}:/cmake`, "--workdir",
|
|
180
|
+
"run", "--user", getOsUserAndGroupId(), "-v", `${base.withoutSlash}:/live`, "-v", `${cMakeParentPath}:/cmake`, "--workdir", `${output}`, getDockerImage(),
|
|
146
181
|
"emmake", "make", "install"
|
|
147
182
|
];
|
|
148
183
|
const options = { cwd: this.config.paths.temp, stdio : 'pipe' };
|
|
@@ -151,12 +186,11 @@ class CppjsCompiler {
|
|
|
151
186
|
}
|
|
152
187
|
|
|
153
188
|
cc() {
|
|
154
|
-
const
|
|
155
|
-
const output = getPathInfo(this.config.paths.temp, this.config.paths.base);
|
|
189
|
+
const output = this.getPath(this.config.paths.temp);
|
|
156
190
|
const base = getBaseInfo(this.config.paths.base);
|
|
157
191
|
const args = [
|
|
158
192
|
"run", "--user", getOsUserAndGroupId(), "-v", `${base.withoutSlash}:/live`, "-v", `${this.config.paths.cli}:/cli`, getDockerImage(),
|
|
159
|
-
"emcc", "-lembind", "-Wl,--whole-archive", ...this.libs, ...(this.options.cc || []), "-s", "WASM=1", "-s", "MODULARIZE=1", '-o',
|
|
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'
|
|
160
194
|
];
|
|
161
195
|
const options = { cwd: this.config.paths.temp, stdio : 'pipe' };
|
|
162
196
|
execFileSync("docker", args, options);
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import createBridge from './functions/createBridge.js';
|
|
2
2
|
import findOrCreateInterfaceFile from './functions/findOrCreateInterfaceFile.js';
|
|
3
|
-
import createWasm from './functions/createWasm.js';
|
|
3
|
+
import createWasm, { getCmakeParams } from './functions/createWasm.js';
|
|
4
4
|
import getConfig from './utils/getConfig.js';
|
|
5
5
|
|
|
6
6
|
export default class CppjsCompiler {
|
|
@@ -20,4 +20,8 @@ export default class CppjsCompiler {
|
|
|
20
20
|
createWasm(options) {
|
|
21
21
|
return createWasm(this, options);
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
getCmakeParams() {
|
|
25
|
+
return getCmakeParams(this);
|
|
26
|
+
}
|
|
23
27
|
}
|