@@ -451,11 +451,18 @@ fn setup_windows_dll_path(codegen_backend_path: &Path) {
451451 let separator = ";" ;
452452
453453 let dir_str = dir. to_string_lossy ( ) ;
454- // Check if the directory is already in the path
455- if !existing_path
456- . split ( separator)
457- . any ( |p| p == dir_str. as_ref ( ) )
458- {
454+
455+ // Windows paths can have different case and still be the same
456+ // Also check with canonicalized paths
457+ let dir_canonical = dir. canonicalize ( ) . ok ( ) ;
458+ let already_exists = existing_path. split ( separator) . any ( |p| {
459+ let p_lower = p. to_lowercase ( ) ;
460+ let dir_lower = dir_str. to_lowercase ( ) ;
461+ p_lower == dir_lower
462+ || ( dir_canonical. is_some ( ) && Path :: new ( p) . canonicalize ( ) . ok ( ) == dir_canonical)
463+ } ) ;
464+
465+ if !already_exists {
459466 let new_path = if existing_path. is_empty ( ) {
460467 dir_str. to_string ( )
461468 } else {
@@ -471,6 +478,27 @@ fn setup_windows_dll_path(codegen_backend_path: &Path) {
471478 // Add the directory containing the codegen backend
472479 if let Some ( dir) = codegen_backend_path. parent ( ) {
473480 add_to_dylib_path ( dir) ;
481+
482+ // On Windows, check if LLVM DLLs were copied to the build directory
483+ println ! ( "Checking for LLVM DLLs in build directory..." ) ;
484+ if let Ok ( entries) = std:: fs:: read_dir ( dir) {
485+ let mut found_llvm_dlls = Vec :: new ( ) ;
486+ for entry in entries. flatten ( ) {
487+ if let Some ( name) = entry. file_name ( ) . to_str ( ) {
488+ if name. ends_with ( ".dll" ) && name. starts_with ( "LLVM" ) {
489+ found_llvm_dlls. push ( name. to_string ( ) ) ;
490+ }
491+ }
492+ }
493+ if !found_llvm_dlls. is_empty ( ) {
494+ println ! ( " Found LLVM DLLs in build directory:" ) ;
495+ for dll in & found_llvm_dlls {
496+ println ! ( " - {dll}" ) ;
497+ }
498+ } else {
499+ println ! ( " No LLVM DLLs found in build directory" ) ;
500+ }
501+ }
474502 }
475503
476504 // Try to find LLVM directories and add them to PATH
@@ -519,19 +547,67 @@ fn setup_windows_dll_path(codegen_backend_path: &Path) {
519547 "C:\\ Program Files (x86)\\ LLVM\\ bin" ,
520548 "C:\\ Tools\\ LLVM\\ bin" ,
521549 "C:\\ llvm\\ bin" ,
550+ "C:\\ Program Files\\ LLVM-7.0.0\\ bin" ,
551+ "C:\\ Program Files\\ LLVM-7\\ bin" ,
552+ "C:\\ LLVM-7.0.0\\ bin" ,
522553 ] ;
523554
524555 for path_str in & common_llvm_paths {
525556 let path = Path :: new ( path_str) ;
526557 if path. exists ( ) {
527558 println ! ( " Found LLVM directory: {}" , path_str) ;
528559 add_to_dylib_path ( path) ;
560+
561+ // Also check if there's a lib directory with DLLs
562+ if let Some ( parent) = path. parent ( ) {
563+ let lib_path = parent. join ( "lib" ) ;
564+ if lib_path. exists ( ) {
565+ println ! ( " Also checking lib directory: {}" , lib_path. display( ) ) ;
566+ // List DLLs in lib directory
567+ if let Ok ( entries) = std:: fs:: read_dir ( & lib_path) {
568+ let mut found_dlls = false ;
569+ for entry in entries. flatten ( ) {
570+ if let Some ( name) = entry. file_name ( ) . to_str ( ) {
571+ if name. ends_with ( ".dll" ) && name. contains ( "LLVM" ) {
572+ if !found_dlls {
573+ println ! ( " Found LLVM DLLs in lib:" ) ;
574+ found_dlls = true ;
575+ }
576+ println ! ( " - {}" , name) ;
577+ }
578+ }
579+ }
580+ if found_dlls {
581+ add_to_dylib_path ( & lib_path) ;
582+ }
583+ }
584+ }
585+ }
529586 }
530587 }
531588
532589 // Print final PATH for debugging
533590 let final_path = env:: var ( dylib_path_envvar ( ) ) . unwrap_or_default ( ) ;
534591 println ! ( "Final PATH: {}" , final_path) ;
592+
593+ // Try to use dumpbin to check what DLLs are needed
594+ println ! ( "\n Checking DLL dependencies..." ) ;
595+ let dumpbin_result = Command :: new ( "dumpbin" )
596+ . args ( [ "/dependents" , codegen_backend_path. to_str ( ) . unwrap ( ) ] )
597+ . output ( ) ;
598+
599+ if let Ok ( output) = dumpbin_result {
600+ if output. status . success ( ) {
601+ if let Ok ( stdout) = String :: from_utf8 ( output. stdout ) {
602+ println ! ( "Dependencies of rustc_codegen_nvvm.dll:" ) ;
603+ for line in stdout. lines ( ) {
604+ if line. contains ( ".dll" ) && !line. contains ( "Dump of file" ) {
605+ println ! ( " {}" , line. trim( ) ) ;
606+ }
607+ }
608+ }
609+ }
610+ }
535611}
536612
537613fn find_rustc_codegen_nvvm ( workspace_root : & Path ) -> PathBuf {
0 commit comments