Skip to content

Commit 0285e9e

Browse files
committed
Remember relative libdir and bindir from build time
1 parent 8502ded commit 0285e9e

File tree

4 files changed

+37
-47
lines changed

4 files changed

+37
-47
lines changed

configure

+6
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ need_cmd date
340340
need_cmd tr
341341
need_cmd sed
342342
need_cmd file
343+
need_cmd realpath
343344

344345
msg "inspecting environment"
345346

@@ -563,6 +564,11 @@ then
563564
exit 0
564565
fi
565566

567+
# Determine libdir and bindir relative to prefix
568+
step_msg "calculating relative paths to prefix = ${CFG_PREFIX}"
569+
CFG_BINDIR_RELATIVE=$(realpath --relative-to="${CFG_PREFIX}" "${CFG_BINDIR}")
570+
CFG_LIBDIR_RELATIVE=$(realpath --relative-to="${CFG_PREFIX}" "${CFG_LIBDIR}")
571+
566572
# Validate Options
567573
step_msg "validating $CFG_SELF args"
568574
validate_opt

mk/install.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ifeq (root user, $(USER) $(patsubst %,user,$(SUDO_USER)))
2121
else
2222
$(Q)$(MAKE) prepare_install
2323
endif
24-
$(Q)cd tmp/empty_dir && sh ../../tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --prefix="$(DESTDIR)$(CFG_PREFIX)" --libdir="$(DESTDIR)$(CFG_LIBDIR)" --mandir="$(DESTDIR)$(CFG_MANDIR)" "$(MAYBE_DISABLE_VERIFY)" --bindir="$(DESTDIR)$(CFG_BINDIR)"
24+
$(Q)cd tmp/empty_dir && sh ../../tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --prefix="$(DESTDIR)$(CFG_PREFIX)" --libdir="$(DESTDIR)$(CFG_LIBDIR)" --mandir="$(DESTDIR)$(CFG_MANDIR)" --bindir="$(DESTDIR)$(CFG_BINDIR)" "$(MAYBE_DISABLE_VERIFY)"
2525
# Remove tmp files because it's a decent amount of disk space
2626
$(Q)rm -R tmp/dist
2727

