@@ -173,6 +173,21 @@ fn find_metacall_library() -> Result<LibraryPath, Box<dyn std::error::Error>> {
173173 . into ( ) )
174174}
175175
176+ fn define_library_search_path ( env_var : & str , separator : & str , path : & PathBuf ) -> String {
177+ // Get the current value of the env var, if any
178+ let existing = env:: var ( env_var) . unwrap_or_default ( ) ;
179+ let path_str: String = String :: from ( path. to_str ( ) . unwrap ( ) ) ;
180+
181+ // Append to it
182+ let combined = if existing. is_empty ( ) {
183+ path_str
184+ } else {
185+ format ! ( "{}{}{}" , existing, separator, path_str)
186+ } ;
187+
188+ format ! ( "{}={}" , env_var, combined)
189+ }
190+
176191fn main ( ) {
177192 // When running tests from CMake
178193 if let Ok ( val) = env:: var ( "PROJECT_OUTPUT_DIR" ) {
@@ -203,19 +218,27 @@ fn main() {
203218
204219 // Set the runtime environment variable for finding the library during tests
205220 #[ cfg( target_os = "linux" ) ]
206- println ! (
207- "cargo:rustc-env=LD_LIBRARY_PATH={}" ,
208- lib_path. path. display( )
209- ) ;
221+ const ENV_VAR : & str = "LD_LIBRARY_PATH" ;
210222
211223 #[ cfg( target_os = "macos" ) ]
212- println ! (
213- "cargo:rustc-env=DYLD_LIBRARY_PATH={}" ,
214- lib_path. path. display( )
215- ) ;
224+ const ENV_VAR : & str = "DYLD_LIBRARY_PATH" ;
216225
217226 #[ cfg( target_os = "windows" ) ]
218- println ! ( "cargo:rustc-env=PATH={}" , lib_path. path. display( ) ) ;
227+ const ENV_VAR : & str = "PATH" ;
228+
229+ #[ cfg( target_os = "aix" ) ]
230+ const ENV_VAR : & str = "LIBPATH" ;
231+
232+ #[ cfg( any( target_os = "linux" , target_os = "macos" , target_os = "aix" ) ) ]
233+ const SEPARATOR : & str = ":" ;
234+
235+ #[ cfg( target_os = "windows" ) ]
236+ const SEPARATOR : & str = ";" ;
237+
238+ println ! (
239+ "cargo:rustc-env={}" ,
240+ define_library_search_path( ENV_VAR , SEPARATOR , & lib_path. path)
241+ ) ;
219242 }
220243 Err ( e) => {
221244 // Print the error
0 commit comments