@@ -78,11 +78,8 @@ impl Step for Std {
78
78
builder. info ( & format ! ( "Uplifting stage1 std ({} -> {})" , from. host, target) ) ;
79
79
80
80
// Even if we're not building std this stage, the new sysroot must
81
- // still contain the musl startup objects.
82
- if target. contains ( "musl" ) {
83
- let libdir = builder. sysroot_libdir ( compiler, target) ;
84
- copy_musl_third_party_objects ( builder, target, & libdir) ;
85
- }
81
+ // still contain the third party objects needed by various targets.
82
+ copy_third_party_objects ( builder, & compiler, target) ;
86
83
87
84
builder. ensure ( StdLink {
88
85
compiler : from,
@@ -92,10 +89,7 @@ impl Step for Std {
92
89
return ;
93
90
}
94
91
95
- if target. contains ( "musl" ) {
96
- let libdir = builder. sysroot_libdir ( compiler, target) ;
97
- copy_musl_third_party_objects ( builder, target, & libdir) ;
98
- }
92
+ copy_third_party_objects ( builder, & compiler, target) ;
99
93
100
94
let mut cargo = builder. cargo ( compiler, Mode :: Std , target, "build" ) ;
101
95
std_cargo ( builder, & compiler, target, & mut cargo) ;
@@ -116,17 +110,36 @@ impl Step for Std {
116
110
}
117
111
}
118
112
119
- /// Copies the crt(1,i,n).o startup objects
120
- ///
121
- /// Since musl supports fully static linking, we can cross link for it even
122
- /// with a glibc-targeting toolchain, given we have the appropriate startup
123
- /// files. As those shipped with glibc won't work, copy the ones provided by
124
- /// musl so we have them on linux-gnu hosts.
125
- fn copy_musl_third_party_objects ( builder : & Builder ,
126
- target : Interned < String > ,
127
- into : & Path ) {
128
- for & obj in & [ "crt1.o" , "crti.o" , "crtn.o" ] {
129
- builder. copy ( & builder. musl_root ( target) . unwrap ( ) . join ( "lib" ) . join ( obj) , & into. join ( obj) ) ;
113
+ /// Copies third pary objects needed by various targets.
114
+ fn copy_third_party_objects ( builder : & Builder , compiler : & Compiler , target : Interned < String > ) {
115
+ let libdir = builder. sysroot_libdir ( * compiler, target) ;
116
+
117
+ // Copies the crt(1,i,n).o startup objects
118
+ //
119
+ // Since musl supports fully static linking, we can cross link for it even
120
+ // with a glibc-targeting toolchain, given we have the appropriate startup
121
+ // files. As those shipped with glibc won't work, copy the ones provided by
122
+ // musl so we have them on linux-gnu hosts.
123
+ if target. contains ( "musl" ) {
124
+ for & obj in & [ "crt1.o" , "crti.o" , "crtn.o" ] {
125
+ builder. copy (
126
+ & builder. musl_root ( target) . unwrap ( ) . join ( "lib" ) . join ( obj) ,
127
+ & libdir. join ( obj) ,
128
+ ) ;
129
+ }
130
+ }
131
+
132
+ // Copies libunwind.a compiled to be linked wit x86_64-fortanix-unknown-sgx.
133
+ //
134
+ // This target needs to be linked to Fortanix's port of llvm's libunwind.
135
+ // libunwind requires support for rwlock and printing to stderr,
136
+ // which is provided by std for this target.
137
+ if target == "x86_64-fortanix-unknown-sgx" {
138
+ let src_path_env = "X86_FORTANIX_SGX_LIBS" ;
139
+ let obj = "libunwind.a" ;
140
+ let src = env:: var ( src_path_env) . expect ( & format ! ( "{} not found in env" , src_path_env) ) ;
141
+ let src = Path :: new ( & src) . join ( obj) ;
142
+ builder. copy ( & src, & libdir. join ( obj) ) ;
130
143
}
131
144
}
132
145
0 commit comments