summaryrefslogtreecommitdiff
path: root/upstream-layers/meta-openembedded/meta-python/recipes-devtools/python/python3-autobahn/0001-Skip-march-guessing-for-external-cross-toolchains.patch
blob: 8f2e8f0d0157a68596844e8903727e4ff1bf5bfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
From c677aa7a80fd551abb391a8f6abd28dc9f5c43a2 Mon Sep 17 00:00:00 2001
From: Leon Anavi <leon.anavi@konsulko.com>
Date: Mon, 20 Jul 2026 15:52:32 +0300
Subject: [PATCH] Skip -march guessing for external cross toolchains

Don't add -march flag when CC/CROSS_COMPILE names an external cross
toolchain (Yocto/OpenEmbedded, Buildroot, ...). These already
inject the correct target. Avoid issues such as an unknown value
'x86-64-v2' for '-march' when cross compiling for ARM machine.

Upstream-Status: Pending [https://github.com/crossbario/autobahn-python/pull/1934]

Signed-off-by: Leon Anavi <leon.anavi@konsulko.com>
---
 src/autobahn/nvx/_compile_args.py | 36 ++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/src/autobahn/nvx/_compile_args.py b/src/autobahn/nvx/_compile_args.py
index 2a35ab31..173e5fd4 100644
--- a/src/autobahn/nvx/_compile_args.py
+++ b/src/autobahn/nvx/_compile_args.py
@@ -81,6 +81,10 @@ CIBUILDWHEEL : str, optional
 AUDITWHEEL_PLAT : str, optional
     Set by auditwheel/manylinux builds. Indicates wheel build.
 
+CC, CROSS_COMPILE : str, optional
+    If either names a triplet-prefixed compiler (e.g. "aarch64-poky-linux-gcc"),
+    an external cross toolchain is assumed and no -march flag is added.
+
 Examples
 --------
 
@@ -212,9 +216,6 @@ def get_compile_args():
         # But default codegen is already optimized for current arch
         return ["/O2", "/W3"]
 
-    # GCC/Clang on POSIX (Linux, macOS, *BSD)
-    machine = _get_target_machine()
-
     # Base flags for all POSIX platforms
     base_args = [
         "-std=c99",
@@ -233,6 +234,14 @@ def get_compile_args():
         # deployments). It is NOT safe for distributed wheels or cross-compilation.
         return base_args + ["-march=native"]
 
+    if _is_external_toolchain():
+        # Cross toolchain (Yocto/OpenEmbedded, Buildroot, ...) already sets its
+        # own -march/-mtune; don't second-guess it (#1930).
+        return base_args
+
+    # GCC/Clang on POSIX (Linux, macOS, *BSD)
+    machine = _get_target_machine()
+
     # Default for everyone (AUTOBAHN_ARCH_TARGET unset or "safe"): a portable
     # baseline architecture. Defaulting to "safe" rather than -march=native is
     # what makes cross-compilation work out of the box - a cross toolchain
@@ -248,6 +257,27 @@ def get_compile_args():
     return base_args
 
 
+def _is_external_toolchain():
+    """
+    True if ``CC`` or ``CROSS_COMPILE`` names a triplet-prefixed compiler (e.g.
+    ``aarch64-poky-linux-gcc``), the convention used by externally managed
+    toolchains such as Yocto/OpenEmbedded and Buildroot.
+
+    Returns
+    -------
+    bool
+        True if an externally managed cross toolchain is detected.
+    """
+    for var in ("CC", "CROSS_COMPILE"):
+        value = os.environ.get(var, "")
+        if not value:
+            continue
+        exe = os.path.basename(value.split()[0])
+        if "-" in exe:
+            return True
+    return False
+
+
 def _get_target_machine():
     """
     Return the *target* machine architecture for the build.
-- 
2.43.0