From 1d2b7f4f11205ac4d4f88fdfd78f80fb5d24df95 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Wed, 3 Dec 2014 14:03:38 -0500 Subject: [PATCH] new cargo, rust tweaks, etc --- classes/cargo.bbclass | 4 +- classes/rust.bbclass | 7 ++ recipes/cargo/cargo_2014-12-03.bb | 9 +- ...-custom_build-add-BUILD_KIND-env-var.patch | 59 ++++++++++++ ...-the-CFLAGS-and-CC-variables-for-HOS.patch | 54 ----------- ...amespaced-environment-variables-base.patch | 90 +++++++++++++++++++ recipes/rust/rust.inc | 7 -- 7 files changed, 165 insertions(+), 65 deletions(-) create mode 100644 recipes/cargo/files/0001-custom_build-add-BUILD_KIND-env-var.patch delete mode 100644 recipes/cargo/files/0001-custom_build-map-the-CFLAGS-and-CC-variables-for-HOS.patch create mode 100644 recipes/cargo/files/gcc-rs/0001-Support-use-of-namespaced-environment-variables-base.patch diff --git a/classes/cargo.bbclass b/classes/cargo.bbclass index 89be460..4842766 100644 --- a/classes/cargo.bbclass +++ b/classes/cargo.bbclass @@ -71,8 +71,8 @@ oe_cargo_build () { cargo_do_compile () { cd "${B}" - export CC="${RUST_CC}" - export CFLAGS="${RUST_CFLAGS}" + export TARGET_CC="${RUST_CC}" + export TARGET_CFLAGS="${RUST_CFLAGS}" export HOST_CC="${RUST_BUILD_CC}" export HOST_CFLAGS="${RUST_BUILD_CFLAGS}" oe_cargo_build diff --git a/classes/rust.bbclass b/classes/rust.bbclass index 332e580..234cad9 100644 --- a/classes/rust.bbclass +++ b/classes/rust.bbclass @@ -73,3 +73,10 @@ 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}" +HOST_CFLAGS ?= "${CFLAGS}" +HOST_CXXFLAGS ?= "${CXXFLAGS}" +HOST_CPPFLAGS ?= "${CPPFLAGS}" diff --git a/recipes/cargo/cargo_2014-12-03.bb b/recipes/cargo/cargo_2014-12-03.bb index e461c95..d20c49e 100644 --- a/recipes/cargo/cargo_2014-12-03.bb +++ b/recipes/cargo/cargo_2014-12-03.bb @@ -2,7 +2,7 @@ SRCREV_cargo = "a0f0abca4f718e36ddc7cc23f9bce4c51d93cbe5" require cargo.inc SRC_URI += " \ - file://0001-custom_build-map-the-CFLAGS-and-CC-variables-for-HOS.patch \ + file://0001-custom_build-add-BUILD_KIND-env-var.patch \ \ git://github.com/carllerche/curl-rust.git;protocol=https;name=curl-rust;destsuffix=curl-rust \ file://curl-rust/0001-curl-sys-avoid-explicitly-linking-in-openssl-If-it-.patch;patchdir=../curl-rust \ @@ -10,12 +10,17 @@ SRC_URI += " \ \ git://github.com/alexcrichton/ssh2-rs.git;protocol=https;name=ssh2-rs;destsuffix=ssh2-rs \ file://ssh2-rs/0001-Unconditionally-depend-on-openssl-sys.patch;patchdir=../ssh2-rs \ +\ + git://github.com/alexcrichton/gcc-rs.git;protocol=https;name=gcc-rs;destsuffix=gcc-rs \ + file://gcc-rs/0001-Support-use-of-namespaced-environment-variables-base.patch;patchdir=../gcc-rs \ " SRCREV_curl-rust = "5d0f5c8848e3cf1e12480a1923ae888e24d58f63" SRCREV_ssh2-rs = "490f91fb9e90bf4e305f1a23a051228c59e60eaf" -SRCREV_FORMAT = "cargo_curl-rust_ssh2-rs" +SRCREV_gcc-rs = "d32b24466d3e0094cef1c1809a04d7a28536f0e0" +SRCREV_FORMAT = "cargo_curl-rust_ssh2-rs_gcc-rs" EXTRA_OECARGO_PATHS = "\ ${WORKDIR}/curl-rust \ ${WORKDIR}/ssh2-rs \ + ${WORKDIR}/gcc-rs \ " diff --git a/recipes/cargo/files/0001-custom_build-add-BUILD_KIND-env-var.patch b/recipes/cargo/files/0001-custom_build-add-BUILD_KIND-env-var.patch new file mode 100644 index 0000000..a04f18b --- /dev/null +++ b/recipes/cargo/files/0001-custom_build-add-BUILD_KIND-env-var.patch @@ -0,0 +1,59 @@ +From ccbbb148c237bbd6bfb8b98e34fb3ad8404348f0 Mon Sep 17 00:00:00 2001 +From: Cody P Schafer +Date: Wed, 3 Dec 2014 13:09:46 -0500 +Subject: [PATCH] custom_build: add BUILD_KIND env var + +--- + src/cargo/ops/cargo_rustc/custom_build.rs | 6 +++++- + src/doc/build-script.md | 3 +++ + tests/test_cargo_compile_custom_build.rs | 3 +++ + 3 files changed, 11 insertions(+), 1 deletion(-) + +diff --git a/src/cargo/ops/cargo_rustc/custom_build.rs b/src/cargo/ops/cargo_rustc/custom_build.rs +index 6791e66..b0d2bf7 100644 +--- a/src/cargo/ops/cargo_rustc/custom_build.rs ++++ b/src/cargo/ops/cargo_rustc/custom_build.rs +@@ -61,7 +61,11 @@ pub fn prepare(pkg: &Package, target: &Target, req: Platform, + })) + .env("DEBUG", Some(profile.get_debug().to_string())) + .env("OPT_LEVEL", Some(profile.get_opt_level().to_string())) +- .env("PROFILE", Some(profile.get_env())); ++ .env("PROFILE", Some(profile.get_env())) ++ .env("BUILD_KIND", Some(match kind { ++ Kind::Host => "HOST", ++ Kind::Target => "TARGET", ++ })); + + // Be sure to pass along all enabled features for this package, this is the + // last piece of statically known information that we have. +diff --git a/src/doc/build-script.md b/src/doc/build-script.md +index f5ece41..34de9cd 100644 +--- a/src/doc/build-script.md ++++ b/src/doc/build-script.md +@@ -43,6 +43,9 @@ all passed in the form of environment variables: + * `TARGET` - the target triple that is being compiled for. Native code should be + compiled for this triple. Some more information about target + triples can be found in [clang's own documentation][clang]. ++* `BUILD_KIND` - the kind of the build, one of "TARGET" or "HOST". Use ++ discretion when utilizing this, very often the `TARGET` ++ variable is preferable. + * `NUM_JOBS` - the parallelism specified as the top-level parallelism. This can + be useful to pass a `-j` parameter to a system like `make`. + * `CARGO_MANIFEST_DIR` - The directory containing the manifest for the package +diff --git a/tests/test_cargo_compile_custom_build.rs b/tests/test_cargo_compile_custom_build.rs +index 9ea71f0..1dd3c6b 100644 +--- a/tests/test_cargo_compile_custom_build.rs ++++ b/tests/test_cargo_compile_custom_build.rs +@@ -99,6 +99,9 @@ test!(custom_build_env_vars { + assert!(out.as_slice().starts_with(r"{0}")); + assert!(Path::new(out).is_dir()); + ++ let kind = os::getenv("BUILD_KIND").unwrap(); ++ assert_eq!(kind.as_slice(), "TARGET"); ++ + let _feat = os::getenv("CARGO_FEATURE_FOO").unwrap(); + }} + "#, +-- +2.1.3 + diff --git a/recipes/cargo/files/0001-custom_build-map-the-CFLAGS-and-CC-variables-for-HOS.patch b/recipes/cargo/files/0001-custom_build-map-the-CFLAGS-and-CC-variables-for-HOS.patch deleted file mode 100644 index 0b1d34c..0000000 --- a/recipes/cargo/files/0001-custom_build-map-the-CFLAGS-and-CC-variables-for-HOS.patch +++ /dev/null @@ -1,54 +0,0 @@ -From fdfb4d60b8aed0b99ba3615286767fb11d5ef361 Mon Sep 17 00:00:00 2001 -From: Cody P Schafer -Date: Tue, 2 Dec 2014 23:24:14 -0500 -Subject: [PATCH] custom_build: map the CFLAGS and CC variables for HOST builds - -If a build.rs script uses gcc-rs, CC and CFLAGS are used to find the -c compiler and flags. Often, host & target will have different flags -and compilers. - -Without this mapping (which allows the use of HOST_CC and HOST_CFLAGS), -it was imposible to specify the compiler and cflags to use for the host -while doing cross builds, and gcc-rs would attempt to use the target -compiler and cflags, typically failing. - -We preserve the previous behavoir when the HOST_CC and HOST_CFLAGS -variables are unset, though I'm not sure if this is a good idea unless -host happens to equal target. We may want to restrict the fallback in -the future. ---- - src/cargo/ops/cargo_rustc/custom_build.rs | 11 ++++++++++- - 1 file changed, 10 insertions(+), 1 deletion(-) - -diff --git a/src/cargo/ops/cargo_rustc/custom_build.rs b/src/cargo/ops/cargo_rustc/custom_build.rs -index 6791e66..3f6789c 100644 ---- a/src/cargo/ops/cargo_rustc/custom_build.rs -+++ b/src/cargo/ops/cargo_rustc/custom_build.rs -@@ -4,6 +4,7 @@ use std::io::fs::PathExtensions; - use std::io::{fs, USER_RWX, File}; - use std::str; - use std::sync::Mutex; -+use std::os; - - use core::{Package, Target, PackageId, PackageSet}; - use util::{CargoResult, CargoError, human}; -@@ -61,7 +62,15 @@ pub fn prepare(pkg: &Package, target: &Target, req: Platform, - })) - .env("DEBUG", Some(profile.get_debug().to_string())) - .env("OPT_LEVEL", Some(profile.get_opt_level().to_string())) -- .env("PROFILE", Some(profile.get_env())); -+ .env("PROFILE", Some(profile.get_env())) -+ .env("CC", match kind { -+ Kind::Host => os::getenv("HOST_CC").or(os::getenv("CC")), -+ Kind::Target => os::getenv("CC") -+ }) -+ .env("CFLAGS", match kind { -+ Kind::Host => os::getenv("HOST_CFLAGS").or(os::getenv("CFLAGS")), -+ Kind::Target => os::getenv("CFLAGS"), -+ }); - - // Be sure to pass along all enabled features for this package, this is the - // last piece of statically known information that we have. --- -2.0.4 - diff --git a/recipes/cargo/files/gcc-rs/0001-Support-use-of-namespaced-environment-variables-base.patch b/recipes/cargo/files/gcc-rs/0001-Support-use-of-namespaced-environment-variables-base.patch new file mode 100644 index 0000000..3c47ca2 --- /dev/null +++ b/recipes/cargo/files/gcc-rs/0001-Support-use-of-namespaced-environment-variables-base.patch @@ -0,0 +1,90 @@ +From 364ff39932c6281cb90c5ebe8c9fd04e7b05a1f3 Mon Sep 17 00:00:00 2001 +From: Cody P Schafer +Date: Wed, 3 Dec 2014 13:41:11 -0500 +Subject: [PATCH] Support use of namespaced environment variables based on + target triplet and BUILD_KIND + +--- + README.md | 25 +++++++++++++++++++++++++ + src/lib.rs | 18 +++++++++++++++--- + 2 files changed, 40 insertions(+), 3 deletions(-) + +diff --git a/README.md b/README.md +index bb7047d..73b72d7 100644 +--- a/README.md ++++ b/README.md +@@ -11,6 +11,31 @@ fn main() { + } + ``` + ++# External configuration via environment variables ++ ++To control the programs and flags used for building, the builder can set a number of different enviroment variables. ++* `CFLAGS` - a series of space seperated flags passed to "gcc". Note that ++ individual flags cannot currently contain spaces, so doing ++ something like: "-L=foo\ bar" is not possible. ++* `CC` - the actual c compiler used. Note that this is used as an exact ++ executable name, so (for example) no extra flags can be passed inside ++ this variable, and the builder must ensure that there aren't any ++ trailing spaces. This compiler must understand the `-c` flag. For ++ certain `TARGET`s, it also is assumed to know about other flags (most ++ common is `-fPIC`). ++* `AR` - the `ar` (archiver) executable to use to build the static library. ++ ++Each of these variables can also be supplied with certain prefixes and suffixes, in the following prioritized order: ++ ++1. `_` - for example, `CC_x86_64-unknown-linux-gnu` ++1. `_` - for example, `CC_x86_64_unknown_linux_gnu` ++1. `_` - for example, `HOST_CC` or `TARGET_CFLAGS` ++1. `` - a plain `CC`, `AR` as above. ++ ++If none of these varaibles exist, gcc-rs uses built-in defaults ++ ++In addition to the the above optional environment variables, `gcc-rs` has some functions with hard requirements on some variables supplied by [cargo's build-script driver][cargo] that it has the `TARGET`, `OUT_DIR`, `OPT_LEVEL`, and `BUILD_KIND` variables ++ + # Windows notes + + Currently use of this crate means that Windows users will require gcc to be +diff --git a/src/lib.rs b/src/lib.rs +index 51157c8..ffd5aef 100644 +--- a/src/lib.rs ++++ b/src/lib.rs +@@ -109,8 +109,20 @@ fn run(cmd: &mut Command) { + } + } + ++fn get_var(var_base: &str) -> Option { ++ let target = os::getenv("TARGET").unwrap(); ++ let target_u = target.split('-') ++ .collect::>() ++ .connect("_"); ++ let kind = os::getenv("BUILD_KIND").unwrap(); ++ os::getenv(format!("{}_{}", var_base, target).as_slice()) ++ .or_else(|| os::getenv(format!("{}_{}", var_base, target_u).as_slice())) ++ .or_else(|| os::getenv(format!("{}_{}", kind, var_base).as_slice())) ++ .or_else(|| os::getenv(var_base)) ++} ++ + fn gcc() -> String { +- os::getenv("CC").unwrap_or(if cfg!(windows) { ++ get_var("CC").unwrap_or(if cfg!(windows) { + "gcc".to_string() + } else { + "cc".to_string() +@@ -118,11 +130,11 @@ fn gcc() -> String { + } + + fn ar() -> String { +- os::getenv("AR").unwrap_or("ar".to_string()) ++ get_var("AR").unwrap_or("ar".to_string()) + } + + fn cflags() -> Vec { +- os::getenv("CFLAGS").unwrap_or(String::new()) ++ get_var("CFLAGS").unwrap_or(String::new()) + .as_slice().words().map(|s| s.to_string()) + .collect() + } +-- +2.1.3 + diff --git a/recipes/rust/rust.inc b/recipes/rust/rust.inc index 9aa1e15..b3dc0e4 100644 --- a/recipes/rust/rust.inc +++ b/recipes/rust/rust.inc @@ -47,13 +47,6 @@ TARGET_ENDIAN[i586] = "little" TARGET_WORD_SIZE[i586] = "32" PRE_LINK_ARGS[i586] = "-Wl,--as-needed -m32" -# 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}" -HOST_CFLAGS ?= "${CFLAGS}" -HOST_CXXFLAGS ?= "${CXXFLAGS}" -HOST_CPPFLAGS ?= "${CPPFLAGS}" - # XXX: BITBAKE-BUG: *_PRE_LINK_ARGS used to be set via function invocation, but # that caused bitbake to error on users of these variables without any # backtrace or error message other than "failed" (of some form or another).