@@ -3,7 +3,9 @@ use std::path::Path;
3
3
use std:: process:: { self , Command } ;
4
4
5
5
use super :: path:: { Dirs , RelPath } ;
6
- use super :: rustc_info:: { get_file_name, get_rustc_version, get_wrapper_file_name} ;
6
+ use super :: rustc_info:: {
7
+ get_file_name, get_rustc_version, get_toolchain_name, get_wrapper_file_name,
8
+ } ;
7
9
use super :: utils:: { spawn_and_wait, try_hard_link, CargoProject , Compiler } ;
8
10
use super :: SysrootKind ;
9
11
@@ -17,15 +19,17 @@ pub(crate) fn build_sysroot(
17
19
channel : & str ,
18
20
sysroot_kind : SysrootKind ,
19
21
cg_clif_dylib_src : & Path ,
20
- host_compiler : & Compiler ,
21
- target_triple : & str ,
22
- ) {
22
+ bootstrap_host_compiler : & Compiler ,
23
+ target_triple : String ,
24
+ ) -> Compiler {
23
25
eprintln ! ( "[BUILD] sysroot {:?}" , sysroot_kind) ;
24
26
25
27
DIST_DIR . ensure_fresh ( dirs) ;
26
28
BIN_DIR . ensure_exists ( dirs) ;
27
29
LIB_DIR . ensure_exists ( dirs) ;
28
30
31
+ let is_native = bootstrap_host_compiler. triple == target_triple;
32
+
29
33
// Copy the backend
30
34
let cg_clif_dylib_path = if cfg ! ( windows) {
31
35
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
@@ -42,32 +46,34 @@ pub(crate) fn build_sysroot(
42
46
for wrapper in [ "rustc-clif" , "rustdoc-clif" , "cargo-clif" ] {
43
47
let wrapper_name = get_wrapper_file_name ( wrapper, "bin" ) ;
44
48
45
- let mut build_cargo_wrapper_cmd = Command :: new ( " rustc" ) ;
49
+ let mut build_cargo_wrapper_cmd = Command :: new ( & bootstrap_host_compiler . rustc ) ;
46
50
build_cargo_wrapper_cmd
51
+ . env ( "TOOLCHAIN_NAME" , get_toolchain_name ( ) )
47
52
. arg ( RelPath :: SCRIPTS . to_path ( dirs) . join ( & format ! ( "{wrapper}.rs" ) ) )
48
53
. arg ( "-o" )
49
54
. arg ( DIST_DIR . to_path ( dirs) . join ( wrapper_name) )
50
55
. arg ( "-g" ) ;
51
56
spawn_and_wait ( build_cargo_wrapper_cmd) ;
52
57
}
53
58
54
- let default_sysroot = super :: rustc_info:: get_default_sysroot ( ) ;
59
+ let default_sysroot = super :: rustc_info:: get_default_sysroot ( & bootstrap_host_compiler . rustc ) ;
55
60
56
- let host_rustlib_lib = RUSTLIB_DIR . to_path ( dirs) . join ( & host_compiler. triple ) . join ( "lib" ) ;
57
- let target_rustlib_lib = RUSTLIB_DIR . to_path ( dirs) . join ( target_triple) . join ( "lib" ) ;
61
+ let host_rustlib_lib =
62
+ RUSTLIB_DIR . to_path ( dirs) . join ( & bootstrap_host_compiler. triple ) . join ( "lib" ) ;
63
+ let target_rustlib_lib = RUSTLIB_DIR . to_path ( dirs) . join ( & target_triple) . join ( "lib" ) ;
58
64
fs:: create_dir_all ( & host_rustlib_lib) . unwrap ( ) ;
59
65
fs:: create_dir_all ( & target_rustlib_lib) . unwrap ( ) ;
60
66
61
67
if target_triple == "x86_64-pc-windows-gnu" {
62
- if !default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( target_triple) . join ( "lib" ) . exists ( ) {
68
+ if !default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( & target_triple) . join ( "lib" ) . exists ( ) {
63
69
eprintln ! (
64
70
"The x86_64-pc-windows-gnu target needs to be installed first before it is possible \
65
71
to compile a sysroot for it.",
66
72
) ;
67
73
process:: exit ( 1 ) ;
68
74
}
69
75
for file in fs:: read_dir (
70
- default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( target_triple) . join ( "lib" ) ,
76
+ default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( & target_triple) . join ( "lib" ) ,
71
77
)
72
78
. unwrap ( )
73
79
{
@@ -83,7 +89,11 @@ pub(crate) fn build_sysroot(
83
89
SysrootKind :: None => { } // Nothing to do
84
90
SysrootKind :: Llvm => {
85
91
for file in fs:: read_dir (
86
- default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( & host_compiler. triple ) . join ( "lib" ) ,
92
+ default_sysroot
93
+ . join ( "lib" )
94
+ . join ( "rustlib" )
95
+ . join ( & bootstrap_host_compiler. triple )
96
+ . join ( "lib" ) ,
87
97
)
88
98
. unwrap ( )
89
99
{
@@ -103,9 +113,9 @@ pub(crate) fn build_sysroot(
103
113
try_hard_link ( & file, host_rustlib_lib. join ( file. file_name ( ) . unwrap ( ) ) ) ;
104
114
}
105
115
106
- if target_triple != host_compiler . triple {
116
+ if !is_native {
107
117
for file in fs:: read_dir (
108
- default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( target_triple) . join ( "lib" ) ,
118
+ default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( & target_triple) . join ( "lib" ) ,
109
119
)
110
120
. unwrap ( )
111
121
{
@@ -118,19 +128,19 @@ pub(crate) fn build_sysroot(
118
128
build_clif_sysroot_for_triple (
119
129
dirs,
120
130
channel,
121
- host_compiler . clone ( ) ,
131
+ bootstrap_host_compiler . clone ( ) ,
122
132
& cg_clif_dylib_path,
123
133
) ;
124
134
125
- if host_compiler . triple != target_triple {
135
+ if !is_native {
126
136
build_clif_sysroot_for_triple (
127
137
dirs,
128
138
channel,
129
139
{
130
- let mut target_compiler = host_compiler . clone ( ) ;
131
- target_compiler . triple = target_triple. to_owned ( ) ;
132
- target_compiler . set_cross_linker_and_runner ( ) ;
133
- target_compiler
140
+ let mut bootstrap_target_compiler = bootstrap_host_compiler . clone ( ) ;
141
+ bootstrap_target_compiler . triple = target_triple. clone ( ) ;
142
+ bootstrap_target_compiler . set_cross_linker_and_runner ( ) ;
143
+ bootstrap_target_compiler
134
144
} ,
135
145
& cg_clif_dylib_path,
136
146
) ;
@@ -147,6 +157,12 @@ pub(crate) fn build_sysroot(
147
157
}
148
158
}
149
159
}
160
+
161
+ let mut target_compiler = Compiler :: clif_with_triple ( & dirs, target_triple) ;
162
+ if !is_native {
163
+ target_compiler. set_cross_linker_and_runner ( ) ;
164
+ }
165
+ target_compiler
150
166
}
151
167
152
168
pub ( crate ) static ORIG_BUILD_SYSROOT : RelPath = RelPath :: SOURCE . join ( "build_sysroot" ) ;
@@ -169,7 +185,7 @@ fn build_clif_sysroot_for_triple(
169
185
process:: exit ( 1 ) ;
170
186
}
171
187
Ok ( source_version) => {
172
- let rustc_version = get_rustc_version ( ) ;
188
+ let rustc_version = get_rustc_version ( & compiler . rustc ) ;
173
189
if source_version != rustc_version {
174
190
eprintln ! ( "The patched sysroot source is outdated" ) ;
175
191
eprintln ! ( "Source version: {}" , source_version. trim( ) ) ;
0 commit comments