@@ -30,8 +30,8 @@ pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
30
30
pub use clang:: { clang, Clang } ;
31
31
pub use diff:: { diff, Diff } ;
32
32
pub use llvm:: {
33
- llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmFilecheck , LlvmObjdump ,
34
- LlvmProfdata , LlvmReadobj ,
33
+ llvm_ar , llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr , LlvmFilecheck ,
34
+ LlvmObjdump , LlvmProfdata , LlvmReadobj ,
35
35
} ;
36
36
pub use run:: { cmd, run, run_fail, run_with_args} ;
37
37
pub use rustc:: { aux_build, bare_rustc, rustc, Rustc } ;
@@ -321,6 +321,26 @@ pub fn count_regex_matches_in_files_with_extension(re: ®ex::Regex, ext: &str)
321
321
count
322
322
}
323
323
324
+ /// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name.
325
+ #[ track_caller]
326
+ pub fn build_native_static_lib ( lib_name : & str ) -> PathBuf {
327
+ let obj_file = if is_msvc ( ) { format ! ( "{lib_name}" ) } else { format ! ( "{lib_name}.o" ) } ;
328
+ let src = format ! ( "{lib_name}.c" ) ;
329
+ let lib_path = static_lib_name ( lib_name) ;
330
+ if is_msvc ( ) {
331
+ cc ( ) . arg ( "-c" ) . out_exe ( & obj_file) . input ( src) . run ( ) ;
332
+ } else {
333
+ cc ( ) . arg ( "-v" ) . arg ( "-c" ) . out_exe ( & obj_file) . input ( src) . run ( ) ;
334
+ } ;
335
+ let mut obj_file = PathBuf :: from ( format ! ( "{lib_name}.o" ) ) ;
336
+ if is_msvc ( ) {
337
+ obj_file. set_extension ( "" ) ;
338
+ obj_file. set_extension ( "obj" ) ;
339
+ }
340
+ llvm_ar ( ) . obj_to_ar ( ) . output_input ( & lib_path, & obj_file) . run ( ) ;
341
+ path ( lib_path)
342
+ }
343
+
324
344
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
325
345
/// available on the platform!
326
346
#[ track_caller]
0 commit comments