diff mbox series

makewrappers: Allow the wrapper architecture to be set for cross builds

Message ID 20261029135701.300718-1-sunilkumar.dora@windriver.com
State New
Headers show
Series makewrappers: Allow the wrapper architecture to be set for cross builds | expand

Commit Message

Dora, Sunil Kumar Oct. 29, 2026, 1:57 p.m. UTC
From: Sunil Dora <sunilkumar.dora@windriver.com>

Architecture specific modifiers in wrapfuncs.in, such as
version-aarch64="GLIBC_2.17" on the xattr wrappers, are selected with
platform.machine(), so they follow the machine running the script
rather than the one pseudo is built for. An aarch64 pseudo cross built
on x86_64 ends up with GLIBC_2.3 and the reverse with GLIBC_2.17, which
shows up as pseudo not being reproducible between x86_64 and aarch64
builders.

Add a MAKEWRAPPERS_ARCH variable the build can set and pass it through
from the Makefile. Unset, the build machine is used as before.

[YOCTO #16376]

Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
---
 Makefile.in  | 5 ++++-
 makewrappers | 9 +++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

Comments

Mark Hatle Oct. 29, 2026, 2:43 p.m. UTC | #1
I would prefer that the configure script is modified with an optional --target= 
value.  This value can then feed through as appropriate.

This way if a user passed ./configure --target=aarch64-foo-linux-gnu ... it'll 
do the things necessary for that.

Then in the other components we can split between target and build host (if 
necessary) behavior.

I don't have much of an opinion on MAKEWRAPPERS_ARCH and the way it's passed 
through the environment to makewrappers, but it does feel a bit strange.  I'm 
wondering if makewrappers would be better if it also took an optional target= 
argument instead of using the environment.

This would result in something like:

configure:

     echo >&2 "usage:"
     echo >&2 "  configure --prefix=..."
     echo >&2 "           [--libdir=...]"
     echo >&2 "           [--suffix=...]"
+   echo >&2 "           [--target=...]"
     echo >&2 "           [--enable-memory-db]"
     echo >&2 "           [--enable-epoll]"
     echo >&2 "           [--enable-xattr]"

target (if set) sends up in "opt_target", which is used to replace @TARGET@ in 
the Makefile.in.


In Makefile.in:

  ARCH_FLAGS=@ARCH_FLAGS@
  MARK64=@MARK64@
  RPATH=@RPATH@
+TARGET_ARCH=@TARGET@
  VERSION=1.99.0

  LIB=@LIB@


  wrappers: makewrappers templatefile.py $(TEMPLATES) ports/*/wrapfuncs.in
-	CC="$(CC) $(CFLAGS) $(CFLAGS_PSEUDO)" ./makewrappers "xattr=$(XATTR)"
+	CC="$(CC) $(CFLAGS) $(CFLAGS_PSEUDO)" ./makewrappers --target=$(TARGET 
"xattr=$(XATTR)"


makewrappers:

def main(argv):
     """Read in function definitions, write out files based on templates."""
     funcs = []
     sources = []

     for arg in argv:
         if arg.startswith('--'):
             # Check here for --target, set global for target
             continue
         if '=' not in arg:
             print("Invalid argument '%s', must be of the form name=value" % arg)
             exit(1)
         name, value = arg.split('=')
         os.environ["port_" + name] = value

Adjust wrapper_arch function in your change to use the new global.

--Mark

On 10/29/26 8:57 AM, Dora, Sunil Kumar via lists.yoctoproject.org wrote:
> From: Sunil Dora <sunilkumar.dora@windriver.com>
> 
> Architecture specific modifiers in wrapfuncs.in, such as
> version-aarch64="GLIBC_2.17" on the xattr wrappers, are selected with
> platform.machine(), so they follow the machine running the script
> rather than the one pseudo is built for. An aarch64 pseudo cross built
> on x86_64 ends up with GLIBC_2.3 and the reverse with GLIBC_2.17, which
> shows up as pseudo not being reproducible between x86_64 and aarch64
> builders.
> 
> Add a MAKEWRAPPERS_ARCH variable the build can set and pass it through
> from the Makefile. Unset, the build machine is used as before.
> 
> [YOCTO #16376]
> 
> Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
> ---
>   Makefile.in  | 5 ++++-
>   makewrappers | 9 +++++++--
>   2 files changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/Makefile.in b/Makefile.in
> index 6640a73..bc2ab92 100644
> --- a/Makefile.in
> +++ b/Makefile.in
> @@ -34,6 +34,9 @@ BITS=@BITS@
>   ARCH_FLAGS=@ARCH_FLAGS@
>   MARK64=@MARK64@
>   RPATH=@RPATH@
> +# Architecture the wrappers are generated for, as a uname -m name.
> +# Empty means the build machine; set it when cross compiling.
> +MAKEWRAPPERS_ARCH ?=
>   VERSION=1.99.0
>   
>   LIB=@LIB@
> @@ -146,7 +149,7 @@ tables: enums/*.in maketables templatefile.py $(TABLES)
>   	./maketables enums/*.in
>   
>   wrappers: makewrappers templatefile.py $(TEMPLATES) ports/*/wrapfuncs.in
> -	CC="$(CC) $(CFLAGS) $(CFLAGS_PSEUDO)" ./makewrappers "xattr=$(XATTR)"
> +	CC="$(CC) $(CFLAGS) $(CFLAGS_PSEUDO)" MAKEWRAPPERS_ARCH="$(MAKEWRAPPERS_ARCH)" ./makewrappers "xattr=$(XATTR)"
>   
>   .SECONDARY: tables wrappers
>   
> diff --git a/makewrappers b/makewrappers
> index 19508fa..c90f5c7 100755
> --- a/makewrappers
> +++ b/makewrappers
> @@ -15,6 +15,10 @@ import platform
>   import subprocess
>   from templatefile import TemplateFile
>   
> +def wrapper_arch():
> +    """Architecture the wrappers are built for: MAKEWRAPPERS_ARCH or the build machine."""
> +    return os.environ.get("MAKEWRAPPERS_ARCH", "").strip() or platform.machine()
> +
>   class ArgumentList:
>       """A (possibly empty) list of arguments"""
>   
> @@ -319,11 +323,11 @@ class Function:
>               # Strip all leading/trailing whitespace
>               modifiers = {k.strip():v.strip() for k, v in modifiers.items()}
>   
> -            arch = "-" + platform.machine()
> +            arch = "-" + wrapper_arch()
>               # Sorted so that versions-foo appear after versions, so overrides are easy
>               for key in sorted(modifiers):
>                   value = modifiers[key].replace('<equals>', '==')
> -                # If the key is version-arm64 and we're on arm64 then rename this to version
> +                # If the key is version-arm64 and we're building for arm64 then rename this to version
>                   if key.endswith(arch):
>                       key = key.replace(arch, "")
>                   setattr(self, key, value)
> @@ -702,6 +706,7 @@ def main(argv):
>       port = Port('common', sources)
>   
>       # the per-function stuff
> +    print("Architecture for wrapper modifiers: %s" % wrapper_arch())
>       print("Writing functions...")
>       all_funcs = port.functions()
>       for name in sorted(all_funcs.keys()):
Dora, Sunil Kumar Oct. 29, 2026, 4:15 p.m. UTC | #2
Thanks Mark. Will do in v2.

~Sunil
diff mbox series

Patch

diff --git a/Makefile.in b/Makefile.in
index 6640a73..bc2ab92 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -34,6 +34,9 @@  BITS=@BITS@
 ARCH_FLAGS=@ARCH_FLAGS@
 MARK64=@MARK64@
 RPATH=@RPATH@
+# Architecture the wrappers are generated for, as a uname -m name.
+# Empty means the build machine; set it when cross compiling.
+MAKEWRAPPERS_ARCH ?=
 VERSION=1.99.0
 
 LIB=@LIB@
@@ -146,7 +149,7 @@  tables: enums/*.in maketables templatefile.py $(TABLES)
 	./maketables enums/*.in
 
 wrappers: makewrappers templatefile.py $(TEMPLATES) ports/*/wrapfuncs.in
-	CC="$(CC) $(CFLAGS) $(CFLAGS_PSEUDO)" ./makewrappers "xattr=$(XATTR)"
+	CC="$(CC) $(CFLAGS) $(CFLAGS_PSEUDO)" MAKEWRAPPERS_ARCH="$(MAKEWRAPPERS_ARCH)" ./makewrappers "xattr=$(XATTR)"
 
 .SECONDARY: tables wrappers
 
diff --git a/makewrappers b/makewrappers
index 19508fa..c90f5c7 100755
--- a/makewrappers
+++ b/makewrappers
@@ -15,6 +15,10 @@  import platform
 import subprocess
 from templatefile import TemplateFile
 
+def wrapper_arch():
+    """Architecture the wrappers are built for: MAKEWRAPPERS_ARCH or the build machine."""
+    return os.environ.get("MAKEWRAPPERS_ARCH", "").strip() or platform.machine()
+
 class ArgumentList:
     """A (possibly empty) list of arguments"""
 
@@ -319,11 +323,11 @@  class Function:
             # Strip all leading/trailing whitespace
             modifiers = {k.strip():v.strip() for k, v in modifiers.items()}
 
-            arch = "-" + platform.machine()
+            arch = "-" + wrapper_arch()
             # Sorted so that versions-foo appear after versions, so overrides are easy
             for key in sorted(modifiers):
                 value = modifiers[key].replace('<equals>', '==')
-                # If the key is version-arm64 and we're on arm64 then rename this to version
+                # If the key is version-arm64 and we're building for arm64 then rename this to version
                 if key.endswith(arch):
                     key = key.replace(arch, "")
                 setattr(self, key, value)
@@ -702,6 +706,7 @@  def main(argv):
     port = Port('common', sources)
 
     # the per-function stuff
+    print("Architecture for wrapper modifiers: %s" % wrapper_arch())
     print("Writing functions...")
     all_funcs = port.functions()
     for name in sorted(all_funcs.keys()):