Skip to content

Commit

Permalink
M1 wheel (#219)
Browse files Browse the repository at this point in the history
* Build wheels for Apple Silicon

* Update CHANGELOG.rst

* Update build_wheels.yml

* Update build_wheels.yml

* Update build_wheels.yml

* Update build_wheels.yml

* update pyproject.toml

* update build_wheels.yml

* jemalloc and xsimd build-specific

* typo

* arm64 brew

* force arm64

* debugging

* adjust path

* use intel llvm

* oops

* conda instead of brew

* getting there

* typo

* don't use local jemalloc

* use lomp instead of fopenmp flag

* setup.py error

* copying sklearn

* cleanup

* delete unused file

---------

Co-authored-by: Uwe L. Korn <[email protected]>
  • Loading branch information
MarcAntoineSchmidtQC and xhochy authored Jan 30, 2023
1 parent 6e7763d commit 0bf1214
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 21 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Build and upload to PyPI

on:
push:
pull_request:
release:
types:
Expand All @@ -12,7 +13,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, macos-10.15, windows-2019]
os: [ubuntu-20.04, windows-2019, macos-11]

steps:
- uses: actions/checkout@v3
Expand All @@ -25,6 +26,8 @@ jobs:
uses: pypa/[email protected]
env:
CIBW_ARCHS_LINUX: auto aarch64
CIBW_ARCHS_MACOS: x86_64 arm64
GLM_ARCHITECTURE: default

- uses: actions/upload-artifact@v3
with:
Expand All @@ -41,7 +44,7 @@ jobs:
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.8'
python-version: '3.10'

- name: Install build dependencies
run: python -m pip install setuptools setuptools-scm wheel mako numpy Cython
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
Changelog
=========

3.1.3 - 2022-01-26
------------------

**Other changes:**

- Build and upload wheels for Apple Silicon.

3.1.2 - 2022-07-01
------------------
Expand Down
12 changes: 12 additions & 0 deletions build_tools/prepare_macos_wheel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -e
set -x

if [[ "$CIBW_BUILD" == *-macosx_arm64 ]]; then
CONDA_CHANNEL="conda-forge/osx-arm64"
else
CONDA_CHANNEL="conda-forge/osx-64"
fi

conda create -n build -c $CONDA_CHANNEL jemalloc xsimd llvm-openmp
25 changes: 6 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,15 @@ environment = "GLM_ARCHITECTURE='default'"
# note: ARCHS_LINUX defined in build_wheels.yml file.

[tool.cibuildwheel.macos]
before-all = [
"brew install llvm libomp",
"cd ~/",
"git clone --branch 5.2.1 https://github.com/jemalloc/jemalloc.git",
"cd jemalloc",
"./autogen.sh --disable-cxx --with-jemalloc-prefix=local --with-install-suffix=local",
"make",
"make install_bin install_include install_lib",
"cd ~/",
"git clone --branch 7.6.0 https://github.com/xtensor-stack/xsimd.git",
"cd xsimd",
"mkdir build",
"cd build",
"cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..",
"make install"
before-build = [
"bash build_tools/prepare_macos_wheel.sh",
]

[tool.cibuildwheel.macos.environment]
LDFLAGS="-L/usr/local/lib"
CFLAGS="-I/usr/local/include"
CXX="/usr/local/opt/llvm/bin/clang++"
CC="/usr/local/opt/llvm/bin/clang"
LDFLAGS="-Wl,-rpath,$CONDA/envs/build/lib -L$CONDA/envs/build/lib -lomp"
CFLAGS="-I$CONDA/envs/build/include"
CXX="/usr/bin/clang++"
CC="/usr/bin/clang"

[tool.cibuildwheel.windows]
before-all = [
Expand Down
21 changes: 21 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@
extra_link_args = ["/openmp"]
# make sure we can find xsimd headers
include_dirs.append(os.path.join(sys.prefix, "Library", "include"))
elif sys.platform == "darwin":
jemalloc_config = shutil.which("jemalloc-config")
if jemalloc_config is None:
je_install_suffix = ""
else:
pkg_info = (
Path(jemalloc_config).parent.parent / "lib" / "pkgconfig" / "jemalloc.pc"
).read_text()
je_install_suffix = [
i.split("=")[1]
for i in pkg_info.split("\n")
if i.startswith("install_suffix=")
].pop()
allocator_libs = [f"jemalloc{je_install_suffix}"]
extra_compile_args = [
"-O3",
"-ffast-math",
"--std=c++17",
f"-DJEMALLOC_INSTALL_SUFFIX={je_install_suffix}",
]
extra_link_args = [""]
else:
jemalloc_config = shutil.which("jemalloc-config")
if jemalloc_config is None:
Expand Down

0 comments on commit 0bf1214

Please sign in to comment.