Skip to content

Commit ce1e48a

Browse files
committed
install: Support --libdir and --mandir correctly
This adds a hack to rustc to make it find the library directory regardless of whether it is named lib/lib64/lib32.
1 parent 380fe97 commit ce1e48a

File tree

5 files changed

+98
-38
lines changed

5 files changed

+98
-38
lines changed

mk/dist.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ dist-install-dir-$(1): PREPARE_MAN_CMD=$(DEFAULT_PREPARE_MAN_CMD)
200200
dist-install-dir-$(1): PREPARE_CLEAN=true
201201
dist-install-dir-$(1): prepare-base-dir-$(1)
202202
$$(Q)(cd $$(PREPARE_DEST_DIR)/ && find -type f | sed 's/^\.\///') \
203-
> $$(PREPARE_DEST_DIR)/$$(CFG_LIBDIR_RELATIVE)/rustlib/manifest
203+
> tmp/manifest-$(1) # NB Use a tmp file so `find` doesn't *find the manifest*
204+
$$(Q)cp tmp/manifest-$(1) $$(PREPARE_DEST_DIR)/$$(CFG_LIBDIR_RELATIVE)/rustlib/manifest
204205
$$(Q)$$(PREPARE_MAN_CMD) $$(S)COPYRIGHT $$(PREPARE_DEST_DIR)
205206
$$(Q)$$(PREPARE_MAN_CMD) $$(S)LICENSE-APACHE $$(PREPARE_DEST_DIR)
206207
$$(Q)$$(PREPARE_MAN_CMD) $$(S)LICENSE-MIT $$(PREPARE_DEST_DIR)

mk/install.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111

1212
install: dist-install-dir-$(CFG_BUILD)
13-
$(Q)sh tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --prefix="$(CFG_PREFIX)"
13+
$(Q)sh tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --prefix="$(CFG_PREFIX)" --libdir="$(CFG_LIBDIR)" --mandir="$(CFG_MANDIR)"
1414

1515
uninstall: dist-install-dir-$(CFG_BUILD)
16-
$(Q)sh tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --prefix="$(CFG_PREFIX)" --uninstall
16+
$(Q)sh tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --uninstall --prefix="$(CFG_PREFIX)" --libdir="$(CFG_LIBDIR)" --mandir="$(CFG_MANDIR)"
1717

1818

1919
######################################################################

src/etc/install.sh

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ VAL_OPTIONS=""
213213

214214
flag uninstall "only uninstall from the installation prefix"
215215
valopt prefix "/usr/local" "set installation prefix"
216+
# NB This isn't quite the same definition as in `configure`.
217+
# just using 'lib' instead of CFG_LIBDIR_RELATIVE
218+
valopt libdir "${CFG_PREFIX}/lib" "install libraries"
219+
valopt mandir "${CFG_PREFIX}/share/man" "install man pages in PATH"
216220

217221
if [ $HELP -eq 1 ]
218222
then
@@ -224,47 +228,48 @@ step_msg "validating $CFG_SELF args"
224228
validate_opt
225229

226230
# Sanity check: can we can write to the destination?
227-
umask 022 && mkdir -p "${CFG_PREFIX}/lib"
231+
umask 022 && mkdir -p "${CFG_LIBDIR}"
228232
need_ok "directory creation failed"
229-
touch "${CFG_PREFIX}/lib/rust-install-probe" 2> /dev/null
233+
touch "${CFG_LIBDIR}/rust-install-probe" 2> /dev/null
230234
if [ $? -ne 0 ]
231235
then
232236
err "can't write to destination. try again with 'sudo'."
233237
fi
234-
rm "${CFG_PREFIX}/lib/rust-install-probe"
238+
rm "${CFG_LIBDIR}/rust-install-probe"
235239
need_ok "failed to remove install probe"
236240

241+
INSTALLED_MANIFEST="${CFG_LIBDIR}/rustlib/manifest"
237242

238243
# First, uninstall from the installation prefix.
239244
# Errors are warnings - try to rm everything in the manifest even if some fail.
240-
if [ -f "${CFG_PREFIX}/lib/rustlib/manifest" ]
245+
if [ -f "${INSTALLED_MANIFEST}" ]
241246
then
242247
# Iterate through installed manifest and remove files
243248
while read p; do
244-
msg "removing ${CFG_PREFIX}/$p"
245-
if [ -f "${CFG_PREFIX}/$p" ]
249+
# The installed manifest contains absolute paths
250+
msg "removing $p"
251+
if [ -f "$p" ]
246252
then
247-
rm "${CFG_PREFIX}/$p"
253+
rm "$p"
248254
if [ $? -ne 0 ]
249255
then
250-
warn "failed to remove ${CFG_PREFIX}/$p"
256+
warn "failed to remove $p"
251257
fi
252258
else
253-
warn "supposedly installed file ${CFG_PREFIX}/$p does not exist!"
259+
warn "supposedly installed file $p does not exist!"
254260
fi
255-
done < "${CFG_PREFIX}/lib/rustlib/manifest"
261+
done < "${INSTALLED_MANIFEST}"
256262

