Files
dmtrkovalenko--fff/packages/fff-node/src/platform.ts
T
wehub-resource-sync d5f207424b
Python CI / Python bindings (ubuntu-latest) (push) Failing after 0s
Build & Publish / Build Neovim aarch64-linux-android (push) Failing after 0s
Build & Publish / Build Neovim aarch64-unknown-linux-gnu (push) Failing after 0s
Build & Publish / Build MCP x86_64-unknown-linux-musl (push) Failing after 1s
Build & Publish / Build Python wheels aarch64 (ubuntu-latest) (push) Failing after 0s
Build & Publish / Build Python wheels x86_64 (ubuntu-latest) (push) Failing after 1s
Build & Publish / Build Python sdist (push) Failing after 1s
Rust CI / Fuzz Tests (ubuntu-latest) (push) Failing after 1s
Rust CI / Build i686-unknown-linux-gnu (push) Failing after 0s
Rust CI / cargo clippy (push) Failing after 1s
e2e Tests / e2e (ubuntu-latest) (push) Failing after 1s
Lua CI / luacheck lint (push) Failing after 1s
Build & Publish / Build Neovim aarch64-unknown-linux-musl (push) Failing after 1s
Build & Publish / Build Neovim x86_64-unknown-linux-gnu (push) Failing after 0s
Build & Publish / Build Neovim x86_64-unknown-linux-musl (push) Failing after 1s
Build & Publish / Build C FFI aarch64-linux-android (push) Failing after 0s
Build & Publish / Build C FFI aarch64-unknown-linux-gnu (push) Failing after 0s
Build & Publish / Build C FFI aarch64-unknown-linux-musl (push) Failing after 1s
Build & Publish / Build C FFI x86_64-unknown-linux-gnu (push) Failing after 0s
Build & Publish / Build C FFI x86_64-unknown-linux-musl (push) Failing after 1s
Build & Publish / Build MCP aarch64-unknown-linux-gnu (push) Failing after 1s
Build & Publish / Build MCP aarch64-unknown-linux-musl (push) Failing after 0s
Build & Publish / Build MCP x86_64-unknown-linux-gnu (push) Failing after 1s
Spelling / Spell Check with Typos (push) Failing after 0s
Rust CI / Test (ubuntu-latest) (push) Failing after 0s
Rust CI / cargo fmt (push) Failing after 0s
Stylua / Check lua files using Stylua (push) Failing after 1s
Lua CI / lua-language-server type check (push) Failing after 12m29s
e2e Tests / e2e (alpine-musl) (push) Successful in 57m31s
e2e Tests / e2e (macos-latest) (push) Has been cancelled
Build & Publish / Build C FFI aarch64-apple-darwin (push) Has been cancelled
Rust CI / Test (windows-latest) (push) Has been cancelled
e2e Tests / e2e (windows-latest) (push) Has been cancelled
Nix CI / check (push) Has been cancelled
Python CI / Python bindings (macos-latest) (push) Has been cancelled
Python CI / Python bindings (windows-latest) (push) Has been cancelled
Build & Publish / Build Neovim aarch64-apple-darwin (push) Has been cancelled
Build & Publish / Build Neovim aarch64-pc-windows-msvc (push) Has been cancelled
Build & Publish / Build Neovim x86_64-apple-darwin (push) Has been cancelled
Build & Publish / Build Neovim x86_64-pc-windows-msvc (push) Has been cancelled
Build & Publish / Build C FFI aarch64-pc-windows-msvc (push) Has been cancelled
Build & Publish / Build C FFI x86_64-apple-darwin (push) Has been cancelled
Build & Publish / Build C FFI x86_64-pc-windows-msvc (push) Has been cancelled
Build & Publish / Build MCP aarch64-apple-darwin (push) Has been cancelled
Build & Publish / Build MCP aarch64-pc-windows-msvc (push) Has been cancelled
Build & Publish / Build MCP x86_64-apple-darwin (push) Has been cancelled
Build & Publish / Build MCP x86_64-pc-windows-msvc (push) Has been cancelled
Build & Publish / Build Python wheels aarch64 (macos-latest) (push) Has been cancelled
Build & Publish / Build Python wheels x86_64 (macos-latest) (push) Has been cancelled
Build & Publish / Build Python wheels x86_64 (windows-latest) (push) Has been cancelled
Build & Publish / Release (push) Has been cancelled
Build & Publish / Publish Python wheels to PyPI (push) Has been cancelled
Build & Publish / Publish Rust crates (push) Has been cancelled
Build & Publish / Publish npm packages (push) Has been cancelled
Rust CI / Fuzz Tests (windows-latest) (push) Has been cancelled
Rust CI / Test (macos-latest) (push) Has been cancelled
Rust CI / Fuzz Tests (macos-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:27:16 +08:00

128 lines
3.4 KiB
TypeScript

/**
* Platform detection utilities for downloading the correct binary
*/
import { execSync } from "node:child_process";
/**
* Get the platform triple (e.g., "x86_64-unknown-linux-gnu")
*/
export function getTriple(): string {
const platform = process.platform;
const arch = process.arch;
let osName: string;
if (platform === "darwin") {
osName = "apple-darwin";
} else if (platform === "linux") {
osName = detectLinuxLibc();
} else if (platform === "win32") {
osName = "pc-windows-msvc";
} else {
throw new Error(`Unsupported platform: ${platform}`);
}
const archName = normalizeArch(arch);
return `${archName}-${osName}`;
}
/**
* Detect whether we're on musl or glibc Linux
*/
function detectLinuxLibc(): string {
let output = "";
try {
output = execSync("ldd --version 2>&1", {
encoding: "utf-8",
timeout: 5000,
});
} catch (e: unknown) {
const err = e as { stdout?: string | Buffer; stderr?: string | Buffer };
output = String(err?.stdout ?? "") + String(err?.stderr ?? "");
}
// ldd on musl can produce stdout with musl either with exit code 1 or 0
if (output.toLowerCase().includes("musl")) {
return "unknown-linux-musl";
}
return "unknown-linux-gnu";
}
/**
* Normalize architecture name to Rust target format
*/
function normalizeArch(arch: string): string {
switch (arch) {
case "x64":
case "amd64":
return "x86_64";
case "arm64":
return "aarch64";
case "arm":
return "arm";
default:
throw new Error(`Unsupported architecture: ${arch}`);
}
}
/**
* Get the library file extension for the current platform
*/
export function getLibExtension(): "dylib" | "so" | "dll" {
switch (process.platform) {
case "darwin":
return "dylib";
case "win32":
return "dll";
default:
return "so";
}
}
/**
* Get the library filename prefix (empty on Windows)
*/
export function getLibPrefix(): string {
return process.platform === "win32" ? "" : "lib";
}
/**
* Get the full library filename for the current platform
*/
export function getLibFilename(): string {
const prefix = getLibPrefix();
const ext = getLibExtension();
return `${prefix}fff_c.${ext}`;
}
/**
* Map from Rust target triple to npm platform package name.
* The @ff-labs/fff-bin-* packages contain the pre-built libfff_c
* shared library and are runtime-agnostic (used by both Bun and Node).
*/
const TRIPLE_TO_NPM_PACKAGE: Record<string, string> = {
"aarch64-apple-darwin": "@ff-labs/fff-bin-darwin-arm64",
"x86_64-apple-darwin": "@ff-labs/fff-bin-darwin-x64",
"x86_64-unknown-linux-gnu": "@ff-labs/fff-bin-linux-x64-gnu",
"aarch64-unknown-linux-gnu": "@ff-labs/fff-bin-linux-arm64-gnu",
"x86_64-unknown-linux-musl": "@ff-labs/fff-bin-linux-x64-musl",
"aarch64-unknown-linux-musl": "@ff-labs/fff-bin-linux-arm64-musl",
"x86_64-pc-windows-msvc": "@ff-labs/fff-bin-win32-x64",
"aarch64-pc-windows-msvc": "@ff-labs/fff-bin-win32-arm64",
};
/**
* Get the npm package name for the current platform's native binary.
*
* @returns Package name like "@ff-labs/fff-bin-darwin-arm64"
* @throws If the current platform is not supported
*/
export function getNpmPackageName(): string {
const triple = getTriple();
const packageName = TRIPLE_TO_NPM_PACKAGE[triple];
if (!packageName) {
throw new Error(`No npm package available for platform: ${triple}`);
}
return packageName;
}