@@ -26,17 +26,47 @@ fn generate_target_mapping(f: &mut File, target_specs: &RustcTargetSpecs) -> std
2626 let env = spec. env . as_deref ( ) . unwrap_or ( "" ) ;
2727 let abi = spec. abi . as_deref ( ) . unwrap_or ( "" ) ;
2828
29- // Remove deployment target information from LLVM target triples (we
30- // will add this in another part of CC).
31- //
32- // FIXME(madsmtm): Should become unnecessary after
33- // https://github.com/rust-lang/rust/pull/131037
3429 let unversioned_llvm_target = if spec. llvm_target . contains ( "apple" ) {
30+ // Remove deployment target information from LLVM target triples (we
31+ // will add this in another part of CC).
32+ //
33+ // FIXME(madsmtm): Should become unnecessary after
34+ // https://github.com/rust-lang/rust/pull/131037
3535 let mut components = spec. llvm_target . split ( "-" ) . collect :: < Vec < _ > > ( ) ;
3636
3737 components[ 2 ] = components[ 2 ] . trim_end_matches ( |c : char | c. is_numeric ( ) || c == '.' ) ;
3838
3939 components. join ( "-" )
40+ } else if os == "uefi" {
41+ // Override the UEFI LLVM targets.
42+ //
43+ // The rustc mappings (as of 1.82) for the UEFI targets are:
44+ // * i686-unknown-uefi -> i686-unknown-windows-gnu
45+ // * x86_64-unknown-uefi -> x86_64-unknown-windows
46+ // * aarch64-unknown-uefi -> aarch64-unknown-windows
47+ //
48+ // However, in cc-rs all the UEFI targets use
49+ // -windows-gnu. This has been the case since 2021 [1].
50+ // * i686-unknown-uefi -> i686-unknown-windows-gnu
51+ // * x86_64-unknown-uefi -> x86_64-unknown-windows-gnu
52+ // * aarch64-unknown-uefi -> aarch64-unknown-windows-gnu
53+ //
54+ // For now, override the UEFI mapping to keep the behavior
55+ // of cc-rs unchanged.
56+ //
57+ // TODO: as discussed in [2], it may be possible to switch
58+ // to new UEFI targets added to clang, and regardless it
59+ // would be good to have consistency between rustc and
60+ // cc-rs.
61+ //
62+ // [1]: https://github.com/rust-lang/cc-rs/pull/623
63+ // [2]: https://github.com/rust-lang/cc-rs/pull/1264
64+ let arch = if spec. arch == "x86" {
65+ "i686"
66+ } else {
67+ & spec. arch
68+ } ;
69+ format ! ( "{}-unknown-windows-gnu" , arch)
4070 } else {
4171 spec. llvm_target . clone ( )
4272 } ;
0 commit comments