From da71abbef174b51c886e633c997efcb93691df9c Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Sun, 28 Aug 2016 14:49:01 -0400 Subject: [PATCH 1/6] cargo_util: prefix DEPENDS_append with space --- classes/cargo_util.bbclass | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/cargo_util.bbclass b/classes/cargo_util.bbclass index 5f0003f..dca4f84 100644 --- a/classes/cargo_util.bbclass +++ b/classes/cargo_util.bbclass @@ -11,7 +11,7 @@ export CARGO_HOME = "${WORKDIR}/cargo_home" BASEDEPENDS_append = " cargo-native" # Ensure we get the right rust variant -DEPENDS_append_class-target = "virtual/${TARGET_PREFIX}rust" +DEPENDS_append_class-target = " virtual/${TARGET_PREFIX}rust" # Cargo only supports in-tree builds at the moment B = "${S}" From 00429e037bc861bf38220f9e44d0668863591896 Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Sun, 28 Aug 2016 15:10:02 -0400 Subject: [PATCH 2/6] cargo_util: make rustlibdir available This is needed for install and potentially link paths. --- classes/cargo_util.bbclass | 1 + classes/rust-vars.bbclass | 4 ++++ classes/rust.bbclass | 6 ++---- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 classes/rust-vars.bbclass diff --git a/classes/cargo_util.bbclass b/classes/cargo_util.bbclass index dca4f84..e508f89 100644 --- a/classes/cargo_util.bbclass +++ b/classes/cargo_util.bbclass @@ -1,3 +1,4 @@ +inherit rust-vars # add crate fetch support inherit crate-fetch diff --git a/classes/rust-vars.bbclass b/classes/rust-vars.bbclass new file mode 100644 index 0000000..c987d91 --- /dev/null +++ b/classes/rust-vars.bbclass @@ -0,0 +1,4 @@ +export rustlibdir = "${libdir}/rust" +FILES_${PN} += "${rustlibdir}/*.so" +FILES_${PN}-dev += "${rustlibdir}/*.rlib" +FILES_${PN}-dbg += "${rustlibdir}/.debug" diff --git a/classes/rust.bbclass b/classes/rust.bbclass index 9251d27..132a402 100644 --- a/classes/rust.bbclass +++ b/classes/rust.bbclass @@ -1,3 +1,5 @@ +inherit rust-vars + RUSTC = "rustc" # FIXME: --sysroot might be needed @@ -107,7 +109,3 @@ rustlib_suffix="${TUNE_ARCH}${TARGET_VENDOR}-${TARGET_OS}/rustlib/${HOST_SYS}/li rustlib_src="${prefix}/lib/${rustlib_suffix}" # Host sysroot standard library path rustlib="${libdir}/${rustlib_suffix}" -export rustlibdir = "${libdir}/rust" -FILES_${PN} += "${rustlibdir}/*.so" -FILES_${PN}-dev += "${rustlibdir}/*.rlib" -FILES_${PN}-dbg += "${rustlibdir}/.debug" From d320edc05fa20d34c34d5005686e656eae5014a9 Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Sun, 28 Aug 2016 14:28:53 -0400 Subject: [PATCH 3/6] cargo_util: install libraries The final output of a crate may be a library along with one or more executables. Install the libraries as well. --- classes/cargo_util.bbclass | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/classes/cargo_util.bbclass b/classes/cargo_util.bbclass index e508f89..967eb04 100644 --- a/classes/cargo_util.bbclass +++ b/classes/cargo_util.bbclass @@ -71,12 +71,15 @@ cargo_util_do_compile () { oe_cargo_build } -# All but the most simple projects will need to override this. cargo_util_do_install () { local have_installed=false - install -d "${D}${bindir}" for tgt in "${B}/target/${CARGO_TARGET_SUBDIR}/"*; do - if [ -f "$tgt" ] && [ -x "$tgt" ]; then + if [[ $tgt == *.so || $tgt == *.rlib ]]; then + install -d "${D}${rustlibdir}" + install -m755 "$tgt" "${D}${rustlibdir}" + have_installed=true + elif [ -f "$tgt" ] && [ -x "$tgt" ]; then + install -d "${D}${bindir}" install -m755 "$tgt" "${D}${bindir}" have_installed=true fi From e3140137e5d5ee75f07d797b2b3ac4d67ee1a868 Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Sun, 28 Aug 2016 16:06:26 -0400 Subject: [PATCH 4/6] cargo_util: pass RUSTFLAGS to cargo build --- classes/cargo_util.bbclass | 2 ++ 1 file changed, 2 insertions(+) diff --git a/classes/cargo_util.bbclass b/classes/cargo_util.bbclass index 967eb04..614baf9 100644 --- a/classes/cargo_util.bbclass +++ b/classes/cargo_util.bbclass @@ -36,12 +36,14 @@ 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" # 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" oe_cargo_build () { + export RUSTFLAGS="${RUSTFLAGS}" bbnote "cargo = $(which cargo)" bbnote "rustc = $(which rustc)" bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@" From e2d09d03628697b9c16285375bbb5da4eb9e75a8 Mon Sep 17 00:00:00 2001 From: Steven Walter Date: Thu, 5 May 2016 18:01:24 -0400 Subject: [PATCH 5/6] libstd-rs: cross compile rust's runtime This can replace rustlib, which just copies the binaries already built by rust-cross. --- recipes-devtools/rust/compiler-rt.bb | 23 +++++++++++++++++++++ recipes-devtools/rust/libstd-rs.bb | 30 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 recipes-devtools/rust/compiler-rt.bb create mode 100644 recipes-devtools/rust/libstd-rs.bb diff --git a/recipes-devtools/rust/compiler-rt.bb b/recipes-devtools/rust/compiler-rt.bb new file mode 100644 index 0000000..a9644d1 --- /dev/null +++ b/recipes-devtools/rust/compiler-rt.bb @@ -0,0 +1,23 @@ +SUMMARY = "Rust compiler run-time" +HOMEPAGE = "http://www.rust-lang.org" +SECTION = "devel" +LICENSE = "MIT" + +require rust-shared-source.inc +LIC_FILES_CHKSUM = "file://LICENSE.TXT;md5=27b14ab4ce08d04c3a9a5f0ed7997362" + +S .= "/src/compiler-rt" +B = "${WORKDIR}/build" + +do_compile () { + oe_runmake -C ${S} \ + ProjSrcRoot="${S}" \ + ProjObjRoot="${B}" \ + TargetTriple=${HOST_SYS} \ + triple-builtins +} + +do_install () { + mkdir -p ${D}${libdir} + cp triple/builtins/libcompiler_rt.a ${D}${libdir}/libcompiler-rt.a +} diff --git a/recipes-devtools/rust/libstd-rs.bb b/recipes-devtools/rust/libstd-rs.bb new file mode 100644 index 0000000..d8e72a5 --- /dev/null +++ b/recipes-devtools/rust/libstd-rs.bb @@ -0,0 +1,30 @@ +SUMMARY = "Rust standard libaries" +HOMEPAGE = "http://www.rust-lang.org" +SECTION = "devel" +LICENSE = "MIT | Apache-2.0" + +LIC_FILES_CHKSUM ="file://COPYRIGHT;md5=43e1f1fb9c0ee3af66693d8c4fecafa8" +require rust-shared-source.inc + +DEPENDS += "compiler-rt" + +RUSTLIB_DEP = "" +inherit cargo_util + +# Needed so cargo can find libbacktrace +RUSTFLAGS += "-L ${STAGING_LIBDIR}" + +B = "${WORKDIR}/build" + +do_compile () { + cd ${S}/src/rustc/std_shim + export CARGO_TARGET_DIR="${B}" + export RUSTC_BOOTSTRAP_KEY="e8edd0fd" + oe_cargo_fix_env + oe_cargo_build +} + +do_install () { + mkdir -p ${D}${rustlibdir} + cp ${B}/${TARGET_SYS}/release/deps/* ${D}${rustlibdir} +} From f6c7789c950c65e3fcf8ba4eabbdacae6236b42c Mon Sep 17 00:00:00 2001 From: Steven Walter Date: Tue, 30 Aug 2016 16:49:50 -0400 Subject: [PATCH 6/6] rust-cross: don't actually build a compiler Instead of building a full compiler, we can use rust-native to cross-compile. All we need is a cross-compiled standard library, which libstd-rs builds, and a compiler spec file. rust-cross is now just used to generate the json spec file for cross-compiling, which is naturally much faster. --- classes/cargo_util.bbclass | 2 +- classes/rust-vars.bbclass | 4 ++++ classes/rust.bbclass | 3 --- recipes-devtools/rust/rust-cross.bb | 23 ++++++++++++++--------- recipes-devtools/rust/rust.bb | 1 + recipes-devtools/rust/rust.inc | 1 - recipes-devtools/rust/rustlib.bb | 26 -------------------------- 7 files changed, 20 insertions(+), 40 deletions(-) delete mode 100644 recipes-devtools/rust/rustlib.bb diff --git a/classes/cargo_util.bbclass b/classes/cargo_util.bbclass index 614baf9..f38a519 100644 --- a/classes/cargo_util.bbclass +++ b/classes/cargo_util.bbclass @@ -12,7 +12,7 @@ export CARGO_HOME = "${WORKDIR}/cargo_home" BASEDEPENDS_append = " cargo-native" # Ensure we get the right rust variant -DEPENDS_append_class-target = " virtual/${TARGET_PREFIX}rust" +DEPENDS_append_class-target = " virtual/${TARGET_PREFIX}rust ${RUSTLIB_DEP}" # Cargo only supports in-tree builds at the moment B = "${S}" diff --git a/classes/rust-vars.bbclass b/classes/rust-vars.bbclass index c987d91..a3acc44 100644 --- a/classes/rust-vars.bbclass +++ b/classes/rust-vars.bbclass @@ -2,3 +2,7 @@ export rustlibdir = "${libdir}/rust" FILES_${PN} += "${rustlibdir}/*.so" FILES_${PN}-dev += "${rustlibdir}/*.rlib" FILES_${PN}-dbg += "${rustlibdir}/.debug" + +RUSTLIB = "-L ${STAGING_LIBDIR}/rust" +RUSTFLAGS += "-C rpath -C crate_hash=${BB_TASKHASH} ${RUSTLIB}" +RUSTLIB_DEP ?= "libstd-rs" diff --git a/classes/rust.bbclass b/classes/rust.bbclass index 132a402..15299b2 100644 --- a/classes/rust.bbclass +++ b/classes/rust.bbclass @@ -2,11 +2,8 @@ inherit rust-vars RUSTC = "rustc" -# FIXME: --sysroot might be needed -RUSTFLAGS += "-C rpath -C crate_hash=${BB_TASKHASH}" RUSTC_ARCHFLAGS += "--target=${TARGET_SYS} ${RUSTFLAGS}" -RUSTLIB_DEP ?= "rustlib" def rust_base_dep(d): # Taken from meta/classes/base.bbclass `base_dep_prepend` and modified to # use rust instead of gcc diff --git a/recipes-devtools/rust/rust-cross.bb b/recipes-devtools/rust/rust-cross.bb index d4324f1..70ce2b4 100644 --- a/recipes-devtools/rust/rust-cross.bb +++ b/recipes-devtools/rust/rust-cross.bb @@ -10,6 +10,7 @@ INHIBIT_DEFAULT_RUST_DEPS = "1" # the bits we need explicitly. DEPENDS += "rust-llvm-native" DEPENDS += "virtual/${TARGET_PREFIX}gcc virtual/${TARGET_PREFIX}compilerlibs virtual/libc" +DEPENDS += "rust-native" PROVIDES = "virtual/${TARGET_PREFIX}rust" PN = "rust-cross-${TARGET_ARCH}" @@ -31,14 +32,18 @@ BUILD_POST_LINK_ARGS_append = " -Wl,-rpath=../../lib" # We need the same thing for the calls to the compiler when building the runtime crap TARGET_CC_ARCH_append = " --sysroot=${STAGING_DIR_TARGET}" -# cross.bbclass is "helpful" and overrides our do_install. Tell it not to. -do_install () { - rust_do_install +do_configure () { } -# using host-strip on target .so files generated by this recipie causes build errors. -# for now, disable stripping. -# A better (but more complex) approach would be to mimic gcc-runtime and build -# the target.so files in a seperate .bb file. -INHIBIT_PACKAGE_STRIP = "1" -INHIBIT_SYSROOT_STRIP = "1" +do_compile () { +} + +do_install () { + mkdir -p ${D}${prefix}/${baselib}/rustlib + cp ${WORKDIR}/targets/${TARGET_ARCH}* ${D}${prefix}/${baselib}/rustlib +} + +rust_cross_sysroot_preprocess() { + sysroot_stage_dir ${D}${prefix}/${baselib}/rustlib ${SYSROOT_DESTDIR}${prefix}/${baselib}/rustlib +} +SYSROOT_PREPROCESS_FUNCS += "rust_cross_sysroot_preprocess" diff --git a/recipes-devtools/rust/rust.bb b/recipes-devtools/rust/rust.bb index 93ceab2..ab61226 100644 --- a/recipes-devtools/rust/rust.bb +++ b/recipes-devtools/rust/rust.bb @@ -1,3 +1,4 @@ +inherit rust-installer require rust.inc DEPENDS += "rust-llvm" diff --git a/recipes-devtools/rust/rust.inc b/recipes-devtools/rust/rust.inc index 3c7d7fa..253f676 100644 --- a/recipes-devtools/rust/rust.inc +++ b/recipes-devtools/rust/rust.inc @@ -1,6 +1,5 @@ # ex: sts=4 et sw=4 ts=8 inherit rust -inherit rust-installer require rust-shared-source.inc require rust-snapshot-2016-05-24.inc diff --git a/recipes-devtools/rust/rustlib.bb b/recipes-devtools/rust/rustlib.bb deleted file mode 100644 index 9d371f7..0000000 --- a/recipes-devtools/rust/rustlib.bb +++ /dev/null @@ -1,26 +0,0 @@ -SUMMARY = "Rust runtime libaries" -HOMEPAGE = "http://www.rust-lang.org" -SECTION = "devel" -LICENSE = "MIT | Apache-2.0" - -inherit rust-bin - -DEPENDS += "virtual/${TARGET_PREFIX}rust" -RUSTLIB_DEP = "" - -do_install () { - for f in ${STAGING_DIR_NATIVE}/${rustlib_src}/*; do - echo Installing $f - install -D -m 755 $f ${D}/${rustlib}/$(basename $f) - done -} - -# This has no license file -python do_qa_configure() { - return True -} - -FILES_${PN} += "${rustlib}/*.so" -FILES_${PN}-dev += "${rustlib}/*.rlib" -FILES_${PN}-staticdev += "${rustlib}/*.a" -FILES_${PN}-dbg += "${rustlib}/.debug"