Skip to content

Commit

Permalink
Fixes issues that occur when building on Apple Silicon (#88)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mcbarton authored Nov 25, 2023
1 parent efc1423 commit e5e76b1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
4 changes: 3 additions & 1 deletion clingwrapper/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion clingwrapper/src/clingwrapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,32 @@ class ApplicationStarter {
Interp = existingInterp;
}
else {
#ifdef __arm64__
#ifdef __APPLE__
// If on apple silicon don't use -march=native
std::vector<const char *> InterpArgs({"-std=c++17"});
#else
std::vector<const char *> InterpArgs(
{"-std=c++17", "-march=native"});
#endif
#else
std::vector <const char *> 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
Expand Down
4 changes: 3 additions & 1 deletion python/cppyy_backend/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit e5e76b1

Please sign in to comment.