@@ -62,8 +62,6 @@ fn cargo_main() {
6262 . include ( "third_party/musl/arch/x86_64" ) ;
6363 }
6464
65- let is_pe = env:: var ( "CARGO_CFG_WINDOWS" ) . is_ok ( ) ;
66-
6765 if cfg ! ( any( feature = "printf" , feature = "libc" ) ) {
6866 cfg. define ( "HYPERLIGHT" , None ) ; // used in certain musl files for conditional compilation
6967
@@ -78,37 +76,28 @@ fn cargo_main() {
7876 . flag ( "-Wno-unused-parameter" )
7977 . flag ( "-Wno-string-plus-int" ) ;
8078
81- if is_pe {
82- cfg. flag ( "-Wno-unused-label" ) ;
83- cfg. flag ( "-Wno-unused-variable" ) ;
84- cfg. compiler ( "clang-cl" ) ;
85- } else {
86- cfg. flag ( "-fPIC" ) ;
87- // This is a terrible hack, because
88- // - we need stack clash protection, because we have put the
89- // stack right smack in the middle of everything in the guest
90- // - clang refuses to do stack clash protection unless it is
91- // required by a target ABI (Windows, MacOS) or the target is
92- // is Linux or FreeBSD (see Clang.cpp RenderSCPOptions
93- // https://github.com/llvm/llvm-project/blob/1bb52e9/clang/lib/Driver/ToolChains/Clang.cpp#L3724).
94- // Hopefully a flag to force stack clash protection on generic
95- // targets will eventually show up.
96- cfg. flag ( "--target=x86_64-unknown-linux-none" ) ;
79+ cfg. flag ( "-fPIC" ) ;
80+ // This is a terrible hack, because
81+ // - we need stack clash protection, because we have put the
82+ // stack right smack in the middle of everything in the guest
83+ // - clang refuses to do stack clash protection unless it is
84+ // required by a target ABI (Windows, MacOS) or the target is
85+ // is Linux or FreeBSD (see Clang.cpp RenderSCPOptions
86+ // https://github.com/llvm/llvm-project/blob/1bb52e9/clang/lib/Driver/ToolChains/Clang.cpp#L3724).
87+ // Hopefully a flag to force stack clash protection on generic
88+ // targets will eventually show up.
89+ cfg. flag ( "--target=x86_64-unknown-linux-none" ) ;
9790
98- // We don't support stack protectors at the moment, but Arch Linux clang
99- // auto-enables them for -linux platforms, so explicitly disable them.
100- cfg. flag ( "-fno-stack-protector" ) ;
101- cfg. flag ( "-fstack-clash-protection" ) ;
102- cfg. flag ( "-mstack-probe-size=4096" ) ;
103- cfg. compiler ( "clang" ) ;
104- }
91+ // We don't support stack protectors at the moment, but Arch Linux clang
92+ // auto-enables them for -linux platforms, so explicitly disable them.
93+ cfg. flag ( "-fno-stack-protector" ) ;
94+ cfg. flag ( "-fstack-clash-protection" ) ;
95+ cfg. flag ( "-mstack-probe-size=4096" ) ;
96+ cfg. compiler ( "clang" ) ;
10597
10698 if cfg ! ( windows) {
10799 unsafe { env:: set_var ( "AR_x86_64_unknown_none" , "llvm-ar" ) } ;
108- } else {
109- unsafe { env:: set_var ( "AR_x86_64_pc_windows_msvc" , "llvm-lib" ) } ;
110100 }
111-
112101 cfg. compile ( "hyperlight_guest_bin" ) ;
113102 }
114103
@@ -183,29 +172,20 @@ fn cargo_main() {
183172 fs:: create_dir_all ( & binroot)
184173 . unwrap_or_else ( |e| panic ! ( "Could not create binary root {:?}: {}" , & binroot, e) ) ;
185174 fs:: write ( binroot. join ( ".out_dir" ) , out_dir) . expect ( "Could not write out_dir" ) ;
186- fs:: copy ( & binpath, binroot. join ( "ml64.exe" ) ) . expect ( "Could not copy to ml64.exe" ) ;
187175 fs:: copy ( & binpath, binroot. join ( "clang" ) ) . expect ( "Could not copy to clang" ) ;
188176 fs:: copy ( & binpath, binroot. join ( "clang.exe" ) ) . expect ( "Could not copy to clang.exe" ) ;
189- fs:: copy ( & binpath, binroot. join ( "clang-cl" ) ) . expect ( "Could not copy to clang-cl" ) ;
190- fs:: copy ( & binpath, binroot. join ( "clang-cl.exe" ) ) . expect ( "Could not copy to clang-cl.exe" ) ;
191177 }
192178}
193179
194180#[ derive( PartialEq ) ]
195181enum Tool {
196182 CargoBuildScript ,
197- Ml64 ,
198183 Clang ,
199- ClangCl ,
200184}
201185impl From < & std:: ffi:: OsStr > for Tool {
202186 fn from ( x : & std:: ffi:: OsStr ) -> Tool {
203- if x == "ml64.exe" {
204- Tool :: Ml64
205- } else if x == "clang" || x == "clang.exe" {
187+ if x == "clang" || x == "clang.exe" {
206188 Tool :: Clang
207- } else if x == "clang-cl" || x == "clang-cl.exe" {
208- Tool :: ClangCl
209189 } else {
210190 Tool :: CargoBuildScript
211191 }
@@ -252,44 +232,29 @@ fn main() -> std::process::ExitCode {
252232 let mut args = env:: args ( ) ;
253233 args. next ( ) ; // ignore the exe name
254234 let include_dir = <String as AsRef < Path > >:: as_ref ( & out_dir) . join ( "include" ) ;
235+
255236 match tool {
256- Tool :: Ml64 => std:: process:: Command :: new ( "llvm-ml" )
257- . arg ( "-m64" )
258- . args ( args)
259- . status ( )
260- . ok ( )
261- . and_then ( |x| ( x. code ( ) ) )
262- . map ( |x| ( x as u8 ) . into ( ) )
263- . unwrap_or ( std:: process:: ExitCode :: FAILURE ) ,
264- Tool :: Clang => std:: process:: Command :: new ( find_next ( root_dir, "clang" ) )
265- // terrible hack, see above
266- . arg ( "--target=x86_64-unknown-linux-none" )
267- . args ( [
268- // We don't support stack protectors at the moment, but Arch Linux clang
269- // auto-enables them for -linux platforms, so explicitly disable them.
270- "-fno-stack-protector" ,
271- "-fstack-clash-protection" ,
272- "-mstack-probe-size=4096" ,
273- ] )
274- . arg ( "-nostdinc" )
275- . arg ( "-isystem" )
276- . arg ( include_dir)
277- . args ( args)
278- . status ( )
279- . ok ( )
280- . and_then ( |x| ( x. code ( ) ) )
281- . map ( |x| ( x as u8 ) . into ( ) )
282- . unwrap_or ( std:: process:: ExitCode :: FAILURE ) ,
283- Tool :: ClangCl => std:: process:: Command :: new ( find_next ( root_dir, "clang-cl" ) )
284- . arg ( "-nostdinc" )
285- . arg ( "/external:I" )
286- . arg ( include_dir)
287- . args ( args)
288- . status ( )
289- . ok ( )
290- . and_then ( |x| ( x. code ( ) ) )
291- . map ( |x| ( x as u8 ) . into ( ) )
292- . unwrap_or ( std:: process:: ExitCode :: FAILURE ) ,
293- _ => std:: process:: ExitCode :: FAILURE ,
237+ Tool :: CargoBuildScript => unreachable ! ( "cargo build script should not be called directly" ) ,
238+ Tool :: Clang => {
239+ std:: process:: Command :: new ( find_next ( root_dir, "clang" ) )
240+ // terrible hack, see above
241+ . arg ( "--target=x86_64-unknown-linux-none" )
242+ . args ( [
243+ // We don't support stack protectors at the moment, but Arch Linux clang
244+ // auto-enables them for -linux platforms, so explicitly disable them.
245+ "-fno-stack-protector" ,
246+ "-fstack-clash-protection" ,
247+ "-mstack-probe-size=4096" ,
248+ ] )
249+ . arg ( "-nostdinc" )
250+ . arg ( "-isystem" )
251+ . arg ( include_dir)
252+ . args ( args)
253+ . status ( )
254+ . ok ( )
255+ . and_then ( |x| ( x. code ( ) ) )
256+ . map ( |x| ( x as u8 ) . into ( ) )
257+ . unwrap_or ( std:: process:: ExitCode :: FAILURE )
258+ }
294259 }
295260}
0 commit comments