From 7645b9b3312d9a900b2929f3db01a23b7a8b5f24 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Mon, 21 Nov 2016 14:55:54 -0600 Subject: [PATCH 1/4] RUSTC_ARCHFLAGS: build for the proper system triple Change to build for the machine we are building for when compiling rust code and not the compiler itself. See #109. --- classes/rust.bbclass | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/rust.bbclass b/classes/rust.bbclass index 15299b2..bab2dfa 100644 --- a/classes/rust.bbclass +++ b/classes/rust.bbclass @@ -2,7 +2,7 @@ inherit rust-vars RUSTC = "rustc" -RUSTC_ARCHFLAGS += "--target=${TARGET_SYS} ${RUSTFLAGS}" +RUSTC_ARCHFLAGS += "--target=${HOST_SYS} ${RUSTFLAGS}" def rust_base_dep(d): # Taken from meta/classes/base.bbclass `base_dep_prepend` and modified to From 0b6b45fbcab7894f15b999fe54953f507614acf1 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Mon, 21 Nov 2016 15:12:34 -0600 Subject: [PATCH 2/4] break the triples logic into its own class This is so we can use the Rust triples in Cargo builds and other places in addition to the Rust build. --- classes/rust-triples.bbclass | 31 +++++++++++++++++++++++++++++++ classes/rust.bbclass | 31 +------------------------------ 2 files changed, 32 insertions(+), 30 deletions(-) create mode 100644 classes/rust-triples.bbclass diff --git a/classes/rust-triples.bbclass b/classes/rust-triples.bbclass new file mode 100644 index 0000000..6833762 --- /dev/null +++ b/classes/rust-triples.bbclass @@ -0,0 +1,31 @@ +# Responseible for taking Yocto triples and converting it to Rust triples + +def rust_base_triple(d, thing): + ''' + Mangle bitbake's *_SYS into something that rust might support (see + rust/mk/cfg/* for a list) + + Note that os is assumed to be some linux form + ''' + + arch = d.getVar('{}_ARCH'.format(thing), True) + vendor = d.getVar('{}_VENDOR'.format(thing), True) + os = d.getVar('{}_OS'.format(thing), True) + + vendor = "-unknown" + + if arch.startswith("arm"): + if os.endswith("gnueabi"): + os += bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'hf', '', d) + elif arch.startswith("aarch64"): + os = "linux-gnu" + elif arch.startswith("x86_64"): + os = "linux-gnu" + elif arch.startswith("i586"): + arch = "i686" + os = "linux-gnu" + return arch + vendor + '-' + os + +RUST_BUILD_SYS = "${@rust_base_triple(d, 'BUILD')}" +RUST_HOST_SYS = "${@rust_base_triple(d, 'HOST')}" +RUST_TARGET_SYS = "${@rust_base_triple(d, 'TARGET')}" diff --git a/classes/rust.bbclass b/classes/rust.bbclass index bab2dfa..0809186 100644 --- a/classes/rust.bbclass +++ b/classes/rust.bbclass @@ -1,4 +1,5 @@ inherit rust-vars +inherit rust-triples RUSTC = "rustc" @@ -17,36 +18,6 @@ def rust_base_dep(d): DEPENDS_append = " ${@rust_base_dep(d)} patchelf-native" -def rust_base_triple(d, thing): - ''' - Mangle bitbake's *_SYS into something that rust might support (see - rust/mk/cfg/* for a list) - - Note that os is assumed to be some linux form - ''' - - arch = d.getVar('{}_ARCH'.format(thing), True) - vendor = d.getVar('{}_VENDOR'.format(thing), True) - os = d.getVar('{}_OS'.format(thing), True) - - vendor = "-unknown" - - if arch.startswith("arm"): - if os.endswith("gnueabi"): - os += bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'hf', '', d) - elif arch.startswith("aarch64"): - os = "linux-gnu" - elif arch.startswith("x86_64"): - os = "linux-gnu" - elif arch.startswith("i586"): - arch = "i686" - os = "linux-gnu" - return arch + vendor + '-' + os - -RUST_BUILD_SYS = "${@rust_base_triple(d, 'BUILD')}" -RUST_HOST_SYS = "${@rust_base_triple(d, 'HOST')}" -RUST_TARGET_SYS = "${@rust_base_triple(d, 'TARGET')}" - # BUILD_LDFLAGS # ${STAGING_LIBDIR_NATIVE} # ${STAGING_BASE_LIBDIR_NATIVE} From 5d60f129570163dfbcc4dedd6331876d09b0a360 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Mon, 21 Nov 2016 15:38:32 -0600 Subject: [PATCH 3/4] rust-triples: simplify vendor gathering We don't need to look up the vendor since it will always be unknown. --- classes/rust-triples.bbclass | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/classes/rust-triples.bbclass b/classes/rust-triples.bbclass index 6833762..6b781ae 100644 --- a/classes/rust-triples.bbclass +++ b/classes/rust-triples.bbclass @@ -9,10 +9,9 @@ def rust_base_triple(d, thing): ''' arch = d.getVar('{}_ARCH'.format(thing), True) - vendor = d.getVar('{}_VENDOR'.format(thing), True) - os = d.getVar('{}_OS'.format(thing), True) - + # All the Yocto targets are Linux and are 'unknown' vendor = "-unknown" + os = d.getVar('{}_OS'.format(thing), True) if arch.startswith("arm"): if os.endswith("gnueabi"): From 957ede76f8ccabdb6d35b90e37122af57605fd1b Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Mon, 21 Nov 2016 15:53:16 -0600 Subject: [PATCH 4/4] convert to real Rust triples properly This should fix conversion to real Rust triples for musl targets, for i686 targets and possibly others. --- classes/rust-triples.bbclass | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/classes/rust-triples.bbclass b/classes/rust-triples.bbclass index 6b781ae..1f67775 100644 --- a/classes/rust-triples.bbclass +++ b/classes/rust-triples.bbclass @@ -12,18 +12,24 @@ def rust_base_triple(d, thing): # All the Yocto targets are Linux and are 'unknown' vendor = "-unknown" os = d.getVar('{}_OS'.format(thing), True) + libc = d.getVar('TCLIBC', True) - if arch.startswith("arm"): - if os.endswith("gnueabi"): - os += bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'hf', '', d) - elif arch.startswith("aarch64"): - os = "linux-gnu" - elif arch.startswith("x86_64"): - os = "linux-gnu" - elif arch.startswith("i586"): - arch = "i686" - os = "linux-gnu" - return arch + vendor + '-' + os + # Prefix with a dash and convert glibc -> gnu + if libc == "glibc": + libc = "-gnu" + elif libc == "musl": + libc = "-musl" + + # Don't double up musl (only appears to be the case on aarch64) + if os == "linux-musl": + if libc != "-musl": + bb.fatal("{}_OS was '{}' but TCLIBC was not 'musl'".format(thing, os)) + os = "linux" + + # This catches ARM targets and appends the necessary hard float bits + if os == "linux-gnueabi" or os == "linux-musleabi": + libc = bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'hf', '', d) + return arch + vendor + '-' + os + libc RUST_BUILD_SYS = "${@rust_base_triple(d, 'BUILD')}" RUST_HOST_SYS = "${@rust_base_triple(d, 'HOST')}"