@@ -26,17 +26,47 @@ fn generate_target_mapping(f: &mut File, target_specs: &RustcTargetSpecs) -> std
26
26
let env = spec. env . as_deref ( ) . unwrap_or ( "" ) ;
27
27
let abi = spec. abi . as_deref ( ) . unwrap_or ( "" ) ;
28
28
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
34
29
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
35
35
let mut components = spec. llvm_target . split ( "-" ) . collect :: < Vec < _ > > ( ) ;
36
36
37
37
components[ 2 ] = components[ 2 ] . trim_end_matches ( |c : char | c. is_numeric ( ) || c == '.' ) ;
38
38
39
39
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)
40
70
} else {
41
71
spec. llvm_target . clone ( )
42
72
} ;
0 commit comments