@flowscripter/template-bun-rust-library 1.2.56 → 1.2.57
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 +10 -0
- package/dist/package.json +5 -2
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +5 -6
- package/package.json +5 -2
- package/src/lib.ts +12 -11
- package/dist/src/lib-path.d.ts +0 -5
- package/dist/src/lib-path.d.ts.map +0 -1
- package/dist/src/lib-path.js +0 -54
- package/src/lib-path.ts +0 -71
package/README.md
CHANGED
|
@@ -68,6 +68,16 @@ classDiagram
|
|
|
68
68
|
Foo <|-- Bar
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
### Native Library Loading
|
|
72
|
+
|
|
73
|
+
`src/lib.ts` opens the compiled Rust library with `loadLibrary` from [@flowscripter/bun-ffi-loader](https://github.com/flowscripter/bun-ffi-loader), passing the `ffiLibBaseUri` from `package.json` as `baseUri`. The loader uses the first of:
|
|
74
|
+
|
|
75
|
+
1. a local release build in `target/release` relative to the working directory
|
|
76
|
+
2. the installed copy in `~/.flowscripter/lib`
|
|
77
|
+
3. a download from `ffiLibBaseUri` into `~/.flowscripter/lib`
|
|
78
|
+
|
|
79
|
+
If none works it throws a `LibraryNotFoundError` listing the candidates it tried. The release workflow updates `ffiLibBaseUri` to point at the release assets.
|
|
80
|
+
|
|
71
81
|
### API
|
|
72
82
|
|
|
73
83
|
Link to auto-generated API docs:
|
package/dist/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.56",
|
|
4
4
|
"description": "Project template for a Rust library with Bun FFI bindings",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -40,6 +40,9 @@
|
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsc -p tsconfig.build.json"
|
|
42
42
|
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@flowscripter/bun-ffi-loader": "^1.1.1"
|
|
45
|
+
},
|
|
43
46
|
"devDependencies": {
|
|
44
47
|
"@types/bun": "^1.4.5",
|
|
45
48
|
"oxfmt": "0.79.0",
|
|
@@ -48,7 +51,7 @@
|
|
|
48
51
|
"peerDependencies": {
|
|
49
52
|
"typescript": "^7.0.2"
|
|
50
53
|
},
|
|
51
|
-
"ffiLibBaseUri": "https://github.com/flowscripter/template-bun-rust-library/releases/download/v1.2.
|
|
54
|
+
"ffiLibBaseUri": "https://github.com/flowscripter/template-bun-rust-library/releases/download/v1.2.56",
|
|
52
55
|
"typedocOptions": {
|
|
53
56
|
"readme": "none",
|
|
54
57
|
"exclude": [
|
package/dist/src/lib.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAiBA;;GAEG;AACH,wBAAgB,KAAK,IAAI,IAAI,CAE5B"}
|
package/dist/src/lib.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { symbols: { add }, } = dlopen(libPath, {
|
|
1
|
+
import { FFIType } from "bun:ffi";
|
|
2
|
+
import { loadLibrary } from "@flowscripter/bun-ffi-loader";
|
|
3
|
+
import packageJson from "../package.json";
|
|
4
|
+
const { symbols: { add }, } = await loadLibrary("flowscripter_template_bun_rust_library", {
|
|
6
5
|
add: {
|
|
7
6
|
args: [FFIType.i32, FFIType.i32],
|
|
8
7
|
returns: FFIType.i32,
|
|
9
8
|
},
|
|
10
|
-
});
|
|
9
|
+
}, { baseUri: packageJson.ffiLibBaseUri });
|
|
11
10
|
/**
|
|
12
11
|
* Adds 2 and 2 and logs the result as "World 4"
|
|
13
12
|
*/
|
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.57",
|
|
4
4
|
"description": "Project template for a Rust library with Bun FFI bindings",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -40,6 +40,9 @@
|
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsc -p tsconfig.build.json"
|
|
42
42
|
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@flowscripter/bun-ffi-loader": "^1.1.1"
|
|
45
|
+
},
|
|
43
46
|
"devDependencies": {
|
|
44
47
|
"@types/bun": "^1.4.5",
|
|
45
48
|
"oxfmt": "0.79.0",
|
|
@@ -48,7 +51,7 @@
|
|
|
48
51
|
"peerDependencies": {
|
|
49
52
|
"typescript": "^7.0.2"
|
|
50
53
|
},
|
|
51
|
-
"ffiLibBaseUri": "https://github.com/flowscripter/template-bun-rust-library/releases/download/v1.2.
|
|
54
|
+
"ffiLibBaseUri": "https://github.com/flowscripter/template-bun-rust-library/releases/download/v1.2.57",
|
|
52
55
|
"typedocOptions": {
|
|
53
56
|
"readme": "none",
|
|
54
57
|
"exclude": [
|
package/src/lib.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const libPath = await getLibPath("flowscripter_template_bun_rust_library");
|
|
5
|
-
|
|
6
|
-
console.debug(`dlopen libPath: ${libPath}`);
|
|
1
|
+
import { FFIType } from "bun:ffi";
|
|
2
|
+
import { loadLibrary } from "@flowscripter/bun-ffi-loader";
|
|
3
|
+
import packageJson from "../package.json";
|
|
7
4
|
|
|
8
5
|
const {
|
|
9
6
|
symbols: { add },
|
|
10
|
-
} =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
} = await loadLibrary(
|
|
8
|
+
"flowscripter_template_bun_rust_library",
|
|
9
|
+
{
|
|
10
|
+
add: {
|
|
11
|
+
args: [FFIType.i32, FFIType.i32],
|
|
12
|
+
returns: FFIType.i32,
|
|
13
|
+
},
|
|
14
14
|
},
|
|
15
|
-
}
|
|
15
|
+
{ baseUri: packageJson.ffiLibBaseUri },
|
|
16
|
+
);
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Adds 2 and 2 and logs the result as "World 4"
|
package/dist/src/lib-path.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export declare function buildLocalLibName(libName: string, libSuffix: string): string;
|
|
2
|
-
export declare function buildRemoteLibName(libName: string, libSuffix: string, arch: string): string;
|
|
3
|
-
export declare function buildRemoteUrl(baseUri: string, remoteLibName: string): string;
|
|
4
|
-
export declare function getLibPath(libName: string): Promise<string>;
|
|
5
|
-
//# sourceMappingURL=lib-path.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lib-path.d.ts","sourceRoot":"","sources":["../../src/lib-path.ts"],"names":[],"mappings":"AAMA,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAG5E;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI3F;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAG7E;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,mBAgD/C"}
|
package/dist/src/lib-path.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
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/src/lib-path.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
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
|
-
|
|
7
|
-
export function buildLocalLibName(libName: string, libSuffix: string): string {
|
|
8
|
-
const base = `${libName}.${libSuffix}`;
|
|
9
|
-
return libSuffix === "dll" ? base : `lib${base}`;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function buildRemoteLibName(libName: string, libSuffix: string, arch: string): string {
|
|
13
|
-
if (libSuffix === "so") return `${arch}.${libSuffix}`;
|
|
14
|
-
if (libSuffix === "dll") return `${libName}.${arch}.${libSuffix}`;
|
|
15
|
-
return buildLocalLibName(libName, libSuffix);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function buildRemoteUrl(baseUri: string, remoteLibName: string): string {
|
|
19
|
-
const base = baseUri.endsWith("/") ? baseUri : baseUri + "/";
|
|
20
|
-
return new URL(remoteLibName, base).href;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function getLibPath(libName: string) {
|
|
24
|
-
const fullLibName = buildLocalLibName(libName, suffix);
|
|
25
|
-
|
|
26
|
-
// look in release build location
|
|
27
|
-
const builtLibPath = path.join("target", "release", fullLibName);
|
|
28
|
-
|
|
29
|
-
console.debug(`builtLibPath: ${builtLibPath}`);
|
|
30
|
-
|
|
31
|
-
const builtLibFile = Bun.file(builtLibPath);
|
|
32
|
-
let exists = await builtLibFile.exists();
|
|
33
|
-
|
|
34
|
-
console.debug(`${builtLibPath} exists: ${exists}`);
|
|
35
|
-
|
|
36
|
-
if (exists) {
|
|
37
|
-
return builtLibPath;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// look in release installed location
|
|
41
|
-
const installedLibFolder = path.join(os.homedir(), ".flowscripter", "lib");
|
|
42
|
-
const installedLibPath = path.join(installedLibFolder, fullLibName);
|
|
43
|
-
const installedLibFile = Bun.file(installedLibPath);
|
|
44
|
-
|
|
45
|
-
exists = await installedLibFile.exists();
|
|
46
|
-
|
|
47
|
-
console.debug(`${installedLibPath} exists: ${exists}`);
|
|
48
|
-
|
|
49
|
-
if (exists) {
|
|
50
|
-
return installedLibPath;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
console.debug(`packageJson.ffiLibBaseUri: ${packageJson.ffiLibBaseUri}`);
|
|
54
|
-
|
|
55
|
-
const remoteLibName = buildRemoteLibName(libName, suffix, process.arch);
|
|
56
|
-
const remotePath = buildRemoteUrl(packageJson.ffiLibBaseUri, remoteLibName);
|
|
57
|
-
|
|
58
|
-
console.debug(`remotePath: ${remotePath}`);
|
|
59
|
-
|
|
60
|
-
await mkdir(installedLibFolder, { recursive: true });
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
const result = await fetch(remotePath);
|
|
64
|
-
|
|
65
|
-
await Bun.write(installedLibPath, result);
|
|
66
|
-
} catch (e) {
|
|
67
|
-
console.error(`Failed to download ${remotePath} to ${installedLibPath}: ${e}`);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return installedLibPath;
|
|
71
|
-
}
|