src/librustc/back/link.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1015,11 +1015,10 @@ fn link_args(cmd: &mut Command,
10151015
// where extern libraries might live, based on the
10161016
// addl_lib_search_paths
10171017
if sess.opts.cg.rpath {
1018-
let sysroot = sess.sysroot();
10191018
let target_triple = sess.opts.target_triple.as_slice();
10201019
let get_install_prefix_lib_path = || {
10211020
let install_prefix = option_env!("CFG_PREFIX").expect("CFG_PREFIX");
1022-
let tlib = filesearch::relative_target_lib_path(sysroot, target_triple);
1021+
let tlib = filesearch::relative_target_lib_path(target_triple);
10231022
let mut path = Path::new(install_prefix);
10241023
path.push(&tlib);
10251024

src/librustc/metadata/filesearch.rs

+29-44
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ impl<'a> FileSearch<'a> {
6666
if !found {
6767
let rustpath = rust_path();
6868
for path in rustpath.iter() {
69-
let tlib_path = make_rustpkg_lib_path(
70-
self.sysroot, path, self.triple);
69+
let tlib_path = make_rustpkg_lib_path(path, self.triple);
7170
debug!("is {} in visited_dirs? {}", tlib_path.display(),
7271
visited_dirs.contains(&tlib_path.as_vec().to_vec()));
7372

@@ -149,16 +148,16 @@ impl<'a> FileSearch<'a> {
149148
// Returns a list of directories where target-specific tool binaries are located.
150149
pub fn get_tools_search_paths(&self) -> Vec<Path> {
151150
let mut p = Path::new(self.sysroot);
152-
p.push(find_libdir(self.sysroot));
151+
p.push(libdir_str());
153152
p.push(rustlibdir());
154153
p.push(self.triple);
155154
p.push("bin");
156155
vec![p]
157156
}
158157
}
159158

160-
pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> Path {
161-
let mut p = Path::new(find_libdir(sysroot));
159+
pub fn relative_target_lib_path(target_triple: &str) -> Path {
160+
let mut p = Path::new(libdir_str());
162161
assert!(p.is_relative());
163162
p.push(rustlibdir());
164163
p.push(target_triple);
@@ -168,17 +167,24 @@ pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> Path {
168167

169168
fn make_target_lib_path(sysroot: &Path,
170169
target_triple: &str) -> Path {
171-
sysroot.join(&relative_target_lib_path(sysroot, target_triple))
170+
sysroot.join(&relative_target_lib_path(target_triple))
172171
}
173172

174-
fn make_rustpkg_lib_path(sysroot: &Path,
175-
dir: &Path,
173+
fn make_rustpkg_lib_path(dir: &Path,
176174
triple: &str) -> Path {
177-
let mut p = dir.join(find_libdir(sysroot));
175+
let mut p = dir.join(libdir_str());
178176
p.push(triple);
179177
p
180178
}
181179

180+
pub fn bindir_relative_str() -> &'static str {
181+
env!("CFG_BINDIR_RELATIVE")
182+
}
183+
184+
pub fn bindir_relative_path() -> Path {
185+
Path::new(bindir_relative_str())
186+
}
187+
182188
pub fn get_or_default_sysroot() -> Path {
183189
// Follow symlinks. If the resolved path is relative, make it absolute.
184190
fn canonicalize(path: Option<Path>) -> Option<Path> {
@@ -190,7 +196,17 @@ pub fn get_or_default_sysroot() -> Path {
190196
}
191197

192198
match canonicalize(os::self_exe_name()) {
193-
Some(mut p) => { p.pop(); p.pop(); p }
199+
Some(mut p) => {
200+
// Remove the exe name
201+
p.pop();
202+
let mut rel = bindir_relative_path();
203+
// Remove a number of elements equal to the number of elements in the bindir relative
204+
// path
205+
while rel.pop() {
206+
p.pop();
207+
}
208+
p
209+
}
194210
None => panic!("can't determine value for sysroot")
195211
}
196212
}
@@ -248,40 +264,9 @@ pub fn rust_path() -> Vec<Path> {
248264
env_rust_path
249265
}
250266

251-
// The name of the directory rustc expects libraries to be located.
252-
// On Unix should be "lib", on windows "bin"
253-
#[cfg(unix)]
254-
fn find_libdir(sysroot: &Path) -> String {
255-
// FIXME: This is a quick hack to make the rustc binary able to locate
256-
// Rust libraries in Linux environments where libraries might be installed
257-
// to lib64/lib32. This would be more foolproof by basing the sysroot off
258-
// of the directory where librustc is located, rather than where the rustc
259-
// binary is.
260-
261-
if sysroot.join(primary_libdir_name()).join(rustlibdir()).exists() {
262-
return primary_libdir_name();
263-
} else {
264-
return secondary_libdir_name();
265-
}
266-
267-
#[cfg(target_word_size = "64")]
268-
fn primary_libdir_name() -> String {
269-
"lib64".to_string()
270-
}
271-
272-
#[cfg(target_word_size = "32")]
273-
fn primary_libdir_name() -> String {
274-
"lib32".to_string()
275-
}
276-
277-
fn secondary_libdir_name() -> String {
278-
"lib".to_string()
279-
}
280-
}
281-
282-
#[cfg(windows)]
283-
fn find_libdir(_sysroot: &Path) -> String {
284-
"bin".to_string()
267+
// The name of the directory rustc expects libraries to be located, relative to the sysroot
268+
fn libdir_str() -> &'static str {
269+
env!("CFG_LIBDIR_RELATIVE")
285270
}
286271

287272
// The name of rustc's own place to organize libraries.

0 commit comments

Comments
 (0)