or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-napi-rs--triples

Rust target triples objects for cross-compilation scenarios in Node.js applications

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@napi-rs/triples@2.0.x

To install, run

npx @tessl/cli install tessl/npm-napi-rs--triples@2.0.0

index.mddocs/

@napi-rs/triples

@napi-rs/triples provides comprehensive Rust target triples definitions organized by platform and architecture combinations. It exports structured data containing target triple strings along with parsed platform, architecture, and ABI information for cross-compilation scenarios.

Package Information

  • Package Name: @napi-rs/triples
  • Package Type: npm
  • Language: JavaScript/TypeScript
  • Installation: npm install @napi-rs/triples

Core Imports

import { platformArchTriples } from "@napi-rs/triples";

CommonJS:

const { platformArchTriples } = require("@napi-rs/triples");

Basic Usage

import { platformArchTriples } from "@napi-rs/triples";

// Get all Linux x64 target triples
const linuxX64Triples = platformArchTriples.linux.x64;
console.log(linuxX64Triples);
// [
//   {
//     "triple": "x86_64-unknown-linux-gnu",
//     "platformArchABI": "linux-x64-gnu",
//     "platform": "linux",
//     "arch": "x64",
//     "abi": "gnu"
//   },
//   {
//     "triple": "x86_64-unknown-linux-musl",
//     "platformArchABI": "linux-x64-musl",
//     "platform": "linux",
//     "arch": "x64",
//     "abi": "musl"
//   }
// ]

// Find a specific target triple for Windows ARM64 with MSVC
const winArm64MSVC = platformArchTriples.win32.arm64.find(
  triple => triple.abi === "msvc"
);
console.log(winArm64MSVC?.triple); // "aarch64-pc-windows-msvc"

// Get all available platforms
const platforms = Object.keys(platformArchTriples);
console.log(platforms); // ["darwin", "ios", "android", "win32", "linux", "openharmony", "freebsd"]

// Get all architectures for a specific platform
const linuxArchs = Object.keys(platformArchTriples.linux);
console.log(linuxArchs); // ["arm64", "arm", "armv5te", "i586", "ia32", "loongarch64", ...]

Architecture

The package is designed around a simple nested object structure that makes it easy to:

  • Cross-compilation workflows: Select appropriate Rust target triples based on deployment requirements
  • Build automation: Map Node.js platform/architecture identifiers to Rust compilation targets
  • Target discovery: Enumerate available targets for specific platform/architecture combinations
  • ABI selection: Choose between different ABI variants (GNU, MSVC, musl, etc.) for the same platform/arch

Capabilities

Platform-Architecture Target Triples

The main export provides comprehensive mappings of Rust target triples organized by platform and architecture combinations.

export const platformArchTriples: {
  [platform: string]: {
    [architecture: string]: Triple[]
  }
};

interface Triple {
  /** The raw Rust target triple string (e.g., "x86_64-unknown-linux-gnu") */
  triple: string;
  /** Normalized platform-arch-abi identifier (e.g., "linux-x64-gnu") */
  platformArchABI: string;
  /** Target platform name (e.g., "linux", "darwin", "win32") */
  platform: string;
  /** Target architecture name (e.g., "x64", "arm64", "ia32") */
  arch: string;
  /** Application Binary Interface variant (e.g., "gnu", "msvc", "musl") or null */
  abi: string | null;
}

Supported Platforms

The following platforms are included with their respective architectures:

Desktop Platforms:

  • darwin (macOS): arm64, x64
  • linux: arm64, arm, armv5te, i586, ia32, loongarch64, powerpc, powerpc64, ppc64, riscv64, s390x, sparc64, thumbv7neon, x64
  • win32 (Windows): arm64, arm64ec, ia32, x64
  • freebsd: ia32, x64

Mobile Platforms:

  • ios: arm64, x64
  • android: arm64, arm, ia32, thumbv7neon, x64

Embedded/Other Platforms:

  • openharmony: arm64, arm, x64

ABI Variants

Each platform/architecture combination may include multiple ABI (Application Binary Interface) variants:

  • GNU toolchain: "gnu", "gnueabihf", "gnux32", "gnullvm"
  • Microsoft Visual C++: "msvc"
  • musl libc: "musl", "musleabihf"
  • Other specialized ABIs: "macabi", "sim", "eabi"
  • No specific ABI: null for platforms without specific ABI requirements

Target Triple Structure

Each target triple follows the Rust target triple format: <arch>-<vendor>-<sys>[-<abi>]

Examples:

  • x86_64-unknown-linux-gnu → Linux x64 with GNU toolchain
  • aarch64-pc-windows-msvc → Windows ARM64 with MSVC
  • aarch64-apple-darwin → macOS ARM64 (no specific ABI)
  • armv7-linux-androideabi → Android ARMv7 with EABI

Usage Examples

Target Selection for Cross-compilation:

import { platformArchTriples } from "@napi-rs/triples";

function selectTargetTriple(platform: string, arch: string, preferredABI?: string): string | null {
  const platformTargets = platformArchTriples[platform];
  if (!platformTargets) return null;
  
  const archTargets = platformTargets[arch];
  if (!archTargets || archTargets.length === 0) return null;
  
  // If ABI preference specified, try to find it
  if (preferredABI) {
    const preferred = archTargets.find(target => target.abi === preferredABI);
    if (preferred) return preferred.triple;
  }
  
  // Return first available target
  return archTargets[0].triple;
}

// Examples
const linuxTarget = selectTargetTriple("linux", "x64", "gnu");
// "x86_64-unknown-linux-gnu"

const windowsTarget = selectTargetTriple("win32", "arm64", "msvc");  
// "aarch64-pc-windows-msvc"

Build Matrix Generation:

import { platformArchTriples } from "@napi-rs/triples";

function generateBuildMatrix(): { platform: string; arch: string; target: string }[] {
  const matrix = [];
  
  for (const [platform, architectures] of Object.entries(platformArchTriples)) {
    for (const [arch, targets] of Object.entries(architectures)) {
      // Use first target for each platform/arch combination
      matrix.push({
        platform,
        arch,
        target: targets[0].triple
      });
    }
  }
  
  return matrix;
}

const buildMatrix = generateBuildMatrix();
// [
//   { platform: "darwin", arch: "arm64", target: "aarch64-apple-darwin" },
//   { platform: "darwin", arch: "x64", target: "x86_64-apple-darwin" },
//   { platform: "linux", arch: "arm64", target: "aarch64-unknown-linux-gnu" },
//   ...
// ]

Platform Compatibility Check:

import { platformArchTriples } from "@napi-rs/triples";

function isPlatformSupported(platform: string, arch: string): boolean {
  return !!(platformArchTriples[platform]?.[arch]?.length > 0);
}

function getAvailableABIs(platform: string, arch: string): string[] {
  const targets = platformArchTriples[platform]?.[arch] || [];
  return [...new Set(targets.map(t => t.abi).filter(Boolean))];
}

// Examples
console.log(isPlatformSupported("linux", "riscv64")); // true
console.log(isPlatformSupported("linux", "mips")); // false
console.log(getAvailableABIs("linux", "x64")); // ["gnu", "gnux32", "musl"]