space-data-module-sdk 0.5.14 → 0.5.18
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/README.md +91 -1
- package/package.json +8 -4
- package/schemas/HostStorageAbi.fbs +53 -0
- package/src/bundle/codec.js +1 -1
- package/src/compliance/pluginCompliance.js +0 -130
- package/src/generated/orbpro/invoke/plugin-invoke-request.js +1 -1
- package/src/generated/orbpro/invoke/plugin-invoke-response.js +1 -1
- package/src/generated/orbpro/manifest/accepted-type-set.js +1 -1
- package/src/generated/orbpro/manifest/build-artifact.js +1 -1
- package/src/generated/orbpro/manifest/host-capability.js +1 -1
- package/src/generated/orbpro/manifest/method-manifest.js +1 -1
- package/src/generated/orbpro/manifest/plugin-manifest.js +1 -1
- package/src/generated/orbpro/manifest/port-manifest.js +1 -1
- package/src/generated/orbpro/manifest/protocol-spec.js +1 -1
- package/src/generated/orbpro/manifest/timer-spec.js +1 -1
- package/src/generated/orbpro/module/canonicalization-rule.js +1 -1
- package/src/generated/orbpro/module/module-bundle-entry.js +1 -1
- package/src/generated/orbpro/module/module-bundle.js +1 -1
- package/src/generated/orbpro/stream/flat-buffer-type-ref.js +1 -1
- package/src/generated/orbpro/stream/typed-arena-buffer.js +1 -1
- package/src/index.d.ts +157 -1
- package/src/index.js +1 -0
- package/src/invoke/codec.js +10 -8
- package/src/manifest/codec.js +1 -1
- package/src/runtime-host/flatsqlRuntimeStore.js +217 -0
- package/src/runtime-host/index.js +21 -0
- package/src/runtime-host/moduleRegistry.js +92 -0
- package/src/runtime-host/runtimeRegionStore.js +245 -0
- package/src/testing/buildWasmEdgeRunner.js +253 -0
- package/src/testing/index.d.ts +311 -0
- package/src/testing/index.js +21 -0
- package/src/testing/moduleHarness.js +163 -0
- package/src/testing/native/wasmedge_emscripten_pthread_runner.c +3111 -0
- package/src/testing/processInvoke.js +467 -0
- package/src/testing/publicationProtectionDemo.js +271 -0
- package/src/testing/streamInvokeCodec.js +175 -0
- package/src/transport/records.js +56 -55
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
function cloneBytes(bytes) {
|
|
2
|
+
return new Uint8Array(bytes);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function normalizePositiveInteger(value, label) {
|
|
6
|
+
const normalized = Number(value);
|
|
7
|
+
if (!Number.isInteger(normalized) || normalized < 0) {
|
|
8
|
+
throw new TypeError(`${label} must be a non-negative integer`);
|
|
9
|
+
}
|
|
10
|
+
return normalized;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function normalizeStrictlyPositiveInteger(value, label) {
|
|
14
|
+
const normalized = Number(value);
|
|
15
|
+
if (!Number.isInteger(normalized) || normalized <= 0) {
|
|
16
|
+
throw new TypeError(`${label} must be a positive integer`);
|
|
17
|
+
}
|
|
18
|
+
return normalized;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function normalizeRequiredString(value, label) {
|
|
22
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
23
|
+
throw new TypeError(`${label} must be a non-empty string`);
|
|
24
|
+
}
|
|
25
|
+
return value.trim();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function normalizeOptionalFunction(value, label) {
|
|
29
|
+
if (value === undefined) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
if (typeof value !== "function") {
|
|
33
|
+
throw new TypeError(`${label} must be a function`);
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function toRecordBytes(value, recordByteLength) {
|
|
39
|
+
const bytes = new Uint8Array(recordByteLength);
|
|
40
|
+
if (value === null || value === undefined) {
|
|
41
|
+
return bytes;
|
|
42
|
+
}
|
|
43
|
+
if (ArrayBuffer.isView(value)) {
|
|
44
|
+
const view = value;
|
|
45
|
+
if (view.byteLength > recordByteLength) {
|
|
46
|
+
throw new RangeError("record bytes exceed recordByteLength");
|
|
47
|
+
}
|
|
48
|
+
bytes.set(new Uint8Array(view.buffer, view.byteOffset, view.byteLength));
|
|
49
|
+
return bytes;
|
|
50
|
+
}
|
|
51
|
+
if (value instanceof ArrayBuffer) {
|
|
52
|
+
if (value.byteLength > recordByteLength) {
|
|
53
|
+
throw new RangeError("record bytes exceed recordByteLength");
|
|
54
|
+
}
|
|
55
|
+
bytes.set(new Uint8Array(value));
|
|
56
|
+
return bytes;
|
|
57
|
+
}
|
|
58
|
+
throw new TypeError("runtime region records must be byte-oriented");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function createRuntimeRegionStore() {
|
|
62
|
+
let nextRegionId = 1;
|
|
63
|
+
const regions = new Map();
|
|
64
|
+
|
|
65
|
+
function getRegionRecordCount(region) {
|
|
66
|
+
if (typeof region.getRecordCount === "function") {
|
|
67
|
+
return normalizePositiveInteger(
|
|
68
|
+
region.getRecordCount(region.regionId),
|
|
69
|
+
"recordCount",
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return region.records.length;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function describeRegion(regionId) {
|
|
76
|
+
const normalizedRegionId = normalizePositiveInteger(regionId, "regionId");
|
|
77
|
+
const region = regions.get(normalizedRegionId);
|
|
78
|
+
if (!region) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
regionId: region.regionId,
|
|
83
|
+
layoutId: region.layoutId,
|
|
84
|
+
recordByteLength: region.recordByteLength,
|
|
85
|
+
alignment: region.alignment,
|
|
86
|
+
recordCount: getRegionRecordCount(region),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function allocateRegion({
|
|
91
|
+
layoutId,
|
|
92
|
+
recordByteLength,
|
|
93
|
+
alignment = 1,
|
|
94
|
+
initialRecords = [],
|
|
95
|
+
}) {
|
|
96
|
+
const region = {
|
|
97
|
+
regionId: nextRegionId++,
|
|
98
|
+
kind: "owned",
|
|
99
|
+
layoutId: normalizeRequiredString(layoutId, "layoutId"),
|
|
100
|
+
recordByteLength: normalizeStrictlyPositiveInteger(
|
|
101
|
+
recordByteLength,
|
|
102
|
+
"recordByteLength",
|
|
103
|
+
),
|
|
104
|
+
alignment: normalizeStrictlyPositiveInteger(alignment, "alignment"),
|
|
105
|
+
records: [],
|
|
106
|
+
};
|
|
107
|
+
region.records = Array.from(initialRecords, (record) =>
|
|
108
|
+
toRecordBytes(record, region.recordByteLength),
|
|
109
|
+
);
|
|
110
|
+
regions.set(region.regionId, region);
|
|
111
|
+
return describeRegion(region.regionId);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function registerExternalRegion({
|
|
115
|
+
layoutId,
|
|
116
|
+
recordByteLength,
|
|
117
|
+
alignment = 1,
|
|
118
|
+
recordCount = 0,
|
|
119
|
+
getRecordCount,
|
|
120
|
+
resolveRecordView,
|
|
121
|
+
}) {
|
|
122
|
+
const region = {
|
|
123
|
+
regionId: nextRegionId++,
|
|
124
|
+
kind: "external",
|
|
125
|
+
layoutId: normalizeRequiredString(layoutId, "layoutId"),
|
|
126
|
+
recordByteLength: normalizeStrictlyPositiveInteger(
|
|
127
|
+
recordByteLength,
|
|
128
|
+
"recordByteLength",
|
|
129
|
+
),
|
|
130
|
+
alignment: normalizeStrictlyPositiveInteger(alignment, "alignment"),
|
|
131
|
+
records: [],
|
|
132
|
+
getRecordCount: normalizeOptionalFunction(getRecordCount, "getRecordCount"),
|
|
133
|
+
resolveRecordView: normalizeOptionalFunction(
|
|
134
|
+
resolveRecordView,
|
|
135
|
+
"resolveRecordView",
|
|
136
|
+
),
|
|
137
|
+
};
|
|
138
|
+
if (region.getRecordCount === undefined) {
|
|
139
|
+
region.records.length = normalizePositiveInteger(recordCount, "recordCount");
|
|
140
|
+
}
|
|
141
|
+
regions.set(region.regionId, region);
|
|
142
|
+
return describeRegion(region.regionId);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function setRegionRecordCount(regionId, recordCount) {
|
|
146
|
+
const normalizedRegionId = normalizePositiveInteger(regionId, "regionId");
|
|
147
|
+
const region = regions.get(normalizedRegionId);
|
|
148
|
+
if (!region) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
if (typeof region.getRecordCount === "function") {
|
|
152
|
+
throw new Error("Cannot set recordCount for externally counted regions");
|
|
153
|
+
}
|
|
154
|
+
const normalizedRecordCount = normalizePositiveInteger(
|
|
155
|
+
recordCount,
|
|
156
|
+
"recordCount",
|
|
157
|
+
);
|
|
158
|
+
if (normalizedRecordCount < region.records.length) {
|
|
159
|
+
region.records.length = normalizedRecordCount;
|
|
160
|
+
} else {
|
|
161
|
+
while (region.records.length < normalizedRecordCount) {
|
|
162
|
+
region.records.push(new Uint8Array(region.recordByteLength));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return describeRegion(normalizedRegionId);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function resolveRecord({ regionId, recordIndex }) {
|
|
169
|
+
const normalizedRegionId = normalizePositiveInteger(regionId, "regionId");
|
|
170
|
+
const normalizedRecordIndex = normalizePositiveInteger(
|
|
171
|
+
recordIndex,
|
|
172
|
+
"recordIndex",
|
|
173
|
+
);
|
|
174
|
+
const region = regions.get(normalizedRegionId);
|
|
175
|
+
if (!region) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
if (normalizedRecordIndex >= getRegionRecordCount(region)) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
if (region.kind === "external") {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
regionId: region.regionId,
|
|
186
|
+
recordIndex: normalizedRecordIndex,
|
|
187
|
+
layoutId: region.layoutId,
|
|
188
|
+
recordByteLength: region.recordByteLength,
|
|
189
|
+
alignment: region.alignment,
|
|
190
|
+
byteLength: region.recordByteLength,
|
|
191
|
+
bytes: cloneBytes(region.records[normalizedRecordIndex]),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function resolveRecordView({ regionId, recordIndex }) {
|
|
196
|
+
const normalizedRegionId = normalizePositiveInteger(regionId, "regionId");
|
|
197
|
+
const normalizedRecordIndex = normalizePositiveInteger(
|
|
198
|
+
recordIndex,
|
|
199
|
+
"recordIndex",
|
|
200
|
+
);
|
|
201
|
+
const region = regions.get(normalizedRegionId);
|
|
202
|
+
if (!region) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
if (normalizedRecordIndex >= getRegionRecordCount(region)) {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
if (region.kind !== "external") {
|
|
209
|
+
return resolveRecord({
|
|
210
|
+
regionId: normalizedRegionId,
|
|
211
|
+
recordIndex: normalizedRecordIndex,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (typeof region.resolveRecordView !== "function") {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
const view = region.resolveRecordView({
|
|
218
|
+
regionId: normalizedRegionId,
|
|
219
|
+
recordIndex: normalizedRecordIndex,
|
|
220
|
+
layoutId: region.layoutId,
|
|
221
|
+
recordByteLength: region.recordByteLength,
|
|
222
|
+
alignment: region.alignment,
|
|
223
|
+
});
|
|
224
|
+
if (view === null || view === undefined) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
regionId: normalizedRegionId,
|
|
229
|
+
recordIndex: normalizedRecordIndex,
|
|
230
|
+
layoutId: region.layoutId,
|
|
231
|
+
recordByteLength: region.recordByteLength,
|
|
232
|
+
alignment: region.alignment,
|
|
233
|
+
...view,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return {
|
|
238
|
+
allocateRegion,
|
|
239
|
+
describeRegion,
|
|
240
|
+
registerExternalRegion,
|
|
241
|
+
resolveRecord,
|
|
242
|
+
resolveRecordView,
|
|
243
|
+
setRegionRecordCount,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { accessSync, existsSync } from "node:fs";
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { promisify } from "node:util";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const execFileAsync = promisify(execFile);
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
|
|
13
|
+
function normalizeResolvedPath(value) {
|
|
14
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return path.resolve(value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function ensureReadableSync(targetPath, label) {
|
|
21
|
+
try {
|
|
22
|
+
accessSync(targetPath);
|
|
23
|
+
} catch {
|
|
24
|
+
throw new Error(`${label} not found: ${targetPath}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function resolveWasmEdgeSharedLibraryFilename() {
|
|
29
|
+
if (process.platform === "darwin") {
|
|
30
|
+
return "libwasmedge.0.dylib";
|
|
31
|
+
}
|
|
32
|
+
if (process.platform === "win32") {
|
|
33
|
+
return "wasmedge.dll";
|
|
34
|
+
}
|
|
35
|
+
return "libwasmedge.so.0";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function resolveGeneratedIncludeDir(requestedIncludeDir) {
|
|
39
|
+
const directHeaderPath = path.join(
|
|
40
|
+
requestedIncludeDir,
|
|
41
|
+
"wasmedge",
|
|
42
|
+
"enum_configure.h",
|
|
43
|
+
);
|
|
44
|
+
if (existsSync(directHeaderPath)) {
|
|
45
|
+
return requestedIncludeDir;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const repoRoot = path.resolve(requestedIncludeDir, "..", "..");
|
|
49
|
+
const generatedDir = path.join(repoRoot, "build", "include", "api");
|
|
50
|
+
if (existsSync(path.join(generatedDir, "wasmedge", "enum_configure.h"))) {
|
|
51
|
+
return generatedDir;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
throw new Error(
|
|
55
|
+
`WasmEdge include directory does not contain wasmedge/enum_configure.h: ${requestedIncludeDir}`,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function resolveWasmEdgeRunnerSourcePath() {
|
|
60
|
+
return path.resolve(
|
|
61
|
+
__dirname,
|
|
62
|
+
"native",
|
|
63
|
+
"wasmedge_emscripten_pthread_runner.c",
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function resolveDefaultWasmEdgeInstall() {
|
|
68
|
+
const home = os.homedir();
|
|
69
|
+
const candidates = [
|
|
70
|
+
{
|
|
71
|
+
includeDir: path.join(home, ".wasmedge", "include"),
|
|
72
|
+
libDir: path.join(home, ".wasmedge", "lib"),
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
includeDir: "/opt/homebrew/include",
|
|
76
|
+
libDir: "/opt/homebrew/opt/wasmedge/lib",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
includeDir: "/usr/local/include",
|
|
80
|
+
libDir: "/usr/local/lib",
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
for (const candidate of candidates) {
|
|
84
|
+
const header = path.join(
|
|
85
|
+
candidate.includeDir,
|
|
86
|
+
"wasmedge",
|
|
87
|
+
"enum_configure.h",
|
|
88
|
+
);
|
|
89
|
+
const library = path.join(
|
|
90
|
+
candidate.libDir,
|
|
91
|
+
resolveWasmEdgeSharedLibraryFilename(),
|
|
92
|
+
);
|
|
93
|
+
if (existsSync(header) && existsSync(library)) {
|
|
94
|
+
return candidate;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function resolveWasmEdgeRunnerBuildPlan(options = {}) {
|
|
101
|
+
const detectedInstall = resolveDefaultWasmEdgeInstall();
|
|
102
|
+
const requestedIncludeDir = normalizeResolvedPath(
|
|
103
|
+
options.wasmedgeIncludeDir ??
|
|
104
|
+
process.env.WASMEDGE_INCLUDE_DIR ??
|
|
105
|
+
detectedInstall?.includeDir,
|
|
106
|
+
);
|
|
107
|
+
const wasmedgeLibDir = normalizeResolvedPath(
|
|
108
|
+
options.wasmedgeLibDir ??
|
|
109
|
+
process.env.WASMEDGE_LIB_DIR ??
|
|
110
|
+
detectedInstall?.libDir,
|
|
111
|
+
);
|
|
112
|
+
const outputPath = normalizeResolvedPath(
|
|
113
|
+
options.outputPath ?? options.output,
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
if (!requestedIncludeDir) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
"Missing WasmEdge include directory. Set wasmedgeIncludeDir, --wasmedge-include-dir, or WASMEDGE_INCLUDE_DIR.",
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (!wasmedgeLibDir) {
|
|
122
|
+
throw new Error(
|
|
123
|
+
"Missing WasmEdge library directory. Set wasmedgeLibDir, --wasmedge-lib-dir, or WASMEDGE_LIB_DIR.",
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
if (!outputPath) {
|
|
127
|
+
throw new Error("Missing runner outputPath.");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const runnerSourcePath = resolveWasmEdgeRunnerSourcePath();
|
|
131
|
+
const wasmedgeSharedLibraryPath = path.join(
|
|
132
|
+
wasmedgeLibDir,
|
|
133
|
+
resolveWasmEdgeSharedLibraryFilename(),
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
runnerSourcePath,
|
|
138
|
+
requestedIncludeDir,
|
|
139
|
+
wasmedgeIncludeDir: requestedIncludeDir,
|
|
140
|
+
wasmedgeLibDir,
|
|
141
|
+
wasmedgeSharedLibraryPath,
|
|
142
|
+
outputPath,
|
|
143
|
+
compilerCommand:
|
|
144
|
+
process.platform === "darwin" ? "xcrun" : process.env.CC ?? "cc",
|
|
145
|
+
compilerArgs:
|
|
146
|
+
process.platform === "darwin"
|
|
147
|
+
? [
|
|
148
|
+
"clang",
|
|
149
|
+
runnerSourcePath,
|
|
150
|
+
"-std=c11",
|
|
151
|
+
"-O2",
|
|
152
|
+
"-pthread",
|
|
153
|
+
"-Wall",
|
|
154
|
+
"-Wextra",
|
|
155
|
+
"-Werror",
|
|
156
|
+
"-Wno-unused-parameter",
|
|
157
|
+
"-Wno-error=visibility",
|
|
158
|
+
`-I${requestedIncludeDir}`,
|
|
159
|
+
`-L${wasmedgeLibDir}`,
|
|
160
|
+
"-lwasmedge",
|
|
161
|
+
`-Wl,-rpath,${wasmedgeLibDir}`,
|
|
162
|
+
"-o",
|
|
163
|
+
outputPath,
|
|
164
|
+
]
|
|
165
|
+
: [
|
|
166
|
+
runnerSourcePath,
|
|
167
|
+
"-std=c11",
|
|
168
|
+
"-O2",
|
|
169
|
+
"-pthread",
|
|
170
|
+
"-Wall",
|
|
171
|
+
"-Wextra",
|
|
172
|
+
"-Werror",
|
|
173
|
+
"-Wno-unused-parameter",
|
|
174
|
+
"-Wno-error=visibility",
|
|
175
|
+
`-I${requestedIncludeDir}`,
|
|
176
|
+
`-L${wasmedgeLibDir}`,
|
|
177
|
+
"-lwasmedge",
|
|
178
|
+
`-Wl,-rpath,${wasmedgeLibDir}`,
|
|
179
|
+
"-o",
|
|
180
|
+
outputPath,
|
|
181
|
+
],
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export async function buildWasmEdgeEmscriptenPthreadRunner(options = {}) {
|
|
186
|
+
const basePlan = resolveWasmEdgeRunnerBuildPlan(options);
|
|
187
|
+
const wasmedgeIncludeDir = resolveGeneratedIncludeDir(
|
|
188
|
+
basePlan.requestedIncludeDir,
|
|
189
|
+
);
|
|
190
|
+
const compilerArgs =
|
|
191
|
+
process.platform === "darwin"
|
|
192
|
+
? [
|
|
193
|
+
"clang",
|
|
194
|
+
basePlan.runnerSourcePath,
|
|
195
|
+
"-std=c11",
|
|
196
|
+
"-O2",
|
|
197
|
+
"-pthread",
|
|
198
|
+
"-Wall",
|
|
199
|
+
"-Wextra",
|
|
200
|
+
"-Werror",
|
|
201
|
+
"-Wno-unused-parameter",
|
|
202
|
+
"-Wno-error=visibility",
|
|
203
|
+
`-I${wasmedgeIncludeDir}`,
|
|
204
|
+
`-L${basePlan.wasmedgeLibDir}`,
|
|
205
|
+
"-lwasmedge",
|
|
206
|
+
`-Wl,-rpath,${basePlan.wasmedgeLibDir}`,
|
|
207
|
+
"-o",
|
|
208
|
+
basePlan.outputPath,
|
|
209
|
+
]
|
|
210
|
+
: [
|
|
211
|
+
basePlan.runnerSourcePath,
|
|
212
|
+
"-std=c11",
|
|
213
|
+
"-O2",
|
|
214
|
+
"-pthread",
|
|
215
|
+
"-Wall",
|
|
216
|
+
"-Wextra",
|
|
217
|
+
"-Werror",
|
|
218
|
+
"-Wno-unused-parameter",
|
|
219
|
+
"-Wno-error=visibility",
|
|
220
|
+
`-I${wasmedgeIncludeDir}`,
|
|
221
|
+
`-L${basePlan.wasmedgeLibDir}`,
|
|
222
|
+
"-lwasmedge",
|
|
223
|
+
`-Wl,-rpath,${basePlan.wasmedgeLibDir}`,
|
|
224
|
+
"-o",
|
|
225
|
+
basePlan.outputPath,
|
|
226
|
+
];
|
|
227
|
+
const plan = {
|
|
228
|
+
...basePlan,
|
|
229
|
+
wasmedgeIncludeDir,
|
|
230
|
+
compilerArgs,
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
ensureReadableSync(plan.runnerSourcePath, "Runner source");
|
|
234
|
+
ensureReadableSync(plan.wasmedgeIncludeDir, "WasmEdge include directory");
|
|
235
|
+
ensureReadableSync(plan.wasmedgeLibDir, "WasmEdge library directory");
|
|
236
|
+
ensureReadableSync(
|
|
237
|
+
plan.wasmedgeSharedLibraryPath,
|
|
238
|
+
"WasmEdge shared library",
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
await execFileAsync(plan.compilerCommand, plan.compilerArgs, {
|
|
242
|
+
cwd: options.cwd ?? process.cwd(),
|
|
243
|
+
});
|
|
244
|
+
if (process.platform === "darwin") {
|
|
245
|
+
await execFileAsync("install_name_tool", [
|
|
246
|
+
"-change",
|
|
247
|
+
"@rpath/libwasmedge.0.dylib",
|
|
248
|
+
plan.wasmedgeSharedLibraryPath,
|
|
249
|
+
plan.outputPath,
|
|
250
|
+
]);
|
|
251
|
+
}
|
|
252
|
+
return plan.outputPath;
|
|
253
|
+
}
|