257263
# Remove 'rustlib' directory
258-
msg "removing ${CFG_PREFIX}/lib/rustlib"
259-
rm -r "${CFG_PREFIX}/lib/rustlib"
264+
rm -r "${CFG_LIBDIR}/rustlib"
260265
if [ $? -ne 0 ]
261266
then
262267
warn "failed to remove rustlib"
263268
fi
264269
else
265270
if [ -n "${CFG_UNINSTALL}" ]
266271
then
267-
err "unable to find installation manifest at ${CFG_PREFIX}/lib/rustlib"
272+
err "unable to find installation manifest at ${CFG_LIBDIR}/rustlib"
268273
fi
269274
fi
270275

@@ -277,22 +282,53 @@ then
277282
exit 0
278283
fi
279284

285+
# Create the installed manifest, which we will fill in with absolute file paths
286+
mkdir -p "${CFG_LIBDIR}/rustlib"
287+
touch "${INSTALLED_MANIFEST}"
280288

281289
# Now install, iterate through the new manifest and copy files
282290
while read p; do
283291

284-
umask 022 && mkdir -p "${CFG_PREFIX}/$(dirname $p)"
292+
# Decide the destination of the file
293+
FILE_INSTALL_PATH="${CFG_PREFIX}/$p"
294+
295+
if echo "$p" | grep "^lib/" > /dev/null
296+
then
297+
pp=`echo $p | sed 's/^lib\///'`
298+
FILE_INSTALL_PATH="${CFG_LIBDIR}/$pp"
299+
fi
300+
301+
if echo "$p" | grep "^share/man/" > /dev/null
302+
then
303+
pp=`echo $p | sed 's/^share\/man\///'`
304+
FILE_INSTALL_PATH="${CFG_MANDIR}/$pp"
305+
fi
306+
307+
# Make sure ther's a directory for it
308+
umask 022 && mkdir -p "$(dirname ${FILE_INSTALL_PATH})"
285309
need_ok "directory creation failed"
286310

287-
msg "${CFG_PREFIX}/$p"
288-
if echo "$p" | grep "/bin/" > /dev/null
311+
# Make the path absolute so we can uninstall it later without
312+
# starting from the installation cwd
313+
FILE_INSTALL_PATH_DIRNAME="$(dirname ${FILE_INSTALL_PATH})"
314+
FILE_INSTALL_PATH_BASENAME="$(basename ${FILE_INSTALL_PATH})"
315+
FILE_INSTALL_ABS_PATH="$(cd ${FILE_INSTALL_PATH_DIRNAME} && pwd)"
316+
FILE_INSTALL_PATH="${FILE_INSTALL_ABS_PATH}/${FILE_INSTALL_PATH_BASENAME}"
317+
318+
# Install the file
319+
msg "${FILE_INSTALL_PATH}"
320+
if echo "$p" | grep "^bin/" > /dev/null
289321
then
290-
install -m755 "${CFG_SRC_DIR}/$p" "${CFG_PREFIX}/$p"
322+
install -m755 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}"
291323
else
292-
install -m644 "${CFG_SRC_DIR}/$p" "${CFG_PREFIX}/$p"
324+
install -m644 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}"
293325
fi
294326
need_ok "file creation failed"
295327

328+
# Update the manifest
329+
echo "${FILE_INSTALL_PATH}" >> "${INSTALLED_MANIFEST}"
330+
need_ok "failed to update manifest"
331+
296332
# The manifest lists all files to install
297333
done < "${CFG_SRC_DIR}/lib/rustlib/manifest"
298334

src/librustc/back/rpath.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> {
5454
}
5555

