Skip to content

Commit 781a4a6

Browse files
authored
Build macos wheels (#6)
* 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
1 parent 105425e commit 781a4a6

File tree

4 files changed

+61
-17
lines changed

4 files changed

+61
-17
lines changed

.github/workflows/build_wheels.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ${{ matrix.os }}
1616
strategy:
1717
matrix:
18-
os: [ubuntu-latest]
18+
os: [macos-latest, ubuntu-latest]
1919
steps:
2020
- uses: actions/checkout@v3
2121
- run: |
@@ -27,6 +27,8 @@ jobs:
2727
uses: pypa/[email protected]
2828
env:
2929
CIBW_BUILD_VERBOSITY: 1
30+
CIBW_ARCHS_MACOS: x86_64
31+
CIBW_ENVIRONMENT_MACOS: CC=clang CXX=clang FC=gfortran-11
3032
CIBW_ARCHS: auto64
3133
CIBW_SKIP: skip = pp* *-musllinux*
3234

.github/workflows/python.yml

+12-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,22 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
os: [ubuntu]
17+
os: [ubuntu, macos]
1818
python_version: ["3.8", "3.9", "3.10"]
1919
include:
2020
- os: ubuntu
2121
cc: gcc-10
2222
cxx: g++-10
2323
fc: gfortran-10
24-
24+
- os: macos
25+
cc: gcc-11
26+
cxx: g++-11
27+
fc: gfortran-11
28+
exclude:
29+
- os: macos
30+
python_version: "3.8"
31+
- os: macos
32+
python_version: "3.9"
2533
steps:
2634
- uses: actions/checkout@v3
2735
- name: Install Python ${{ matrix.python_version }}
@@ -39,6 +47,7 @@ jobs:
3947
CXX: ${{ matrix.cxx }}
4048
FC: ${{ matrix.fc }}
4149
- name: Upload coverage data
50+
if: contains(matrix.os, 'ubuntu')
4251
uses: "actions/upload-artifact@v3"
4352
with:
4453
name: coverage-data
@@ -71,4 +80,5 @@ jobs:
7180
uses: codecov/codecov-action@v3
7281
with:
7382
files: ./coverage.xml
83+
verbose: true
7484

config.cmake

+23-6
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,30 @@
1010
option(BUILD_SHARED_LIBS "Whether the libraries built should be shared" TRUE)
1111

1212
if (${BUILD_SHARED_LIBS})
13-
file(RELATIVE_PATH relativeRpath
14-
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
15-
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
16-
)
17-
set(CMAKE_INSTALL_RPATH $ORIGIN $ORIGIN/${relativeRpath})
13+
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
14+
message(STATUS "Darwin specific RPATH configuration")
15+
if(SKBUILD)
16+
set(CMAKE_MACOSX_RPATH FALSE)
17+
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/sotb_wrapper")
18+
else()
19+
set(CMAKE_MACOSX_RPATH TRUE)
20+
set(CMAKE_SKIP_BUILD_RPATH FALSE)
21+
# when building, don't use the install RPATH already
22+
# (but later on when installing)
23+
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
24+
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
25+
# add the automatically determined parts of the RPATH
26+
# which point to directories outside the build tree to the install RPATH
27+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
28+
endif()
29+
else()
30+
file(RELATIVE_PATH relativeRpath
31+
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
32+
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
33+
)
34+
set(CMAKE_INSTALL_RPATH $ORIGIN $ORIGIN/${relativeRpath})
35+
endif()
1836
endif()
19-
2037
#
2138
# Fortran compiler dependent config options
2239
#

sotb_wrapper/interface.py

+23-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import ctypes
55
from ctypes import byref, c_float, c_int, POINTER
66
from pathlib import Path
7+
import sys
78
from typing import Optional
89

910
import numpy as np
@@ -113,7 +114,12 @@ def __repr__(self) -> str:
113114
# Load shared library
114115
path = Path(__file__).parent
115116
name = "libsotb"
116-
name = f"{name}.so"
117+
if sys.platform.startswith("linux"):
118+
name = f"{name}.so"
119+
elif sys.platform == "darwin":
120+
name = f"{name}.dylib"
121+
else:
122+
raise ImportError(f"Your OS is not supported: {sys.platform}")
117123

118124
# This is how a dll/so library is loaded
119125
try:
@@ -129,21 +135,30 @@ def __repr__(self) -> str:
129135
github_url = "https://github.com/ofmla/seiscope_opt_toolbox_w_ctypes#compiling"
130136
print()
131137
print(
132-
"Failed to load the required SEISCOPE OPTIMIZATION TOOLBOX (sotb) "
138+
"Failed to load the required SEISCOPE OPTIMIZATION TOOLBOX (sotb) shared"
139+
+ " library."
133140
+ "\n"
134-
+ "shared library. You can likely resolve this error by building "
141+
+ "You are likely to see this message as consequence of the attempt to "
142+
+ "run the tests "
135143
+ "\n"
136-
+ "the required sotb shared library on your linux system. "
144+
+ "from the local project directory (the one obtained with the clone command). "
137145
+ "\n"
138146
+ "\n"
139-
+ "Visit"
147+
+ "If your objective is to contribute to sotb-wrapper and you got a development "
140148
+ "\n"
149+
+ "copy via `git clone` command, you must have the nox package to be able to run"
141150
+ "\n"
142-
+ " "
143-
+ github_url
151+
+ "the tests from the local repository. So an immediate step after cloning the "
152+
+ "repo"
144153
+ "\n"
154+
+ "is to install nox in your python environment"
145155
+ "\n"
146-
+ "for instructions to build the sotb library on your linux system. "
156+
+ "\n"
157+
+ "python3 -m pip install nox"
158+
+ "\n"
159+
+ "\n"
160+
+ "You can then make changes and use the command `nox -s tests` to execute the "
161+
+ "tests session. "
147162
+ "\n"
148163
)
149164
print()

0 commit comments

Comments
 (0)