From 709957b3b67eeb428a9204db9c22d512d417b69b Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Thu, 11 Jun 2015 17:06:39 -0400 Subject: [PATCH 1/6] Add rustlib for publishing rust runtime --- recipes/rust/rustlib.bb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 recipes/rust/rustlib.bb diff --git a/recipes/rust/rustlib.bb b/recipes/rust/rustlib.bb new file mode 100644 index 0000000..9d767a3 --- /dev/null +++ b/recipes/rust/rustlib.bb @@ -0,0 +1,24 @@ +SUMMARY = "Rust runtime libaries" +HOMEPAGE = "http://www.rust-lang.org" +SECTION = "devel" +LICENSE = "MIT | Apache-2.0" + +inherit rust + +DEPENDS += "virtual/${TARGET_PREFIX}rust" +RUSTLIB_DEP = "" + +rustlib="${libdir}/${TUNE_PKGARCH}${TARGET_VENDOR}-${TARGET_OS}/rustlib/${HOST_SYS}/lib" + +do_install () { + mkdir -p ${D}/${rustlib} + cp ${STAGING_DIR_NATIVE}/${rustlib}/*.so ${D}/${rustlib} +} + +# This has no license file +python do_qa_configure() { + return True +} + +FILES_${PN} += "${rustlib}/*.so" +FILES_${PN}-dbg += "${rustlib}/.debug" From a91af9bbaec5151723a259a0941f58dac6cdb3ce Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Fri, 12 Jun 2015 12:52:19 -0400 Subject: [PATCH 2/6] Add rust-bin class This provides more defaults that aren't required for compiling with rustc, but standardize the output for inclusion in a distro. Things like - Where to install libraries - Stripping rustc note sections - Optimization by default --- classes/rust-bin.bbclass | 31 +++++++++++++++++++++++++++++++ recipes/rust/rustlib.bb | 4 +--- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 classes/rust-bin.bbclass diff --git a/classes/rust-bin.bbclass b/classes/rust-bin.bbclass new file mode 100644 index 0000000..22335bb --- /dev/null +++ b/classes/rust-bin.bbclass @@ -0,0 +1,31 @@ +inherit rust + +RUSTLIB_DEP ?= " rustlib" +DEPENDS .= "${RUSTLIB_DEP}" +DEPENDS += "patchelf-native" + +export rustlibdir = "${libdir}/rust" +FILES_${PN} += "${rustlibdir}/*.so" +FILES_${PN}-dev += "${rustlibdir}/*.rlib" +FILES_${PN}-dbg += "${rustlibdir}/.debug" + +RUSTC_ARCHFLAGS += "-C opt-level=3 -L ${STAGING_DIR_HOST}/${rustlibdir}" +EXTRA_OEMAKE += 'RUSTC_ARCHFLAGS="${RUSTC_ARCHFLAGS}"' + +rustlib="${libdir}/${TUNE_PKGARCH}${TARGET_VENDOR}-${TARGET_OS}/rustlib/${HOST_SYS}/lib" + +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 RPATH | 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/recipes/rust/rustlib.bb b/recipes/rust/rustlib.bb index 9d767a3..c13be30 100644 --- a/recipes/rust/rustlib.bb +++ b/recipes/rust/rustlib.bb @@ -3,13 +3,11 @@ HOMEPAGE = "http://www.rust-lang.org" SECTION = "devel" LICENSE = "MIT | Apache-2.0" -inherit rust +inherit rust-bin DEPENDS += "virtual/${TARGET_PREFIX}rust" RUSTLIB_DEP = "" -rustlib="${libdir}/${TUNE_PKGARCH}${TARGET_VENDOR}-${TARGET_OS}/rustlib/${HOST_SYS}/lib" - do_install () { mkdir -p ${D}/${rustlib} cp ${STAGING_DIR_NATIVE}/${rustlib}/*.so ${D}/${rustlib} From 8a6f084c66fd93b983d10b52fa3c8d596f8a5280 Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Thu, 25 Jun 2015 15:08:19 -0400 Subject: [PATCH 3/6] rust-bin: prefer-dynamic We control static/dynamic by only making one or the other available. Apparently the default of prefer static causes duplicate symbols for the standard library. --- classes/rust-bin.bbclass | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/classes/rust-bin.bbclass b/classes/rust-bin.bbclass index 22335bb..51820b2 100644 --- a/classes/rust-bin.bbclass +++ b/classes/rust-bin.bbclass @@ -12,6 +12,10 @@ FILES_${PN}-dbg += "${rustlibdir}/.debug" RUSTC_ARCHFLAGS += "-C opt-level=3 -L ${STAGING_DIR_HOST}/${rustlibdir}" EXTRA_OEMAKE += 'RUSTC_ARCHFLAGS="${RUSTC_ARCHFLAGS}"' +# Prevents multiple static copies of standard library modules +# See https://github.com/rust-lang/rust/issues/19680 +RUSTC_FLAGS += "-C prefer-dynamic" + rustlib="${libdir}/${TUNE_PKGARCH}${TARGET_VENDOR}-${TARGET_OS}/rustlib/${HOST_SYS}/lib" do_rust_bin_fixups() { From 837000f68a9eaacc75354c8dba69c4dd81026822 Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Thu, 25 Jun 2015 10:46:13 -0400 Subject: [PATCH 4/6] rust-bin: common code for building libs Libraries that overlap with the standard library must have explicit extern declarations. Without something like pkg-config where the libraries can publish this info, it's easiest to just hard-code the list of troublesome libraries. --- classes/rust-bin.bbclass | 65 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/classes/rust-bin.bbclass b/classes/rust-bin.bbclass index 51820b2..35e640f 100644 --- a/classes/rust-bin.bbclass +++ b/classes/rust-bin.bbclass @@ -9,14 +9,77 @@ FILES_${PN} += "${rustlibdir}/*.so" FILES_${PN}-dev += "${rustlibdir}/*.rlib" FILES_${PN}-dbg += "${rustlibdir}/.debug" -RUSTC_ARCHFLAGS += "-C opt-level=3 -L ${STAGING_DIR_HOST}/${rustlibdir}" +RUSTC_ARCHFLAGS += "-C opt-level=3 -g -L ${STAGING_DIR_HOST}/${rustlibdir}" EXTRA_OEMAKE += 'RUSTC_ARCHFLAGS="${RUSTC_ARCHFLAGS}"' +# Some libraries alias with the standard library but libstd is configured to +# make it difficult or imposisble to use its version. Unfortunately libstd +# must be explicitly overridden using extern. +OVERLAP_LIBS = "\ + libc \ + log \ + getopts \ +" +def get_overlap_deps(d): + deps = d.getVar("DEPENDS").split() + overlap_deps = [] + for o in d.getVar("OVERLAP_LIBS", True).split(): + l = len([o for dep in deps if (o + '-rs' in dep)]) + if l > 0: + overlap_deps.append(o) + return " ".join(overlap_deps) +OVERLAP_DEPS = "${@get_overlap_deps(d)}" + # Prevents multiple static copies of standard library modules # See https://github.com/rust-lang/rust/issues/19680 RUSTC_FLAGS += "-C prefer-dynamic" rustlib="${libdir}/${TUNE_PKGARCH}${TARGET_VENDOR}-${TARGET_OS}/rustlib/${HOST_SYS}/lib" +CRATE_NAME ?= "${@d.getVar('BPN', True).replace('-rs', '').replace('-', '_')}" +BINNAME ?= "${BPN}" +LIBNAME ?= "lib${CRATE_NAME}" +CRATE_TYPE ?= "dylib" +BIN_SRC ?= "${S}/src/main.rs" +LIB_SRC ?= "${S}/src/lib.rs" + +get_overlap_externs () { + externs= + for dep in ${OVERLAP_DEPS}; do + extern=$(ls ${STAGING_DIR_HOST}/${rustlibdir}/lib$dep.{so,rlib} 2>/dev/null \ + | awk '{print $1}'); + if [ -n "$extern" ]; then + externs="$externs --extern $dep=$extern" + else + echo "$dep in depends but no such library found in ${rustlibdir}!" >&2 + exit 1 + fi + done + echo "$externs" +} + +oe_compile_rust_lib () { + rm -rf ${LIBNAME}.{rlib,so} + oe_runrustc $(get_overlap_externs) ${LIB_SRC} --crate-name=${CRATE_NAME} --crate-type=${CRATE_TYPE} "$@" +} +oe_compile_rust_lib[vardeps] += "get_overlap_externs" + +oe_compile_rust_bin () { + rm -rf ${BINNAME} + oe_runrustc $(get_overlap_externs) ${BIN_SRC} -o ${BINNAME} "$@" +} +oe_compile_rust_bin[vardeps] += "get_overlap_externs" + +oe_install_rust_lib () { + for lib in $(ls ${LIBNAME}.{so,rlib} 2>/dev/null); do + echo Installing $lib + install -D -m 644 $lib ${D}/${rustlibdir}/$lib + done +} + +oe_install_rust_bin () { + echo Installing ${BINNAME} + install -D -m 644 ${BINNAME} ${D}/${bindir}/${BINNAME} +} do_rust_bin_fixups() { for f in `find ${PKGD} -name '*.so*'`; do From 06f6aeaa79a3922647deba0df503ff9ad69c93d5 Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Mon, 29 Jun 2015 14:23:25 -0400 Subject: [PATCH 5/6] rust-bin: set soname of shared objects Poky will fail to automatically create RDEPENDS on shared objects lacking a SONAME in the ELF. --- classes/rust-bin.bbclass | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/classes/rust-bin.bbclass b/classes/rust-bin.bbclass index 35e640f..5429e4b 100644 --- a/classes/rust-bin.bbclass +++ b/classes/rust-bin.bbclass @@ -59,7 +59,16 @@ get_overlap_externs () { oe_compile_rust_lib () { rm -rf ${LIBNAME}.{rlib,so} - oe_runrustc $(get_overlap_externs) ${LIB_SRC} --crate-name=${CRATE_NAME} --crate-type=${CRATE_TYPE} "$@" + local -a link_args + if [ "${CRATE_TYPE}" == "dylib" ]; then + link_args[0]="-C" + link_args[1]="link-args=-Wl,-soname -Wl,${LIBNAME}.so" + fi + oe_runrustc $(get_overlap_externs) \ + "${link_args[@]}" \ + ${LIB_SRC} \ + --crate-name=${CRATE_NAME} --crate-type=${CRATE_TYPE} \ + "$@" } oe_compile_rust_lib[vardeps] += "get_overlap_externs" From 8c83519133a3a86c8d5be66b81d3067ac797fe1b Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Mon, 29 Jun 2015 14:27:44 -0400 Subject: [PATCH 6/6] rust-bin/rustlib: install with executable permission Necessary for binaries and required to appease OE's automatic library RDEPENDS. --- classes/rust-bin.bbclass | 4 ++-- recipes/rust/rustlib.bb | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/classes/rust-bin.bbclass b/classes/rust-bin.bbclass index 5429e4b..a9195bf 100644 --- a/classes/rust-bin.bbclass +++ b/classes/rust-bin.bbclass @@ -81,13 +81,13 @@ oe_compile_rust_bin[vardeps] += "get_overlap_externs" oe_install_rust_lib () { for lib in $(ls ${LIBNAME}.{so,rlib} 2>/dev/null); do echo Installing $lib - install -D -m 644 $lib ${D}/${rustlibdir}/$lib + install -D -m 755 $lib ${D}/${rustlibdir}/$lib done } oe_install_rust_bin () { echo Installing ${BINNAME} - install -D -m 644 ${BINNAME} ${D}/${bindir}/${BINNAME} + install -D -m 755 ${BINNAME} ${D}/${bindir}/${BINNAME} } do_rust_bin_fixups() { diff --git a/recipes/rust/rustlib.bb b/recipes/rust/rustlib.bb index c13be30..ae05dfd 100644 --- a/recipes/rust/rustlib.bb +++ b/recipes/rust/rustlib.bb @@ -9,8 +9,10 @@ DEPENDS += "virtual/${TARGET_PREFIX}rust" RUSTLIB_DEP = "" do_install () { - mkdir -p ${D}/${rustlib} - cp ${STAGING_DIR_NATIVE}/${rustlib}/*.so ${D}/${rustlib} + for f in ${STAGING_DIR_NATIVE}/${rustlib}/*.so; do + echo Installing $f + install -D -m 755 $f ${D}/${rustlib}/$(basename $f) + done } # This has no license file