diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 6b866270..e784dd9f 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -1,6 +1,7 @@ name: Build and upload to PyPI on: + push: pull_request: release: types: @@ -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 @@ -25,6 +26,8 @@ jobs: uses: pypa/cibuildwheel@v2.12.0 env: CIBW_ARCHS_LINUX: auto aarch64 + CIBW_ARCHS_MACOS: x86_64 arm64 + GLM_ARCHITECTURE: default - uses: actions/upload-artifact@v3 with: @@ -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 diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9c59b1a2..8d5541d5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 ------------------ diff --git a/build_tools/prepare_macos_wheel.sh b/build_tools/prepare_macos_wheel.sh new file mode 100644 index 00000000..d3b3f142 --- /dev/null +++ b/build_tools/prepare_macos_wheel.sh @@ -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 diff --git a/pyproject.toml b/pyproject.toml index ceb512c0..d39af3ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ diff --git a/setup.py b/setup.py index d452c8db..6b7a4fbc 100644 --- a/setup.py +++ b/setup.py @@ -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: