@mediaway/ffi 0.1.6 → 0.1.8

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.d.ts CHANGED
@@ -14,10 +14,8 @@
14
14
  * `_free` — the public packages do this automatically.
15
15
  */
16
16
  import { type TypeObject } from "koffi";
17
- export declare function findLibrary(name: string): string;
18
- export declare const containerLib: import("koffi").LibraryHandle;
19
- export declare const pipelineLib: import("koffi").LibraryHandle;
20
- export declare const deviceLib: import("koffi").LibraryHandle;
17
+ import { findLibrary, containerLib, pipelineLib, deviceLib } from "./loader.js";
18
+ export { findLibrary, containerLib, pipelineLib, deviceLib };
21
19
  export declare const MwRational: TypeObject;
22
20
  export declare const MwVideoTrackInfo: TypeObject;
23
21
  export declare const MwAudioTrackInfo: TypeObject;
package/dist/index.js CHANGED
@@ -14,58 +14,8 @@
14
14
  * `_free` — the public packages do this automatically.
15
15
  */
16
16
  import koffi, {} from "koffi";
17
- import fs from "node:fs";
18
- import path from "node:path";
19
- import { fileURLToPath } from "node:url";
20
- // ── Library discovery ──────────────────────────────────────────────────────────
21
- // The cdylibs are Rust build artifacts, not installed system libraries. Search:
22
- // 1. $MEDIAWAY_FFI_DIR
23
- // 2. <this package>/native (DLLs bundled at pack time — the npm distribution)
24
- // 3. <repo root>/target/x86_64-pc-windows-gnu/debug (GNU toolchain, dev runs)
25
- // 4. <repo root>/target/debug (host/MSVC toolchain)
26
- // 5. cwd
27
- const here = path.dirname(fileURLToPath(import.meta.url));
28
- const repoRoot = path.resolve(here, "..", "..", "..", "..", "..");
29
- const searchDirs = [
30
- process.env.MEDIAWAY_FFI_DIR ?? "",
31
- path.resolve(here, "..", "native"),
32
- path.join(repoRoot, "target", "x86_64-pc-windows-gnu", "debug"),
33
- path.join(repoRoot, "target", "debug"),
34
- process.cwd(),
35
- ];
36
- export function findLibrary(name) {
37
- for (const dir of searchDirs) {
38
- if (!dir)
39
- continue;
40
- const candidate = path.join(dir, name);
41
- if (fs.existsSync(candidate))
42
- return candidate;
43
- }
44
- throw new Error(`cannot find ${name}; set $MEDIAWAY_FFI_DIR or build the -ffi crates`);
45
- }
46
- /**
47
- * cdylib filename Cargo produces for this platform. Windows and Linux only —
48
- * the workspace's own hardware/CI coverage is limited to those two (see
49
- * docs/ai/wiki/platform/order.md); macOS support is not claimed here since
50
- * it has never been built or run.
51
- */
52
- function libraryFilename() {
53
- switch (process.platform) {
54
- case "win32":
55
- return "mediaway_ffi.dll";
56
- case "linux":
57
- return "libmediaway_ffi.so";
58
- default:
59
- throw new Error(`mediaway: unsupported platform ${process.platform} (Windows and Linux only)`);
60
- }
61
- }
62
- function load(name) {
63
- return koffi.load(findLibrary(name));
64
- }
65
- const libraryName = libraryFilename();
66
- export const containerLib = load(libraryName);
67
- export const pipelineLib = load(libraryName);
68
- export const deviceLib = load(libraryName);
17
+ import { findLibrary, containerLib, pipelineLib, deviceLib } from "./loader.js";
18
+ export { findLibrary, containerLib, pipelineLib, deviceLib };
69
19
  // ── Structs (layouts mirror the headers exactly) ───────────────────────────────
