Basic target naming rules #850
Labels
major-change
A proposal to make a major change to rustc
T-compiler
Add this label so rfcbot knows to poll the compiler team
Motivation
While code in
build.rs
can and should take advantage ofCARGO_CFG_*
,cc-rs
still has to parserustc
target names/triples/tuples to support bootstrap and other such code outsidebuild.rs
. I suspectcc-rs
is not the only one that wants to do this.Parsing the arch, vendor, OS, env and ABI information from
rustc
targets is difficult however, because while they may have started out as mostly matching Clang's naming scheme, they have slowly diverged from that, and are at this point mostly an arbitary mapping to target information.To remedy this, I propose that we define a set of machine-verifyable "rules" that can govern new target tuples, to ensure that the cfgs
target_arch
,target_vendor
,target_os
,target_env
andtarget_abi
can (more) easily be figured out from the tuple alone.To be clear here, I'm not against letting targets fix their definitions (e.g. in the past,
i386-apple-ios
did not settarget_abi = "sim"
, but fixing that was the correct move). But making the target name diverge from the information it contains does impose a cost that we should be aware of.Related: rust-lang/rust#135376, rust-lang/rust#136495, #846 and rust-lang/lang-team#102.
Implementation
A consistency check for
rustc_target::spec::Target
with roughly the following logic:arch+subarch-os
.arch+subarch-os-env+abi
orarch+subarch-vendor-os
.arch+subarch-vendor-os-env+abi
.unknown
, and the vendor-less forms should be preferred.There would be targets that wouldn't fit under these rules, and would have to be added to an exception table. I think the full list is below (but I'd have to fully implement it to be certain):
x86_64-unknown-linux-none
x86_64-unknown-linux
none
is not an environment*-apple-darwin
*-apple-macos
i386-apple-ios
i686-apple-ios-sim
x86_64-apple-ios
x86_64-apple-ios-sim
x86_64-apple-tvos
x86_64-apple-tvos-sim
mips64-openwrt-linux-musl
mips64-openwrt-linux-muslabi64
mips64-unknown-linux-muslabi64
armv6-unknown-freebsd
armv6-unknown-freebsd-eabihf
armv6-unknown-netbsd-eabihf
,armv7-wrs-vxworks-eabihf
etc.armv7-unknown-freebsd
armv7-unknown-freebsd-eabihf
armv6k-nintendo-3ds
armv6k-nintendo-3ds-eabihf
armv7-unknown-trusty
armv7-unknown-trusty-eabi
wasm*-unknown-unknown
wasm*-none
unknown
is not an OS,none
iswasm32-wasip1
wasm32-wasi-p1
target_os
, and what istarget_env
. Alternatively we'd usetarget_os = "wasip1"
wasm32-wasip2
wasm32-wasi-p2
wasm32-wasip1-threads
*-linux-android
*-android
*-linux-androideabi
*-android-eabi
*-unknown-linux-ohos
*-ohos
x86_64-fortanix-unknown-sgx
target_vendor = "fortanix"
andtarget_abi = "fortanix"
xtensa-esp32*-none-elf
xtensa-espressif-none-esp32*
esp32
is not the vendor, Espressif isxtensa-esp32*-espidf
xtensa-espressif-espidf-esp32*
*-uwp-windows-gnu
*-windows-gnuuwp
target_abi = "uwp"
)*-uwp-windows-msvc
*-windows-msvcuwp
*-unknown-linux-gnu_ilp32
*-unknown-linux-gnuilp32
Note that I am not proposing renaming these, that is probably not feasible for most of them, and should be done separately in any case. I am only proposing that new targets do not have the same flaws.
Example reasons to add to the exceptions table in the future (but should ideally happen rarely):
target_env
/target_abi
is added where it was previously incorrect/missing for a target.wasm32-wasip3
overwasm32-wasi-p3
).Precedent / Prior art
Zig's
-target
is pretty consistent with roughly$ARCH-$OS-$ENV
, though they can more easily do that because they don't ship a pre-compiled standard library like rustup does (and because they can still make sweeping breaking changes). Also, they're considering adding a fourth component to more clearly represent ABI information.rustc
already does a consistency check on the target information, seeTarget::check_consistency
. This would probably "just" be an expansion of that to take into account the target name itself as well.Alternatives
Users must invoke and parse
rustc --print cfg --target $target
when outsidebuild.rs
.Process
The main points of the Major Change Process are as follows:
@rustbot second
.-C flag
, then full team check-off is required.@rfcbot fcp merge
on either the MCP or the PR.You can read more about Major Change Proposals on forge.
CC @ChrisDenton @workingjubilee @NobodyXu
The text was updated successfully, but these errors were encountered: