Initial, untested

- rust-cross builds
 - cargo-native still broken
 - untested wrappers for rust and cargo provided in rust.bbclass
This commit is contained in:
Cody P Schafer
2014-10-15 16:03:30 -04:00
commit f7801cf999
19 changed files with 412 additions and 0 deletions

17
COPYING.MIT Normal file
View File

@@ -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.

21
README.md Normal file
View File

@@ -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

View File

68
classes/rust.bbclass Normal file
View File

@@ -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 <<EOF
[target.${RUST_TARGET_SYS}]
ar = "${TARGET_PREFIX}ar"
linker = "${TARGET_PREFIX}gcc"
EOF
}
oe_runcargo_build () {
# FIXME: if there is already an entry for this target, in an existing
# cargo/config, this won't work.
which cargo
bbnote ${CARGO} build --target ${RUST_TARGET_SYS} "$@"
oe_cargo_config
export RUST_PATH="${RUST_PATH}"
"${CARGO}" build -v --target "${RUST_TARGET_SYS}" --release "$@"
}

9
conf/layer.conf Normal file
View File

@@ -0,0 +1,9 @@
# We have a conf and classes directory, append to BBPATH
BBPATH .= ":${LAYERDIR}"
# We have a recipes directory, add to BBFILES
BBFILES += "${LAYERDIR}/recipes*/*/*.bb ${LAYERDIR}/recipes*/*/*.bbappend"
BBFILE_COLLECTIONS += "rust-layer"
BBFILE_PATTERN_rust-layer := "^${LAYERDIR}/"
BBFILE_PRIORITY_rust-layer = "7"

1
conf/licenses.conf Normal file
View File

@@ -0,0 +1 @@
SRC_DISTRIBUTE_LICENSES += "GPL-2.0-with-linking-exception"

View File

@@ -0,0 +1,11 @@
LINKING EXCEPTION
In addition to the permissions in the GNU General Public License, the authors
give you unlimited permission to link the compiled version of this library into
combinations with other programs, and to distribute those combinations without
any restriction coming from the use of this file. (The General Public License
restrictions do apply in other respects; for example, they cover modification
of the file, and distribution when not linked into a combined executable.)
insert GPL v2 text here

View File

@@ -0,0 +1,16 @@
SUMMARY = "the Git linkable library"
HOMEPAGE = "http://libgit2.github.com/"
LICENSE = "GPL-2.0-with-linking-exception"
SRC_URI = "https://github.com/libgit2/libgit2/archive/v${PV}.tar.gz"
LIC_FILES_CHKSUM = "\
file://COPYING;md5=29c24df0df4c2bab5efb8d5a33a73202 \
"
inherit cmake
# CLAR = tests, needs python-native
EXTRA_OECMAKE = "-DBUILD_CLAR=OFF"
BBCLASSEXTEND = "native"

View File

@@ -0,0 +1,3 @@
SRC_URI[md5sum] = "cbf3422d54dd6f55f09855a6eb749f41"
require libgit2.inc

View File

@@ -0,0 +1,5 @@
# cargo tries to build a shared object using several static objects, one of
# which includes the contenst of zlib (zutil.o)
do_configure_prepend () {
export CFLAGS="${CFLAGS} -fPIC"
}

62
recipes/cargo/cargo.inc Normal file
View File

