Merge pull request #116 from cardoe/ldflags-via-rustflags
refactor linker flags out of custom targets
This commit is contained in:
Vendored
+1
-1
@@ -15,7 +15,7 @@ for (int i = 0; i < targets.size(); i++) {
|
||||
sh "./scripts/setup-env.sh"
|
||||
}
|
||||
stage('Yocto Fetch') {
|
||||
sh "GIT_LOCAL_REF_DIR=/srv/git-cache/ ./scripts/fetch.sh master"
|
||||
sh "GIT_LOCAL_REF_DIR=/srv/git-cache/ ./scripts/fetch.sh morty"
|
||||
}
|
||||
stage('Build') {
|
||||
sh "MACHINE=${machine} ./scripts/build.sh"
|
||||
|
||||
+19
-4
@@ -1,6 +1,7 @@
|
||||
inherit rust-vars
|
||||
# add crate fetch support
|
||||
inherit crate-fetch
|
||||
inherit rust-triples
|
||||
|
||||
# the binary we will use
|
||||
CARGO = "cargo"
|
||||
@@ -47,6 +48,21 @@ local-registry = "${WORKDIR}/cargo_registry"
|
||||
replace-with = "local"
|
||||
registry = "https://github.com/rust-lang/crates.io-index"
|
||||
EOF
|
||||
|
||||
# We need to use the real Yocto linker and get the linker
|
||||
# flags to it. Yocto has the concept of BUILD and TARGET
|
||||
# and uses HOST to be the currently selected one. However
|
||||
# LDFLAGS and TOOLCHAIN_OPTIONS are not prefixed with HOST
|
||||
echo "[build]" >> ${CARGO_HOME}/config
|
||||
echo "rustflags = [" >> ${CARGO_HOME}/config
|
||||
echo "'-C'," >> ${CARGO_HOME}/config
|
||||
echo "'link-args=${LDFLAGS}${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}'," >> ${CARGO_HOME}/config
|
||||
for p in ${RUSTFLAGS}; do
|
||||
printf "'%s'\n" "$p"
|
||||
done | sed -e 's/$/,/' >> ${CARGO_HOME}/config
|
||||
echo "]" >> ${CARGO_HOME}/config
|
||||
echo "[target.${RUST_HOST_SYS}]" >> ${CARGO_HOME}/config
|
||||
echo "linker = '${HOST_PREFIX}gcc'" >> ${CARGO_HOME}/config
|
||||
}
|
||||
|
||||
# All the rust & cargo ecosystem assume that CC, LD, etc are a path to a single
|
||||
@@ -59,14 +75,13 @@ export RUST_CFLAGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${CFLAGS}"
|
||||
export RUST_BUILD_CC = "${CCACHE}${BUILD_PREFIX}gcc"
|
||||
export RUST_BUILD_CFLAGS = "${BUILD_CC_ARCH} ${BUILD_CFLAGS}"
|
||||
|
||||
RUSTFLAGS ??= ""
|
||||
export CARGO_BUILD_FLAGS = "-v --target ${HOST_SYS} --release"
|
||||
CARGO_BUILD_FLAGS = "-v --target ${HOST_SYS} --release"
|
||||
|
||||
# This is based on the content of CARGO_BUILD_FLAGS and generally will need to
|
||||
# change if CARGO_BUILD_FLAGS changes.
|
||||
export CARGO_TARGET_SUBDIR="${HOST_SYS}/release"
|
||||
CARGO_TARGET_SUBDIR="${HOST_SYS}/release"
|
||||
oe_cargo_build () {
|
||||
export RUSTFLAGS="${RUSTFLAGS}"
|
||||
unset RUSTFLAGS
|
||||
bbnote "cargo = $(which cargo)"
|
||||
bbnote "rustc = $(which rustc)"
|
||||
bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
inherit rust
|
||||
|
||||
DEPENDS_append = " patchelf-native"
|
||||
RDEPENDS_${PN} += "${RUSTLIB_DEP}"
|
||||
|
||||
RUSTC_ARCHFLAGS += "-C opt-level=3 -g -L ${STAGING_DIR_HOST}/${rustlibdir}"
|
||||
@@ -54,6 +55,11 @@ get_overlap_externs () {
|
||||
do_configure () {
|
||||
}
|
||||
|
||||
oe_runrustc () {
|
||||
bbnote ${RUSTC} ${RUSTC_ARCHFLAGS} ${RUSTC_FLAGS} "$@"
|
||||
"${RUSTC}" ${RUSTC_ARCHFLAGS} ${RUSTC_FLAGS} "$@"
|
||||
}
|
||||
|
||||
oe_compile_rust_lib () {
|
||||
[ "${CRATE_TYPE}" == "dylib" ] && suffix=so || suffix=rlib
|
||||
rm -rf ${LIBNAME}.{rlib,so}
|
||||
@@ -88,3 +94,19 @@ oe_install_rust_bin () {
|
||||
echo Installing ${BINNAME}
|
||||
install -D -m 755 ${BINNAME} ${D}/${bindir}/${BINNAME}
|
||||
}
|
||||
|
||||
do_rust_bin_fixups() {
|
||||
for f in `find ${PKGD} -name '*.so*'`; do
|
||||
echo "Strip rust note: $f"
|
||||
${OBJCOPY} -R .note.rustc $f $f
|
||||
done
|
||||
|
||||
for f in `find ${PKGD}`; do
|
||||
file "$f" | grep -q ELF || continue
|
||||
readelf -d "$f" | grep RUNPATH | grep -q rustlib || continue
|
||||
echo "Set rpath:" "$f"
|
||||
patchelf --set-rpath '$ORIGIN:'${rustlibdir}:${rustlib} "$f"
|
||||
done
|
||||
}
|
||||
PACKAGE_PREPROCESS_FUNCS += "do_rust_bin_fixups"
|
||||
|
||||
|
||||
+1
-21
@@ -16,7 +16,7 @@ def rust_base_dep(d):
|
||||
deps += " rust-native"
|
||||
return deps
|
||||
|
||||
DEPENDS_append = " ${@rust_base_dep(d)} patchelf-native"
|
||||
DEPENDS_append = " ${@rust_base_dep(d)}"
|
||||
|
||||
# BUILD_LDFLAGS
|
||||
# ${STAGING_LIBDIR_NATIVE}
|
||||
@@ -31,11 +31,6 @@ DEPENDS_append = " ${@rust_base_dep(d)} patchelf-native"
|
||||
# -L${STAGING_BASE_LIBDIR_NATIVE} \
|
||||
#"
|
||||
|
||||
oe_runrustc () {
|
||||
bbnote ${RUSTC} ${RUSTC_ARCHFLAGS} ${RUSTC_FLAGS} "$@"
|
||||
"${RUSTC}" ${RUSTC_ARCHFLAGS} ${RUSTC_FLAGS} "$@"
|
||||
}
|
||||
|
||||
# XXX: for some reason bitbake sets BUILD_* & TARGET_* but uses the bare
|
||||
# variables for HOST. Alias things to make it easier for us.
|
||||
HOST_LDFLAGS ?= "${LDFLAGS}"
|
||||
@@ -45,21 +40,6 @@ HOST_CPPFLAGS ?= "${CPPFLAGS}"
|
||||
|
||||
EXTRA_OECONF_remove = "--disable-static"
|
||||
|
||||
do_rust_bin_fixups() {
|
||||
for f in `find ${PKGD} -name '*.so*'`; do
|
||||
echo "Strip rust note: $f"
|
||||
${OBJCOPY} -R .note.rustc $f $f
|
||||
done
|
||||
|
||||
for f in `find ${PKGD}`; do
|
||||
file "$f" | grep -q ELF || continue
|
||||
readelf -d "$f" | grep RUNPATH | grep -q rustlib || continue
|
||||
echo "Set rpath:" "$f"
|
||||
patchelf --set-rpath '$ORIGIN:'${rustlibdir}:${rustlib} "$f"
|
||||
done
|
||||
}
|
||||
PACKAGE_PREPROCESS_FUNCS += "do_rust_bin_fixups"
|
||||
|
||||
rustlib_suffix="${TUNE_ARCH}${TARGET_VENDOR}-${TARGET_OS}/rustlib/${HOST_SYS}/lib"
|
||||
# Native sysroot standard library path
|
||||
rustlib_src="${prefix}/lib/${rustlib_suffix}"
|
||||
|
||||
@@ -67,11 +67,9 @@ SRC_URI = "\
|
||||
|
||||
B = "${S}"
|
||||
|
||||
PACKAGECONFIG ??= ""
|
||||
|
||||
# Note: this does not appear to work very well due to our use of bitbake triples
|
||||
# & rust's use of cooked triples
|
||||
PACKAGECONFIG[rust-snapshot] = "--local-rust-root=${B}/rustc"
|
||||
# Can't use the default from rust-vars as it cause a compiler crash
|
||||
# the crate_hash option will cause the compiler to crash
|
||||
RUSTFLAGS = "-C rpath ${RUSTLIB}"
|
||||
|
||||
# Used in libgit2-sys's build.rs, needed for pkg-config to be used
|
||||
export LIBGIT2_SYS_USE_PKG_CONFIG = "1"
|
||||
@@ -80,8 +78,6 @@ export LIBGIT2_SYS_USE_PKG_CONFIG = "1"
|
||||
DISABLE_STATIC = ""
|
||||
|
||||
do_configure () {
|
||||
${@bb.utils.contains('PACKAGECONFIG', 'rust-snapshot', '${S}/.travis.install.deps.sh', ':', d)}
|
||||
|
||||
"${S}/configure" \
|
||||
"--prefix=${prefix}" \
|
||||
"--build=${BUILD_SYS}" \
|
||||
@@ -107,7 +103,7 @@ do_compile () {
|
||||
mkdir -p target
|
||||
cp -R ${WORKDIR}/cargo-nightly-x86_64-unknown-linux-gnu/cargo target/snapshot
|
||||
|
||||
oe_runmake ARGS="--verbose"
|
||||
oe_runmake VERBOSE=1
|
||||
}
|
||||
|
||||
do_install () {
|
||||
|
||||
@@ -119,45 +119,29 @@ LLVM_TARGET[arm] = "${RUST_TARGET_SYS}"
|
||||
TARGET_ENDIAN[arm] = "little"
|
||||
TARGET_POINTER_WIDTH[arm] = "32"
|
||||
FEATURES[arm] = "+v6,+vfp2"
|
||||
PRE_LINK_ARGS[arm] = "-Wl,--as-needed"
|
||||
|
||||
DATA_LAYOUT[aarch64] = "e-m:e-i64:64-i128:128-n32:64-S128"
|
||||
LLVM_TARGET[aarch64] = "aarch64-unknown-linux-gnu"
|
||||
TARGET_ENDIAN[aarch64] = "little"
|
||||
TARGET_POINTER_WIDTH[aarch64] = "64"
|
||||
PRE_LINK_ARGS[aarch64] = "-Wl,--as-needed"
|
||||
|
||||
## x86_64-unknown-linux-gnu
|
||||
DATA_LAYOUT[x86_64] = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
LLVM_TARGET[x86_64] = "x86_64-unknown-linux-gnu"
|
||||
TARGET_ENDIAN[x86_64] = "little"
|
||||
TARGET_POINTER_WIDTH[x86_64] = "64"
|
||||
PRE_LINK_ARGS[x86_64] = "-Wl,--as-needed -m64"
|
||||
|
||||
## i686-unknown-linux-gnu
|
||||
DATA_LAYOUT[i686] = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
|
||||
LLVM_TARGET[i686] = "i686-unknown-linux-gnu"
|
||||
TARGET_ENDIAN[i686] = "little"
|
||||
TARGET_POINTER_WIDTH[i686] = "32"
|
||||
PRE_LINK_ARGS[i686] = "-Wl,--as-needed -m32"
|
||||
|
||||
## XXX: a bit of a hack so qemux86 builds, clone of i686-unknown-linux-gnu above
|
||||
DATA_LAYOUT[i586] = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
|
||||
LLVM_TARGET[i586] = "i586-unknown-linux-gnu"
|
||||
TARGET_ENDIAN[i586] = "little"
|
||||
TARGET_POINTER_WIDTH[i586] = "32"
|
||||
PRE_LINK_ARGS[i586] = "-Wl,--as-needed -m32"
|
||||
|
||||
TARGET_PRE_LINK_ARGS = "${TARGET_CC_ARCH} ${TOOLCHAIN_OPTIONS}"
|
||||
BUILD_PRE_LINK_ARGS = "${BUILD_CC_ARCH} ${TOOLCHAIN_OPTIONS}"
|
||||
HOST_PRE_LINK_ARGS = "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS}"
|
||||
|
||||
# These LDFLAGS have '-L' options in them. We need these to come last so they
|
||||
# don't screw up the link order and pull in the wrong rust build/version.
|
||||
# TODO: may want to strip out all the '-L' flags entirely here
|
||||
TARGET_POST_LINK_ARGS = "${TARGET_LDFLAGS}"
|
||||
BUILD_POST_LINK_ARGS = "${BUILD_LDFLAGS}"
|
||||
HOST_POST_LINK_ARGS = "${HOST_LDFLAGS}"
|
||||
|
||||
def arch_for(d, thing):
|
||||
return d.getVar('{}_ARCH'.format(thing), True)
|
||||
@@ -208,21 +192,6 @@ def llvm_cpu(d):
|
||||
except:
|
||||
return trans.get(target, "generic")
|
||||
|
||||
def post_link_args_for(d, thing, arch):
|
||||
post_link_args = (d.getVar('{}_POST_LINK_ARGS'.format(thing), True) or "").split()
|
||||
post_link_args.extend((d.getVarFlag('POST_LINK_ARGS', arch, True) or "").split())
|
||||
return post_link_args
|
||||
|
||||
def pre_link_args_for(d, thing, arch):
|
||||
ldflags = (d.getVar('{}_PRE_LINK_ARGS'.format(thing), True) or "").split()
|
||||
ldflags.extend((d.getVarFlag('PRE_LINK_ARGS', arch, True) or "").split())
|
||||
return ldflags
|
||||
|
||||
def ldflags_for(d, thing, arch):
|
||||
a = pre_link_args_for(d, thing, arch)
|
||||
a.extend(post_link_args_for(d, thing, arch))
|
||||
return a
|
||||
|
||||
TARGET_LLVM_CPU="${@llvm_cpu(d)}"
|
||||
TARGET_LLVM_FEATURES = "${@llvm_features_from_tune(d)} ${@llvm_features_from_cc_arch(d)}"
|
||||
|
||||
@@ -267,8 +236,6 @@ def rust_gen_target(d, thing, wd):
|
||||
tspec['has-rpath'] = True
|
||||
tspec['has-elf-tls'] = True
|
||||
tspec['position-independent-executables'] = True
|
||||
tspec['pre-link-args'] = pre_link_args_for(d, thing, arch)
|
||||
tspec['post-link-args'] = post_link_args_for(d, thing, arch)
|
||||
|
||||
# write out the target spec json file
|
||||
with open(wd + sys + '.json', 'w') as f:
|
||||
@@ -306,7 +273,7 @@ def rust_gen_mk_cfg(d, thing):
|
||||
sys = sys_for(d, thing)
|
||||
prefix = prefix_for(d, thing)
|
||||
llvm_target = d.getVarFlag('LLVM_TARGET', arch, True)
|
||||
ldflags = ' '.join(ldflags_for(d, thing, arch))
|
||||
ldflags = d.getVar('LDFLAGS', True) + d.getVar('HOST_CC_ARCH', True) + d.getVar('TOOLCHAIN_OPTIONS', True)
|
||||
|
||||
b = d.getVar('WORKDIR', True) + '/mk-cfg/'
|
||||
o = open(b + sys_for(d, thing) + '.mk', 'w')
|
||||
|
||||
Reference in New Issue
Block a user