bytecodealliance / bytecodealliance/target-lexicon

Remove build script?

Open
#112 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
60
Forks
70
PR merge metrics
No merged PRs in 30d

Description

I've been considering if we could get rid of the build script for determining the host architecture, using [`target_*` cfgs](https://doc.rust-lang.org/reference/conditional-compilation.html) instead of parsing the `TARGET`. Something like the following:

```rust
// 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`](https://github.com/rust-lang/cc-rs/issues/1219), 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](https://doc.rust-lang.org/nightly/rustc/platform-support.html)? 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 = "..."`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.