0
# @napi-rs/triples
1
2
@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.
3
4
## Package Information
5
6
- **Package Name**: @napi-rs/triples
7
- **Package Type**: npm
8
- **Language**: JavaScript/TypeScript
9
- **Installation**: `npm install @napi-rs/triples`
10
11
## Core Imports
12
13
```typescript
14
import { platformArchTriples } from "@napi-rs/triples";
15
```
16
17
CommonJS:
18
19
```javascript
20
const { platformArchTriples } = require("@napi-rs/triples");
21
```
22
23
## Basic Usage
24
25
```typescript
26
import { platformArchTriples } from "@napi-rs/triples";
27
28
// Get all Linux x64 target triples
29
const linuxX64Triples = platformArchTriples.linux.x64;
30
console.log(linuxX64Triples);
31
// [
32
// {
33
// "triple": "x86_64-unknown-linux-gnu",
34
// "platformArchABI": "linux-x64-gnu",
35
// "platform": "linux",
36
// "arch": "x64",
37
// "abi": "gnu"
38
// },
39
// {
40
// "triple": "x86_64-unknown-linux-musl",
41
// "platformArchABI": "linux-x64-musl",
42
// "platform": "linux",
43
// "arch": "x64",
44
// "abi": "musl"
45
// }
46
// ]
47
48
// Find a specific target triple for Windows ARM64 with MSVC
49
const winArm64MSVC = platformArchTriples.win32.arm64.find(
50
triple => triple.abi === "msvc"
51
);
52
console.log(winArm64MSVC?.triple); // "aarch64-pc-windows-msvc"
53
54
// Get all available platforms
55
const platforms = Object.keys(platformArchTriples);
56
console.log(platforms); // ["darwin", "ios", "android", "win32", "linux", "openharmony", "freebsd"]
57
58
// Get all architectures for a specific platform
59
const linuxArchs = Object.keys(platformArchTriples.linux);
60
console.log(linuxArchs); // ["arm64", "arm", "armv5te", "i586", "ia32", "loongarch64", ...]
61
```
62
63
## Architecture
64
65
The package is designed around a simple nested object structure that makes it easy to:
66
67
- **Cross-compilation workflows**: Select appropriate Rust target triples based on deployment requirements
68
- **Build automation**: Map Node.js platform/architecture identifiers to Rust compilation targets
69
- **Target discovery**: Enumerate available targets for specific platform/architecture combinations
70
- **ABI selection**: Choose between different ABI variants (GNU, MSVC, musl, etc.) for the same platform/arch
71
72
## Capabilities
73
74
### Platform-Architecture Target Triples
75
76
The main export provides comprehensive mappings of Rust target triples organized by platform and architecture combinations.
77
78
```typescript { .api }
79
export const platformArchTriples: {
80
[platform: string]: {
81
[architecture: string]: Triple[]
82
}
83
};
84
85
interface Triple {
86
/** The raw Rust target triple string (e.g., "x86_64-unknown-linux-gnu") */
87
triple: string;
88
/** Normalized platform-arch-abi identifier (e.g., "linux-x64-gnu") */
89
platformArchABI: string;
90
/** Target platform name (e.g., "linux", "darwin", "win32") */
91
platform: string;
92
/** Target architecture name (e.g., "x64", "arm64", "ia32") */
93
arch: string;
94
/** Application Binary Interface variant (e.g., "gnu", "msvc", "musl") or null */
95
abi: string | null;
96
}
97
```
98
99
### Supported Platforms
100
101
The following platforms are included with their respective architectures:
102
103
**Desktop Platforms:**
104
- `darwin` (macOS): arm64, x64
105
- `linux`: arm64, arm, armv5te, i586, ia32, loongarch64, powerpc, powerpc64, ppc64, riscv64, s390x, sparc64, thumbv7neon, x64
106
- `win32` (Windows): arm64, arm64ec, ia32, x64
107
- `freebsd`: ia32, x64
108
109
**Mobile Platforms:**
110
- `ios`: arm64, x64
111
- `android`: arm64, arm, ia32, thumbv7neon, x64
112
113
**Embedded/Other Platforms:**
114
- `openharmony`: arm64, arm, x64
115
116
### ABI Variants
117
118
Each platform/architecture combination may include multiple ABI (Application Binary Interface) variants:
119
120
- **GNU toolchain**: `"gnu"`, `"gnueabihf"`, `"gnux32"`, `"gnullvm"`
121
- **Microsoft Visual C++**: `"msvc"`
122
- **musl libc**: `"musl"`, `"musleabihf"`
123
- **Other specialized ABIs**: `"macabi"`, `"sim"`, `"eabi"`
124
- **No specific ABI**: `null` for platforms without specific ABI requirements
125
126
### Target Triple Structure
127
128
Each target triple follows the Rust target triple format: `<arch>-<vendor>-<sys>[-<abi>]`
129
130
Examples:
131
- `x86_64-unknown-linux-gnu` → Linux x64 with GNU toolchain
132
- `aarch64-pc-windows-msvc` → Windows ARM64 with MSVC
133
- `aarch64-apple-darwin` → macOS ARM64 (no specific ABI)
134
- `armv7-linux-androideabi` → Android ARMv7 with EABI
135
136
### Usage Examples
137
138
**Target Selection for Cross-compilation:**
139
140
```typescript
141
import { platformArchTriples } from "@napi-rs/triples";
142
143
function selectTargetTriple(platform: string, arch: string, preferredABI?: string): string | null {
144
const platformTargets = platformArchTriples[platform];
145
if (!platformTargets) return null;
146
147
const archTargets = platformTargets[arch];
148
if (!archTargets || archTargets.length === 0) return null;
149
150
// If ABI preference specified, try to find it
151
if (preferredABI) {
152
const preferred = archTargets.find(target => target.abi === preferredABI);
153
if (preferred) return preferred.triple;
154
}
155
156
// Return first available target
157
return archTargets[0].triple;
158
}
159
160
// Examples
161
const linuxTarget = selectTargetTriple("linux", "x64", "gnu");
162
// "x86_64-unknown-linux-gnu"
163
164
const windowsTarget = selectTargetTriple("win32", "arm64", "msvc");
165
// "aarch64-pc-windows-msvc"
166
```
167
168
**Build Matrix Generation:**
169
170
```typescript
171
import { platformArchTriples } from "@napi-rs/triples";
172
173
function generateBuildMatrix(): { platform: string; arch: string; target: string }[] {
174
const matrix = [];
175
176
for (const [platform, architectures] of Object.entries(platformArchTriples)) {
177
for (const [arch, targets] of Object.entries(architectures)) {
178
// Use first target for each platform/arch combination
179
matrix.push({
180
platform,
181
arch,
182
target: targets[0].triple
183
});
184
}
185
}
186
187
return matrix;
188
}
189
190
const buildMatrix = generateBuildMatrix();
191
// [
192
// { platform: "darwin", arch: "arm64", target: "aarch64-apple-darwin" },
193
// { platform: "darwin", arch: "x64", target: "x86_64-apple-darwin" },
194
// { platform: "linux", arch: "arm64", target: "aarch64-unknown-linux-gnu" },
195
// ...
196
// ]
197
```
198
199
**Platform Compatibility Check:**
200
201
```typescript
202
import { platformArchTriples } from "@napi-rs/triples";
203
204
function isPlatformSupported(platform: string, arch: string): boolean {
205
return !!(platformArchTriples[platform]?.[arch]?.length > 0);
206
}
207
208
function getAvailableABIs(platform: string, arch: string): string[] {
209
const targets = platformArchTriples[platform]?.[arch] || [];
210
return [...new Set(targets.map(t => t.abi).filter(Boolean))];
211
}
212
213
// Examples
214
console.log(isPlatformSupported("linux", "riscv64")); // true
215
console.log(isPlatformSupported("linux", "mips")); // false
216
console.log(getAvailableABIs("linux", "x64")); // ["gnu", "gnux32", "musl"]
217
```