target_arch and target_os documentation for supported platforms

709269c
Opened by gnzlbg at 2023-11-27 18:14:47

The platform support site is great.

However, it is hard to extract from it which target_arch and target_os macros to use to detect each platform. Is this documented anywhere?

Maybe one could expand this site with the information about how to extract the value of target_arch and target_os from the triples, or better even, expand the tables with a column for each of these macros, and show which values to use for each platform.

  1. It would be really GREAT if someone could just make a site where all the target_arch values are listed and if cargo could support the --target_arch flag. Every time I want to do target_arch=native I have to search on how to do it because there is no documentation to be found anywhere.

    Felix Schütt at 2018-02-18 00:37:17

  2. if cargo could support the --target_arch flag.

    cargo already supports --target which sets the arch flag, amongst other things (the first part of the target triple is the arch on all targets AFAIK). The target_os is not part of the target triple though (e.g. apple in the target triple vs macos in target_os).

    gnzlbg at 2018-02-20 10:07:42

  3. I'd definitely love some official documentation of this as well.

    Shea Levy at 2018-07-02 15:27:35

  4. I am confused... Isn't it just <cpu>-<vendor>-<os>? Why would rust list it as x86_64-apple-darwin but expect us to use use macos?

    Matthew Bauer at 2018-07-02 23:53:52

  5. Isn't it just <cpu>-<vendor>-<os>?

    No.

    Why would rust list it as x86_64-apple-darwin but expect us to use use macos?

    That's a good question.

    gnzlbg at 2018-07-03 08:04:34

  6. I made a crate that might be helpful here:

    https://docs.rs/platforms/ https://crates.io/crates/platforms https://github.com/RustSec/platforms-crate

    (apologies if this is duplicating any existing efforts, or just a bad idea in general)

    This crate has a registry of all of the platforms listed on the platform support page, and for each platform knows the "target triple", target_arch, target_env, and target_os attributes. The target_* attributes are mapped onto enums which can in turn be converted to strings.

    My goal with this crate was to be able to include platform information in RustSec security advisories and when doing so ensuring that the information is valid (i.e. matches known valid platforms).

    Tony Arcieri at 2018-07-27 01:09:27

  7. https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch and https://doc.rust-lang.org/reference/conditional-compilation.html#target_os are decent?

    John Ericson at 2022-08-07 20:40:39

  8. decent but not complete, but maybe the platform support page in the book is good enough: https://doc.rust-lang.org/nightly/rustc/platform-support.html

    Alexander Kjäll at 2022-09-03 08:15:49

  9. Transferred to rust-lang/rust since the platform support page has moved here.

    Eric Huss at 2023-10-26 17:18:31