target-lexicon icon indicating copy to clipboard operation
target-lexicon copied to clipboard

Remove build script?

Open madsmtm opened this issue 1 year ago • 1 comments

I've been considering if we could get rid of the build script for determining the host architecture, using target_* cfgs instead of parsing the TARGET. Something like the following:

// Architecture
if cfg!(target_arch = "aarch64") {
    Architecture::Aarch64(if cfg!(target_endian = "big") { Aarch64Architecture::Aarch64be } else { Aarch64Architecture::Aarch64 })
} else if cfg!(target_arch = "x86_64") {
    Architecture::X86_64
} else if ... // etc.

// Vendor
if cfg!(target_vendor = "unknown") {
    Vendor::Amd
} else if cfg!(target_vendor = "amd") {
    Vendor::Amd
} else if ... // etc.

This would likely allow target-lexicon to be used in cc, which in turn would allow us to centralize target parsing even more, to the benefit of all in the ecosystem.


One complication though is that Rust's target_* cfgs aren't as descriptive, for example target_arch = "arm" is often used for several ARM architectures.

I think this may turn out to not really matter though, since there are fewer targets with host tool support? But then again, this would not allow us to distinguish between armv6-unknown-freebsd and armv7-unknown-freebsd, which, although tier 3, seemingly have host tool support.

There are several ways to solve this, including splitting the build script out into a separate crate that is only loaded when really needed, something like [target.armv7-unknown-freebsd.dependencies] target-lexion-with-build-script = "...".

madsmtm avatar Sep 30 '24 14:09 madsmtm

There are ways to test for things like "v6" vs "v7", for example all(target_arch = "arm", target_feature = "v7"). I wonder if that goes far enough.

sunfishcode avatar Oct 02 '24 17:10 sunfishcode