Description
Could be great to support custom target-specs (json files).
As we all know, env TARGET
contains rustc's "short target name", not exactly target-triple. It can be triple only if builtin target requested.
So cc
couldn't use it directly if some custom target requested, e.g. for --target=my-spec.json
env TARGET
will be "my-spec"
.
How to do it:
- change there
target
type - wrap into something likeenum Target { Builtin(...), Custom(...) }
- probe target to determine is it builtin or not and get details:
- we have env
RUSTC
by cargo $RUSTC --print cfg --target {target-short-name}.json
$RUSTC --print target-spec-json --target {target-short-name}.json -Zunstable-options
(nightly only)
From this step we can getllvm-target
But actually we already have almost all we need by cargo's env:
CARGO_CFG_TARGET_ABI
CARGO_CFG_TARGET_ARCH
CARGO_CFG_TARGET_FEATURE
CARGO_CFG_RELOCATION_MODEL
- other vars starting with
CARGO_CFG_TARGET_
excluding_VENDOR
and_OS
, and probably_ENV
.
Note, CARGO_CFG_TARGET_FEATURE
contains features added in the my-spec.json
too, so it really useful.
So, could be great to support target-json-specs, use info from them.
Also to respect and use all available data from vars CARGO_CFG_TARGET_
- translate and pass to compiler if possible.
Example of env vars given by cargo
In my case, my target.json contains "llvm-target": "thumbv7em-none-eabihf"
, uses it as base target, but overrides features and some more.
TARGET: "my-spec"
CARGO_CFG_OVERFLOW_CHECKS: ""
CARGO_CFG_PANIC: "abort"
CARGO_CFG_RELOCATION_MODEL: "pic"
CARGO_CFG_TARGET_ABI: "eabihf"
CARGO_CFG_TARGET_ARCH: "arm"
CARGO_CFG_TARGET_ENDIAN: "little"
CARGO_CFG_TARGET_ENV: "elf"
CARGO_CFG_TARGET_FEATURE: "dsp,mclass,thumb-mode,thumb2,v5te,v6,v6k,v6t2,v7,neon"
CARGO_CFG_TARGET_HAS_ATOMIC: "16,32,8,ptr"
CARGO_CFG_TARGET_HAS_ATOMIC_EQUAL_ALIGNMENT: "16,32,8,ptr"
CARGO_CFG_TARGET_HAS_ATOMIC_LOAD_STORE: "16,32,8,ptr"
CARGO_CFG_TARGET_OS: "myneatos"
CARGO_CFG_TARGET_POINTER_WIDTH: "32"
CARGO_CFG_TARGET_THREAD_LOCAL: ""
CARGO_CFG_TARGET_VENDOR: "custom"
CARGO_CFG_UB_CHECKS: ""
CARGO_ENCODED_RUSTFLAGS: ""
RUSTC: "path/to/rustc"
Probably related issue: #994