Skip to content

Commit

Permalink
Build macos wheels (#6)
Browse files Browse the repository at this point in the history
* take into account the extension of the shared lib for macos

* build macos wheels for PYPI

* add CMake variables related to RPATH for macos

* Update config.cmake

* Update config.cmake

* Update python.yml

* set the rpath properly for macOS

* upload coverage data only for ubuntu tests

* Update setup.py

* set INSTALL_NAME_DIR

* upload coverage with verbose=true
  • Loading branch information
ofmla authored Sep 27, 2022
1 parent 105425e commit 781a4a6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 17 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v3
- run: |
Expand All @@ -27,6 +27,8 @@ jobs:
uses: pypa/[email protected]
env:
CIBW_BUILD_VERBOSITY: 1
CIBW_ARCHS_MACOS: x86_64
CIBW_ENVIRONMENT_MACOS: CC=clang CXX=clang FC=gfortran-11
CIBW_ARCHS: auto64
CIBW_SKIP: skip = pp* *-musllinux*

Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu]
os: [ubuntu, macos]
python_version: ["3.8", "3.9", "3.10"]
include:
- os: ubuntu
cc: gcc-10
cxx: g++-10
fc: gfortran-10

- os: macos
cc: gcc-11
cxx: g++-11
fc: gfortran-11
exclude:
- os: macos
python_version: "3.8"
- os: macos
python_version: "3.9"
steps:
- uses: actions/checkout@v3
- name: Install Python ${{ matrix.python_version }}
Expand All @@ -39,6 +47,7 @@ jobs:
CXX: ${{ matrix.cxx }}
FC: ${{ matrix.fc }}
- name: Upload coverage data
if: contains(matrix.os, 'ubuntu')
uses: "actions/upload-artifact@v3"
with:
name: coverage-data
Expand Down Expand Up @@ -71,4 +80,5 @@ jobs:
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml
verbose: true

29 changes: 23 additions & 6 deletions config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,30 @@
option(BUILD_SHARED_LIBS "Whether the libraries built should be shared" TRUE)

if (${BUILD_SHARED_LIBS})
file(RELATIVE_PATH relativeRpath
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
)
set(CMAKE_INSTALL_RPATH $ORIGIN $ORIGIN/${relativeRpath})
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
message(STATUS "Darwin specific RPATH configuration")
if(SKBUILD)
set(CMAKE_MACOSX_RPATH FALSE)
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/sotb_wrapper")
else()
set(CMAKE_MACOSX_RPATH TRUE)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
else()
file(RELATIVE_PATH relativeRpath
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
)
set(CMAKE_INSTALL_RPATH $ORIGIN $ORIGIN/${relativeRpath})
endif()
endif()

#
# Fortran compiler dependent config options
#
Expand Down
31 changes: 23 additions & 8 deletions sotb_wrapper/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ctypes
from ctypes import byref, c_float, c_int, POINTER
from pathlib import Path
import sys
from typing import Optional

import numpy as np
Expand Down Expand Up @@ -113,7 +114,12 @@ def __repr__(self) -> str:
# Load shared library
path = Path(__file__).parent
name = "libsotb"
name = f"{name}.so"
if sys.platform.startswith("linux"):
name = f"{name}.so"
elif sys.platform == "darwin":
name = f"{name}.dylib"
else:
raise ImportError(f"Your OS is not supported: {sys.platform}")

# This is how a dll/so library is loaded
try:
Expand All @@ -129,21 +135,30 @@ def __repr__(self) -> str:
github_url = "https://github.com/ofmla/seiscope_opt_toolbox_w_ctypes#compiling"
print()
print(
"Failed to load the required SEISCOPE OPTIMIZATION TOOLBOX (sotb) "
"Failed to load the required SEISCOPE OPTIMIZATION TOOLBOX (sotb) shared"
+ " library."
+ "\n"
+ "shared library. You can likely resolve this error by building "
+ "You are likely to see this message as consequence of the attempt to "
+ "run the tests "
+ "\n"
+ "the required sotb shared library on your linux system. "
+ "from the local project directory (the one obtained with the clone command). "
+ "\n"
+ "\n"
+ "Visit"
+ "If your objective is to contribute to sotb-wrapper and you got a development "
+ "\n"
+ "copy via `git clone` command, you must have the nox package to be able to run"
+ "\n"
+ " "
+ github_url
+ "the tests from the local repository. So an immediate step after cloning the "
+ "repo"
+ "\n"
+ "is to install nox in your python environment"
+ "\n"
+ "for instructions to build the sotb library on your linux system. "
+ "\n"
+ "python3 -m pip install nox"
+ "\n"
+ "\n"
+ "You can then make changes and use the command `nox -s tests` to execute the "
+ "tests session. "
+ "\n"
)
print()
Expand Down

0 comments on commit 781a4a6

Please sign in to comment.