70
20
  export const MwRational = koffi.struct("MwRational", {
71
21
  num: "uint64",
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Native library discovery + koffi load for @mediaway/ffi.
3
+ *
4
+ * Split out of index.ts (ADR-0024, multi-platform binding distribution)
5
+ * once the added per-platform search-path logic pushed index.ts's struct/
6
+ * function-binding definitions past the workspace's 1000-line source cap.
7
+ */
8
+ export declare function findLibrary(name: string): string;
9
+ export declare const containerLib: import("koffi").LibraryHandle;
10
+ export declare const pipelineLib: import("koffi").LibraryHandle;
11
+ export declare const deviceLib: import("koffi").LibraryHandle;
package/dist/loader.js ADDED
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Native library discovery + koffi load for @mediaway/ffi.
3
+ *
4
+ * Split out of index.ts (ADR-0024, multi-platform binding distribution)
5
+ * once the added per-platform search-path logic pushed index.ts's struct/
6
+ * function-binding definitions past the workspace's 1000-line source cap.
7
+ */
8
+ import koffi from "koffi";
9
+ import fs from "node:fs";
10
+ import path from "node:path";
11
+ import { fileURLToPath } from "node:url";
12
+ // ── Library discovery ──────────────────────────────────────────────────────────
13
+ // The cdylib is a Rust build artifact, not an installed system library.
14
+ // Search:
15
+ // 1. $MEDIAWAY_FFI_DIR
16
+ // 2. <this package>/native/<platform>-<arch> (libs for every platform
17
+ // bundled at pack time — the npm distribution; see § platform tag)
18
+ // 3. <repo root>/target/x86_64-pc-windows-gnu/debug (GNU toolchain, dev runs)
19
+ // 4. <repo root>/target/debug (host/MSVC toolchain)
20
+ // 5. cwd
21
+ const here = path.dirname(fileURLToPath(import.meta.url));
22
+ const repoRoot = path.resolve(here, "..", "..", "..", "..", "..");
23
+ /**
24
+ * `os-arch` tag matching one of `native/<tag>`'s subdirectories (this
25
+ * package bundles every platform's prebuilt lib directly — see
26
+ * tools/scripts/copy-native-dlls.ts). Returns `undefined` for an
27
+ * unsupported platform/arch pair rather than throwing, so callers can still
28
+ * fall through to the other search dirs (e.g. `$MEDIAWAY_FFI_DIR` during
29
+ * local development on an unlisted arch).
30
+ */
31
+ function platformTag() {
32
+ const os = process.platform === "win32" ? "win32" : process.platform === "linux" ? "linux"
33
+ : process.platform === "darwin" ? "darwin" : undefined;
34
+ const arch = process.arch === "x64" ? "x64" : process.arch === "arm64" ? "arm64" : undefined;
35
+ return os && arch ? `${os}-${arch}` : undefined;
36
+ }
37
+ const tag = platformTag();
38
+ const searchDirs = [
39
+ process.env.MEDIAWAY_FFI_DIR ?? "",
40
+ tag ? path.resolve(here, "..", "native", tag) : "",
41
+ path.join(repoRoot, "target", "x86_64-pc-windows-gnu", "debug"),
42
+ path.join(repoRoot, "target", "debug"),
43
+ process.cwd(),
44
+ ];
45
+ export function findLibrary(name) {
46
+ for (const dir of searchDirs) {
47
+ if (!dir)
48
+ continue;
49
+ const candidate = path.join(dir, name);
50
+ if (fs.existsSync(candidate))
51
+ return candidate;
52
+ }
53
+ throw new Error(`cannot find ${name}; set $MEDIAWAY_FFI_DIR or build the -ffi crates`);
54
+ }
55
+ /** cdylib filename Cargo produces for this platform. */
56
+ function libraryFilename() {
57
+ switch (process.platform) {
58
+ case "win32":
59
+ return "mediaway_ffi.dll";
60
+ case "linux":
61
+ return "libmediaway_ffi.so";
62
+ case "darwin":
63
+ return "libmediaway_ffi.dylib";
64
+ default:
65
+ throw new Error(`mediaway: unsupported platform ${process.platform}`);
66
+ }
67
+ }
68
+ function load(name) {
69
+ return koffi.load(findLibrary(name));
70
+ }
71
+ const libraryName = libraryFilename();
72
+ export const containerLib = load(libraryName);
73
+ export const pipelineLib = load(libraryName);
74
+ export const deviceLib = load(libraryName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mediaway/ffi",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Rust-based, lightweight, fast — Mediaway native C ABI bindings for Node.js — the shared DLL behind the @mediaway packages",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",