@@ -30,8 +30,8 @@ pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
3030pub use clang:: { clang, Clang } ;
3131pub use diff:: { diff, Diff } ;
3232pub 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 ,
3535} ;
3636pub use run:: { cmd, run, run_fail, run_with_args} ;
3737pub 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)
321321 count
322322}
323323
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+
324344/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
325345/// available on the platform!
326346#[ track_caller]
0 commit comments