-
Notifications
You must be signed in to change notification settings - Fork 14k
rustc_target: introduce Vendor, Abi, Env, Os #148531
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
base: main
Are you sure you want to change the base?
Conversation
|
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 These commits modify compiler targets. Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred in cfg and check-cfg configuration cc @Urgau The Miri subtree was changed cc @rust-lang/miri |
|
FWIW for a related change recently we had quite a bit of discussion: rust-lang/compiler-team#926. |
e47f7c3 to
013077b
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a bunch of nits but this generally looks good. Linker is another candidate for enum-ification, if you aren't yet bored of this stuff :)
| Unikraft = "unikraft", | ||
| Uwp = "uwp", | ||
| Vex = "vex", | ||
| Win7 = "win7", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea what "win7" is? Makes me think of Windows 7, which is a weird name for a vendor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dates back to #118150 which explains:
I went with naming the target x86_64-win7-windows-msvc, inserting the win7 in the vendor field (usually set to to pc). This is done to avoid ecosystem churn, as quite a few crates have cfg(target_os = "windows") or cfg(target_env = "msvc"), but nearly no cfg(target_vendor = "pc"). Since my goal is to be able to seamlessly swap to the win7 target, I figured it'd be easier this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, ok. Thanks for the info!
IMO these changes are so similar to the change in that MCP that additional discussion isn't needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed all but one comment and left things unsquashed to (somewhat) ease review. I do plan to squash once you're happy with it.
| Unikraft = "unikraft", | ||
| Uwp = "uwp", | ||
| Vex = "vex", | ||
| Win7 = "win7", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dates back to #118150 which explains:
I went with naming the target x86_64-win7-windows-msvc, inserting the win7 in the vendor field (usually set to to pc). This is done to avoid ecosystem churn, as quite a few crates have cfg(target_os = "windows") or cfg(target_env = "msvc"), but nearly no cfg(target_vendor = "pc"). Since my goal is to be able to seamlessly swap to the win7 target, I figured it'd be easier this way.
|
r=me with the commits squashed, thanks! @bors delegate=tamird |
|
✌️ @tamird, you can now approve this pull request! If @nnethercote told you to " |
This comment has been minimized.
This comment has been minimized.
|
range-diff is ~empty, which is what I expected! |
| } | ||
|
|
||
| crate::target_spec_enum! { | ||
| pub enum Vendor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm semi against making target_vendor an enum - it's not like the other ones, in that it's not supposed to carry any meaning (at least not after rust-lang/lang-team#102).
I'd prefer to keep it as just a String.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds nice, but it is just not the case. There are many places where the vendor is consulted, especially to check if it's Apple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking for apple should be done through is_like_darwin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
% git grep -E '[^:] Vendor::' -- ':!compiler/rustc_target/src/spec/targets/' ':!compiler/rustc_target/src/spec/base'
compiler/rustc_codegen_cranelift/src/abi/mod.rs: (Arch::X86_64, _) | (Arch::AArch64, Vendor::Apple) => match (ty, is_signed) {
compiler/rustc_codegen_cranelift/src/codegen_f16_f128.rs: if fx.tcx.sess.target.vendor == Vendor::Apple && fx.tcx.sess.target.arch == Arch::X86_64 {
compiler/rustc_codegen_cranelift/src/codegen_f16_f128.rs: if fx.tcx.sess.target.vendor == Vendor::Apple && fx.tcx.sess.target.arch == Arch::X86_64 {
compiler/rustc_codegen_cranelift/src/codegen_f16_f128.rs: if fx.tcx.sess.target.vendor == Vendor::Apple && fx.tcx.sess.target.arch == Arch::X86_64 {
compiler/rustc_codegen_ssa/src/back/link.rs: && sess.target.vendor != Vendor::Uwp
compiler/rustc_codegen_ssa/src/back/linker.rs: if matches!(flavor, LinkerFlavor::Msvc(..)) && t.vendor == Vendor::Uwp {
compiler/rustc_codegen_ssa/src/back/linker.rs: assert!(cmd.get_args().is_empty() || sess.target.vendor == Vendor::Uwp);
compiler/rustc_codegen_ssa/src/common.rs: target.vendor == Vendor::Pc
compiler/rustc_metadata/src/native_libs.rs: if sess.target.vendor == Vendor::Fortanix
compiler/rustc_target/src/spec/mod.rs: self.vendor == Vendor::Apple,
compiler/rustc_target/src/spec/mod.rs: if let Vendor::Other(s) = &self.vendor {
compiler/rustc_target/src/spec/mod.rs: || (self.env == Env::Sgx && self.vendor == Vendor::Fortanix)
src/tools/miri/src/machine.rs: if target.options.vendor == Vendor::Apple {
It's not just Apple, either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For UWP it can probably check target.abi instead. is_mingw_gnu_toolchain doesn't need to check the vendor at all. It already checks OS and environment. And IMO we should change x86_64-fortanix-unknown-sgx to x86_64-unknown-fortanix-sgx. Fortanix effectively operates as an OS for SGX enclaves. I believe that covers everything currently checking the vendor field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These sound like good improvements to me. How would you prevent backsliding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The vendor field coule be marked with #[rustc_lint_opt_deny_field_access] if you mark the TargetOptions struct with #[rustc_lint_opt_ty].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x86_64-fortanix-unknown-sgx is a tier 2 platform. Surely we can't just go and change it? Other than that, I have a branch with this change that I'll PR in a moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid duplicating this comment in preparation for adding more enums.
Prepare for additional enums like Vendor and Os which have true `Unknown` variants. We want to use the same name for the escape hatch for all of these, thus rename this one.
Improve type safety by using an enum rather than strings.
Improve type safety by using an enum rather than strings.
Improve type safety by using an enum rather than strings.
Improve type safety by using an enum rather than strings.
| Sony = "sony", | ||
| Sun = "sun", | ||
| Unikraft = "unikraft", | ||
| Unknown = "unknown", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be placed under Other IMO. Matching on Vendor::Unknown never makes sense under any circumstance. It is a catch-all for when there is no known vendor value, which is also what the Other variant is for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see prior discussion here
|
I'm gonna unmark this as accepted, since I'd like to see the (Do correct me if this is bad form). We should bump the priority next time it's scheduled for merging, to avoid further merge conflicts. |
Annoying is a crucial part of doing OSS :) |
|
Yeah, I didn't mean anything rude by it, I do appreciate the work you're doing here! |
rustc_target: hide TargetOptions::vendor Discussed in rust-lang#148531 (comment). r? `@bjorn3`
rustc_target: hide TargetOptions::vendor Discussed in rust-lang#148531 (comment). r? ``@bjorn3``
rustc_target: hide TargetOptions::vendor Discussed in rust-lang#148531 (comment). r? ``@bjorn3``
rustc_target: hide TargetOptions::vendor Discussed in rust-lang#148531 (comment). r? ```@bjorn3```
rustc_target: hide TargetOptions::vendor Discussed in rust-lang#148531 (comment). r? ````@bjorn3````
rustc_target: hide TargetOptions::vendor Discussed in rust-lang#148531 (comment). r? `````@bjorn3`````
Rollup merge of #148760 - tamird:avoid-vendor-logic, r=madsmtm rustc_target: hide TargetOptions::vendor Discussed in #148531 (comment). r? `````@bjorn3`````
|
☔ The latest upstream changes (presumably #148818) made this pull request unmergeable. Please resolve the merge conflicts. |
Improve type safety by using an enum rather than strings.
I'm not really sure this is better since only a few vendors have special semantics. r? @nnethercote