11use c2rust_build_paths:: find_llvm_config;
22use cmake:: Config ;
33use std:: env;
4- use std:: ffi:: OsStr ;
4+ use std:: ffi:: { OsStr , OsString } ;
55use std:: path:: { Path , PathBuf } ;
66use std:: process:: { self , Command } ;
77
@@ -129,13 +129,13 @@ fn build_native(llvm_info: &LLVMInfo) {
129129 // Where to find LLVM/Clang CMake files
130130 . define (
131131 "LLVM_DIR" ,
132- env:: var ( "CMAKE_LLVM_DIR" )
133- . unwrap_or_else ( |_| format ! ( "{}/ cmake/llvm", llvm_lib_dir ) ) ,
132+ env:: var_os ( "CMAKE_LLVM_DIR" )
133+ . unwrap_or_else ( || llvm_lib_dir . join ( " cmake/llvm") . into ( ) ) ,
134134 )
135135 . define (
136136 "Clang_DIR" ,
137- env:: var ( "CMAKE_CLANG_DIR" )
138- . unwrap_or_else ( |_| format ! ( "{}/ cmake/clang", llvm_lib_dir ) ) ,
137+ env:: var_os ( "CMAKE_CLANG_DIR" )
138+ . unwrap_or_else ( || llvm_lib_dir . join ( " cmake/clang") . into ( ) ) ,
139139 )
140140 // What to build
141141 . build_target ( "clangAstExporter" )
@@ -153,7 +153,7 @@ fn build_native(llvm_info: &LLVMInfo) {
153153 println ! ( "cargo:rustc-link-lib=static=tinycbor" ) ;
154154 println ! ( "cargo:rustc-link-lib=static=clangAstExporter" ) ;
155155
156- println ! ( "cargo:rustc-link-search=native={}" , llvm_lib_dir) ;
156+ println ! ( "cargo:rustc-link-search=native={}" , llvm_lib_dir. display ( ) ) ;
157157
158158 // Some distro's, including arch and Fedora, no longer build with
159159 // BUILD_SHARED_LIBS=ON; programs linking to clang are required to
@@ -231,7 +231,7 @@ fn build_native(llvm_info: &LLVMInfo) {
231231/// Holds information about LLVM paths we have found
232232struct LLVMInfo {
233233 /// LLVM lib dir containing libclang* and libLLVM* libraries
234- pub lib_dir : String ,
234+ pub lib_dir : PathBuf ,
235235
236236 /// List of libs we need to link against
237237 pub libs : Vec < String > ,
@@ -267,16 +267,12 @@ impl LLVMInfo {
267267 $ export LLVM_LIB_DIR=/usr/local/opt/llvm/lib
268268 " ;
269269 let lib_dir = {
270- let path_str = env:: var ( "LLVM_LIB_DIR" )
271- . ok ( )
272- . or_else ( || invoke_command ( llvm_config. as_deref ( ) , [ "--libdir" ] ) )
270+ let path_str = env:: var_os ( "LLVM_LIB_DIR" )
271+ . or_else ( || {
272+ invoke_command ( llvm_config. as_deref ( ) , [ "--libdir" ] ) . map ( OsString :: from)
273+ } )
273274 . expect ( llvm_config_missing) ;
274- String :: from (
275- Path :: new ( & path_str)
276- . canonicalize ( )
277- . unwrap ( )
278- . to_string_lossy ( ) ,
279- )
275+ Path :: new ( & path_str) . canonicalize ( ) . unwrap ( )
280276 } ;
281277
282278 let llvm_shared_libs = invoke_command ( llvm_config. as_deref ( ) , [ "--libs" , "--link-shared" ] ) ;
0 commit comments