Target-lexicon
Decode and represent LLVM target triples in Rust with a typed, queryable Triple struct.
Repository Health
Technical Analysis
Target-lexicon is a small, foundational Rust library for managing compilation targets. Its core feature is decoding LLVM “triples” — the strings like x86_64-unknown-linux-gnu that identify a target configuration — into a strongly typed Triple struct with enums for architecture, vendor, operating system, environment, and binary format.
Maintained by the Bytecode Alliance and depended on by Cranelift, Wasmtime, and much of the Rust compiler-tooling ecosystem, it lets tools parse, construct, and inspect targets without hand-rolling string matching. Triple implements FromStr and Display for round-tripping, exposes host constructors, and answers queries about endianness, pointer width, and binary format.
What You Get
- A typed
Triplestruct with enums for architecture, vendor, OS, environment, and binary format FromStrandDisplayimplementations for parsing and printing conventional triple stringshost()constructors that produce aTripledescribing the current build host- Query helpers for endianness, pointer bit width, and binary format
- Partial compatibility with the triples used by rustc and rustup
Common Use Cases
- Parsing a target triple string into structured fields inside a compiler backend
- Constructing a host
Tripleto configure code generation for the current machine - Querying endianness or pointer width to make target-dependent codegen decisions
- Round-tripping between the string and typed representation of a target in build tooling
Under The Hood
Architecture - The crate is deliberately small: triple.rs defines the central Triple struct and its parsing/display logic, targets.rs holds the large enums (Architecture, Vendor, OperatingSystem, Environment, BinaryFormat) and their string mappings, data_model.rs derives properties like pointer width and endianness, host.rs provides host-detection constructors, and parse_error.rs defines the error types surfaced by FromStr.
Tech Stack - Pure Rust with a minimal dependency footprint, built as a standard Cargo crate. It uses serde optionally for (de)serialization and relies on generated/hand-maintained tables for the target enums; there is no build-script code generation beyond ordinary crate compilation.
Code Quality - The code is compact and stable, with unit tests across four files exercising parsing round-trips and host detection. Because the API surface is narrow and the enums are exhaustive, the crate is easy to audit despite low recent commit activity — its maturity, not neglect, explains the slow cadence.
API Design - The public API is ergonomic and discoverable: parse with "...".parse::<Triple>(), print with Display, build the host with Triple::host(), and query properties via straightforward methods. Naming closely mirrors LLVM’s own triple vocabulary, so users familiar with target triples need almost no ramp-up.