1
+ use crate :: utils:: spawn_and_wait;
1
2
use crate :: utils:: try_hard_link;
2
3
use crate :: SysrootKind ;
3
- use std:: env;
4
4
use std:: fs;
5
5
use std:: path:: Path ;
6
6
use std:: process:: { self , Command } ;
@@ -100,24 +100,14 @@ pub(crate) fn build_sysroot(
100
100
}
101
101
}
102
102
SysrootKind :: Clif => {
103
- let cwd = env:: current_dir ( ) . unwrap ( ) ;
104
-
105
- let mut cmd = Command :: new ( cwd. join ( "build_sysroot" ) . join ( "build_sysroot.sh" ) ) ;
106
- cmd. current_dir ( target_dir) . env ( "TARGET_TRIPLE" , target_triple) ;
107
- eprintln ! ( "[BUILD] sysroot" ) ;
108
- if !cmd. spawn ( ) . unwrap ( ) . wait ( ) . unwrap ( ) . success ( ) {
109
- process:: exit ( 1 ) ;
110
- }
103
+ build_clif_sysroot_for_triple ( channel, target_dir, target_triple) ;
111
104
112
105
if host_triple != target_triple {
113
- let mut cmd = Command :: new ( cwd. join ( "build_sysroot" ) . join ( "build_sysroot.sh" ) ) ;
114
- cmd. current_dir ( target_dir) . env ( "TARGET_TRIPLE" , host_triple) ;
115
- eprintln ! ( "[BUILD] sysroot" ) ;
116
- if !cmd. spawn ( ) . unwrap ( ) . wait ( ) . unwrap ( ) . success ( ) {
117
- process:: exit ( 1 ) ;
118
- }
106
+ build_clif_sysroot_for_triple ( channel, target_dir, host_triple) ;
119
107
}
120
108
109
+ // Copy std for the host to the lib dir. This is necessary for the jit mode to find
110
+ // libstd.
121
111
for file in fs:: read_dir ( host_rustlib_lib) . unwrap ( ) {
122
112
let file = file. unwrap ( ) . path ( ) ;
123
113
if file. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . contains ( "std-" ) {
@@ -127,3 +117,49 @@ pub(crate) fn build_sysroot(
127
117
}
128
118
}
129
119
}
120
+
121
+ fn build_clif_sysroot_for_triple ( channel : & str , target_dir : & Path , triple : & str ) {
122
+ let build_dir = Path :: new ( "build_sysroot" ) . join ( "target" ) . join ( triple) . join ( channel) ;
123
+
124
+ // FIXME add option to skip this
125
+ // Cleanup the target dir with the exception of build scripts and the incremental cache
126
+ for dir in [ "build" , "deps" , "examples" , "native" ] {
127
+ if build_dir. join ( dir) . exists ( ) {
128
+ fs:: remove_dir_all ( build_dir. join ( dir) ) . unwrap ( ) ;
129
+ }
130
+ }
131
+
132
+ // Build sysroot
133
+ let mut build_cmd = Command :: new ( "cargo" ) ;
134
+ build_cmd. arg ( "build" ) . arg ( "--target" ) . arg ( triple) . current_dir ( "build_sysroot" ) ;
135
+ let mut rustflags = "--clif -Zforce-unstable-if-unmarked" . to_string ( ) ;
136
+ if channel == "release" {
137
+ build_cmd. arg ( "--release" ) ;
138
+ rustflags. push_str ( " -Zmir-opt-level=3" ) ;
139
+ }
140
+ build_cmd. env ( "RUSTFLAGS" , rustflags) ;
141
+ build_cmd
142
+ . env ( "RUSTC" , target_dir. join ( "bin" ) . join ( "cg_clif_build_sysroot" ) . canonicalize ( ) . unwrap ( ) ) ;
143
+ // FIXME Enable incremental again once rust-lang/rust#74946 is fixed
144
+ build_cmd. env ( "CARGO_INCREMENTAL" , "0" ) . env ( "__CARGO_DEFAULT_LIB_METADATA" , "cg_clif" ) ;
145
+ spawn_and_wait ( build_cmd) ;
146
+
147
+ // Copy all relevant files to the sysroot
148
+ for entry in
149
+ fs:: read_dir ( Path :: new ( "build_sysroot/target" ) . join ( triple) . join ( channel) . join ( "deps" ) )
150
+ . unwrap ( )
151
+ {
152
+ let entry = entry. unwrap ( ) ;
153
+ if let Some ( ext) = entry. path ( ) . extension ( ) {
154
+ if ext == "rmeta" || ext == "d" || ext == "dSYM" {
155
+ continue ;
156
+ }
157
+ } else {
158
+ continue ;
159
+ } ;
160
+ try_hard_link (
161
+ entry. path ( ) ,
162
+ target_dir. join ( "lib" ) . join ( "rustlib" ) . join ( triple) . join ( "lib" ) . join ( entry. file_name ( ) ) ,
163
+ ) ;
164
+ }
165
+ }
0 commit comments