Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc_target: The differences between target_os = "none" and target_os = "unknown", and target_vendor = "unknown" and target_vendor = "" are unclear #77730

Closed
petrochenkov opened this issue Oct 8, 2020 · 1 comment · Fixed by #78951
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools A-target-specs Area: Compile-target specifications

Comments

@petrochenkov
Copy link
Contributor

petrochenkov commented Oct 8, 2020

The majority of targets use target_os = "none" / target_vendor = "unknown" respectively, but some targets deviate and use target_os = "unknown" / target_vendor = "".

Possible solutions:

  • There's no difference between "", "none" and "unknown", normalize to the more common variants.
  • There are deep reasons for the status quo, keep and document it.
  • 50 / 50 of the above.
@ehuss
Copy link
Contributor

ehuss commented Oct 8, 2020

For OS, none has a specific meaning of being bare-metal (no OS). unknown would mean there is an OS, but it is not specified. One way rustc cares about this is that none targets are built as no_std by default.

Generally a missing component of the triple is supposed to be interpreted as "unknown". I think it might be reasonable to use "unknown" instead of an empty string in the Target definition, though I'm not sure if it matters too much in practice. Generally people only care about the canonical target string (like x86_64-linux-kernel or aarch64-fuchsia), and the vendor string is never used (like one probably wouldn't bother doing cfg(target_vendor="unknown") or printing it anywhere).

This is sorta documented at https://doc.rust-lang.org/cargo/appendix/glossary.html#target (which is derived from https://clang.llvm.org/docs/CrossCompilation.html#target-triple, which is in turn derived from GNU AIUI). https://doc.rust-lang.org/rustc/targets/index.html should probably discuss this in more detail.

@jyn514 jyn514 added A-target-specs Area: Compile-target specifications A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools labels Oct 9, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 8, 2020
…crum

rustc_target: Move some target options from `Target` to `TargetOptions`

The only reason for `Target` to `TargetOptions` to be separate structures is that options in `TargetOptions` have reasonable defaults and options in `Target` don't.
(Otherwise all the options logically belong to a single `Target` struct.)

This PR moves a number of options with reasonable defaults from `Target` to `TargetOptions`, so they no longer needs to be specified explicitly for majority of the targets.
The move also allows to inherit the options from `rustc_target/src/spec/*_base.rs` files in a nicer way.
I didn't change any specific option values here.

The moved options are `target_c_int_width` (defaults to `"32"`), `target_endian` (defaults to `"little"`), `target_os` (defaults to `"none"`), `target_env` (defaults to `""`), `target_vendor` (defaults to `"unknown"`) and `linker_flavor` (defaults to `LinkerFlavor::Gcc`).

Next steps (in later PRs):
- Find a way to merge `TargetOptions` into `Target`
- If not, always access `TargetOptions` fields through `Deref` making it a part of `Target` at least logically (`session.target.target.options.foo` -> `session.target.target.foo`)
- ~Eliminate `session::config::Config` and use `Target` instead (`session.target.target.foo` -> `session.target.foo`)~ Done in rust-lang#77943.
- Avoid tautologies in option names (`target.target_os` -> `target.os`)
- Resolve _ rust-lang#77730 (rustc_target: The differences between `target_os = "none"` and `target_os = "unknown"`, and `target_vendor = "unknown"` and `target_vendor = ""` are unclear) noticed during implementation of this PR.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 13, 2020
rustc_target: Change os and vendor values to "none" and "unknown" for some targets

Closes rust-lang#77730
r? `@ehuss`
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 13, 2020
rustc_target: Change os and vendor values to "none" and "unknown" for some targets

Closes rust-lang#77730
r? ``@ehuss``
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 14, 2020
rustc_target: Change os and vendor values to "none" and "unknown" for some targets

Closes rust-lang#77730
r? ```@ehuss```
@bors bors closed this as completed in 1a25580 Nov 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools A-target-specs Area: Compile-target specifications
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants