Skip to content

Commit

Permalink
Merge pull request #146 from andriish/mac
Browse files Browse the repository at this point in the history
Adding support for compilation with external LLVM on Mac
  • Loading branch information
lyskov authored Oct 29, 2020
2 parents 89a2a3b + c1d56c4 commit 25bf97f
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 7 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,15 @@ jobs:
uses: ./.github/workflows/fedora33
- name: Get the output status
run: exit ${{ steps.compileindocker.outputs.out }}

compilejobOSX:
runs-on: macos-latest
name: Binder_on_OSX
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Compile
id: compile
run: ./.github/workflows/osx/entrypoint.sh
- name: Get the output status
run: exit ${{ steps.compile.outputs.out }}
12 changes: 12 additions & 0 deletions .github/workflows/osx/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh -l
set -x
brew install wget coreutils xz pybind11
wget --no-verbose https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/clang+llvm-11.0.0-x86_64-apple-darwin.tar.xz
ls
tar -xJf clang+llvm-11.0.0-x86_64-apple-darwin.tar.xz
export PATH=$PATH:clang+llvm-11.0.0-x86_64-apple-darwin/bin

cmake CMakeLists.txt
make
otool -L source/binder
ctest . --output-on-failure
20 changes: 20 additions & 0 deletions documentation/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,26 @@ For Ubuntu18+ run, an example for LLVM/Clang 10:
sudo apt-get -y install clang-10 llvm-10 libclang-10-dev llvm-10-dev
sudo apt-get -y install cmake make gcc g++
For MacOSX:

Make sure the XCode is installed. If needed, install cmake, python and other utilities, e.g. using homebrew:

.. code-block:: console
brew install wget coreutils xz pybind11 cmake
Note: the pybind11 version from https://github.com/RosettaCommons/pybind11 should be preffered ,
but pybind11 version from homebrew might work as well.

Download and install the llvm+clang from the official site, e.g. using ``wget`` and
add the location of llvm config to the $PATH:

.. code-block:: console
wget --no-verbose https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/clang+llvm-11.0.0-x86_64-apple-darwin.tar.xz
tar -xJf clang+llvm-11.0.0-x86_64-apple-darwin.tar.xz
export PATH=$PATH:$(pwd)/clang+llvm-11.0.0-x86_64-apple-darwin/bin
Building
********
Expand Down
6 changes: 5 additions & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ if(USE_EXTERNAL_LLVM)
REQUIRED
)
else()
find_library(lib_llvm_path NAMES LLVM
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
set(lib_llvm_path )
else()
find_library(lib_llvm_path NAMES LLVM
LLVM-${LLVM_VERSION_MAJOR}
LLVM-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}
LLVM-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}
PATHS ${LLVM_LIBRARY_DIR} ${LLVMLIBDIR}
REQUIRED
)
endif()
endif()
add_definitions(${LLVM_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_COMPILE_FLAGS}")
Expand Down
33 changes: 27 additions & 6 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ else()
SET(${stestname}_config_flag --config ${stestname}.config )
endif()
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${stestname}.hpp.include "#include <${stestname}.hpp>" )
ADD_CUSTOM_TARGET(target${stestnamenodot}cpp
#The first two expressions below are for older clang
COMMAND C_INCLUDE_PATH=${LibClang_INCLUDE_DIR} CPLUS_INCLUDE_PATH=${LibClang_INCLUDE_DIR} ${CMAKE_BINARY_DIR}/source/binder --bind "" -max-file-size=100000
--root-module ${stestnamenodot} --prefix ${CMAKE_CURRENT_BINARY_DIR}/ ${${stestname}_config_flag} --single-file --annotate-includes ${stestname}.hpp.include
-- -x c++ -std=c++11 -I . -I ${CMAKE_CURRENT_SOURCE_DIR} -isystem / -I ${CLANG_INCLUDE_DIRS} -iwithsysroot${LibClang_INCLUDE_DIR}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" VERBATIM)
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
ADD_CUSTOM_TARGET(target${stestnamenodot}cpp
#The first two expressions below are for older clang
COMMAND C_INCLUDE_PATH=${LibClang_INCLUDE_DIR}:/Library/Developer/CommandLineTools/usr/include/c++/v1/ CPLUS_INCLUDE_PATH=${LibClang_INCLUDE_DIR}:/Library/Developer/CommandLineTools/usr/include/c++/v1/
${CMAKE_BINARY_DIR}/source/binder --bind "" -max-file-size=100000
--root-module ${stestnamenodot} --prefix ${CMAKE_CURRENT_BINARY_DIR}/ ${${stestname}_config_flag} --single-file --annotate-includes ${stestname}.hpp.include
-- -x c++ -std=c++11 -I . -I ${CMAKE_CURRENT_SOURCE_DIR} -isystem / -I ${CLANG_INCLUDE_DIRS} -iwithsysroot${LibClang_INCLUDE_DIR}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" VERBATIM)
else()
ADD_CUSTOM_TARGET(target${stestnamenodot}cpp
#The first two expressions below are for older clang
COMMAND C_INCLUDE_PATH=${LibClang_INCLUDE_DIR} CPLUS_INCLUDE_PATH=${LibClang_INCLUDE_DIR} ${CMAKE_BINARY_DIR}/source/binder --bind "" -max-file-size=100000
--root-module ${stestnamenodot} --prefix ${CMAKE_CURRENT_BINARY_DIR}/ ${${stestname}_config_flag} --single-file --annotate-includes ${stestname}.hpp.include
-- -x c++ -std=c++11 -I . -I ${CMAKE_CURRENT_SOURCE_DIR} -isystem / -I ${CLANG_INCLUDE_DIRS} -iwithsysroot${LibClang_INCLUDE_DIR}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" VERBATIM)
endif()
endif()
endmacro( binder_src stestname)

Expand Down Expand Up @@ -101,6 +111,17 @@ if (pybind11_VERSION VERSION_LESS 2.5.99)
list(REMOVE_ITEM binder_tests T11.override)
list(REMOVE_ITEM binder_tests T15.inner_class)
endif()
if( CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin" )
list(REMOVE_ITEM binder_tests T42.stl.names.multimap)
list(REMOVE_ITEM binder_tests T42.stl.names.multiset)
list(REMOVE_ITEM binder_tests T42.stl.names.set)
list(REMOVE_ITEM binder_tests T42.stl.names.map)
list(REMOVE_ITEM binder_tests T42.stl.names)
list(REMOVE_ITEM binder_tests T40.stl)
list(REMOVE_ITEM binder_tests T11.override)
list(REMOVE_ITEM binder_tests T10.inheritance)
list(REMOVE_ITEM binder_tests T02.function)
endif()
string(REPLACE "," ";" TESTVERSIONS ${BINDER_TEST_PYTHON_VERSIONS})
foreach ( tests ${binder_tests} )
binder_src( ${tests})
Expand Down

0 comments on commit 25bf97f

Please sign in to comment.