@@ -12,7 +12,6 @@ use super::SysrootKind;
12
12
static DIST_DIR : RelPath = RelPath :: DIST ;
13
13
static BIN_DIR : RelPath = RelPath :: DIST . join ( "bin" ) ;
14
14
static LIB_DIR : RelPath = RelPath :: DIST . join ( "lib" ) ;
15
- static RUSTLIB_DIR : RelPath = LIB_DIR . join ( "rustlib" ) ;
16
15
17
16
pub ( crate ) fn build_sysroot (
18
17
dirs : & Dirs ,
@@ -56,86 +55,37 @@ pub(crate) fn build_sysroot(
56
55
spawn_and_wait ( build_cargo_wrapper_cmd) ;
57
56
}
58
57
59
- match sysroot_kind {
60
- SysrootKind :: None => { } // Nothing to do
61
- SysrootKind :: Llvm => {
62
- let default_sysroot =
63
- super :: rustc_info:: get_default_sysroot ( & bootstrap_host_compiler. rustc ) ;
64
-
65
- let host_rustlib_lib =
66
- RUSTLIB_DIR . to_path ( dirs) . join ( & bootstrap_host_compiler. triple ) . join ( "lib" ) ;
67
- let target_rustlib_lib = RUSTLIB_DIR . to_path ( dirs) . join ( & target_triple) . join ( "lib" ) ;
68
- fs:: create_dir_all ( & host_rustlib_lib) . unwrap ( ) ;
69
- fs:: create_dir_all ( & target_rustlib_lib) . unwrap ( ) ;
70
-
71
- for file in fs:: read_dir (
72
- default_sysroot
73
- . join ( "lib" )
74
- . join ( "rustlib" )
75
- . join ( & bootstrap_host_compiler. triple )
76
- . join ( "lib" ) ,
77
- )
78
- . unwrap ( )
79
- {
80
- let file = file. unwrap ( ) . path ( ) ;
81
- let file_name_str = file. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
82
- if ( file_name_str. contains ( "rustc_" )
83
- && !file_name_str. contains ( "rustc_std_workspace_" )
84
- && !file_name_str. contains ( "rustc_demangle" ) )
85
- || file_name_str. contains ( "chalk" )
86
- || file_name_str. contains ( "tracing" )
87
- || file_name_str. contains ( "regex" )
88
- {
89
- // These are large crates that are part of the rustc-dev component and are not
90
- // necessary to run regular programs.
91
- continue ;
92
- }
93
- try_hard_link ( & file, host_rustlib_lib. join ( file. file_name ( ) . unwrap ( ) ) ) ;
94
- }
58
+ let host = build_sysroot_for_triple (
59
+ dirs,
60
+ channel,
61
+ bootstrap_host_compiler. clone ( ) ,
62
+ & cg_clif_dylib_path,
63
+ sysroot_kind,
64
+ ) ;
65
+ host. install_into_sysroot ( & DIST_DIR . to_path ( dirs) ) ;
95
66
96
- if !is_native {
97
- for file in fs:: read_dir (
98
- default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( & target_triple) . join ( "lib" ) ,
99
- )
100
- . unwrap ( )
101
- {
102
- let file = file. unwrap ( ) . path ( ) ;
103
- try_hard_link ( & file, target_rustlib_lib. join ( file. file_name ( ) . unwrap ( ) ) ) ;
104
- }
105
- }
106
- }
107
- SysrootKind :: Clif => {
108
- let host = build_clif_sysroot_for_triple (
109
- dirs,
110
- channel,
111
- bootstrap_host_compiler. clone ( ) ,
112
- & cg_clif_dylib_path,
113
- ) ;
114
- host. install_into_sysroot ( & DIST_DIR . to_path ( dirs) ) ;
115
-
116
- if !is_native {
117
- build_clif_sysroot_for_triple (
118
- dirs,
119
- channel,
120
- {
121
- let mut bootstrap_target_compiler = bootstrap_host_compiler. clone ( ) ;
122
- bootstrap_target_compiler. triple = target_triple. clone ( ) ;
123
- bootstrap_target_compiler. set_cross_linker_and_runner ( ) ;
124
- bootstrap_target_compiler
125
- } ,
126
- & cg_clif_dylib_path,
127
- )
128
- . install_into_sysroot ( & DIST_DIR . to_path ( dirs) ) ;
129
- }
67
+ if !is_native {
68
+ build_sysroot_for_triple (
69
+ dirs,
70
+ channel,
71
+ {
72
+ let mut bootstrap_target_compiler = bootstrap_host_compiler. clone ( ) ;
73
+ bootstrap_target_compiler. triple = target_triple. clone ( ) ;
74
+ bootstrap_target_compiler. set_cross_linker_and_runner ( ) ;
75
+ bootstrap_target_compiler
76
+ } ,
77
+ & cg_clif_dylib_path,
78
+ sysroot_kind,
79
+ )
80
+ . install_into_sysroot ( & DIST_DIR . to_path ( dirs) ) ;
81
+ }
130
82
131
- // Copy std for the host to the lib dir. This is necessary for the jit mode to find
132
- // libstd.
133
- for lib in host. libs {
134
- let filename = lib. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
135
- if filename. contains ( "std-" ) && !filename. contains ( ".rlib" ) {
136
- try_hard_link ( & lib, LIB_DIR . to_path ( dirs) . join ( lib. file_name ( ) . unwrap ( ) ) ) ;
137
- }
138
- }
83
+ // Copy std for the host to the lib dir. This is necessary for the jit mode to find
84
+ // libstd.
85
+ for lib in host. libs {
86
+ let filename = lib. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
87
+ if filename. contains ( "std-" ) && !filename. contains ( ".rlib" ) {
88
+ try_hard_link ( & lib, LIB_DIR . to_path ( dirs) . join ( lib. file_name ( ) . unwrap ( ) ) ) ;
139
89
}
140
90
}
141
91
@@ -170,6 +120,57 @@ pub(crate) static STANDARD_LIBRARY: CargoProject =
170
120
CargoProject :: new ( & BUILD_SYSROOT , "build_sysroot" ) ;
171
121
pub ( crate ) static RTSTARTUP_SYSROOT : RelPath = RelPath :: BUILD . join ( "rtstartup" ) ;
172
122
123
+ #[ must_use]
124
+ fn build_sysroot_for_triple (
125
+ dirs : & Dirs ,
126
+ channel : & str ,
127
+ compiler : Compiler ,
128
+ cg_clif_dylib_path : & Path ,
129
+ sysroot_kind : SysrootKind ,
130
+ ) -> SysrootTarget {
131
+ match sysroot_kind {
132
+ SysrootKind :: None => SysrootTarget { triple : compiler. triple , libs : vec ! [ ] } ,
133
+ SysrootKind :: Llvm => build_llvm_sysroot_for_triple ( compiler) ,
134
+ SysrootKind :: Clif => {
135
+ build_clif_sysroot_for_triple ( dirs, channel, compiler, & cg_clif_dylib_path)
136
+ }
137
+ }
138
+ }
139
+
140
+ #[ must_use]
141
+ fn build_llvm_sysroot_for_triple ( compiler : Compiler ) -> SysrootTarget {
142
+ let default_sysroot = super :: rustc_info:: get_default_sysroot ( & compiler. rustc ) ;
143
+
144
+ let mut target_libs = SysrootTarget { triple : compiler. triple , libs : vec ! [ ] } ;
145
+
146
+ for entry in fs:: read_dir (
147
+ default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( & target_libs. triple ) . join ( "lib" ) ,
148
+ )
149
+ . unwrap ( )
150
+ {
151
+ let entry = entry. unwrap ( ) ;
152
+ if entry. file_type ( ) . unwrap ( ) . is_dir ( ) {
153
+ continue ;
154
+ }
155
+ let file = entry. path ( ) ;
156
+ let file_name_str = file. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
157
+ if ( file_name_str. contains ( "rustc_" )
158
+ && !file_name_str. contains ( "rustc_std_workspace_" )
159
+ && !file_name_str. contains ( "rustc_demangle" ) )
160
+ || file_name_str. contains ( "chalk" )
161
+ || file_name_str. contains ( "tracing" )
162
+ || file_name_str. contains ( "regex" )
163
+ {
164
+ // These are large crates that are part of the rustc-dev component and are not
165
+ // necessary to run regular programs.
166
+ continue ;
167
+ }
168
+ target_libs. libs . push ( file) ;
169
+ }
170
+
171
+ target_libs
172
+ }
173
+
173
174
#[ must_use]
174
175
fn build_clif_sysroot_for_triple (
175
176
dirs : & Dirs ,
0 commit comments