@flowscripter/template-bun-rust-library 1.2.5 → 1.2.6
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/dist/index.js +1 -134
- package/dist/package.json +58 -0
- package/dist/src/lib-path.js +54 -0
- package/dist/src/lib.js +16 -0
- package/package.json +3 -3
- package/dist/tests/lib_path_test.d.ts +0 -2
- package/dist/tests/lib_path_test.d.ts.map +0 -1
- package/dist/tests/world_test.d.ts +0 -2
- package/dist/tests/world_test.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,134 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// src/lib.ts
|
|
3
|
-
import { dlopen, FFIType } from "bun:ffi";
|
|
4
|
-
|
|
5
|
-
// src/lib-path.ts
|
|
6
|
-
import os from "os";
|
|
7
|
-
import { suffix } from "bun:ffi";
|
|
8
|
-
import path from "path";
|
|
9
|
-
import { mkdir } from "fs/promises";
|
|
10
|
-
// package.json
|
|
11
|
-
var package_default = {
|
|
12
|
-
name: "@flowscripter/template-bun-rust-library",
|
|
13
|
-
version: "1.2.4",
|
|
14
|
-
description: "Project template for a Rust library with Bun FFI bindings",
|
|
15
|
-
keywords: [
|
|
16
|
-
"bun",
|
|
17
|
-
"example",
|
|
18
|
-
"ffi",
|
|
19
|
-
"library",
|
|
20
|
-
"rust",
|
|
21
|
-
"template"
|
|
22
|
-
],
|
|
23
|
-
homepage: "https://github.com/flowscripter/template-bun-rust-library#readme",
|
|
24
|
-
license: "MIT",
|
|
25
|
-
repository: {
|
|
26
|
-
type: "git",
|
|
27
|
-
url: "git+https://github.com/flowscripter/template-bun-rust-library.git"
|
|
28
|
-
},
|
|
29
|
-
files: [
|
|
30
|
-
"dist",
|
|
31
|
-
"src",
|
|
32
|
-
"index.ts",
|
|
33
|
-
"README.md",
|
|
34
|
-
"LICENSE"
|
|
35
|
-
],
|
|
36
|
-
type: "module",
|
|
37
|
-
main: "dist/index.js",
|
|
38
|
-
module: "dist/index.js",
|
|
39
|
-
types: "dist/index.d.ts",
|
|
40
|
-
exports: {
|
|
41
|
-
".": {
|
|
42
|
-
bun: "./index.ts",
|
|
43
|
-
types: "./dist/index.d.ts",
|
|
44
|
-
default: "./dist/index.js"
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
publishConfig: {
|
|
48
|
-
access: "public"
|
|
49
|
-
},
|
|
50
|
-
scripts: {
|
|
51
|
-
build: "bun build index.ts --outdir dist --target bun && tsc -p tsconfig.build.json"
|
|
52
|
-
},
|
|
53
|
-
devDependencies: {
|
|
54
|
-
"@types/bun": "^1.3.14",
|
|
55
|
-
oxfmt: "0.57.0",
|
|
56
|
-
oxlint: "1.72.0"
|
|
57
|
-
},
|
|
58
|
-
peerDependencies: {
|
|
59
|
-
typescript: "^6.0.3"
|
|
60
|
-
},
|
|
61
|
-
ffiLibBaseUri: "https://github.com/flowscripter/template-bun-rust-library/releases/download/v1.2.4",
|
|
62
|
-
typedocOptions: {
|
|
63
|
-
readme: "none",
|
|
64
|
-
exclude: [
|
|
65
|
-
"tests/**"
|
|
66
|
-
]
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// src/lib-path.ts
|
|
71
|
-
function buildLocalLibName(libName, libSuffix) {
|
|
72
|
-
const base = `${libName}.${libSuffix}`;
|
|
73
|
-
return libSuffix === "dll" ? base : `lib${base}`;
|
|
74
|
-
}
|
|
75
|
-
function buildRemoteLibName(libName, libSuffix, arch) {
|
|
76
|
-
if (libSuffix === "so")
|
|
77
|
-
return `${arch}.${libSuffix}`;
|
|
78
|
-
if (libSuffix === "dll")
|
|
79
|
-
return `${libName}.${arch}.${libSuffix}`;
|
|
80
|
-
return buildLocalLibName(libName, libSuffix);
|
|
81
|
-
}
|
|
82
|
-
function buildRemoteUrl(baseUri, remoteLibName) {
|
|
83
|
-
const base = baseUri.endsWith("/") ? baseUri : baseUri + "/";
|
|
84
|
-
return new URL(remoteLibName, base).href;
|
|
85
|
-
}
|
|
86
|
-
async function getLibPath(libName) {
|
|
87
|
-
const fullLibName = buildLocalLibName(libName, suffix);
|
|
88
|
-
const builtLibPath = path.join("target", "release", fullLibName);
|
|
89
|
-
console.debug(`builtLibPath: ${builtLibPath}`);
|
|
90
|
-
const builtLibFile = Bun.file(builtLibPath);
|
|
91
|
-
let exists = await builtLibFile.exists();
|
|
92
|
-
console.debug(`${builtLibPath} exists: ${exists}`);
|
|
93
|
-
if (exists) {
|
|
94
|
-
return builtLibPath;
|
|
95
|
-
}
|
|
96
|
-
const installedLibFolder = path.join(os.homedir(), ".flowscripter", "lib");
|
|
97
|
-
const installedLibPath = path.join(installedLibFolder, fullLibName);
|
|
98
|
-
const installedLibFile = Bun.file(installedLibPath);
|
|
99
|
-
exists = await installedLibFile.exists();
|
|
100
|
-
console.debug(`${installedLibPath} exists: ${exists}`);
|
|
101
|
-
if (exists) {
|
|
102
|
-
return installedLibPath;
|
|
103
|
-
}
|
|
104
|
-
console.debug(`packageJson.ffiLibBaseUri: ${package_default.ffiLibBaseUri}`);
|
|
105
|
-
const remoteLibName = buildRemoteLibName(libName, suffix, process.arch);
|
|
106
|
-
const remotePath = buildRemoteUrl(package_default.ffiLibBaseUri, remoteLibName);
|
|
107
|
-
console.debug(`remotePath: ${remotePath}`);
|
|
108
|
-
await mkdir(installedLibFolder, { recursive: true });
|
|
109
|
-
try {
|
|
110
|
-
const result = await fetch(remotePath);
|
|
111
|
-
await Bun.write(installedLibPath, result);
|
|
112
|
-
} catch (e) {
|
|
113
|
-
console.error(`Failed to download ${remotePath} to ${installedLibPath}: ${e}`);
|
|
114
|
-
}
|
|
115
|
-
return installedLibPath;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// src/lib.ts
|
|
119
|
-
var libPath = await getLibPath("flowscripter_template_bun_rust_library");
|
|
120
|
-
console.debug(`dlopen libPath: ${libPath}`);
|
|
121
|
-
var {
|
|
122
|
-
symbols: { add }
|
|
123
|
-
} = dlopen(libPath, {
|
|
124
|
-
add: {
|
|
125
|
-
args: [FFIType.i32, FFIType.i32],
|
|
126
|
-
returns: FFIType.i32
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
function world() {
|
|
130
|
-
console.info(`World ${add(2, 2)}`);
|
|
131
|
-
}
|
|
132
|
-
export {
|
|
133
|
-
world
|
|
134
|
-
};
|
|
1
|
+
export * from "./src/lib.js";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flowscripter/template-bun-rust-library",
|
|
3
|
+
"version": "1.2.5",
|
|
4
|
+
"description": "Project template for a Rust library with Bun FFI bindings",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"bun",
|
|
7
|
+
"example",
|
|
8
|
+
"ffi",
|
|
9
|
+
"library",
|
|
10
|
+
"rust",
|
|
11
|
+
"template"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/flowscripter/template-bun-rust-library#readme",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/flowscripter/template-bun-rust-library.git"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"src",
|
|
22
|
+
"index.ts",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "dist/index.js",
|
|
28
|
+
"module": "dist/index.js",
|
|
29
|
+
"types": "dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"bun": "./index.ts",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsc -p tsconfig.build.json"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/bun": "^1.3.14",
|
|
45
|
+
"oxfmt": "0.57.0",
|
|
46
|
+
"oxlint": "1.72.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"typescript": "^6.0.3"
|
|
50
|
+
},
|
|
51
|
+
"ffiLibBaseUri": "https://github.com/flowscripter/template-bun-rust-library/releases/download/v1.2.5",
|
|
52
|
+
"typedocOptions": {
|
|
53
|
+
"readme": "none",
|
|
54
|
+
"exclude": [
|
|
55
|
+
"tests/**"
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import { suffix } from "bun:ffi";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { mkdir } from "node:fs/promises";
|
|
5
|
+
import packageJson from "../package.json";
|
|
6
|
+
export function buildLocalLibName(libName, libSuffix) {
|
|
7
|
+
const base = `${libName}.${libSuffix}`;
|
|
8
|
+
return libSuffix === "dll" ? base : `lib${base}`;
|
|
9
|
+
}
|
|
10
|
+
export function buildRemoteLibName(libName, libSuffix, arch) {
|
|
11
|
+
if (libSuffix === "so")
|
|
12
|
+
return `${arch}.${libSuffix}`;
|
|
13
|
+
if (libSuffix === "dll")
|
|
14
|
+
return `${libName}.${arch}.${libSuffix}`;
|
|
15
|
+
return buildLocalLibName(libName, libSuffix);
|
|
16
|
+
}
|
|
17
|
+
export function buildRemoteUrl(baseUri, remoteLibName) {
|
|
18
|
+
const base = baseUri.endsWith("/") ? baseUri : baseUri + "/";
|
|
19
|
+
return new URL(remoteLibName, base).href;
|
|
20
|
+
}
|
|
21
|
+
export async function getLibPath(libName) {
|
|
22
|
+
const fullLibName = buildLocalLibName(libName, suffix);
|
|
23
|
+
// look in release build location
|
|
24
|
+
const builtLibPath = path.join("target", "release", fullLibName);
|
|
25
|
+
console.debug(`builtLibPath: ${builtLibPath}`);
|
|
26
|
+
const builtLibFile = Bun.file(builtLibPath);
|
|
27
|
+
let exists = await builtLibFile.exists();
|
|
28
|
+
console.debug(`${builtLibPath} exists: ${exists}`);
|
|
29
|
+
if (exists) {
|
|
30
|
+
return builtLibPath;
|
|
31
|
+
}
|
|
32
|
+
// look in release installed location
|
|
33
|
+
const installedLibFolder = path.join(os.homedir(), ".flowscripter", "lib");
|
|
34
|
+
const installedLibPath = path.join(installedLibFolder, fullLibName);
|
|
35
|
+
const installedLibFile = Bun.file(installedLibPath);
|
|
36
|
+
exists = await installedLibFile.exists();
|
|
37
|
+
console.debug(`${installedLibPath} exists: ${exists}`);
|
|
38
|
+
if (exists) {
|
|
39
|
+
return installedLibPath;
|
|
40
|
+
}
|
|
41
|
+
console.debug(`packageJson.ffiLibBaseUri: ${packageJson.ffiLibBaseUri}`);
|
|
42
|
+
const remoteLibName = buildRemoteLibName(libName, suffix, process.arch);
|
|
43
|
+
const remotePath = buildRemoteUrl(packageJson.ffiLibBaseUri, remoteLibName);
|
|
44
|
+
console.debug(`remotePath: ${remotePath}`);
|
|
45
|
+
await mkdir(installedLibFolder, { recursive: true });
|
|
46
|
+
try {
|
|
47
|
+
const result = await fetch(remotePath);
|
|
48
|
+
await Bun.write(installedLibPath, result);
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
console.error(`Failed to download ${remotePath} to ${installedLibPath}: ${e}`);
|
|
52
|
+
}
|
|
53
|
+
return installedLibPath;
|
|
54
|
+
}
|
package/dist/src/lib.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { dlopen, FFIType } from "bun:ffi";
|
|
2
|
+
import { getLibPath } from "./lib-path.js";
|
|
3
|
+
const libPath = await getLibPath("flowscripter_template_bun_rust_library");
|
|
4
|
+
console.debug(`dlopen libPath: ${libPath}`);
|
|
5
|
+
const { symbols: { add }, } = dlopen(libPath, {
|
|
6
|
+
add: {
|
|
7
|
+
args: [FFIType.i32, FFIType.i32],
|
|
8
|
+
returns: FFIType.i32,
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Adds 2 and 2 and logs the result as "World 4"
|
|
13
|
+
*/
|
|
14
|
+
export function world() {
|
|
15
|
+
console.info(`World ${add(2, 2)}`);
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowscripter/template-bun-rust-library",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"description": "Project template for a Rust library with Bun FFI bindings",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
-
"build": "
|
|
41
|
+
"build": "tsc -p tsconfig.build.json"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/bun": "^1.3.14",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"typescript": "^6.0.3"
|
|
50
50
|
},
|
|
51
|
-
"ffiLibBaseUri": "https://github.com/flowscripter/template-bun-rust-library/releases/download/v1.2.
|
|
51
|
+
"ffiLibBaseUri": "https://github.com/flowscripter/template-bun-rust-library/releases/download/v1.2.6",
|
|
52
52
|
"typedocOptions": {
|
|
53
53
|
"readme": "none",
|
|
54
54
|
"exclude": [
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lib_path_test.d.ts","sourceRoot":"","sources":["../../tests/lib_path_test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"world_test.d.ts","sourceRoot":"","sources":["../../tests/world_test.ts"],"names":[],"mappings":""}
|