@@ -0,0 +1,62 @@
inherit rust
SUMMARY = "Cargo downloads your Rust project's dependencies and builds your project"
HOMEPAGE = "http://crates.io"
SECTION = "devel"
LICENSE = "MIT | Apache-2.0"
DEPENDS = "openssl-native rust-native zlib-native libgit2-native curl-native"
SRC_URI = "git://github.com/rust-lang/cargo.git;protocol=https"
LIC_FILES_CHKSUM ="\
file://LICENSE-MIT;md5=362255802eb5aa87810d12ddf3cfedb4 \
file://LICENSE-APACHE;md5=1836efb2eb779966696f473ee8540542 \
file://LICENSE-THIRD-PARTY;md5=afbb7ae0aa70c8e437a007314eae5f3b \
"
#PV = "0.0.0+0.0.1-pre+git${SRCPV}"
S = "${WORKDIR}/git"
B = "${S}"
do_patch () {
# Work around a bug in openssl-static-sys
ln -f "${prefix}/../lib/libcrypto.a" "${prefix}/lib/"
}
do_configure () {
"${S}/configure" \
"--prefix=${prefix}" \
"--build=${RUST_BUILD_SYS}" \
"--host=${RUST_HOST_SYS}" \
"--target=${RUST_TARGET_SYS}" \
"--localstatedir=${localstatedir}" \
"--sysconfdir=${sysconfdir}" \
"--datadir=${datadir}" \
"--infodir=${infodir}" \
"--mandir=${mandir}" \
"--libdir=${libdir}"
}
do_compile () {
echo "COMPILE ${PN}"
env
# cargo downloads a cargo snapshot to build itself using cargo, we need
# to override it's arch info.
oe_cargo_config
# FIXME: rustc needs -L flags to know where to look for libs, adding -L
# flags to the linker is not sufficient.
# As a workaround, copy libs locally
local ldep="${S}/target/${RUST_TARGET_SYS}/deps"
mkdir -p "${ldep}"
cp "${libdir}/libz.a" "${ldep}"
export RUST_PATH="${RUST_PATH}"
oe_runmake ARGS="--verbose"
}
do_install () {
oe_runmake DESTDIR="${D}" install
}
BBCLASSEXTEND = "native"

View File

@@ -0,0 +1,3 @@
SRCREV = "2d101e2e3809da5dc6c79c27ad962d7945cddfb5"
require recipes/cargo/cargo.inc

View File

@@ -0,0 +1,5 @@
SRCREV = "0881adf3eef5283bdfc006a23ea907b6529b0027"
# This version doesn't work with rust-0.12.0
DEFAULT_PREFERENCE = "-1"
require recipes/cargo/cargo.inc

View File

@@ -0,0 +1,6 @@
SRCREV = "9788700351f5c236c4e403f28a9156e6ee0b2483"
# This version doesn't work with rust-0.12.0
DEFAULT_PREFERENCE = "-1"
require recipes/cargo/cargo.inc

View File

@@ -0,0 +1,6 @@
SRCREV = "abc712795321d13dcf6839242c476e42d3e211d2"
# This version doesn't work with rust-0.12.0
DEFAULT_PREFERENCE = "-1"
require recipes/cargo/cargo.inc

View File

@@ -0,0 +1,19 @@
SRC_URI = "git://github.com/jmesmon/rust-hello-world.git;protocol=https"
SRCREV="e0fa23f1a3cb1eb1407165bd2fc36d2f6e6ad728"
LIC_FILES_CHKSUM="file://COPYRIGHT;md5=e6b2207ac3740d2d01141c49208c2147"
SUMMARY = "Hello World by Cargo for Rust"
HOMEPAGE = "https://github.com/jmesmon/rust-hello-world"
LICENSE = "MIT | Apache-2.0"
inherit rust
S = "${WORKDIR}/git"
B = "${S}"
do_compile () {
oe_runcargo_build
}
do_install () {
cp ${WORKDIR}/target/* ${D}${bindir}
}

View File

@@ -0,0 +1,9 @@
SRC_URI[md5sum] = "24f80304da2ef1c0362b7caf700390f9"
SRC_URI[sha256sum] = "883e66b24d90d9957c5c538469fcde6f0668e5fb6448beecfc60884060e769b7"
LIC_FILES_CHKSUM ="\
file://COPYRIGHT;md5=0e8e4a3b5d8e1c90eb243d406369763a \
"
SRC_URI_append = "\
file://0001-mk-rt-export-CC-does-not-seem-to-work-gcc-observed-u.patch \
"

View File

@@ -0,0 +1,39 @@
From 74c4900aab22acdb3bff0b7917fbfbe106ec9aec Mon Sep 17 00:00:00 2001
From: Cody P Schafer <dev@codyps.com>
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

112
recipes/rust/rust_0.12.0.bb Normal file
View File

@@ -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