relaxnative 0.1.1 → 0.1.3
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 +130 -0
- package/dist/chunk-4ZOOQ7GU.js +431 -0
- package/dist/chunk-6GKAG5SO.js +1042 -0
- package/dist/chunk-AXIKKGDT.js +788 -0
- package/dist/chunk-CRQZJC5B.js +397 -0
- package/dist/chunk-EMSPE6HY.js +788 -0
- package/dist/chunk-GCYH2XU5.js +788 -0
- package/dist/chunk-GVGWP3E2.js +786 -0
- package/dist/chunk-H6WRQCNQ.js +817 -0
- package/dist/chunk-HBO7F7P4.js +431 -0
- package/dist/chunk-HXUEYL4P.js +1042 -0
- package/dist/chunk-IAQ27C7W.js +788 -0
- package/dist/chunk-JYYW2Q42.js +415 -0
- package/dist/chunk-KHDXEK4J.js +1042 -0
- package/dist/chunk-KJ7GQCDE.js +1042 -0
- package/dist/chunk-N32TLKJ3.js +797 -0
- package/dist/chunk-STPJVBXH.js +817 -0
- package/dist/chunk-UGGUZN4H.js +818 -0
- package/dist/chunk-UGS3DYRK.js +1042 -0
- package/dist/chunk-WERFVUWK.js +1042 -0
- package/dist/chunk-Y6HEDJ2E.js +1042 -0
- package/dist/chunk-YBMUKRIZ.js +1042 -0
- package/dist/chunk-ZIVSD5K6.js +1042 -0
- package/dist/chunk-ZTBXEEMF.js +1042 -0
- package/dist/cli.js +3 -3
- package/dist/index.d.ts +33 -1
- package/dist/index.js +3 -3
- package/dist/memory/memory.selftest.js +2 -2
- package/dist/worker/processEntry.js +50 -3
- package/package.json +3 -1
package/dist/cli.js
CHANGED
|
@@ -10,12 +10,12 @@ import {
|
|
|
10
10
|
removePackage,
|
|
11
11
|
runNativeTests,
|
|
12
12
|
updateIndex
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-YBMUKRIZ.js";
|
|
14
14
|
import {
|
|
15
15
|
detectCompilers,
|
|
16
16
|
getCacheRoot
|
|
17
|
-
} from "./chunk-
|
|
18
|
-
import "./chunk-
|
|
17
|
+
} from "./chunk-UGGUZN4H.js";
|
|
18
|
+
import "./chunk-HBO7F7P4.js";
|
|
19
19
|
import "./chunk-LLZ4I4OR.js";
|
|
20
20
|
import "./chunk-MLKGABMK.js";
|
|
21
21
|
|
package/dist/index.d.ts
CHANGED
|
@@ -12,9 +12,22 @@ type RelaxConfig = {
|
|
|
12
12
|
defaultMode?: ExecutionMode;
|
|
13
13
|
};
|
|
14
14
|
type IsolationMode = 'in-process' | 'worker' | 'process';
|
|
15
|
+
type NativeBuildOptions = {
|
|
16
|
+
/** Additional source files to compile+link into the same shared library (C/C++ only). */
|
|
17
|
+
sources?: string[];
|
|
18
|
+
/** Header search paths (-I). */
|
|
19
|
+
includePaths?: string[];
|
|
20
|
+
/** Library search paths (-L / /LIBPATH). */
|
|
21
|
+
libraryPaths?: string[];
|
|
22
|
+
/** Link libraries (-lfoo / foo.lib). */
|
|
23
|
+
libraries?: string[];
|
|
24
|
+
/** Additional raw compiler/linker flags. */
|
|
25
|
+
flags?: string[];
|
|
26
|
+
};
|
|
15
27
|
declare function loadNative(sourcePath: string, options?: {
|
|
16
28
|
config?: RelaxConfig;
|
|
17
29
|
isolation?: IsolationMode;
|
|
30
|
+
build?: NativeBuildOptions;
|
|
18
31
|
}): Promise<any>;
|
|
19
32
|
/**
|
|
20
33
|
* Advanced API: returns both the wrapped module and the computed bindings.
|
|
@@ -23,6 +36,7 @@ declare function loadNative(sourcePath: string, options?: {
|
|
|
23
36
|
declare function loadNativeWithBindings(sourcePath: string, options?: {
|
|
24
37
|
config?: RelaxConfig;
|
|
25
38
|
isolation?: IsolationMode;
|
|
39
|
+
build?: NativeBuildOptions;
|
|
26
40
|
mutateBindings?: (bindings: any) => void;
|
|
27
41
|
}): Promise<{
|
|
28
42
|
mod: any;
|
|
@@ -390,9 +404,27 @@ type CompilerInfo$1 = {
|
|
|
390
404
|
type NativeLanguage = 'c' | 'cpp' | 'rust';
|
|
391
405
|
|
|
392
406
|
type CompileRequest = {
|
|
407
|
+
/**
|
|
408
|
+
* Primary entry source file.
|
|
409
|
+
*
|
|
410
|
+
* For multi-file builds, `sourcePath` is used as the "entry" for:
|
|
411
|
+
* - language detection (C vs C++)
|
|
412
|
+
* - output library naming
|
|
413
|
+
*
|
|
414
|
+
* The full compilation inputs are `sourcePath` + `sources`.
|
|
415
|
+
*/
|
|
393
416
|
sourcePath: string;
|
|
417
|
+
/** Additional source files to compile and link into the same shared library. */
|
|
418
|
+
sources?: string[];
|
|
394
419
|
outDir: string;
|
|
420
|
+
/** Additional raw compiler/linker flags (advanced escape hatch). */
|
|
395
421
|
flags?: string[];
|
|
422
|
+
/** Header search paths (translated to -I). */
|
|
423
|
+
includePaths?: string[];
|
|
424
|
+
/** Library search paths (translated to -L). */
|
|
425
|
+
libraryPaths?: string[];
|
|
426
|
+
/** Libraries to link (translated to -l<name>). Example: ['m', 'pthread'] */
|
|
427
|
+
libraries?: string[];
|
|
396
428
|
};
|
|
397
429
|
type CompileResult = {
|
|
398
430
|
language: NativeLanguage;
|
|
@@ -404,4 +436,4 @@ declare function compileNative(compiler: CompilerInfo$1, platform: PlatformInfo,
|
|
|
404
436
|
|
|
405
437
|
declare function compileWithCache(compiler: CompilerInfo$1, platform: PlatformInfo, request: CompileRequest): CompileResult;
|
|
406
438
|
|
|
407
|
-
export { type BenchmarkOptions, type BenchmarkResult, type ExecutionMode, type HotReloadHandle, type HotReloadOptions, type InstallOptions, type InstallResult, InvalidFreeError, type IsolationMode, MemoryError, type NativeAddress, NativeBuffer, NativePointer, type NativeTestCase, type NativeTestKind, type NativeTestResult, NullPointerError, type Ownership, type RawAllocation, type RelaxConfig, type TraditionalBenchmarkResult, UseAfterFreeError, alloc, allocRaw, benchmarkCompareSyncVsWorker, benchmarkCompareTraditionalVsRelaxnative, benchmarkJsFunction, benchmarkNativeFunction, compileNative, compileWithCache, detectCompilers, discoverNativeTestFiles, discoverNativeTests, discoverNativeTestsFromFile, formatBenchmarkCompare, formatBenchmarkResult, formatBenchmarkTraditionalCompare, formatNativeTestResults, free, freeRaw, getInstalledPackageDir, getProjectRoot, getRegistryRoot, getSourceLine, installPackage, installPackageEnforcingTrust, listPackages, loadNative, loadNativeDevHot, loadNativeWithBindings, loadRegistry, index as native, readRelaxJson, removePackage, resolveRegistryImport, runNativeTests, updateIndex };
|
|
439
|
+
export { type BenchmarkOptions, type BenchmarkResult, type ExecutionMode, type HotReloadHandle, type HotReloadOptions, type InstallOptions, type InstallResult, InvalidFreeError, type IsolationMode, MemoryError, type NativeAddress, NativeBuffer, type NativeBuildOptions, NativePointer, type NativeTestCase, type NativeTestKind, type NativeTestResult, NullPointerError, type Ownership, type RawAllocation, type RelaxConfig, type TraditionalBenchmarkResult, UseAfterFreeError, alloc, allocRaw, benchmarkCompareSyncVsWorker, benchmarkCompareTraditionalVsRelaxnative, benchmarkJsFunction, benchmarkNativeFunction, compileNative, compileWithCache, detectCompilers, discoverNativeTestFiles, discoverNativeTests, discoverNativeTestsFromFile, formatBenchmarkCompare, formatBenchmarkResult, formatBenchmarkTraditionalCompare, formatNativeTestResults, free, freeRaw, getInstalledPackageDir, getProjectRoot, getRegistryRoot, getSourceLine, installPackage, installPackageEnforcingTrust, listPackages, loadNative, loadNativeDevHot, loadNativeWithBindings, loadRegistry, index as native, readRelaxJson, removePackage, resolveRegistryImport, runNativeTests, updateIndex };
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
runNativeTests,
|
|
25
25
|
trustPolicy,
|
|
26
26
|
updateIndex
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-YBMUKRIZ.js";
|
|
28
28
|
import {
|
|
29
29
|
alloc,
|
|
30
30
|
allocRaw,
|
|
@@ -37,8 +37,8 @@ import {
|
|
|
37
37
|
loadNativeDevHot,
|
|
38
38
|
loadNativeWithBindings,
|
|
39
39
|
memory_exports
|
|
40
|
-
} from "./chunk-
|
|
41
|
-
import "./chunk-
|
|
40
|
+
} from "./chunk-UGGUZN4H.js";
|
|
41
|
+
import "./chunk-HBO7F7P4.js";
|
|
42
42
|
import {
|
|
43
43
|
InvalidFreeError,
|
|
44
44
|
MemoryError,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
wrapFunctions
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-HBO7F7P4.js";
|
|
4
4
|
import {
|
|
5
5
|
loadFfi
|
|
6
6
|
} from "../chunk-LLZ4I4OR.js";
|
|
@@ -75,6 +75,39 @@ import { createRequire as createRequire2 } from "module";
|
|
|
75
75
|
function reply(msg) {
|
|
76
76
|
if (process.send) process.send(msg);
|
|
77
77
|
}
|
|
78
|
+
function reviveArg(a) {
|
|
79
|
+
if (!a || typeof a !== "object") return a;
|
|
80
|
+
if (a.__relaxnative_typedarray === true && a.bytes) {
|
|
81
|
+
const buf = Buffer.isBuffer(a.bytes) ? a.bytes : a.bytes?.type === "Buffer" && Array.isArray(a.bytes?.data) ? Buffer.from(a.bytes.data) : Array.isArray(a.bytes) ? Buffer.from(a.bytes) : Buffer.from([]);
|
|
82
|
+
const u8 = new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
83
|
+
const ab = u8.slice().buffer;
|
|
84
|
+
switch (a.type) {
|
|
85
|
+
case "Uint8Array":
|
|
86
|
+
return new Uint8Array(ab);
|
|
87
|
+
case "Int8Array":
|
|
88
|
+
return new Int8Array(ab);
|
|
89
|
+
case "Uint16Array":
|
|
90
|
+
return new Uint16Array(ab);
|
|
91
|
+
case "Int16Array":
|
|
92
|
+
return new Int16Array(ab);
|
|
93
|
+
case "Uint32Array":
|
|
94
|
+
return new Uint32Array(ab);
|
|
95
|
+
case "Int32Array":
|
|
96
|
+
return new Int32Array(ab);
|
|
97
|
+
case "BigInt64Array":
|
|
98
|
+
return new BigInt64Array(ab);
|
|
99
|
+
case "BigUint64Array":
|
|
100
|
+
return new BigUint64Array(ab);
|
|
101
|
+
case "Float32Array":
|
|
102
|
+
return new Float32Array(ab);
|
|
103
|
+
case "Float64Array":
|
|
104
|
+
return new Float64Array(ab);
|
|
105
|
+
default:
|
|
106
|
+
return new Uint8Array(ab);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return a;
|
|
110
|
+
}
|
|
78
111
|
process.on("message", async (msg) => {
|
|
79
112
|
try {
|
|
80
113
|
if (!msg || typeof msg.id !== "number") return;
|
|
@@ -139,8 +172,22 @@ process.on("message", async (msg) => {
|
|
|
139
172
|
return;
|
|
140
173
|
}
|
|
141
174
|
try {
|
|
142
|
-
const
|
|
143
|
-
|
|
175
|
+
const boxedArgs = Array.isArray(msg.args) ? msg.args : [];
|
|
176
|
+
const revivedArgs = Array.isArray(msg.args) ? msg.args.map(reviveArg) : msg.args;
|
|
177
|
+
const result = await fn(...revivedArgs);
|
|
178
|
+
if (Array.isArray(revivedArgs) && Array.isArray(boxedArgs)) {
|
|
179
|
+
for (let i = 0; i < revivedArgs.length; i++) {
|
|
180
|
+
const revived = revivedArgs[i];
|
|
181
|
+
const boxed = boxedArgs[i];
|
|
182
|
+
if (boxed?.__relaxnative_typedarray === true && revived && ArrayBuffer.isView(revived)) {
|
|
183
|
+
const view = revived;
|
|
184
|
+
boxed.bytes = Buffer.from(
|
|
185
|
+
view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength)
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
reply({ id: msg.id, ok: true, result, args: boxedArgs });
|
|
144
191
|
} finally {
|
|
145
192
|
guards.restore();
|
|
146
193
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "relaxnative",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Zero-config native C/C++/Rust execution for Node.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,6 +40,8 @@
|
|
|
40
40
|
"test": "vitest --run --pool=forks --maxWorkers=1",
|
|
41
41
|
"test:inband": "vitest --run --pool=forks --maxWorkers=1",
|
|
42
42
|
"test:native": "vitest --run --pool=forks --maxWorkers=1 src/memory/memory.test.ts",
|
|
43
|
+
"test:threads": "vitest --run --pool=threads --maxWorkers=1",
|
|
44
|
+
"test:forks": "vitest --run --pool=forks --maxWorkers=1",
|
|
43
45
|
"selftest:memory": "npm run build && node dist/memory/memory.selftest.js",
|
|
44
46
|
"prepack": "npm run build",
|
|
45
47
|
"release:beta": "npm publish --tag beta",
|