@@ -110,6 +110,10 @@ fn main() {
110110 let path_lib_dir = PathBuf :: from ( path) ;
111111 let path_lib_dir_display = path_lib_dir. display ( ) ;
112112
113+ if path_lib_dir. is_relative ( ) {
114+ panic ! ( "{MUJOCO_STATIC_LIB_PATH_VAR} must be an absolute path ('{path_lib_dir_display}' is not)." ) ;
115+ }
116+
113117 let path_lib_file = if cfg ! ( target_os = "windows" ) {
114118 path_lib_dir. join ( "mujoco.lib" )
115119 } else {
@@ -120,7 +124,7 @@ fn main() {
120124 if !path_lib_file. is_file ( ) {
121125 panic ! (
122126 "{MUJOCO_STATIC_LIB_PATH_VAR} must be path to the 'lib/' subdirectory (i.e., 'mujoco-x.x.x/lib/') --- \
123- '{path_lib_dir_display}' does not appear to contain '{}'.",
127+ '{path_lib_dir_display}' does not appear to contain '{}' or it doesn't exist .",
124128 path_lib_file. file_name( ) . unwrap( ) . to_str( ) . unwrap( )
125129 ) ;
126130 }
@@ -152,6 +156,10 @@ fn main() {
152156 let path_lib_dir = PathBuf :: from ( path) ;
153157 let path_lib_dir_display = path_lib_dir. display ( ) ;
154158
159+ if path_lib_dir. is_relative ( ) {
160+ panic ! ( "{MUJOCO_DYN_LIB_PATH_VAR} must be an absolute path ('{path_lib_dir_display}' is not)." ) ;
161+ }
162+
155163 let path_lib_file = if cfg ! ( target_os = "windows" ) {
156164 path_lib_dir. join ( "mujoco.lib" )
157165 } else if cfg ! ( target_os = "macos" ) {
@@ -164,31 +172,14 @@ fn main() {
164172 if !path_lib_file. is_file ( ) {
165173 panic ! (
166174 "{MUJOCO_DYN_LIB_PATH_VAR} must be path to the 'lib/' subdirectory (i.e., 'mujoco-x.x.x/lib/') --- \
167- '{path_lib_dir_display}' does not appear to contain '{}'.",
175+ '{path_lib_dir_display}' does not appear to contain '{}' or it doesn't exist .",
168176 path_lib_file. file_name( ) . unwrap( ) . to_str( ) . unwrap( )
169177 ) ;
170178 }
171179
172180 println ! ( "cargo:rustc-link-search={}" , path_lib_dir_display) ;
173181 println ! ( "cargo:rustc-link-lib=mujoco" ) ;
174182
175- // Set the RPATH
176- #[ cfg( feature = "use-rpath" ) ]
177- {
178- println ! ( "cargo:rustc-link-arg=-Wl,-rpath,{}" , path_lib_dir_display) ;
179- #[ cfg( target_os = "linux" ) ]
180- if path_lib_dir. is_relative ( ) {
181- let rpath = PathBuf :: from ( "$ORIGIN" ) . join ( & path_lib_dir) ;
182- println ! ( "cargo:rustc-link-arg=-Wl,-rpath,{}" , rpath. display( ) ) ;
183- }
184-
185- #[ cfg( target_os = "macos" ) ]
186- if path_lib_dir. is_relative ( ) {
187- let rpath = PathBuf :: from ( "@loader_path" ) . join ( & path_lib_dir) ;
188- println ! ( "cargo:rustc-link-arg=-Wl,-rpath,{}" , rpath. display( ) ) ;
189- }
190- }
191-
192183 // Copy the DLL on Windows, if a relative path is given.
193184 // Otherwise assume the DLL is discoverable through PATH.
194185 #[ cfg( target_os = "windows" ) ]
@@ -223,7 +214,7 @@ fn main() {
223214 \n ---------------- ^^^ pkg-config output ^^^ ----------------\n \
224215 \n =================================================================================================\
225216 \n Unable to locate MuJoCo via pkg-config and neither {MUJOCO_STATIC_LIB_PATH_VAR} nor {MUJOCO_DYN_LIB_PATH_VAR} is set and the 'auto-download-mujoco' Cargo feature is disabled.\
226- \n Consider enabling automatic download of MuJoCo: 'cargo build -- features \" auto-download-mujoco use-rpath \" '.\
217+ \n Consider enabling automatic download of MuJoCo: 'cargo add mujoco-rs -- features \" auto-download-mujoco\" '.\
227218 \n ================================================================================================="
228219 ) ;
229220
@@ -249,7 +240,7 @@ fn main() {
249240 #[ cfg( target_os = "windows" ) ]
250241 panic ! (
251242 "Unable to locate MuJoCo because 'auto-download-mujoco' Cargo feature is disabled and neither {MUJOCO_STATIC_LIB_PATH_VAR} nor {MUJOCO_DYN_LIB_PATH_VAR} is set.\
252- \n Consider enabling automatic download of MuJoCo: 'cargo build --features \" auto-download-mujoco\" '."
243+ \n Consider enabling automatic download of MuJoCo: 'cargo add mujoco-rs --features \" auto-download-mujoco\" '."
253244 ) ;
254245
255246 // On Linux and Windows try to automatically download as a fallback.
@@ -292,19 +283,26 @@ fn main() {
292283 let download_hash_url = format ! ( "{download_url}.sha256" ) ;
293284
294285 // Obtain the download directory from MUJOCO_DOWNLOAD_PATH_VAR.
295- // If not given, assume the current working directory. In the latter case,
296- // also assume that the MuJoCo DLL needs to be copied to the current working
297- // directory, otherwise assume the user will manually add its directory to PATH.
298- #[ allow( unused) ] // copy_dll is only relevant to Windows
299- let ( download_dir, copy_dll) = if let Ok ( value) =
300- std:: env:: var ( MUJOCO_DOWNLOAD_PATH_VAR )
301- {
302- ( PathBuf :: from ( value) , false )
286+ let download_dir = PathBuf :: from ( std:: env:: var ( MUJOCO_DOWNLOAD_PATH_VAR ) . unwrap_or_else ( |_| {
287+ let os_example = if cfg ! ( unix) {
288+ format ! ( "e.g., export {MUJOCO_DOWNLOAD_PATH_VAR}=\" $(realpath .)\" " )
289+ } else {
290+ format ! ( "e.g., $env:{MUJOCO_DOWNLOAD_PATH_VAR}=\" /full/absolute/path/\" " )
291+ } ;
292+ panic ! (
293+ "when Cargo feature 'auto-download-mujoco' is enabled, {MUJOCO_DOWNLOAD_PATH_VAR} must be set to \
294+ an absolute path, where MuJoCo will be extracted --- \
295+ {os_example}",
296+ ) ;
297+ } ) ) ;
298+
299+ if download_dir. is_relative ( ) {
300+ panic ! (
301+ "{MUJOCO_DOWNLOAD_PATH_VAR} must be an absolute path to the location \
302+ where MuJoCo will be downloaded and extracted (was given '{}').",
303+ download_dir. display( )
304+ )
303305 }
304- else
305- {
306- ( PathBuf :: from ( "." ) , true )
307- } ;
308306
309307 // The name of the downloaded archive file.
310308 let download_path = download_dir. join ( download_url. rsplit_once ( "/" ) . unwrap ( ) . 1 ) ;
@@ -365,7 +363,7 @@ fn main() {
365363
366364 /* Extraction */
367365 #[ cfg( target_os = "windows" ) ]
368- extract_windows ( & download_path, & outdirname, copy_dll ) ;
366+ extract_windows ( & download_path, & outdirname) ;
369367
370368 #[ cfg( target_os = "linux" ) ]
371369 extract_linux ( & download_path) ;
@@ -380,23 +378,7 @@ fn main() {
380378 ) ;
381379
382380 let libdir_path = outdirname. join ( "lib" ) ;
383- let libdir_path_display = libdir_path. display ( ) ;
384-
385- // Set RPATH on Linux targets and rerun the script if the .so is changed.
386- #[ cfg( target_os = "linux" ) ]
387- {
388- // Set the RPATH
389- #[ cfg( feature = "use-rpath" ) ]
390- {
391- println ! ( "cargo:rustc-link-arg=-Wl,-rpath,{}" , libdir_path_display) ;
392- if libdir_path. is_relative ( ) {
393- let rpath = PathBuf :: from ( "$ORIGIN" ) . join ( & libdir_path) ;
394- println ! ( "cargo:rustc-link-arg=-Wl,-rpath,{}" , rpath. display( ) ) ;
395- }
396- }
397- }
398-
399- println ! ( "cargo:rustc-link-search={}" , libdir_path_display) ;
381+ println ! ( "cargo:rustc-link-search={}" , libdir_path. display( ) ) ;
400382 println ! ( "cargo:rustc-link-lib=mujoco" ) ;
401383 }
402384 }
@@ -407,7 +389,7 @@ fn main() {
407389
408390#[ cfg( target_os = "windows" ) ]
409391#[ cfg( feature = "auto-download-mujoco" ) ]
410- fn extract_windows ( filename : & Path , outdirname : & Path , copy_mujoco_dll : bool ) {
392+ fn extract_windows ( filename : & Path , outdirname : & Path ) {
411393 let file = File :: open ( filename) . unwrap_or_else ( |err|
412394 panic ! ( "failed to open archive '{}' ({err})." , filename. display( ) )
413395 ) ;
@@ -445,12 +427,6 @@ fn extract_windows(filename: &Path, outdirname: &Path, copy_mujoco_dll: bool) {
445427 ) ;
446428 }
447429 }
448-
449- if copy_mujoco_dll {
450- if let Err ( err) = std:: fs:: copy ( outdirname. join ( "bin" ) . join ( "mujoco.dll" ) , "mujoco.dll" ) {
451- println ! ( "cargo:warning=failed to copy mujoco.dll to the current working directory ({err})" ) ;
452- }
453- }
454430}
455431
456432#[ cfg( target_os = "linux" ) ]
0 commit comments