@@ -17,7 +17,7 @@ pub(crate) fn build_sysroot(
17
17
channel : & str ,
18
18
sysroot_kind : SysrootKind ,
19
19
cg_clif_dylib_src : & Path ,
20
- host_triple : & str ,
20
+ host_compiler : & Compiler ,
21
21
target_triple : & str ,
22
22
) {
23
23
eprintln ! ( "[BUILD] sysroot {:?}" , sysroot_kind) ;
@@ -53,7 +53,7 @@ pub(crate) fn build_sysroot(
53
53
54
54
let default_sysroot = super :: rustc_info:: get_default_sysroot ( ) ;
55
55
56
- let host_rustlib_lib = RUSTLIB_DIR . to_path ( dirs) . join ( host_triple ) . join ( "lib" ) ;
56
+ let host_rustlib_lib = RUSTLIB_DIR . to_path ( dirs) . join ( & host_compiler . triple ) . join ( "lib" ) ;
57
57
let target_rustlib_lib = RUSTLIB_DIR . to_path ( dirs) . join ( target_triple) . join ( "lib" ) ;
58
58
fs:: create_dir_all ( & host_rustlib_lib) . unwrap ( ) ;
59
59
fs:: create_dir_all ( & target_rustlib_lib) . unwrap ( ) ;
@@ -83,7 +83,7 @@ pub(crate) fn build_sysroot(
83
83
SysrootKind :: None => { } // Nothing to do
84
84
SysrootKind :: Llvm => {
85
85
for file in fs:: read_dir (
86
- default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( host_triple ) . join ( "lib" ) ,
86
+ default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( & host_compiler . triple ) . join ( "lib" ) ,
87
87
)
88
88
. unwrap ( )
89
89
{
@@ -103,7 +103,7 @@ pub(crate) fn build_sysroot(
103
103
try_hard_link ( & file, host_rustlib_lib. join ( file. file_name ( ) . unwrap ( ) ) ) ;
104
104
}
105
105
106
- if target_triple != host_triple {
106
+ if target_triple != host_compiler . triple {
107
107
for file in fs:: read_dir (
108
108
default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( target_triple) . join ( "lib" ) ,
109
109
)
@@ -115,21 +115,24 @@ pub(crate) fn build_sysroot(
115
115
}
116
116
}
117
117
SysrootKind :: Clif => {
118
- build_clif_sysroot_for_triple ( dirs, channel, host_triple, & cg_clif_dylib_path, None ) ;
119
-
120
- if host_triple != target_triple {
121
- // When cross-compiling it is often necessary to manually pick the right linker
122
- let linker = match target_triple {
123
- "aarch64-unknown-linux-gnu" => Some ( "aarch64-linux-gnu-gcc" ) ,
124
- "s390x-unknown-linux-gnu" => Some ( "s390x-linux-gnu-gcc" ) ,
125
- _ => None ,
126
- } ;
118
+ build_clif_sysroot_for_triple (
119
+ dirs,
120
+ channel,
121
+ host_compiler. clone ( ) ,
122
+ & cg_clif_dylib_path,
123
+ ) ;
124
+
125
+ if host_compiler. triple != target_triple {
127
126
build_clif_sysroot_for_triple (
128
127
dirs,
129
128
channel,
130
- target_triple,
129
+ {
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
134
+ } ,
131
135
& cg_clif_dylib_path,
132
- linker,
133
136
) ;
134
137
}
135
138
@@ -150,14 +153,14 @@ pub(crate) static ORIG_BUILD_SYSROOT: RelPath = RelPath::SOURCE.join("build_sysr
150
153
pub ( crate ) static BUILD_SYSROOT : RelPath = RelPath :: DOWNLOAD . join ( "sysroot" ) ;
151
154
pub ( crate ) static SYSROOT_RUSTC_VERSION : RelPath = BUILD_SYSROOT . join ( "rustc_version" ) ;
152
155
pub ( crate ) static SYSROOT_SRC : RelPath = BUILD_SYSROOT . join ( "sysroot_src" ) ;
153
- static STANDARD_LIBRARY : CargoProject = CargoProject :: new ( & BUILD_SYSROOT , "build_sysroot" ) ;
156
+ pub ( crate ) static STANDARD_LIBRARY : CargoProject =
157
+ CargoProject :: new ( & BUILD_SYSROOT , "build_sysroot" ) ;
154
158
155
159
fn build_clif_sysroot_for_triple (
156
160
dirs : & Dirs ,
157
161
channel : & str ,
158
- triple : & str ,
162
+ mut compiler : Compiler ,
159
163
cg_clif_dylib_path : & Path ,
160
- linker : Option < & str > ,
161
164
) {
162
165
match fs:: read_to_string ( SYSROOT_RUSTC_VERSION . to_path ( dirs) ) {
163
166
Err ( e) => {
@@ -177,7 +180,7 @@ fn build_clif_sysroot_for_triple(
177
180
}
178
181
}
179
182
180
- let build_dir = STANDARD_LIBRARY . target_dir ( dirs) . join ( triple) . join ( channel) ;
183
+ let build_dir = STANDARD_LIBRARY . target_dir ( dirs) . join ( & compiler . triple ) . join ( channel) ;
181
184
182
185
if !super :: config:: get_bool ( "keep_sysroot" ) {
183
186
// Cleanup the deps dir, but keep build scripts and the incremental cache for faster
@@ -188,18 +191,13 @@ fn build_clif_sysroot_for_triple(
188
191
}
189
192
190
193
// Build sysroot
191
- let mut rustflags = "-Zforce-unstable-if-unmarked -Cpanic=abort" . to_string ( ) ;
194
+ let mut rustflags = " -Zforce-unstable-if-unmarked -Cpanic=abort" . to_string ( ) ;
192
195
rustflags. push_str ( & format ! ( " -Zcodegen-backend={}" , cg_clif_dylib_path. to_str( ) . unwrap( ) ) ) ;
193
196
rustflags. push_str ( & format ! ( " --sysroot={}" , DIST_DIR . to_path( dirs) . to_str( ) . unwrap( ) ) ) ;
194
197
if channel == "release" {
195
198
rustflags. push_str ( " -Zmir-opt-level=3" ) ;
196
199
}
197
- if let Some ( linker) = linker {
198
- use std:: fmt:: Write ;
199
- write ! ( rustflags, " -Clinker={}" , linker) . unwrap ( ) ;
200
- }
201
- let mut compiler = Compiler :: with_triple ( triple. to_owned ( ) ) ;
202
- compiler. rustflags = rustflags;
200
+ compiler. rustflags += & rustflags;
203
201
let mut build_cmd = STANDARD_LIBRARY . build ( & compiler, dirs) ;
204
202
if channel == "release" {
205
203
build_cmd. arg ( "--release" ) ;
@@ -219,7 +217,7 @@ fn build_clif_sysroot_for_triple(
219
217
} ;
220
218
try_hard_link (
221
219
entry. path ( ) ,
222
- RUSTLIB_DIR . to_path ( dirs) . join ( triple) . join ( "lib" ) . join ( entry. file_name ( ) ) ,
220
+ RUSTLIB_DIR . to_path ( dirs) . join ( & compiler . triple ) . join ( "lib" ) . join ( entry. file_name ( ) ) ,
223
221
) ;
224
222
}
225
223
}
0 commit comments