All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] tools/python: Correct extension filenames for Python 3
@ 2020-10-01 22:19 Elliott Mitchell
  0 siblings, 0 replies; only message in thread
From: Elliott Mitchell @ 2020-10-01 22:19 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson, Wei Liu, Marek Marczykowski-Górecki

Python distutils really looks like between 2 and 3, it took two steps
forward and then two steps backward.

First, it broke the linking step off of the compile step.  Thus CC and
LDSHARED were separated, thus CFLAGS and LDFLAGS were separated.  A
substantial step forwards.  Yet then CFLAGS was appended to LDFLAGS,
meaning LDSHARED needed to be able to accept CFLAGS as arguments.  Thus
effectively reuniting them.

Second, now distutils includes the host type in the object file area and
the full host triplet in the shared object name.  As such now a
filesystem can be shared by hosts with distinct architectures.  Great for
mixed environments.  Yet the build machine architecture/triplet is
assumed to be the runtime architecture, thus we end up with a workaround
something like the below.

The current state of this seems like a pretty awful hack.  I'm making
assumptions about the architecture which I won't bet on holding.  This
was really a quick hack for Pry Mar to assist with the current situation.

A proper solution is needed.  This feels like a proof-of-concept, but
needs refinement before ending up in any tree.

---
 tools/pygrub/setup.py | 16 +++++++++++++++-
 tools/python/setup.py | 16 +++++++++++++++-
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/tools/pygrub/setup.py b/tools/pygrub/setup.py
index b8f1dc4590..737f97d679 100644
--- a/tools/pygrub/setup.py
+++ b/tools/pygrub/setup.py
@@ -7,6 +7,19 @@ extra_compile_args  = [ "-fno-strict-aliasing", "-Werror" ]
 
 XEN_ROOT = "../.."
 
+from distutils import command
+import distutils.command.build_ext
+class BuildExtArch(distutils.command.build_ext.build_ext):
+	arch_map = {
+		'x86_64':	'amd64',
+		'x86_32':	'i386',
+		'arm64':	'aarch64',
+		'arm32':	'armel',
+	}
+	def get_ext_filename(self, ext_name):
+		name = super().get_ext_filename(ext_name)
+		return name.replace(os.getenv("XEN_COMPILE_ARCH"), self.arch_map[os.getenv("XEN_TARGET_ARCH")])
+
 xenfsimage = Extension("xenfsimage",
     extra_compile_args = extra_compile_args,
     include_dirs = [ XEN_ROOT + "/tools/libfsimage/common/" ],
@@ -25,5 +38,6 @@ setup(name='pygrub',
       package_dir={'grub': 'src', 'fsimage': 'src'},
       scripts = ["src/pygrub"],
       packages=pkgs,
-      ext_modules = [ xenfsimage ]
+      ext_modules = [ xenfsimage ],
+      cmdclass = {'build_ext': BuildExtArch},
       )
diff --git a/tools/python/setup.py b/tools/python/setup.py
index 8c95db7769..4d761f9360 100644
--- a/tools/python/setup.py
+++ b/tools/python/setup.py
@@ -17,6 +17,19 @@ PATH_LIBXENCTRL = XEN_ROOT + "/tools/libs/ctrl"
 PATH_LIBXENGUEST = XEN_ROOT + "/tools/libs/guest"
 PATH_XENSTORE = XEN_ROOT + "/tools/libs/store"
 
+from distutils import command
+import distutils.command.build_ext
+class BuildExtArch(distutils.command.build_ext.build_ext):
+	arch_map = {
+		'x86_64':	'amd64',
+		'x86_32':	'i386',
+		'arm64':	'aarch64',
+		'arm32':	'armel',
+	}
+	def get_ext_filename(self, ext_name):
+		name = super().get_ext_filename(ext_name)
+		return name.replace(os.getenv("XEN_COMPILE_ARCH"), self.arch_map[os.getenv("XEN_TARGET_ARCH")])
+
 xc = Extension("xc",
                extra_compile_args = extra_compile_args,
                include_dirs       = [ PATH_XEN,
@@ -51,5 +64,6 @@ setup(name            = 'xen',
                          'xen.lowlevel',
                         ],
       ext_package = "xen.lowlevel",
-      ext_modules = modules
+      ext_modules = modules,
+      cmdclass = {'build_ext': BuildExtArch},
       )
-- 


-- 
(\___(\___(\______          --=> 8-) EHM <=--          ______/)___/)___/)
 \BS (    |         ehem+sigmsg@m5p.com  PGP 87145445         |    )   /
  \_CS\   |  _____  -O #include <stddisclaimer.h> O-   _____  |   /  _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445





^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-07 19:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-01 22:19 [RFC PATCH] tools/python: Correct extension filenames for Python 3 Elliott Mitchell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.