rust: avoid some things that break bitbake, add more patches

This commit is contained in:
Cody P Schafer
2014-11-18 01:57:50 -05:00
parent 2d90348be0
commit e3539d1687
6 changed files with 414 additions and 31 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ PN = "rust-cross-${TARGET_ARCH}"
# The same value as ${TOOLCHAIN_OPTIONS}. We can't use that variable directly
# here because cross.bblcass is "helpful" and blanks it out.
TARGET_PRE_LINK_ARGS_append = " --sysroot=${STAGING_DIR_TARGET}"
#TARGET_PRE_LINK_ARGS_append = " --sysroot=${STAGING_DIR_TARGET}"
# We need the same thing for the calls to the compiler when building the runtime crap
TARGET_CC_ARCH_append = " --sysroot=${STAGING_DIR_TARGET}"
@@ -0,0 +1,125 @@
From 8502ded50381200386c52a9c66e77ac3f3ca7188 Mon Sep 17 00:00:00 2001
From: Cody P Schafer <dev@codyps.com>
Date: Mon, 17 Nov 2014 19:44:58 -0500
Subject: [PATCH 8/9] Support --bindir
---
configure | 4 ++++
mk/install.mk | 4 ++--
mk/main.mk | 2 ++
src/etc/install.sh | 13 ++++++++++++-
4 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/configure b/configure
index 7790025..bdfeedd 100755
--- a/configure
+++ b/configure
@@ -554,6 +554,9 @@ fi
valopt libdir "${CFG_PREFIX}/${CFG_LIBDIR_RELATIVE}" "install libraries"
+CFG_BINDIR_RELATIVE=bin
+valopt bindir "${CFG_PREFIX}/${CFG_BINDIR_RELATIVE}" "install binaries"
+
if [ $HELP -eq 1 ]
then
echo
@@ -1312,6 +1315,7 @@ putvar CFG_PREFIX
putvar CFG_HOST
putvar CFG_TARGET
putvar CFG_LIBDIR_RELATIVE
+putvar CFG_BINDIR_RELATIVE
putvar CFG_DISABLE_MANAGE_SUBMODULES
putvar CFG_ANDROID_CROSS_PATH
putvar CFG_MANDIR
diff --git a/mk/install.mk b/mk/install.mk
index 88b451f..4588e83 100644
--- a/mk/install.mk
+++ b/mk/install.mk
@@ -21,7 +21,7 @@ ifeq (root user, $(USER) $(patsubst %,user,$(SUDO_USER)))
else
$(Q)$(MAKE) prepare_install
endif
- $(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)"
+ $(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)"
# Remove tmp files because it's a decent amount of disk space
$(Q)rm -R tmp/dist
@@ -34,7 +34,7 @@ ifeq (root user, $(USER) $(patsubst %,user,$(SUDO_USER)))
else
$(Q)$(MAKE) prepare_uninstall
endif
- $(Q)cd tmp/empty_dir && sh ../../tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --uninstall --prefix="$(DESTDIR)$(CFG_PREFIX)" --libdir="$(DESTDIR)$(CFG_LIBDIR)" --mandir="$(DESTDIR)$(CFG_MANDIR)"
+ $(Q)cd tmp/empty_dir && sh ../../tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --uninstall --prefix="$(DESTDIR)$(CFG_PREFIX)" --libdir="$(DESTDIR)$(CFG_LIBDIR)" --mandir="$(DESTDIR)$(CFG_MANDIR)" --bindir="$(DESTDIR)$(CFG_BINDIR)"
# Remove tmp files because it's a decent amount of disk space
$(Q)rm -R tmp/dist
diff --git a/mk/main.mk b/mk/main.mk
index 3df4d3b..36f0e58 100644
--- a/mk/main.mk
+++ b/mk/main.mk
@@ -315,7 +315,9 @@ export CFG_BUILD
export CFG_LLVM_ROOT
export CFG_PREFIX
export CFG_LIBDIR
+export CFG_BINDIR
export CFG_LIBDIR_RELATIVE
+export CFG_BINDIR_RELATIVE
export CFG_DISABLE_INJECT_STD_VERSION
######################################################################
diff --git a/src/etc/install.sh b/src/etc/install.sh
index 4f43b1e..add1c26 100644
--- a/src/etc/install.sh
+++ b/src/etc/install.sh
@@ -285,6 +285,8 @@ then
CFG_LIBDIR_RELATIVE=bin
fi
+CFG_BINDIR_RELATIVE=bin
+
if [ "$CFG_OSTYPE" = "pc-mingw32" ] || [ "$CFG_OSTYPE" = "w64-mingw32" ]
then
CFG_LD_PATH_VAR=PATH
@@ -304,6 +306,7 @@ valopt prefix "/usr/local" "set installation prefix"
# NB This isn't quite the same definition as in `configure`.
# just using 'lib' instead of CFG_LIBDIR_RELATIVE
valopt libdir "${CFG_PREFIX}/${CFG_LIBDIR_RELATIVE}" "install libraries"
+valopt bindir "${CFG_PREFIX}/${CFG_BINDIR_RELATIVE}" "install binaries"
valopt mandir "${CFG_PREFIX}/share/man" "install man pages in PATH"
if [ $HELP -eq 1 ]
@@ -424,6 +427,7 @@ need_ok "failed to create installed manifest"
# Now install, iterate through the new manifest and copy files
while read p; do
+ is_bin=false
# Decide the destination of the file
FILE_INSTALL_PATH="${CFG_PREFIX}/$p"
@@ -434,6 +438,13 @@ while read p; do
FILE_INSTALL_PATH="${CFG_LIBDIR}/$pp"
fi
+ if echo "$p" | grep "^bin/" > /dev/null
+ then
+ is_bin=true
+ pp=`echo $p | sed 's/^bin\///'`
+ FILE_INSTALL_PATH="${CFG_BINDIR}/$pp"
+ fi
+
if echo "$p" | grep "^share/man/" > /dev/null
then
pp=`echo $p | sed 's/^share\/man\///'`
@@ -451,7 +462,7 @@ while read p; do
# Install the file
msg "${FILE_INSTALL_PATH}"
- if echo "$p" | grep "^bin/" > /dev/null
+ if $is_bin
then
install -m755 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}"
else
--
2.0.4
@@ -0,0 +1,195 @@
From 0285e9ebaea38ccb436e8b7b64a0bac232a89935 Mon Sep 17 00:00:00 2001
From: Cody P Schafer <dev@codyps.com>
Date: Mon, 17 Nov 2014 20:10:42 -0500
Subject: [PATCH 9/9] Remember relative libdir and bindir from build time
---
configure | 6 +++
mk/install.mk | 2 +-
src/librustc/back/link.rs | 3 +-
src/librustc/metadata/filesearch.rs | 73 +++++++++++++++----------------------
4 files changed, 37 insertions(+), 47 deletions(-)
diff --git a/configure b/configure
index bdfeedd..c9bec44 100755
--- a/configure
+++ b/configure
@@ -340,6 +340,7 @@ need_cmd date
need_cmd tr
need_cmd sed
need_cmd file
+need_cmd realpath
msg "inspecting environment"
@@ -563,6 +564,11 @@ then
exit 0
fi
+# Determine libdir and bindir relative to prefix
+step_msg "calculating relative paths to prefix = ${CFG_PREFIX}"
+CFG_BINDIR_RELATIVE=$(realpath --relative-to="${CFG_PREFIX}" "${CFG_BINDIR}")
+CFG_LIBDIR_RELATIVE=$(realpath --relative-to="${CFG_PREFIX}" "${CFG_LIBDIR}")
+
# Validate Options
step_msg "validating $CFG_SELF args"
validate_opt
diff --git a/mk/install.mk b/mk/install.mk
index 4588e83..0fba6ee 100644
--- a/mk/install.mk
+++ b/mk/install.mk
@@ -21,7 +21,7 @@ ifeq (root user, $(USER) $(patsubst %,user,$(SUDO_USER)))
else
$(Q)$(MAKE) prepare_install
endif
- $(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)"
+ $(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)"
# Remove tmp files because it's a decent amount of disk space
$(Q)rm -R tmp/dist
diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs
index 766715f..306e074 100644
--- a/src/librustc/back/link.rs
+++ b/src/librustc/back/link.rs
@@ -1015,11 +1015,10 @@ fn link_args(cmd: &mut Command,
// where extern libraries might live, based on the
// addl_lib_search_paths
if sess.opts.cg.rpath {
- let sysroot = sess.sysroot();
let target_triple = sess.opts.target_triple.as_slice();
let get_install_prefix_lib_path = || {
let install_prefix = option_env!("CFG_PREFIX").expect("CFG_PREFIX");
- let tlib = filesearch::relative_target_lib_path(sysroot, target_triple);
+ let tlib = filesearch::relative_target_lib_path(target_triple);
let mut path = Path::new(install_prefix);
path.push(&tlib);
diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs
index f7d666e..6db56ef 100644
--- a/src/librustc/metadata/filesearch.rs
+++ b/src/librustc/metadata/filesearch.rs
@@ -66,8 +66,7 @@ impl<'a> FileSearch<'a> {
if !found {
let rustpath = rust_path();
for path in rustpath.iter() {
- let tlib_path = make_rustpkg_lib_path(
- self.sysroot, path, self.triple);
+ let tlib_path = make_rustpkg_lib_path(path, self.triple);
debug!("is {} in visited_dirs? {}", tlib_path.display(),
visited_dirs.contains(&tlib_path.as_vec().to_vec()));
@@ -149,7 +148,7 @@ impl<'a> FileSearch<'a> {
// Returns a list of directories where target-specific tool binaries are located.
pub fn get_tools_search_paths(&self) -> Vec<Path> {
let mut p = Path::new(self.sysroot);
- p.push(find_libdir(self.sysroot));
+ p.push(libdir_str());
p.push(rustlibdir());
p.push(self.triple);
p.push("bin");
@@ -157,8 +156,8 @@ impl<'a> FileSearch<'a> {
}
}
-pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> Path {
- let mut p = Path::new(find_libdir(sysroot));
+pub fn relative_target_lib_path(target_triple: &str) -> Path {
+ let mut p = Path::new(libdir_str());
assert!(p.is_relative());
p.push(rustlibdir());
p.push(target_triple);
@@ -168,17 +167,24 @@ pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> Path {
fn make_target_lib_path(sysroot: &Path,
target_triple: &str) -> Path {
- sysroot.join(&relative_target_lib_path(sysroot, target_triple))
+ sysroot.join(&relative_target_lib_path(target_triple))
}
-fn make_rustpkg_lib_path(sysroot: &Path,
- dir: &Path,
+fn make_rustpkg_lib_path(dir: &Path,
triple: &str) -> Path {
- let mut p = dir.join(find_libdir(sysroot));
+ let mut p = dir.join(libdir_str());
p.push(triple);
p
}
+pub fn bindir_relative_str() -> &'static str {
+ env!("CFG_BINDIR_RELATIVE")
+}
+
+pub fn bindir_relative_path() -> Path {
+ Path::new(bindir_relative_str())
+}
+
pub fn get_or_default_sysroot() -> Path {
// Follow symlinks. If the resolved path is relative, make it absolute.
fn canonicalize(path: Option<Path>) -> Option<Path> {
@@ -190,7 +196,17 @@ pub fn get_or_default_sysroot() -> Path {
}
match canonicalize(os::self_exe_name()) {
- Some(mut p) => { p.pop(); p.pop(); p }
+ Some(mut p) => {
+ // Remove the exe name
+ p.pop();
+ let mut rel = bindir_relative_path();
+ // Remove a number of elements equal to the number of elements in the bindir relative
+ // path
+ while rel.pop() {
+ p.pop();
+ }
+ p
+ }
None => panic!("can't determine value for sysroot")
}
}
@@ -248,40 +264,9 @@ pub fn rust_path() -> Vec<Path> {
env_rust_path
}
-// The name of the directory rustc expects libraries to be located.
-// On Unix should be "lib", on windows "bin"
-#[cfg(unix)]
-fn find_libdir(sysroot: &Path) -> String {
- // FIXME: This is a quick hack to make the rustc binary able to locate
- // Rust libraries in Linux environments where libraries might be installed
- // to lib64/lib32. This would be more foolproof by basing the sysroot off
- // of the directory where librustc is located, rather than where the rustc
- // binary is.
-
- if sysroot.join(primary_libdir_name()).join(rustlibdir()).exists() {
- return primary_libdir_name();
- } else {
- return secondary_libdir_name();
- }
-
- #[cfg(target_word_size = "64")]
- fn primary_libdir_name() -> String {
- "lib64".to_string()
- }
-
- #[cfg(target_word_size = "32")]
- fn primary_libdir_name() -> String {
- "lib32".to_string()
- }
-
- fn secondary_libdir_name() -> String {
- "lib".to_string()
- }
-}
-
-#[cfg(windows)]
-fn find_libdir(_sysroot: &Path) -> String {
- "bin".to_string()
+// The name of the directory rustc expects libraries to be located, relative to the sysroot
+fn libdir_str() -> &'static str {
+ env!("CFG_LIBDIR_RELATIVE")
}
// The name of rustc's own place to organize libraries.
--
2.0.4
@@ -0,0 +1,70 @@
From 8346b26f57926960640f5e68d78cd5a7a50e4a6d Mon Sep 17 00:00:00 2001
From: Cody P Schafer <dev@codyps.com>
Date: Tue, 18 Nov 2014 01:40:21 -0500
Subject: [PATCH] Target: add default target.json path: $libdir/rust/targets
---
src/librustc/driver/config.rs | 4 ++--
src/librustc/driver/session.rs | 6 +++++-
src/librustc_back/target/mod.rs | 6 +++---
3 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/librustc/driver/config.rs b/src/librustc/driver/config.rs
index 1a40a04..a5c334c 100644
--- a/src/librustc/driver/config.rs
+++ b/src/librustc/driver/config.rs
@@ -521,8 +521,8 @@ pub fn build_configuration(sess: &Session) -> ast::CrateConfig {
v
}
-pub fn build_target_config(opts: &Options, sp: &SpanHandler) -> Config {
- let target = match Target::search(opts.target_triple.as_slice()) {
+pub fn build_target_config(sysroot: &Path, opts: &Options, sp: &SpanHandler) -> Config {
+ let target = match Target::search(sysroot, opts.target_triple.as_slice()) {
Ok(t) => t,
Err(e) => {
sp.handler().fatal((format!("Error loading target specification: {}", e)).as_slice());
diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs
index 35ccbb4..d31735a 100644
--- a/src/librustc/driver/session.rs
+++ b/src/librustc/driver/session.rs
@@ -219,7 +219,11 @@ pub fn build_session_(sopts: config::Options,
local_crate_source_file: Option<Path>,
span_diagnostic: diagnostic::SpanHandler)
-> Session {
- let target_cfg = config::build_target_config(&sopts, &span_diagnostic);
+ let sysroot = match sopts.maybe_sysroot {
+ Some(ref x) => Path::new(x),
+ None => filesearch::get_or_default_sysroot()
+ };
+ let target_cfg = config::build_target_config(&sysroot, &sopts, &span_diagnostic);
let p_s = parse::new_parse_sess_special_handler(span_diagnostic);
let default_sysroot = match sopts.maybe_sysroot {
Some(_) => None,
diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs
index d7b4285..27ad897 100644
--- a/src/librustc_back/target/mod.rs
+++ b/src/librustc_back/target/mod.rs
@@ -291,7 +291,7 @@ impl Target {
///
/// The error string could come from any of the APIs called, including filesystem access and
/// JSON decoding.
- pub fn search(target: &str) -> Result<Target, String> {
+ pub fn search(sysroot: &Path, target: &str) -> Result<Target, String> {
use std::os;
use std::io::File;
use std::path::Path;
@@ -366,8 +366,8 @@ impl Target {
let target_path = os::getenv("RUST_TARGET_PATH").unwrap_or(String::new());
- let paths = os::split_paths(target_path.as_slice());
- // FIXME 16351: add a sane default search path?
+ let mut paths = os::split_paths(target_path.as_slice());
+ paths.push(sysroot.join_many([env!("CFG_LIBDIR_RELATIVE"), "rust", "targets"]));
for dir in paths.iter() {
let p = dir.join(path.clone());
--
2.0.4
+20 -30
View File
@@ -46,22 +46,13 @@ TARGET_ENDIAN[i586] = "little"
TARGET_WORD_SIZE[i586] = "32"
PRE_LINK_ARGS[i586] = "-Wl,--as-needed -m32"
def ldflags_for(d, thing):
f = d.getVar('{}_CC_ARCH'.format(thing), True) or ""
f += " "
f += d.getVar('TOOLCHAIN_OPTIONS', True) or ""
f += " "
f += d.getVar('{}_LDFLAGS'.format(thing), True) or ""
f += " "
f += d.getVarFlag('PRE_LINK_ARGS', d.getVar('{}_ARCH'.format(thing)), True) or ""
return f
# These are appended to by internal-rust-cross.bbclass and should be used
# instead of ldflags_for() where ever ldflags are needed
TARGET_PRE_LINK_ARGS = "${@ldflags_for(d, 'TARGET')}"
HOST_PRE_LINK_ARGS = "${@ldflags_for(d, 'HOST')}"
BUILD_PRE_LINK_ARGS = "${@ldflags_for(d, 'BUILD')}"
# XXX: BITBAKE-BUG: these used to be set via a function, but that caused bitbake to error on
# users of these variables without any backtrace or error message other than
# "failed" (of some form or another). Probably an issue with bitbake attempting
# to track variable users and us having too many dynamic variable names.
TARGET_PRE_LINK_ARGS = "${TARGET_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${TARGET_LDFLAGS} ${PRE_LINK_ARGS[${TARGET_ARCH}]}"
BUILD_PRE_LINK_ARGS = "${BUILD_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${BUILD_LDFLAGS} ${PRE_LINK_ARGS[${BUILD_ARCH}]}"
HOST_PRE_LINK_ARGS = "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${HOST_LDFLAGS} ${PRE_LINK_ARGS[${HOST_ARCH}]}"
def arch_for(d, thing):
return d.getVar('{}_ARCH'.format(thing), True)
@@ -124,7 +115,7 @@ def rust_gen_target(d, thing, wd):
linker = "{}{}gcc".format(ccache, prefix)
features = d.getVarFlag('FEATURES', arch, True) or ""
pre_link_args = (d.getVar('{}_PRE_LINK_ARGS_PREPEND'.format(thing), True) or "").split()
pre_link_args = (d.getVar('{}_PRE_LINK_ARGS'.format(thing), True) or "").split()
pre_link_args.extend((d.getVarFlag('PRE_LINK_ARGS', arch, True) or "").split())
o.write('''{{
@@ -155,20 +146,18 @@ def rust_gen_target(d, thing, wd):
o.close()
python do_rust_gen_targets () {
import os
wd = d.getVar('WORKDIR', True) + '/targets/'
try:
os.makedirs(wd)
except OSError as e:
if e.errno != 17:
import os
wd = d.getVar('WORKDIR', True) + '/targets/'
try:
os.makedirs(wd)
except OSError as e:
if e.errno != 17:
raise e
for thing in ['HOST', 'BUILD', 'TARGET']:
for thing in ['BUILD', 'HOST', 'TARGET']:
bb.debug(1, "rust_gen_target for " + thing)
rust_gen_target(d, thing, wd)
}
addtask do_rust_gen_targets after do_patch before do_compile
do_rust_gen_targets[dirs] = "${WORKDIR}"
def rust_gen_mk_cfg(d, thing):
''''
@@ -219,11 +208,12 @@ def rust_gen_mk_cfg(d, thing):
raise Exception
python do_rust_arch_fixup () {
for thing in ['HOST', 'BUILD', 'TARGET']:
for thing in ['BUILD', 'HOST', 'TARGET']:
bb.debug(1, "rust_gen_mk_cfg for " + thing)
rust_gen_mk_cfg(d, thing)
}
addtask do_rust_arch_fixup before do_configure after do_patch
do_rust_arch_fixup[dirs] = "${WORKDIR}"
do_rust_arch_fixup[dirs] = "${S}/mk/cfg"
do_configure () {
# FIXME: target_prefix vs prefix, see cross.bbclass
@@ -253,7 +243,7 @@ do_configure () {
"--infodir=${infodir}" \
"--mandir=${mandir}" \
"--libdir=${libdir}" \
"--disable-manage-submodules" \
"--disable-manage-submodules" \
${@base_conditional('USE_LOCAL_RUST', '1', '--enable-local-rust', '', d)} \
${EXTRA_OECONF}
}
+3
View File
@@ -8,4 +8,7 @@ SRC_URI_append = "\
file://0005-CFG_CFLAGS-is-only-used-for-jemalloc-rename-all-uses.patch \
file://0006-mk-rt-jemalloc-pass-CFG_GCCISH_CFLAGS-inside-CC-inst.patch \
file://0007-mk-rt-compiler_rt-pass-LDFLAGS-from-CFG_GCCISH_LINK_.patch \
file://0008-Support-bindir.patch \
file://0009-Remember-relative-libdir-and-bindir-from-build-time.patch \
file://0010-Target-add-default-target.json-path-libdir-rust-targ.patch \
"