Skip to content

Commit a229df0

Browse files
committed
rustc_codegen_ssa: use try_canonicalize in rpath
This is simpler and avoids unnecessary calls to `env::current_dir`.
1 parent a081007 commit a229df0

File tree

1 file changed

+6
-8
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+6
-8
lines changed

compiler/rustc_codegen_ssa/src/back/rpath.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use pathdiff::diff_paths;
22
use rustc_data_structures::fx::FxHashSet;
3-
use std::env;
3+
use rustc_fs_util::try_canonicalize;
44
use std::ffi::OsString;
5-
use std::fs;
65
use std::path::{Path, PathBuf};
76

87
pub struct RPathConfig<'a> {
@@ -82,12 +81,11 @@ fn get_rpath_relative_to_output(config: &mut RPathConfig<'_>, lib: &Path) -> OsS
8281
// Mac doesn't appear to support $ORIGIN
8382
let prefix = if config.is_like_osx { "@loader_path" } else { "$ORIGIN" };
8483

85-
let cwd = env::current_dir().unwrap();
86-
let mut lib = fs::canonicalize(&cwd.join(lib)).unwrap_or_else(|_| cwd.join(lib));
87-
lib.pop(); // strip filename
88-
let mut output = cwd.join(&config.out_filename);
89-
output.pop(); // strip filename
90-
let output = fs::canonicalize(&output).unwrap_or(output);
84+
// Strip filenames
85+
let lib = lib.parent().unwrap();
86+
let output = config.out_filename.parent().unwrap();
87+
let lib = try_canonicalize(lib).unwrap();
88+
let output = try_canonicalize(output).unwrap();
9189
let relative = path_relative_from(&lib, &output)
9290
.unwrap_or_else(|| panic!("couldn't create relative path from {output:?} to {lib:?}"));
9391

0 commit comments

Comments
 (0)