From 0827bc626be58b81ff606a31cec775c825965ccf Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Wed, 23 Nov 2016 11:16:30 -0600 Subject: [PATCH 1/8] rust/rust-bin: move bits to rust-bin Bits that are only used by the rust-bin bbclass should get moved there. They aren't used by any recipe that includes the rust bbclass. --- classes/rust-bin.bbclass | 22 ++++++++++++++++++++++ classes/rust.bbclass | 22 +--------------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/classes/rust-bin.bbclass b/classes/rust-bin.bbclass index 48df8e1..8afe5cb 100644 --- a/classes/rust-bin.bbclass +++ b/classes/rust-bin.bbclass @@ -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" + diff --git a/classes/rust.bbclass b/classes/rust.bbclass index e4fb677..e954825 100644 --- a/classes/rust.bbclass +++ b/classes/rust.bbclass @@ -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}" From f366cff86408b3a46040bf2f6cda69bc1a1b92a0 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Wed, 23 Nov 2016 11:26:53 -0600 Subject: [PATCH 2/8] cargo: change trivial verbose flag --- recipes-devtools/cargo/cargo.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes-devtools/cargo/cargo.inc b/recipes-devtools/cargo/cargo.inc index fa13057..0d4edd1 100644 --- a/recipes-devtools/cargo/cargo.inc +++ b/recipes-devtools/cargo/cargo.inc @@ -107,7 +107,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 () { From c98312fd1d610b2794dd452ac524816c8e1d9f9e Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Wed, 23 Nov 2016 11:32:18 -0600 Subject: [PATCH 3/8] cargo.bbclass: don't export variables --- classes/cargo.bbclass | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/cargo.bbclass b/classes/cargo.bbclass index ded9894..0934fe0 100644 --- a/classes/cargo.bbclass +++ b/classes/cargo.bbclass @@ -60,11 +60,11 @@ 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}" bbnote "cargo = $(which cargo)" From 4e1bda643ef7896bdaa77261a3abd8ce312e41c9 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Wed, 23 Nov 2016 11:40:17 -0600 Subject: [PATCH 4/8] cargo.bbclass: supply linker and link-args via rustflags Supply the linker and the linker args via rustflags which should make it not necessary to specify them via target JSONs. We explicitly cannot use the RUSTFLAGS environment variable do to the way cargo parses arguments and passes them to rustc. --- classes/cargo.bbclass | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/classes/cargo.bbclass b/classes/cargo.bbclass index 0934fe0..a3d0343 100644 --- a/classes/cargo.bbclass +++ b/classes/cargo.bbclass @@ -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,15 @@ 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 = ['-C', 'link-args=${LDFLAGS}${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}']" >> ${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 +69,12 @@ 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 ??= "" 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. CARGO_TARGET_SUBDIR="${HOST_SYS}/release" oe_cargo_build () { - export RUSTFLAGS="${RUSTFLAGS}" bbnote "cargo = $(which cargo)" bbnote "rustc = $(which rustc)" bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@" From 5afc0cc471eef5c18bbce9bc54aed6110e7c55eb Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Wed, 23 Nov 2016 14:03:58 -0600 Subject: [PATCH 5/8] cargo.bbclass: ensure extra RUSTFLAGS are properly passed The RUSTFLAGS env var overrides the rustflags specified in the cargo config so we need to take anything passed in the environment variable and put it in the config. --- classes/cargo.bbclass | 23 +++++++++++++++-------- recipes-devtools/cargo/cargo.inc | 4 ++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/classes/cargo.bbclass b/classes/cargo.bbclass index a3d0343..2ddf3c3 100644 --- a/classes/cargo.bbclass +++ b/classes/cargo.bbclass @@ -49,14 +49,20 @@ 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 = ['-C', 'link-args=${LDFLAGS}${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}']" >> ${CARGO_HOME}/config - echo "[target.${RUST_HOST_SYS}]" >> ${CARGO_HOME}/config - echo "linker = '${HOST_PREFIX}gcc'" >> ${CARGO_HOME}/config + # 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 @@ -75,6 +81,7 @@ CARGO_BUILD_FLAGS = "-v --target ${HOST_SYS} --release" # change if CARGO_BUILD_FLAGS changes. CARGO_TARGET_SUBDIR="${HOST_SYS}/release" oe_cargo_build () { + unset RUSTFLAGS bbnote "cargo = $(which cargo)" bbnote "rustc = $(which rustc)" bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@" diff --git a/recipes-devtools/cargo/cargo.inc b/recipes-devtools/cargo/cargo.inc index 0d4edd1..efa0988 100644 --- a/recipes-devtools/cargo/cargo.inc +++ b/recipes-devtools/cargo/cargo.inc @@ -67,6 +67,10 @@ SRC_URI = "\ B = "${S}" +# 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}" + PACKAGECONFIG ??= "" # Note: this does not appear to work very well due to our use of bitbake triples From dfa7dc1bad25ce9f99cec7a7e7bc7dc757efacad Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Wed, 23 Nov 2016 10:54:53 -0600 Subject: [PATCH 6/8] rust: drop link args from the target JSONs The linker args have been moved into the Cargo configuration so there's no need for them in the target spec files. --- recipes-devtools/rust/rust.inc | 35 +--------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/recipes-devtools/rust/rust.inc b/recipes-devtools/rust/rust.inc index db4dcde..32a1b2a 100644 --- a/recipes-devtools/rust/rust.inc +++ b/recipes-devtools/rust/rust.inc @@ -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') From 61093e260f83cdbd64dc376a00045ae156a857cc Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Wed, 23 Nov 2016 14:15:41 -0600 Subject: [PATCH 7/8] cargo: remove code that doesn't work The comment says it doesn't work and I can confirm it won't work. --- recipes-devtools/cargo/cargo.inc | 8 -------- 1 file changed, 8 deletions(-) diff --git a/recipes-devtools/cargo/cargo.inc b/recipes-devtools/cargo/cargo.inc index efa0988..33aab40 100644 --- a/recipes-devtools/cargo/cargo.inc +++ b/recipes-devtools/cargo/cargo.inc @@ -71,12 +71,6 @@ B = "${S}" # the crate_hash option will cause the compiler to crash RUSTFLAGS = "-C rpath ${RUSTLIB}" -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" - # Used in libgit2-sys's build.rs, needed for pkg-config to be used export LIBGIT2_SYS_USE_PKG_CONFIG = "1" @@ -84,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}" \ From 311ea03c1f4c0508d752f2a3333c0c45c9daee5f Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Thu, 24 Nov 2016 09:22:44 -0600 Subject: [PATCH 8/8] CI: change from Yocto master to morty Currently master is broken and morty is the next release that we'll likely target so bump our version over to morty. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2fc6fdc..77e3e2a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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"