diff --git a/mypyc/build_setup.py b/mypyc/build_setup.py index a3e7a669abee..328518e220d6 100644 --- a/mypyc/build_setup.py +++ b/mypyc/build_setup.py @@ -1,3 +1,4 @@ +import os import platform import sys @@ -30,32 +31,41 @@ ccompiler.CCompiler.__spawn = ccompiler.CCompiler.spawn # type: ignore[attr-defined] X86_64 = platform.machine() in ("x86_64", "AMD64", "amd64") +PYODIDE = "PYODIDE" in os.environ def spawn(self, cmd, **kwargs) -> None: # type: ignore[no-untyped-def] - compiler_type: str = self.compiler_type - extra_options = EXTRA_FLAGS_PER_COMPILER_TYPE_PER_PATH_COMPONENT[compiler_type] - new_cmd = list(cmd) - if X86_64 and extra_options is not None: - # filenames are closer to the end of command line + if PYODIDE: + new_cmd = list(cmd) for argument in reversed(new_cmd): - # Check if the matching argument contains a source filename. if not str(argument).endswith(".c"): continue + if "base64/arch/" in str(argument): + new_cmd.extend(["-msimd128"]) + else: + compiler_type: str = self.compiler_type + extra_options = EXTRA_FLAGS_PER_COMPILER_TYPE_PER_PATH_COMPONENT[compiler_type] + new_cmd = list(cmd) + if X86_64 and extra_options is not None: + # filenames are closer to the end of command line + for argument in reversed(new_cmd): + # Check if the matching argument contains a source filename. + if not str(argument).endswith(".c"): + continue - for path in extra_options.keys(): - if path in str(argument): - if compiler_type == "bcpp": - compiler = new_cmd.pop() - # Borland accepts a source file name at the end, - # insert the options before it - new_cmd.extend(extra_options[path]) - new_cmd.append(compiler) - else: - new_cmd.extend(extra_options[path]) - - # path component is found, no need to search any further - break + for path in extra_options.keys(): + if path in str(argument): + if compiler_type == "bcpp": + compiler = new_cmd.pop() + # Borland accepts a source file name at the end, + # insert the options before it + new_cmd.extend(extra_options[path]) + new_cmd.append(compiler) + else: + new_cmd.extend(extra_options[path]) + + # path component is found, no need to search any further + break self.__spawn(new_cmd, **kwargs) diff --git a/mypyc/lib-rt/base64/arch/neon64/codec.c b/mypyc/lib-rt/base64/arch/neon64/codec.c index 70dc463de94f..72f136f67b8a 100644 --- a/mypyc/lib-rt/base64/arch/neon64/codec.c +++ b/mypyc/lib-rt/base64/arch/neon64/codec.c @@ -12,7 +12,7 @@ #include // Only enable inline assembly on supported compilers. -#if defined(__GNUC__) || defined(__clang__) +#if !defined(__wasm__) && (defined(__GNUC__) || defined(__clang__)) #define BASE64_NEON64_USE_ASM #endif diff --git a/mypyc/lib-rt/base64/config.h b/mypyc/lib-rt/base64/config.h index 467a722c2f11..8517c7b87d8c 100644 --- a/mypyc/lib-rt/base64/config.h +++ b/mypyc/lib-rt/base64/config.h @@ -13,7 +13,7 @@ #define BASE64_WITH_NEON32 0 #define HAVE_NEON32 BASE64_WITH_NEON32 -#if defined(__APPLE__) && defined(__aarch64__) +#if (defined(__APPLE__) && defined(__aarch64__)) || (defined(__wasm__) && defined(__wasm_simd128__)) #define BASE64_WITH_NEON64 1 #else #define BASE64_WITH_NEON64 0 diff --git a/mypyc/lib-rt/setup.py b/mypyc/lib-rt/setup.py index 5f71d332229c..1030ce496ccd 100644 --- a/mypyc/lib-rt/setup.py +++ b/mypyc/lib-rt/setup.py @@ -42,32 +42,41 @@ ccompiler.CCompiler.__spawn = ccompiler.CCompiler.spawn # type: ignore[attr-defined] X86_64 = platform.machine() in ("x86_64", "AMD64", "amd64") +PYODIDE = "PYODIDE" in os.environ def spawn(self, cmd, **kwargs) -> None: # type: ignore[no-untyped-def] - compiler_type: str = self.compiler_type - extra_options = EXTRA_FLAGS_PER_COMPILER_TYPE_PER_PATH_COMPONENT[compiler_type] - new_cmd = list(cmd) - if X86_64 and extra_options is not None: - # filenames are closer to the end of command line + if PYODIDE: + new_cmd = list(cmd) for argument in reversed(new_cmd): - # Check if the matching argument contains a source filename. if not str(argument).endswith(".c"): continue - - for path in extra_options.keys(): - if path in str(argument): - if compiler_type == "bcpp": - compiler = new_cmd.pop() - # Borland accepts a source file name at the end, - # insert the options before it - new_cmd.extend(extra_options[path]) - new_cmd.append(compiler) - else: - new_cmd.extend(extra_options[path]) - - # path component is found, no need to search any further - break + if "base64/arch/" in str(argument): + new_cmd.extend(["-msimd128"]) + else: + compiler_type: str = self.compiler_type + extra_options = EXTRA_FLAGS_PER_COMPILER_TYPE_PER_PATH_COMPONENT[compiler_type] + new_cmd = list(cmd) + if X86_64 and extra_options is not None: + # filenames are closer to the end of command line + for argument in reversed(new_cmd): + # Check if the matching argument contains a source filename. + if not str(argument).endswith(".c"): + continue + + for path in extra_options.keys(): + if path in str(argument): + if compiler_type == "bcpp": + compiler = new_cmd.pop() + # Borland accepts a source file name at the end, + # insert the options before it + new_cmd.extend(extra_options[path]) + new_cmd.append(compiler) + else: + new_cmd.extend(extra_options[path]) + + # path component is found, no need to search any further + break self.__spawn(new_cmd, **kwargs)