This patch is a workaround for 
https://bugzilla.yoctoproject.org/show_bug.cgi?id=15976

cc-rs crate is used by a number of projects, including rust's bootstrap also
to invoke the systems c/c++ compiler.

A few updates ago it has changed the way CFLAGS/CXXFLAGS are handled: it now
merges them with HOST_C*FLAGS and TARGET_C*FLAGS.

This is a problem when a recipe is cross compiled, but it has a build dependency
which uses this crate to be built. In this case the C*FLAGS variable contains
target flags, while the HOST_C*FLAGS contains host-specific flags, and when the
two are mixed, the output is not what one expects.

This change tries to filter out the incorrect flags:
- If the wrapper is invoked as a c or c++ compiler wrapper,
- then determine if it compiles for host or for target
- Depending on the above, it considers the TARGET_*FLAGS or HOST_*FLAGS
  correct, and the C*FLAGS variable content incorrect.
- It subtracts the correct set from the incorrect set, and drops the
  remainder from the compiler flags. (Which might be often an empty list, so
  the flags are frequently unchanged)

Signed-off-by: Gyorgy Sarvari <[email protected]>
---

v2: add empty string fallback value to os.getenv calls, shift code inside if 
block

 meta/classes-recipe/rust-common.bbclass | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/meta/classes-recipe/rust-common.bbclass 
b/meta/classes-recipe/rust-common.bbclass
index 31331c7a26..dedd1cd557 100644
--- a/meta/classes-recipe/rust-common.bbclass
+++ b/meta/classes-recipe/rust-common.bbclass
@@ -148,6 +148,27 @@ create_wrapper_rust () {
 
        binary = orig_binary.split()[0]
        args = orig_binary.split() + sys.argv[1:]
+
+       # The following is trying to be a workaround for
+       # https://bugzilla.yoctoproject.org/show_bug.cgi?id=15976
+       # cc-rs crate passes both host AND target flags at the same time
+       # to this script, in case a recipe is cross-compiled, but a crate
+       # is a build dependency, and is compiled for the host.
+       # This tries to filter out the inappropriate flags.
+       if sys.argv[0].endswith("-cc"):
+           script_type = "C"
+       elif sys.argv[0].endswith("-cxx"):
+           script_type = "CXX"
+       else:
+           script_type = "other"
+
+       if script_type != "other":
+           host_or_target = "HOST" if "build-rust-" in sys.argv[0] else 
"TARGET"
+           incorrect_flags = os.getenv("%sFLAGS" % script_type, "").split()
+           correct_flags = os.getenv("%s_%sFLAGS" % (host_or_target, 
script_type), "").split()
+           flags_to_remove = set(incorrect_flags) - set(correct_flags)
+           args = list(filter(lambda flag: flag not in flags_to_remove, args))
+
        if extras:
            args.append(extras)
        os.execvp(binary, args)
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#226640): 
https://lists.openembedded.org/g/openembedded-core/message/226640
Mute This Topic: https://lists.openembedded.org/mt/116399710/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to