From 5d22027b90f104f1240163cbc1f0e22b40178683 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 10 Apr 2025 09:37:25 +0200 Subject: [PATCH 1/6] emscripten fixes --- setup.py | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index c27fad35..77d5d61a 100644 --- a/setup.py +++ b/setup.py @@ -5,16 +5,32 @@ from distutils.sysconfig import customize_compiler from glob import glob -import cpuinfo from Cython.Distutils.build_ext import new_build_ext as build_ext from setuptools import Extension, setup from setuptools.errors import CCompilerError, ExecError, PlatformError -# determine CPU support for SSE2 and AVX2 -cpu_info = cpuinfo.get_cpu_info() -flags = cpu_info.get('flags', []) -machine = cpuinfo.platform.machine() - +if sys.version_info >= (3, 10): + import sysconfig +else: + from distutils import sysconfig + +# We can't use sys.platform in a cross-compiling situation +# as here it may be set to the host not target platform +is_emscripten = ( + sysconfig.get_config_var("SOABI") + and sysconfig.get_config_var("SOABI").find("emscripten") != -1 +) + + +if not is_emscripten: + import cpuinfo + # determine CPU support for SSE2 and AVX2 + cpu_info = cpuinfo.get_cpu_info() + flags = cpu_info.get('flags', []) + machine = cpuinfo.platform.machine() +else: + flags = [] + machine ="emscripten-wasm32" # only check for x86 features on x86_64 arch have_sse2 = False have_avx2 = False @@ -42,7 +58,7 @@ base_compile_args.append('-mavx2') # On macOS, force libc++ in case the system tries to use `stdlibc++`. # The latter is often absent from modern macOS systems. -if sys.platform == 'darwin': +if sys.platform == 'darwin' and not is_emscripten: base_compile_args.append('-stdlib=libc++') @@ -64,7 +80,7 @@ def blosc_extension(): define_macros = [] # ensure pthread is properly linked on POSIX systems - if os.name == 'posix': + if os.name == 'posix' and not is_emscripten: extra_compile_args.append('-pthread') extra_link_args.append('-pthread') @@ -114,7 +130,7 @@ def blosc_extension(): info('compiling Blosc extension without AVX2 support') # include assembly files - if cpuinfo.platform.machine() == 'x86_64': + if machine == 'x86_64': extra_objects = [ S[:-1] + 'o' for S in glob("c-blosc/internal-complibs/zstd*/decompress/*amd64.S") ] @@ -157,7 +173,7 @@ def zstd_extension(): sources = ['numcodecs/zstd.pyx'] # include assembly files - if cpuinfo.platform.machine() == 'x86_64': + if machine == 'x86_64': extra_objects = [ S[:-1] + 'o' for S in glob("c-blosc/internal-complibs/zstd*/decompress/*amd64.S") ] @@ -321,7 +337,6 @@ class ve_build_ext(build_ext): def run(self): try: - machine = cpuinfo.platform.machine() if machine in ('x86_64', 'aarch64'): pattern = '*amd64.S' if machine == 'x86_64' else '*aarch64.S' S_files = glob(f'c-blosc/internal-complibs/zstd*/decompress/{pattern}') @@ -347,7 +362,7 @@ class Sclean(clean): # Clean up .o files created by .S files def run(self): - if cpuinfo.platform.machine() == 'x86_64': + if machine == 'x86_64': o_files = glob('c-blosc/internal-complibs/zstd*/decompress/*amd64.o') for f in o_files: os.remove(f) @@ -373,6 +388,8 @@ def run_setup(with_extensions): ext_modules = [] cmdclass = {} + print(f"base compile args: {base_compile_args}") + setup( ext_modules=ext_modules, cmdclass=cmdclass, From ff2e4d09ae8142d426036c23c147e295037a0aac Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 10 Apr 2025 09:41:29 +0200 Subject: [PATCH 2/6] emscripten fixes --- setup.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 77d5d61a..526319fe 100644 --- a/setup.py +++ b/setup.py @@ -14,13 +14,8 @@ else: from distutils import sysconfig -# We can't use sys.platform in a cross-compiling situation -# as here it may be set to the host not target platform -is_emscripten = ( - sysconfig.get_config_var("SOABI") - and sysconfig.get_config_var("SOABI").find("emscripten") != -1 -) - +# sys.platform is not trustworthy in a cross-compiling environment +is_emscripten = sysconfig.get_config_var("SOABI") and "emscripten" in sysconfig.get_config_var("SOABI") if not is_emscripten: import cpuinfo From bed71c5cc0a734256b13a5cb2ffa80cf8d7ae848 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 10 Apr 2025 09:47:15 +0200 Subject: [PATCH 3/6] emscripten fixes --- setup.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup.py b/setup.py index 526319fe..43d5d1eb 100644 --- a/setup.py +++ b/setup.py @@ -383,8 +383,6 @@ def run_setup(with_extensions): ext_modules = [] cmdclass = {} - print(f"base compile args: {base_compile_args}") - setup( ext_modules=ext_modules, cmdclass=cmdclass, From 0f2fbbb3bea9954a9f10be188f22e99a96f89694 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 10 Apr 2025 09:52:30 +0200 Subject: [PATCH 4/6] make linter happy --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 43d5d1eb..341092d4 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ from setuptools import Extension, setup from setuptools.errors import CCompilerError, ExecError, PlatformError -if sys.version_info >= (3, 10): +if sys.version_info >= (3, 10): # noqa UP036 import sysconfig else: from distutils import sysconfig From 11d770fbe34e80dd669fb14df0a3cc064bc5d46a Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 10 Apr 2025 09:55:33 +0200 Subject: [PATCH 5/6] make linter happy II --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 341092d4..693d293e 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ from setuptools import Extension, setup from setuptools.errors import CCompilerError, ExecError, PlatformError -if sys.version_info >= (3, 10): # noqa UP036 +if sys.version_info >= (3, 10): # noqa: UP036 import sysconfig else: from distutils import sysconfig From 0291975a04b5a71a5610f787b00f377e5ae52e8b Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 10 Apr 2025 10:01:16 +0200 Subject: [PATCH 6/6] make linter happy III --- setup.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 693d293e..2cd73314 100644 --- a/setup.py +++ b/setup.py @@ -9,23 +9,27 @@ from setuptools import Extension, setup from setuptools.errors import CCompilerError, ExecError, PlatformError -if sys.version_info >= (3, 10): # noqa: UP036 +if sys.version_info >= (3, 10): # noqa: UP036 import sysconfig else: from distutils import sysconfig + # sys.platform is not trustworthy in a cross-compiling environment -is_emscripten = sysconfig.get_config_var("SOABI") and "emscripten" in sysconfig.get_config_var("SOABI") +is_emscripten = sysconfig.get_config_var("SOABI") and "emscripten" in sysconfig.get_config_var( + "SOABI" +) if not is_emscripten: import cpuinfo + # determine CPU support for SSE2 and AVX2 cpu_info = cpuinfo.get_cpu_info() flags = cpu_info.get('flags', []) machine = cpuinfo.platform.machine() else: flags = [] - machine ="emscripten-wasm32" + machine = "emscripten-wasm32" # only check for x86 features on x86_64 arch have_sse2 = False have_avx2 = False