@vulfram/transport-bun 0.5.5-alpha
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/lib/linux-arm64/libvulfram_core.so +0 -0
- package/lib/linux-x64/libvulfram_core.so +0 -0
- package/lib/macos-arm64/libvulfram_core.dylib +0 -0
- package/lib/macos-x64/libvulfram_core.dylib +0 -0
- package/lib/windows-arm64/vulfram_core.dll +0 -0
- package/lib/windows-x64/vulfram_core.dll +0 -0
- package/package.json +16 -0
- package/src/bind/ffi-loader.ts +172 -0
- package/src/bind/types.ts +4 -0
- package/src/bind/utils.ts +33 -0
- package/src/index.ts +4 -0
- package/tsconfig.json +29 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vulfram/transport-bun",
|
|
3
|
+
"version": "0.5.5-alpha",
|
|
4
|
+
"module": "src/index.ts",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"types": "src/index.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@vulfram/transport-types": "^0.2.1",
|
|
10
|
+
"glob": "^13.0.0",
|
|
11
|
+
"msgpackr": "^1.11.8"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@types/bun": "^1.3.6"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { dlopen, ptr, toArrayBuffer, type Pointer } from 'bun:ffi';
|
|
2
|
+
import type { BufferResult } from './types';
|
|
3
|
+
import { detectRuntime } from './utils';
|
|
4
|
+
|
|
5
|
+
const loaders: Record<
|
|
6
|
+
string,
|
|
7
|
+
Record<string, () => Promise<{ default: string }>>
|
|
8
|
+
> = {
|
|
9
|
+
darwin: {
|
|
10
|
+
arm64: () =>
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
import('../../lib/macos-arm64/libvulfram_core.dylib', {
|
|
13
|
+
with: { type: 'file' },
|
|
14
|
+
}),
|
|
15
|
+
x64: () =>
|
|
16
|
+
// @ts-expect-error
|
|
17
|
+
import('../../lib/macos-x64/libvulfram_core.dylib', {
|
|
18
|
+
with: { type: 'file' },
|
|
19
|
+
}),
|
|
20
|
+
},
|
|
21
|
+
linux: {
|
|
22
|
+
arm64: () =>
|
|
23
|
+
// @ts-expect-error
|
|
24
|
+
import('../../lib/linux-arm64/libvulfram_core.so', {
|
|
25
|
+
with: { type: 'file' },
|
|
26
|
+
}),
|
|
27
|
+
x64: () =>
|
|
28
|
+
// @ts-expect-error
|
|
29
|
+
import('../../lib/linux-x64/libvulfram_core.so', {
|
|
30
|
+
with: { type: 'file' },
|
|
31
|
+
}),
|
|
32
|
+
},
|
|
33
|
+
win32: {
|
|
34
|
+
arm64: () =>
|
|
35
|
+
// @ts-expect-error
|
|
36
|
+
import('../../lib/windows-arm64/vulfram_core.dll', {
|
|
37
|
+
with: { type: 'file' },
|
|
38
|
+
}),
|
|
39
|
+
x64: () =>
|
|
40
|
+
// @ts-expect-error
|
|
41
|
+
import('../../lib/windows-x64/vulfram_core.dll', {
|
|
42
|
+
with: { type: 'file' },
|
|
43
|
+
}),
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const importLoader = loaders[process.platform]?.[process.arch];
|
|
48
|
+
|
|
49
|
+
if (!importLoader) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`FFI build not found for the current runtime: ${JSON.stringify(
|
|
52
|
+
detectRuntime(),
|
|
53
|
+
)}`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const lib = await importLoader().then((mod) => mod.default);
|
|
58
|
+
|
|
59
|
+
const { symbols: VULFRAM_CORE_DYLIB, close } = dlopen(lib, {
|
|
60
|
+
vulfram_init: { args: [], returns: 'u32' },
|
|
61
|
+
vulfram_dispose: { args: [], returns: 'u32' },
|
|
62
|
+
vulfram_send_queue: { args: ['ptr', 'usize'], returns: 'u32' },
|
|
63
|
+
vulfram_receive_queue: { args: ['ptr', 'ptr'], returns: 'u32' },
|
|
64
|
+
vulfram_receive_events: { args: ['ptr', 'ptr'], returns: 'u32' },
|
|
65
|
+
vulfram_upload_buffer: {
|
|
66
|
+
args: ['u64', 'u32', 'ptr', 'usize'],
|
|
67
|
+
returns: 'u32',
|
|
68
|
+
},
|
|
69
|
+
vulfram_tick: { args: ['u64', 'u32'], returns: 'u32' },
|
|
70
|
+
vulfram_get_profiling: { args: ['ptr', 'ptr'], returns: 'u32' },
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
process.once('beforeExit', () => {
|
|
74
|
+
close();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
function vulframDispose(): number {
|
|
78
|
+
return VULFRAM_CORE_DYLIB.vulfram_dispose();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function vulframInit(): number {
|
|
82
|
+
return VULFRAM_CORE_DYLIB.vulfram_init();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function vulframReceiveQueue(): BufferResult {
|
|
86
|
+
const ptrHolder = new BigUint64Array(1);
|
|
87
|
+
const sizeHolder = new BigUint64Array(1);
|
|
88
|
+
const result = VULFRAM_CORE_DYLIB.vulfram_receive_queue(
|
|
89
|
+
ptr(ptrHolder),
|
|
90
|
+
ptr(sizeHolder),
|
|
91
|
+
);
|
|
92
|
+
if (!sizeHolder[0]) {
|
|
93
|
+
return { buffer: Buffer.alloc(0), result };
|
|
94
|
+
}
|
|
95
|
+
const srcPtr = Number(ptrHolder[0]) as Pointer;
|
|
96
|
+
if (!srcPtr) {
|
|
97
|
+
return { buffer: Buffer.alloc(0), result };
|
|
98
|
+
}
|
|
99
|
+
const buffer = Buffer.from(toArrayBuffer(srcPtr, 0, Number(sizeHolder[0])));
|
|
100
|
+
|
|
101
|
+
return { buffer, result };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function vulframReceiveEvents(): BufferResult {
|
|
105
|
+
const ptrHolder = new BigUint64Array(1);
|
|
106
|
+
const sizeHolder = new BigUint64Array(1);
|
|
107
|
+
const result = VULFRAM_CORE_DYLIB.vulfram_receive_events(
|
|
108
|
+
ptr(ptrHolder),
|
|
109
|
+
ptr(sizeHolder),
|
|
110
|
+
);
|
|
111
|
+
if (!sizeHolder[0]) {
|
|
112
|
+
return { buffer: Buffer.alloc(0), result };
|
|
113
|
+
}
|
|
114
|
+
const srcPtr = Number(ptrHolder[0]) as Pointer;
|
|
115
|
+
if (!srcPtr) {
|
|
116
|
+
return { buffer: Buffer.alloc(0), result };
|
|
117
|
+
}
|
|
118
|
+
const buffer = Buffer.from(toArrayBuffer(srcPtr, 0, Number(sizeHolder[0])));
|
|
119
|
+
|
|
120
|
+
return { buffer, result };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function vulframSendQueue(data: Buffer): number {
|
|
124
|
+
return VULFRAM_CORE_DYLIB.vulfram_send_queue(ptr(data), data.length);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function vulframTick(time: number, deltaTime: number): number {
|
|
128
|
+
return VULFRAM_CORE_DYLIB.vulfram_tick(time, deltaTime);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function vulframUploadBuffer(
|
|
132
|
+
id: number,
|
|
133
|
+
uploadType: number,
|
|
134
|
+
data: Buffer,
|
|
135
|
+
): number {
|
|
136
|
+
return VULFRAM_CORE_DYLIB.vulfram_upload_buffer(
|
|
137
|
+
id,
|
|
138
|
+
uploadType,
|
|
139
|
+
ptr(data),
|
|
140
|
+
data.length,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function vulframGetProfiling(): BufferResult {
|
|
145
|
+
const ptrHolder = new BigUint64Array(1);
|
|
146
|
+
const sizeHolder = new BigUint64Array(1);
|
|
147
|
+
const result = VULFRAM_CORE_DYLIB.vulfram_get_profiling(
|
|
148
|
+
ptr(ptrHolder),
|
|
149
|
+
ptr(sizeHolder),
|
|
150
|
+
);
|
|
151
|
+
if (!sizeHolder[0]) {
|
|
152
|
+
return { buffer: Buffer.alloc(0), result };
|
|
153
|
+
}
|
|
154
|
+
const srcPtr = Number(ptrHolder[0]) as Pointer;
|
|
155
|
+
if (!srcPtr) {
|
|
156
|
+
return { buffer: Buffer.alloc(0), result };
|
|
157
|
+
}
|
|
158
|
+
const buffer = Buffer.from(toArrayBuffer(srcPtr, 0, Number(sizeHolder[0])));
|
|
159
|
+
|
|
160
|
+
return { buffer, result };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export const VULFRAM_CORE = {
|
|
164
|
+
vulframDispose,
|
|
165
|
+
vulframInit,
|
|
166
|
+
vulframReceiveQueue,
|
|
167
|
+
vulframReceiveEvents,
|
|
168
|
+
vulframSendQueue,
|
|
169
|
+
vulframTick,
|
|
170
|
+
vulframUploadBuffer,
|
|
171
|
+
vulframGetProfiling,
|
|
172
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function detectRuntime() {
|
|
2
|
+
if (
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
typeof globalThis.Deno !== 'undefined' &&
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
typeof globalThis.Deno?.version?.deno === 'string'
|
|
7
|
+
) {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
return { runtime: 'deno', version: globalThis.Deno.version.deno };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
typeof globalThis.Bun !== 'undefined' &&
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
typeof globalThis.Bun?.version === 'string'
|
|
17
|
+
) {
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
return { runtime: 'bun', version: globalThis.Bun.version };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
typeof globalThis.process !== 'undefined' &&
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
typeof globalThis.process?.versions?.node === 'string'
|
|
27
|
+
) {
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
return { runtime: 'node', version: globalThis.process.versions.node };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return { runtime: 'unknown', version: null };
|
|
33
|
+
}
|
package/src/index.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Environment setup & latest features
|
|
4
|
+
"lib": ["ESNext"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "Preserve",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
|
|
11
|
+
// Bundler mode
|
|
12
|
+
"moduleResolution": "bundler",
|
|
13
|
+
"allowImportingTsExtensions": true,
|
|
14
|
+
"verbatimModuleSyntax": true,
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
|
|
17
|
+
// Best practices
|
|
18
|
+
"strict": true,
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
"noFallthroughCasesInSwitch": true,
|
|
21
|
+
"noUncheckedIndexedAccess": true,
|
|
22
|
+
"noImplicitOverride": true,
|
|
23
|
+
|
|
24
|
+
// Some stricter flags (disabled by default)
|
|
25
|
+
"noUnusedLocals": false,
|
|
26
|
+
"noUnusedParameters": false,
|
|
27
|
+
"noPropertyAccessFromIndexSignature": false
|
|
28
|
+
}
|
|
29
|
+
}
|