commit f7801cf999f7fecde6d5564e72db6d94216978df Author: Cody P Schafer Date: Wed Oct 15 16:03:30 2014 -0400 Initial, untested - rust-cross builds - cargo-native still broken - untested wrappers for rust and cargo provided in rust.bbclass diff --git a/COPYING.MIT b/COPYING.MIT new file mode 100644 index 0000000..fb950dc --- /dev/null +++ b/COPYING.MIT @@ -0,0 +1,17 @@ +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..995b181 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +## Introduction + +This openembedded layer provides the rust compiler, tools for building packages +(cargo), and a few example projects. + +## Dependencies + +On the host: + unknown + +On the target: + unknown + +## Build Examples + +## Maintainer(s) & Patch policy + +## Copyright + +MIT/Apache-2.0 - Same as rust + diff --git a/classes/rust-misc.bbclass b/classes/rust-misc.bbclass new file mode 100644 index 0000000..e69de29 diff --git a/classes/rust.bbclass b/classes/rust.bbclass new file mode 100644 index 0000000..eb94b57 --- /dev/null +++ b/classes/rust.bbclass @@ -0,0 +1,68 @@ +def rust_triple(arch, vendor, os, d): + if arch.startswith("arm"): + vendor = "-unknown" + if os.endswith("gnueabi"): + os += bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'hf', '', d) + elif arch.startswith("x86_64"): + vendor = "-unknown" + if os == "linux": + os = "linux-gnu" + return arch + vendor + '-' + os + +RUST_TARGET_SYS = "${@rust_triple('${TARGET_ARCH}','${TARGET_VENDOR}','${TARGET_OS}', d)}" +RUST_BUILD_SYS = "${@rust_triple('${BUILD_ARCH}','${BUILD_VENDOR}','${BUILD_OS}', d)}" +RUST_HOST_SYS = "${@rust_triple('${HOST_ARCH}','${HOST_VENDOR}','${HOST_OS}', d)}" + +RUSTC = "rustc" +RUSTC_ARCHFLAGS += "--target=${RUST_TARGET_SYS} -C linker=${TARGET_PREFIX}gcc\\ ${TARGET_CC_ARCH}" + + +# BUILD_LDFLAGS +# ${STAGING_LIBDIR_NATIVE} +# ${STAGING_BASE_LIBDIR_NATIVE} +# BUILDSDK_LDFLAGS +# ${STAGING_LIBDIR} +# #{STAGING_DIR_HOST} +# TARGET_LDFLAGS ????? +#RUSTC_BUILD_LDFLAGS = "\ +# --sysroot ${STAGING_DIR_NATIVE} \ +# -L${STAGING_LIBDIR_NATIVE} \ +# -L${STAGING_BASE_LIBDIR_NATIVE} \ +#" + +RUST_PATH_NATIVE="${STAGING_LIBDIR_NATIVE}:${STAGING_BASE_LIBDIR_NATIVE}" + +# FIXME: set based on whether we are native vs cross vs buildsdk, etc +RUST_PATH = "${RUST_PATH_NATIVE}" + +CARGO = "cargo" + +oe_runrustc () { + bbnote ${RUSTC} ${RUSTC_ARCHFLAGS} ${RUSTC_FLAGS} "$@" + "${RUSTC}" ${RUSTC_ARCHFLAGS} ${RUSTC_FLAGS} "$@" +} + +oe_cargo_config () { + mkdir -p .cargo + # FIXME: we currently blow away the entire config because duplicate + # sections are treated as a parse error by cargo (causing the entire + # config to be silently ignored. + # NOTE: we cannot pass more flags via this interface, the 'linker' is + # assumed to be a path to a binary. If flags are needed, a wrapper must + # be used. + cat >.cargo/config < +Date: Mon, 20 Oct 2014 14:04:45 -0400 +Subject: [PATCH] mk/rt: "export CC" does not seem to work (gcc observed), use + explicit shell variables instead + +--- + mk/rt.mk | 11 +++++------ + 1 file changed, 5 insertions(+), 6 deletions(-) + +diff --git a/mk/rt.mk b/mk/rt.mk +index de06d49..3e05012 100644 +--- a/mk/rt.mk ++++ b/mk/rt.mk +@@ -284,16 +284,15 @@ endif + # ./configure script. This is done to force libbacktrace to *not* use the + # atomic/sync functionality because it pulls in unnecessary dependencies and we + # never use it anyway. +-$$(BACKTRACE_BUILD_DIR_$(1))/Makefile: \ +- export CFLAGS:=$$(CFG_GCCISH_CFLAGS_$(1):-Werror=) \ +- -fno-stack-protector +-$$(BACKTRACE_BUILD_DIR_$(1))/Makefile: export CC:=$$(CC_$(1)) +-$$(BACKTRACE_BUILD_DIR_$(1))/Makefile: export AR:=$$(AR_$(1)) +-$$(BACKTRACE_BUILD_DIR_$(1))/Makefile: export RANLIB:=$$(AR_$(1)) s + $$(BACKTRACE_BUILD_DIR_$(1))/Makefile: $$(BACKTRACE_DEPS) $$(MKFILE_DEPS) ++ @$$(call E, configure: libbacktrace for $(1)) + $$(Q)rm -rf $$(BACKTRACE_BUILD_DIR_$(1)) + $$(Q)mkdir -p $$(BACKTRACE_BUILD_DIR_$(1)) + $$(Q)(cd $$(BACKTRACE_BUILD_DIR_$(1)) && \ ++ CC="$$(CC_$(1))" \ ++ AR="$$(AR_$(1))" \ ++ RANLIB="$$(AR_$(1)) s" \ ++ CFLAGS="$$(CFG_GCCISH_CFLAGS_$(1):-Werror=) -fno-stack-protector" \ + $(S)src/libbacktrace/configure --target=$(1) --host=$(CFG_BUILD)) + $$(Q)echo '#undef HAVE_ATOMIC_FUNCTIONS' >> \ + $$(BACKTRACE_BUILD_DIR_$(1))/config.h +-- +2.1.2 + diff --git a/recipes/rust/rust_0.12.0.bb b/recipes/rust/rust_0.12.0.bb new file mode 100644 index 0000000..d42618c --- /dev/null +++ b/recipes/rust/rust_0.12.0.bb @@ -0,0 +1,112 @@ +inherit rust + +SUMMARY = "Rust compiler and runtime libaries" +HOMEPAGE = "http://www.rust-lang.org" +SECTION = "devel" +LICENSE = "MIT | Apache-2.0" + +SRC_URI = "\ + https://static.rust-lang.org/dist/rust-${PV}.tar.gz \ +" +B = "${WORKDIR}/build" + +do_configure () { + # FIXME: allow --enable-local-rust + # FIXME: target_prefix vs prefix, see cross.bbclass + # FIXME: handle non-native builds + + # CFLAGS, LDFLAGS, CXXFLAGS, CPPFLAGS are used by rust's build for a + # wide range of targets (not just HOST). Yocto's settings for them will + # be inappropriate, avoid using. + unset CFLAGS + unset LDFLAGS + unset CXXFLAGS + unset CPPFLAGS + + # XXX: rpath is required otherwise rustc fails to resolve symbols + + ${S}/configure \ + "--enable-rpath" \ + "--disable-verify-install" \ + "--prefix=${prefix}" \ + "--target=${RUST_TARGET_SYS}" \ + "--localstatedir=${localstatedir}" \ + "--sysconfdir=${sysconfdir}" \ + "--datadir=${datadir}" \ + "--infodir=${infodir}" \ + "--mandir=${mandir}" \ + "--build=${RUST_BUILD_SYS}" \ + "--host=${RUST_HOST_SYS}" \ + "--libdir=${libdir}" + + +} + +rust_runmake () { + echo "COMPILE ${PN}" "$@" + env + + # CFLAGS, LDFLAGS, CXXFLAGS, CPPFLAGS are used by rust's build for a + # wide range of targets (not just HOST). Yocto's settings for them will + # be inappropriate, avoid using. + unset CFLAGS + unset LDFLAGS + unset CXXFLAGS + unset CPPFLAGS + + # FIXME: this only works if RT != RH. For RT == RH, we need to add + # additional targets to platform.mk and patch rust to understand the + # new triples (so it can find runtime libraries). + + # Note: these variable names include '-', so we can't supply them via + # shell exports + oe_runmake \ + CROSS_PREFIX_${RUST_TARGET_SYS}= \ + CC_${rt}="${CCACHE}${TARGET_PREFIX}gcc ${TARGET_CC_ARCH}" \ + CXX_${rt}="${CCACHE}${TARGET_PREFIX}g++ ${TARGET_CC_ARCH}" \ + CPP_${rt}="${TARGET_PREFIX}gcc ${TARGET_CC_ARCH} -E" \ + AR_${rt}="${TARGET_PREFIX}ar" \ + \ + CROSS_PREFIX_${ROST_HOST_SYS}= \ + CC_${rh}="${CCACHE}${HOST_PREFIX}gcc ${HOST_CC_ARCH}" \ + CXX_${rh}="${CCACHE}${HOST_PREFIX}g++ ${HOST_CC_ARCH}" \ + CPP_${rh}="${HOST_PREFIX}gcc ${HOST_CC_ARCH} -E" \ + AR_${rh}="${HOST_PREFIX}ar" \ + \ + CFG_CFLAGS_${RUST_TARGET_SYS}="${TARGET_CFLAGS}" \ + CFG_LDFLAGS_${RUST_TARGET_SYS}="${TARGET_LDFLAGS}" \ + CFG_CFLAGS_${RUST_HOST_SYS}="${HOST_CFLAGS}" \ + CFG_LDFLAGS_${RUST_HOST_SYS}="${HOST_LDFLAGS}" \ + \ + "$@" +} + +do_compile () { + rust_runmake +} + +do_install () { + rust_runmake DESTDIR="${D}" install +} + +# FIXME: use FILES to create a -runtime (not -native) package +# $PREFIX/lib/rustlib/`rust_triple`/lib/* contains the runtime libraries (and rlibs) +# Need to copy the *.so files to the appropriate target path +# cp $prefix/lib/rustlib/`rust_triple "${TARGET_ARCH}" "${TARGET_VENDOR}" "${TARGET_OS}"`/lib/*.so ${target_libdir}/ + +# cross-canadian: llvm configure fails for host while attempting to build host-only llvm +BBCLASSEXTEND = "cross native" + +#python cross_virtclass_provides_native_handler () { +# classextend = e.data.getVar('BBCLASSEXTEND', True) or "" +# if "cross" not in classextend: +# return +# pn = e.data.getVar("PN", True) +# if not pn.endswith("-cross"): +# return +# e.data.prependVar("PROVIDES", "rust-native ") +#} +#addhandler cross_virtclass_provides_native_handler +#cross_virtclass_provides_native_handler[eventmask] = "bb.event.RecipePreFinalise" + +require recipes/rust/rust-${PV}.inc