@@ -66,8 +66,36 @@ impl Callbacks for CompilerCalls {
6666 }
6767}
6868
69+ fn thrust_macros_path ( ) -> Option < std:: path:: PathBuf > {
70+ let exe = std:: env:: current_exe ( ) . ok ( ) ?;
71+ let dir = exe. parent ( ) ?;
72+ // When thrust-macros is a cargo dependency it lands in deps/ with a hash
73+ // suffix (e.g. libthrust_macros-<hash>.so), so check both locations.
74+ let search_dirs = [ dir. to_path_buf ( ) , dir. join ( "deps" ) ] ;
75+ for search_dir in & search_dirs {
76+ for ext in [ "so" , "dylib" , "dll" ] {
77+ // First try the exact name (e.g. when built standalone).
78+ let candidate = search_dir. join ( format ! ( "libthrust_macros.{ext}" ) ) ;
79+ if candidate. exists ( ) {
80+ return Some ( candidate) ;
81+ }
82+ // Then scan for libthrust_macros-<hash>.<ext>.
83+ if let Ok ( entries) = std:: fs:: read_dir ( search_dir) {
84+ for entry in entries. flatten ( ) {
85+ let name = entry. file_name ( ) ;
86+ let name = name. to_string_lossy ( ) ;
87+ if name. starts_with ( "libthrust_macros-" ) && name. ends_with ( ext) {
88+ return Some ( entry. path ( ) ) ;
89+ }
90+ }
91+ }
92+ }
93+ }
94+ None
95+ }
96+
6997pub fn main ( ) {
70- let args = std:: env:: args ( ) . collect :: < Vec < _ > > ( ) ;
98+ let mut args = std:: env:: args ( ) . collect :: < Vec < _ > > ( ) ;
7199
72100 use tracing_subscriber:: { filter:: EnvFilter , prelude:: * } ;
73101 tracing_subscriber:: registry ( )
@@ -80,6 +108,14 @@ pub fn main() {
80108 )
81109 . init ( ) ;
82110
111+ if let Some ( path) = thrust_macros_path ( ) {
112+ args. push ( "--extern" . to_owned ( ) ) ;
113+ args. push ( format ! ( "thrust_macros={}" , path. display( ) ) ) ;
114+ tracing:: debug!( "linking thrust_macros from {}" , path. display( ) ) ;
115+ } else {
116+ tracing:: warn!( "could not locate thrust_macros library" ) ;
117+ }
118+
83119 let code =
84120 rustc_driver:: catch_with_exit_code ( || RunCompiler :: new ( & args, & mut CompilerCalls { } ) . run ( ) ) ;
85121 std:: process:: exit ( code) ;
0 commit comments