@flowscripter/template-bun-rust-library 1.1.5 → 1.1.7
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/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/package.json +2 -2
- package/src/lib-path.ts +19 -10
- package/tests/lib_path_test.ts +69 -0
package/Cargo.lock
CHANGED
package/Cargo.toml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowscripter/template-bun-rust-library",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Project template for a Rust library with Bun FFI bindings",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"typescript": "^6.0.3"
|
|
31
31
|
},
|
|
32
|
-
"ffiLibBaseUri": "https://github.com/flowscripter/template-bun-rust-library/releases/download/v1.1.
|
|
32
|
+
"ffiLibBaseUri": "https://github.com/flowscripter/template-bun-rust-library/releases/download/v1.1.7",
|
|
33
33
|
"typedocOptions": {
|
|
34
34
|
"readme": "none",
|
|
35
35
|
"exclude": [
|
package/src/lib-path.ts
CHANGED
|
@@ -4,12 +4,24 @@ import path from "node:path";
|
|
|
4
4
|
import { mkdir } from "node:fs/promises";
|
|
5
5
|
import packageJson from "../package.json";
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
|
|
7
|
+
export function buildLocalLibName(libName: string, libSuffix: string): string {
|
|
8
|
+
const base = `${libName}.${libSuffix}`;
|
|
9
|
+
return libSuffix === "dll" ? base : `lib${base}`;
|
|
10
|
+
}
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
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);
|
|
13
25
|
|
|
14
26
|
// look in release build location
|
|
15
27
|
const builtLibPath = path.join("target", "release", fullLibName);
|
|
@@ -40,11 +52,8 @@ export async function getLibPath(libName: string) {
|
|
|
40
52
|
|
|
41
53
|
console.debug(`packageJson.ffiLibBaseUri: ${packageJson.ffiLibBaseUri}`);
|
|
42
54
|
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
? packageJson.ffiLibBaseUri
|
|
46
|
-
: packageJson.ffiLibBaseUri + "/";
|
|
47
|
-
const remotePath = new URL(fullLibName, base).href;
|
|
55
|
+
const remoteLibName = buildRemoteLibName(libName, suffix, process.arch);
|
|
56
|
+
const remotePath = buildRemoteUrl(packageJson.ffiLibBaseUri, remoteLibName);
|
|
48
57
|
|
|
49
58
|
console.debug(`remotePath: ${remotePath}`);
|
|
50
59
|
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { buildLocalLibName, buildRemoteLibName, buildRemoteUrl } from "../src/lib-path.ts";
|
|
3
|
+
|
|
4
|
+
describe("buildLocalLibName", () => {
|
|
5
|
+
test("Linux .so gets lib prefix", () => {
|
|
6
|
+
expect(buildLocalLibName("foo", "so")).toBe("libfoo.so");
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test("macOS .dylib gets lib prefix", () => {
|
|
10
|
+
expect(buildLocalLibName("foo", "dylib")).toBe("libfoo.dylib");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("Windows .dll has no lib prefix", () => {
|
|
14
|
+
expect(buildLocalLibName("foo", "dll")).toBe("foo.dll");
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe("buildRemoteLibName", () => {
|
|
19
|
+
test("Linux x64", () => {
|
|
20
|
+
expect(buildRemoteLibName("foo", "so", "x64")).toBe("x64.so");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("Linux arm64", () => {
|
|
24
|
+
expect(buildRemoteLibName("foo", "so", "arm64")).toBe("arm64.so");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("macOS uses local naming (no arch suffix)", () => {
|
|
28
|
+
expect(buildRemoteLibName("foo", "dylib", "arm64")).toBe("libfoo.dylib");
|
|
29
|
+
expect(buildRemoteLibName("foo", "dylib", "x64")).toBe("libfoo.dylib");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("Windows x64", () => {
|
|
33
|
+
expect(buildRemoteLibName("foo", "dll", "x64")).toBe("foo.x64.dll");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("Windows arm64", () => {
|
|
37
|
+
expect(buildRemoteLibName("foo", "dll", "arm64")).toBe("foo.arm64.dll");
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe("buildRemoteUrl", () => {
|
|
42
|
+
test("base without trailing slash", () => {
|
|
43
|
+
expect(buildRemoteUrl("https://example.com/releases/v1.0", "x64.so")).toBe(
|
|
44
|
+
"https://example.com/releases/v1.0/x64.so",
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("base with trailing slash", () => {
|
|
49
|
+
expect(buildRemoteUrl("https://example.com/releases/v1.0/", "x64.so")).toBe(
|
|
50
|
+
"https://example.com/releases/v1.0/x64.so",
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("does not corrupt https:// into https:/", () => {
|
|
55
|
+
const url = buildRemoteUrl("https://github.com/org/repo/releases/download/v1.0", "x64.so");
|
|
56
|
+
expect(url).toBe("https://github.com/org/repo/releases/download/v1.0/x64.so");
|
|
57
|
+
expect(url.startsWith("https://")).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("real-world example matches expected release asset URL", () => {
|
|
61
|
+
const url = buildRemoteUrl(
|
|
62
|
+
"https://github.com/flowscripter/template-bun-rust-library/releases/download/v1.1.5",
|
|
63
|
+
"x64.so",
|
|
64
|
+
);
|
|
65
|
+
expect(url).toBe(
|
|
66
|
+
"https://github.com/flowscripter/template-bun-rust-library/releases/download/v1.1.5/x64.so",
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
});
|