From bd239144b3aeadc8621b40cbaebf307e4e5053c8 Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Thu, 7 Apr 2022 16:41:13 -0700 Subject: [PATCH] build macos arm64 wheels --- .ci/install_cargo.sh | 1 + .github/workflows/build_wheel.yml | 12 ++++++------ pyproject.toml | 7 +++++++ setup.py | 13 +++++++++++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/.ci/install_cargo.sh b/.ci/install_cargo.sh index d0696d7fdf..94ec2b9beb 100755 --- a/.ci/install_cargo.sh +++ b/.ci/install_cargo.sh @@ -2,3 +2,4 @@ curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable export PATH="$HOME/.cargo/bin:$PATH" rustc -V +rustup target add aarch64-apple-darwin diff --git a/.github/workflows/build_wheel.yml b/.github/workflows/build_wheel.yml index 64b653f0c1..d15fb8a27e 100644 --- a/.github/workflows/build_wheel.yml +++ b/.github/workflows/build_wheel.yml @@ -20,6 +20,7 @@ jobs: linux-ppc64le, linux-s390x, macos-x86_64, + macos-arm64, ] include: - build: linux-x86_64 @@ -41,7 +42,11 @@ jobs: - build: macos-x86_64 os: macos-latest arch: x86_64 - macos_target: 'MACOSX_DEPLOYMENT_TARGET=10.11' + macos_target: 'MACOSX_DEPLOYMENT_TARGET=10.11 CARGO_BUILD_TARGET=x86_64-apple-darwin' + - build: macos-arm64 + os: macos-latest + arch: arm64 + macos_target: 'MACOSX_DEPLOYMENT_TARGET=11 CARGO_BUILD_TARGET=aarch64-apple-darwin' fail-fast: false steps: @@ -63,12 +68,7 @@ jobs: - name: Build wheels uses: pypa/cibuildwheel@v2.2.2 env: - CIBW_BUILD: "cp39-*" - CIBW_SKIP: "*-win32 *-manylinux_i686 *-musllinux_ppc64le *-musllinux_s390x" - CIBW_BEFORE_BUILD: 'source .ci/install_cargo.sh' - CIBW_ENVIRONMENT: 'PATH="$HOME/.cargo/bin:$PATH"' CIBW_ENVIRONMENT_MACOS: ${{ matrix.macos_target }} - CIBW_BUILD_VERBOSITY: 3 CIBW_ARCHS_LINUX: ${{ matrix.arch }} CIBW_ARCHS_MACOS: ${{ matrix.arch }} diff --git a/pyproject.toml b/pyproject.toml index eafbab8578..abe31ec81e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,3 +19,10 @@ include_trailing_comma = true force_grid_wrap = 0 line_length = 88 known_first_party = ["sourmash"] + +[tool.cibuildwheel] +build = "cp39-*" +skip = "*-win32 *-manylinux_i686 *-musllinux_ppc64le *-musllinux_s390x" +before-build = "source .ci/install_cargo.sh" +environment = { PATH="$HOME/.cargo/bin:$PATH" } +build-verbosity = 3 diff --git a/setup.py b/setup.py index 9384aba4b4..e31e09fd1f 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ NO_BUILD = os.environ.get("NO_BUILD") == "1" -def find_dylib(name, paths): +def find_dylib_no_build(name, paths): to_find = None if sys.platform == 'darwin': to_find = f'lib{name}.dylib' @@ -25,6 +25,15 @@ def find_dylib(name, paths): raise LookupError('dylib %r not found' % name) +def find_dylib(build, target): + cargo_target = os.environ.get("CARGO_BUILD_TARGET") + if cargo_target: + in_path = "target/%s/%s" % (cargo_target, target) + else: + in_path = "target/%s" % target + return build.find_dylib("sourmash", in_path=in_path) + + def build_native(spec): cmd = ["cargo", "build", "--manifest-path", "src/core/Cargo.toml", @@ -41,7 +50,7 @@ def build_native(spec): header_filename = lambda: "include/sourmash.h" else: build = spec.add_external_build(cmd=cmd, path=".") - dylib=lambda: build.find_dylib("sourmash", in_path="target/%s" % target) + dylib = lambda: find_dylib(build, target) header_filename=lambda: build.find_header("sourmash.h", in_path="include") rtld_flags = ["NOW"]