Skip to content

Commit

Permalink
ECC-1793: develop binary wheel - macos arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
iainrussell committed Apr 11, 2024
1 parent 57dd510 commit 17fae2e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 14 deletions.
66 changes: 61 additions & 5 deletions gribapi/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,76 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import logging
import os
import pkgutil
import sys

import cffi

__version__ = "1.7.0"

LOG = logging.getLogger(__name__)

try:
import ecmwflibs as findlibs
except ImportError:
import findlibs
_MAP = {
"grib_api": "eccodes",
"gribapi": "eccodes",
}

EXTENSIONS = {
"darwin": ".dylib",
"win32": ".dll",
}


def _lookup(name):
return _MAP.get(name, name)


def find_binary_libs(name):

name = _lookup(name)

if int(os.environ.get("PYTHON_ECCODES_USE_INSTALLED_BINARIES", "0")):
logging.debug(
f"{name} lib search: PYTHON_ECCODES_USE_INSTALLED_BINARIES set, so using findlibs"
)
import findlibs

foundlib = findlibs.find(name)
logging.debug(f"{name} lib search: findlibs returned {foundlib}")
return foundlib

logging.debug(f"{name} lib search: trying to find binary wheel")
here = os.path.dirname(__file__)
# eccodes libs are actually in eccodes dir, not gribapi dir
here = os.path.abspath(os.path.join(here, os.path.pardir, "eccodes"))
extension = EXTENSIONS.get(sys.platform, ".so")

for libdir in [here + ".libs", os.path.join(here, ".dylibs"), here]:
logging.debug(f"{name} lib search: looking in {libdir}")
if not name.startswith("lib"):
libnames = ["lib" + name, name]
else:
libnames = [name, name[3:]]

if os.path.exists(libdir):
for file in os.listdir(libdir):
if file.endswith(extension):
for libname in libnames:
if libname == file.split("-")[0].split(".")[0]:
foundlib = os.path.join(libdir, file)
logging.debug(
f"{name} lib search: returning wheel from {foundlib}"
)
return foundlib

logging.debug(f"{name} lib search: did not find library")

return None


library_path = find_binary_libs("eccodes")

library_path = findlibs.find("eccodes")
if library_path is None:
raise RuntimeError("Cannot find the ecCodes library")

Expand Down
9 changes: 7 additions & 2 deletions scripts/build-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ done
cd $TOPDIR/build-binaries/eccodes

# We disable JASPER because of a linking issue. JPEG support comes from
# other librarues
# other libraries (e.g. openjpeg)
# For performance, we do not enable thread-safety (would be -DENABLE_THREADS=1 -DECCODES_OMP_THREADS=1),
# but may want to consider in the future
$ARCH $TOPDIR/src/ecbuild/bin/ecbuild \
$TOPDIR/src/eccodes \
-GNinja \
-DCMAKE_OSX_ARCHITECTURES=$arch \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DENABLE_PYTHON=0 \
-DENABLE_FORTRAN=0 \
-DENABLE_BUILD_TOOLS=0 \
-DENABLE_JPG_LIBJASPER=0 \
Expand All @@ -58,6 +59,10 @@ $ARCH $TOPDIR/src/ecbuild/bin/ecbuild \
cd $TOPDIR
$ARCH cmake --build build-binaries/eccodes --target install

# Run some basic tests to check the library is ok
cd build-binaries/eccodes
ctest -L sanity
cd $TOPDIR

# Create wheel
rm -fr dist wheelhouse
Expand Down
8 changes: 1 addition & 7 deletions scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@ ECBUILD_VERSION=master

GIT_ECCODES=https://github.com/ecmwf/eccodes.git
ECCODES_VERSION=2.33.2
ECCODES_EXTRA_CMAKE_OPTIONS="-DENABLE_PNG=ON -DENABLE_JPG=ON"
ECCODES_EXTRA_CMAKE_OPTIONS="-DENABLE_PNG=ON -DENABLE_JPG=ON -DENABLE_NETCDF=0 -DENABLE_EXAMPLES=0"

GIT_AEC=https://github.com/MathisRosenhauer/libaec.git
AEC_VERSION=master

GIT_NETCDF=https://github.com/Unidata/netcdf-c.git
NETCDF_VERSION=${NETCDF_VERSION:=master}

GIT_HDF5=https://github.com/HDFGroup/hdf5.git
HDF5_VERSION=${HDF5_VERSION:=hdf5-1_10_5}

rm -fr src build build-binaries

git clone --branch $ECBUILD_VERSION --depth=1 $GIT_ECBUILD src/ecbuild
Expand Down
5 changes: 5 additions & 0 deletions scripts/wheel-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ $ARCH python3 setup.py bdist_wheel # --plat-name $arch
# find dist/*.dist-info -print

$ARCH delocate-wheel -w wheelhouse dist/*.whl

# test the wheel
pip install --force-reinstall wheelhouse/*.whl
cd tests
pytest

0 comments on commit 17fae2e

Please sign in to comment.