From e5e76b1192765fbd600ddee0b0f16fee7bfe6e38 Mon Sep 17 00:00:00 2001 From: mcbarton <150042563+mcbarton@users.noreply.github.com> Date: Sat, 25 Nov 2023 19:37:46 +0000 Subject: [PATCH] Fixes issues that occur when building on Apple Silicon (#88) Add .dylib option when building on MacOS Disabled use of -march=native when on Apple Silicon Link to CppInterOp (without this on MacOS you get undefined symbols error when building). Pick CppInterOp library file extension without hardcoding --- CMakeLists.txt | 5 +++++ clingwrapper/setup.py | 4 +++- clingwrapper/src/clingwrapper.cxx | 23 ++++++++++++++++++++++- python/cppyy_backend/loader.py | 4 +++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4451f373..ea691ceb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.10) project(cppyy-backend) include(ExternalProject) +include(CMakeSystemSpecificInformation) set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL) set(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC) @@ -64,4 +65,8 @@ endif() set_source_files_properties(clingwrapper/src/clingwrapper.cxx PROPERTIES COMPILE_DEFINITIONS "CPPINTEROP_DIR=\"${_interop_install_dir}\"") +# Link to CppInterOp library. Without this can't build on MacOS due to undefined symbols +target_link_libraries(cppyy-backend ${_interop_install_dir}/lib/libclangCppInterOp${CMAKE_SHARED_LIBRARY_SUFFIX}) + + target_include_directories(cppyy-backend PUBLIC ${_interop_install_dir}/include) diff --git a/clingwrapper/setup.py b/clingwrapper/setup.py index 73acb8ba..530f4e9f 100644 --- a/clingwrapper/setup.py +++ b/clingwrapper/setup.py @@ -24,8 +24,10 @@ if 'win32' in sys.platform: soext = '.dll' -else: +elif 'linux' in sys.platform: soext = '.so' +else: + soext = '.dylib' # # platform-dependent helpers diff --git a/clingwrapper/src/clingwrapper.cxx b/clingwrapper/src/clingwrapper.cxx index 38c18835..a6ac2c13 100644 --- a/clingwrapper/src/clingwrapper.cxx +++ b/clingwrapper/src/clingwrapper.cxx @@ -171,11 +171,32 @@ class ApplicationStarter { Interp = existingInterp; } else { +#ifdef __arm64__ +#ifdef __APPLE__ + // If on apple silicon don't use -march=native + std::vector InterpArgs({"-std=c++17"}); +#else + std::vector InterpArgs( + {"-std=c++17", "-march=native"}); +#endif +#else std::vector InterpArgs({"-std=c++17", "-march=native"}); +#endif char *InterpArgString = getenv("CPPINTEROP_EXTRA_INTERPRETER_ARGS"); + if (InterpArgString) - push_tokens_from_string(InterpArgString, InterpArgs); + push_tokens_from_string(InterpArgString, InterpArgs); + +#ifdef __arm64__ +#ifdef __APPLE__ + // If on apple silicon don't use -march=native + Interp = Cpp::CreateInterpreter({"-std=c++17"}); +#else Interp = Cpp::CreateInterpreter({"-std=c++17", "-march=native"}); +#endif +#else + Interp = Cpp::CreateInterpreter({"-std=c++17", "-march=native"}); +#endif } // fill out the builtins diff --git a/python/cppyy_backend/loader.py b/python/cppyy_backend/loader.py index eaef7290..e0f765b6 100644 --- a/python/cppyy_backend/loader.py +++ b/python/cppyy_backend/loader.py @@ -19,8 +19,10 @@ if 'win32' in sys.platform: soext = '.dll' -else: +elif 'linux' in sys.platform: soext = '.so' +else: + soext = '.dylib' soabi = sysconfig.get_config_var("SOABI") soext2 = sysconfig.get_config_var("EXT_SUFFIX")