space-data-module-sdk 0.5.13 → 0.5.14

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,214 +0,0 @@
1
- import { accessSync, existsSync } from "node:fs";
2
- import { execFile } from "node:child_process";
3
- import path from "node:path";
4
- import process from "node:process";
5
- import { promisify } from "node:util";
6
- import { fileURLToPath } from "node:url";
7
-
8
- const execFileAsync = promisify(execFile);
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = path.dirname(__filename);
11
-
12
- function normalizeResolvedPath(value) {
13
- if (typeof value !== "string" || value.trim().length === 0) {
14
- return null;
15
- }
16
- return path.resolve(value);
17
- }
18
-
19
- function ensureReadableSync(targetPath, label) {
20
- try {
21
- accessSync(targetPath);
22
- } catch {
23
- throw new Error(`${label} not found: ${targetPath}`);
24
- }
25
- }
26
-
27
- function resolveWasmEdgeSharedLibraryFilename() {
28
- if (process.platform === "darwin") {
29
- return "libwasmedge.0.dylib";
30
- }
31
- if (process.platform === "win32") {
32
- return "wasmedge.dll";
33
- }
34
- return "libwasmedge.so.0";
35
- }
36
-
37
- function resolveGeneratedIncludeDir(requestedIncludeDir) {
38
- const directHeaderPath = path.join(
39
- requestedIncludeDir,
40
- "wasmedge",
41
- "enum_configure.h",
42
- );
43
- if (existsSync(directHeaderPath)) {
44
- return requestedIncludeDir;
45
- }
46
-
47
- const repoRoot = path.resolve(requestedIncludeDir, "..", "..");
48
- const generatedDir = path.join(repoRoot, "build", "include", "api");
49
- if (existsSync(path.join(generatedDir, "wasmedge", "enum_configure.h"))) {
50
- return generatedDir;
51
- }
52
-
53
- throw new Error(
54
- `WasmEdge include directory does not contain wasmedge/enum_configure.h: ${requestedIncludeDir}`,
55
- );
56
- }
57
-
58
- export function resolveWasmEdgeRunnerSourcePath() {
59
- return path.resolve(
60
- __dirname,
61
- "native",
62
- "wasmedge_emscripten_pthread_runner.c",
63
- );
64
- }
65
-
66
- export function resolveWasmEdgeRunnerBuildPlan(options = {}) {
67
- const requestedIncludeDir = normalizeResolvedPath(
68
- options.wasmedgeIncludeDir ?? process.env.WASMEDGE_INCLUDE_DIR,
69
- );
70
- const wasmedgeLibDir = normalizeResolvedPath(
71
- options.wasmedgeLibDir ?? process.env.WASMEDGE_LIB_DIR,
72
- );
73
- const outputPath = normalizeResolvedPath(
74
- options.outputPath ?? options.output,
75
- );
76
-
77
- if (!requestedIncludeDir) {
78
- throw new Error(
79
- "Missing WasmEdge include directory. Set wasmedgeIncludeDir, --wasmedge-include-dir, or WASMEDGE_INCLUDE_DIR.",
80
- );
81
- }
82
- if (!wasmedgeLibDir) {
83
- throw new Error(
84
- "Missing WasmEdge library directory. Set wasmedgeLibDir, --wasmedge-lib-dir, or WASMEDGE_LIB_DIR.",
85
- );
86
- }
87
- if (!outputPath) {
88
- throw new Error("Missing runner outputPath.");
89
- }
90
-
91
- const runnerSourcePath = resolveWasmEdgeRunnerSourcePath();
92
- const wasmedgeSharedLibraryPath = path.join(
93
- wasmedgeLibDir,
94
- resolveWasmEdgeSharedLibraryFilename(),
95
- );
96
-
97
- return {
98
- runnerSourcePath,
99
- requestedIncludeDir,
100
- wasmedgeIncludeDir: requestedIncludeDir,
101
- wasmedgeLibDir,
102
- wasmedgeSharedLibraryPath,
103
- outputPath,
104
- compilerCommand:
105
- process.platform === "darwin" ? "xcrun" : process.env.CC ?? "cc",
106
- compilerArgs:
107
- process.platform === "darwin"
108
- ? [
109
- "clang",
110
- runnerSourcePath,
111
- "-std=c11",
112
- "-O2",
113
- "-pthread",
114
- "-Wall",
115
- "-Wextra",
116
- "-Werror",
117
- "-Wno-unused-parameter",
118
- "-Wno-error=visibility",
119
- `-I${requestedIncludeDir}`,
120
- `-L${wasmedgeLibDir}`,
121
- "-lwasmedge",
122
- `-Wl,-rpath,${wasmedgeLibDir}`,
123
- "-o",
124
- outputPath,
125
- ]
126
- : [
127
- runnerSourcePath,
128
- "-std=c11",
129
- "-O2",
130
- "-pthread",
131
- "-Wall",
132
- "-Wextra",
133
- "-Werror",
134
- "-Wno-unused-parameter",
135
- "-Wno-error=visibility",
136
- `-I${requestedIncludeDir}`,
137
- `-L${wasmedgeLibDir}`,
138
- "-lwasmedge",
139
- `-Wl,-rpath,${wasmedgeLibDir}`,
140
- "-o",
141
- outputPath,
142
- ],
143
- };
144
- }
145
-
146
- export async function buildWasmEdgeEmscriptenPthreadRunner(options = {}) {
147
- const basePlan = resolveWasmEdgeRunnerBuildPlan(options);
148
- const wasmedgeIncludeDir = resolveGeneratedIncludeDir(
149
- basePlan.requestedIncludeDir,
150
- );
151
- const compilerArgs =
152
- process.platform === "darwin"
153
- ? [
154
- "clang",
155
- basePlan.runnerSourcePath,
156
- "-std=c11",
157
- "-O2",
158
- "-pthread",
159
- "-Wall",
160
- "-Wextra",
161
- "-Werror",
162
- "-Wno-unused-parameter",
163
- "-Wno-error=visibility",
164
- `-I${wasmedgeIncludeDir}`,
165
- `-L${basePlan.wasmedgeLibDir}`,
166
- "-lwasmedge",
167
- `-Wl,-rpath,${basePlan.wasmedgeLibDir}`,
168
- "-o",
169
- basePlan.outputPath,
170
- ]
171
- : [
172
- basePlan.runnerSourcePath,
173
- "-std=c11",
174
- "-O2",
175
- "-pthread",
176
- "-Wall",
177
- "-Wextra",
178
- "-Werror",
179
- "-Wno-unused-parameter",
180
- "-Wno-error=visibility",
181
- `-I${wasmedgeIncludeDir}`,
182
- `-L${basePlan.wasmedgeLibDir}`,
183
- "-lwasmedge",
184
- `-Wl,-rpath,${basePlan.wasmedgeLibDir}`,
185
- "-o",
186
- basePlan.outputPath,
187
- ];
188
- const plan = {
189
- ...basePlan,
190
- wasmedgeIncludeDir,
191
- compilerArgs,
192
- };
193
-
194
- ensureReadableSync(plan.runnerSourcePath, "Runner source");
195
- ensureReadableSync(plan.wasmedgeIncludeDir, "WasmEdge include directory");
196
- ensureReadableSync(plan.wasmedgeLibDir, "WasmEdge library directory");
197
- ensureReadableSync(
198
- plan.wasmedgeSharedLibraryPath,
199
- "WasmEdge shared library",
200
- );
201
-
202
- await execFileAsync(plan.compilerCommand, plan.compilerArgs, {
203
- cwd: options.cwd ?? process.cwd(),
204
- });
205
- if (process.platform === "darwin") {
206
- await execFileAsync("install_name_tool", [
207
- "-change",
208
- "@rpath/libwasmedge.0.dylib",
209
- plan.wasmedgeSharedLibraryPath,
210
- plan.outputPath,
211
- ]);
212
- }
213
- return plan.outputPath;
214
- }
@@ -1,62 +0,0 @@
1
- import {
2
- createPluginInvokeProcessClient,
3
- resolveWasmEdgePluginLaunchPlan,
4
- } from "./processInvoke.js";
5
-
6
- function normalizeRuntimeDescriptor(options = {}) {
7
- if (options.runtime && typeof options.runtime === "object") {
8
- return options.runtime;
9
- }
10
- return options;
11
- }
12
-
13
- export function resolveModuleHarnessLaunchPlan(options = {}) {
14
- const runtime = normalizeRuntimeDescriptor(options);
15
- if (runtime.launchPlan && typeof runtime.launchPlan === "object") {
16
- return runtime.launchPlan;
17
- }
18
-
19
- const kind = String(runtime.kind ?? "process").trim().toLowerCase();
20
- if (kind === "wasmedge") {
21
- return resolveWasmEdgePluginLaunchPlan(runtime);
22
- }
23
- if (kind === "process") {
24
- if (typeof runtime.command !== "string" || runtime.command.trim().length === 0) {
25
- throw new Error(
26
- "resolveModuleHarnessLaunchPlan requires runtime.command for process runtimes.",
27
- );
28
- }
29
- return {
30
- command: runtime.command,
31
- args: Array.isArray(runtime.args) ? runtime.args : [],
32
- env: runtime.env,
33
- cwd: runtime.cwd,
34
- };
35
- }
36
-
37
- throw new Error(`Unsupported module harness runtime kind: ${kind}`);
38
- }
39
-
40
- export async function createModuleHarness(options = {}) {
41
- const runtime = normalizeRuntimeDescriptor(options);
42
- const kind = String(runtime.kind ?? "process").trim().toLowerCase();
43
- const launchPlan = resolveModuleHarnessLaunchPlan(options);
44
- const processClient = await createPluginInvokeProcessClient({ launchPlan });
45
-
46
- return {
47
- runtime: {
48
- ...runtime,
49
- kind,
50
- },
51
- launchPlan,
52
- invokeRaw(requestBytes) {
53
- return processClient.invokeRaw(requestBytes);
54
- },
55
- invoke(request) {
56
- return processClient.invoke(request);
57
- },
58
- destroy() {
59
- return processClient.destroy();
60
- },
61
- };
62
- }