5656
fn get_sysroot_absolute_rt_lib(sess: &Session) -> Path {
57-
let r = filesearch::relative_target_lib_path(sess.opts.target_triple);
58-
let mut p = sess.filesearch().sysroot.join(&r);
57+
let sysroot = sess.filesearch().sysroot;
58+
let r = filesearch::relative_target_lib_path(sysroot, sess.opts.target_triple);
59+
let mut p = sysroot.join(&r);
5960
p.push(os::dll_filename("rustrt"));
6061
p
6162
}
@@ -91,7 +92,7 @@ fn get_rpaths(os: abi::Os,
9192
let abs_rpaths = get_absolute_rpaths(libs);
9293

9394
// And a final backup rpath to the global library location.
94-
let fallback_rpaths = vec!(get_install_prefix_rpath(target_triple));
95+
let fallback_rpaths = vec!(get_install_prefix_rpath(sysroot, target_triple));
9596

9697
fn log_rpaths(desc: &str, rpaths: &[~str]) {
9798
debug!("{} rpaths:", desc);
@@ -156,10 +157,10 @@ pub fn get_absolute_rpath(lib: &Path) -> ~str {
156157
p.as_str().expect("non-utf8 component in rpath").to_owned()
157158
}
158159

159-
pub fn get_install_prefix_rpath(target_triple: &str) -> ~str {
160+
pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &str) -> ~str {
160161
let install_prefix = env!("CFG_PREFIX");
161162

162-
let tlib = filesearch::relative_target_lib_path(target_triple);
163+
let tlib = filesearch::relative_target_lib_path(sysroot, target_triple);
163164
let mut path = Path::new(install_prefix);
164165
path.push(&tlib);
165166
let path = os::make_absolute(&path);
@@ -195,7 +196,8 @@ mod test {
195196
196197
#[test]
197198
fn test_prefix_rpath() {
198-
let res = get_install_prefix_rpath("triple");
199+
let sysroot = filesearch::get_or_default_sysroot();
200+
let res = get_install_prefix_rpath(sysroot, "triple");
199201
let mut d = Path::new(env!("CFG_PREFIX"));
200202
d.push("lib");
201203
d.push(filesearch::rustlibdir());
@@ -208,7 +210,8 @@ mod test {
208210
209211
#[test]
210212
fn test_prefix_rpath_abs() {
211-
let res = get_install_prefix_rpath("triple");
213+
let sysroot = filesearch::get_or_default_sysroot();
214+
let res = get_install_prefix_rpath(sysroot, "triple");
212215
assert!(Path::new(res).is_absolute());
213216
}
214217

src/librustc/metadata/filesearch.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ impl<'a> FileSearch<'a> {
6060
if !found {
6161
let rustpath = rust_path();
6262
for path in rustpath.iter() {
63-
let tlib_path = make_rustpkg_target_lib_path(path, self.target_triple);
63+
let tlib_path = make_rustpkg_target_lib_path(
64+
self.sysroot, path, self.target_triple);
6465
debug!("is {} in visited_dirs? {:?}", tlib_path.display(),
6566
visited_dirs.contains_equiv(&tlib_path.as_vec().to_owned()));
6667

@@ -136,8 +137,8 @@ impl<'a> FileSearch<'a> {
136137
}
137138
}
138139

139-
pub fn relative_target_lib_path(target_triple: &str) -> Path {
140-
let mut p = Path::new(libdir());
140+
pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> Path {
141+
let mut p = Path::new(find_libdir(sysroot));
141142
assert!(p.is_relative());
142143
p.push(rustlibdir());
143144
p.push(target_triple);
@@ -147,12 +148,13 @@ pub fn relative_target_lib_path(target_triple: &str) -> Path {
147148

148149
fn make_target_lib_path(sysroot: &Path,
149150
target_triple: &str) -> Path {
150-
sysroot.join(&relative_target_lib_path(target_triple))
151+
sysroot.join(&relative_target_lib_path(sysroot, target_triple))
151152
}
152153

153-
fn make_rustpkg_target_lib_path(dir: &Path,
154-
target_triple: &str) -> Path {
155-
let mut p = dir.join(libdir());
154+
fn make_rustpkg_target_lib_path(sysroot: &Path,
155+
dir: &Path,
156+
target_triple: &str) -> Path {
157+
let mut p = dir.join(find_libdir(sysroot));
156158
p.push(target_triple);
157159
p
158160
}
@@ -236,12 +238,30 @@ pub fn rust_path() -> Vec<Path> {
236238
// The name of the directory rustc expects libraries to be located.
237239
// On Unix should be "lib", on windows "bin"
238240
#[cfg(unix)]
239-
pub fn libdir() -> ~str {
240-
~"lib"
241+
fn find_libdir(sysroot: &Path) -> ~str {
242+
// FIXME: This is a quick hack to make the rustc binary able to locate
243+
// Rust libraries in Linux environments where libraries might be installed
244+
// to lib64/lib32. This would be more foolproof by basing the sysroot off
245+
// of the directory where librustc is located, rather than where the rustc
246+
// binary is.
247+
248+
if sysroot.join(primary_libdir_name()).exists() {
249+
return primary_libdir_name();
250+
} else {
251+
return secondary_libdir_name();
252+
}
253+
254+
#[cfg(target_word_size = "64")]
255+
fn primary_libdir_name() -> ~str { ~"lib64" }
256+
257+
#[cfg(target_word_size = "32")]
258+
fn primary_libdir_name() -> ~str { ~"lib32" }
259+
260+
fn secondary_libdir_name() -> ~str { ~"lib" }
241261
}
242262

243263
#[cfg(windows)]
244-
pub fn libdir() -> ~str {
264+
fn find_libdir(_sysroot: &Path) -> ~str {
245265
~"bin"
246266
}
247267

0 commit comments

Comments
 (0)