From b7b343efe747eef8ba27722a530239e43f7f6d19 Mon Sep 17 00:00:00 2001 From: "Thomas J. Fan" Date: Mon, 29 Nov 2021 22:29:24 -0500 Subject: [PATCH 1/4] CI Build macOS arm wheels [cd build gh] --- .github/workflows/wheels.yml | 132 +++++++++++++++++++--- build_tools/github/build_wheels.sh | 6 +- build_tools/github/check_build_trigger.sh | 3 +- build_tools/github/check_wheels.py | 10 +- doc/developers/contributing.rst | 1 + sklearn/_build_utils/openmp_helpers.py | 1 + sklearn/_build_utils/pre_build_helpers.py | 1 + 7 files changed, 131 insertions(+), 23 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 1f133d701ca53..850f29063810c 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -47,36 +47,139 @@ jobs: # Ensure that a wheel builder finishes even if another fails fail-fast: false matrix: - os: [windows-latest, ubuntu-latest, macos-latest] - python: [37, 38, 39] - bitness: [32, 64] - manylinux_image: [manylinux1, manylinux2010] include: - # Run 32 and 64 bit version in parallel for Linux and Windows + # Window 64 bit - os: windows-latest + python: 37 bitness: 64 platform_id: win_amd64 - os: windows-latest + python: 38 + bitness: 64 + platform_id: win_amd64 + - os: windows-latest + python: 39 + bitness: 64 + platform_id: win_amd64 + + # Window 32 bit + - os: windows-latest + python: 37 + bitness: 32 + platform_id: win32 + - os: windows-latest + python: 38 bitness: 32 platform_id: win32 + - os: windows-latest + python: 39 + bitness: 32 + platform_id: win32 + + # Linux 64 bit manylinux1 - os: ubuntu-latest + python: 37 bitness: 64 platform_id: manylinux_x86_64 + manylinux_image: manylinux1 - os: ubuntu-latest + python: 38 + bitness: 64 + platform_id: manylinux_x86_64 + manylinux_image: manylinux1 + - os: ubuntu-latest + python: 39 + bitness: 64 + platform_id: manylinux_x86_64 + manylinux_image: manylinux1 + + # Linux 64 bit manylinux2010 + - os: ubuntu-latest + python: 37 + bitness: 64 + platform_id: manylinux_x86_64 + manylinux_image: manylinux2010 + - os: ubuntu-latest + python: 38 + bitness: 64 + platform_id: manylinux_x86_64 + manylinux_image: manylinux2010 + - os: ubuntu-latest + python: 39 + bitness: 64 + platform_id: manylinux_x86_64 + manylinux_image: manylinux2010 + + # Linux 32 bit manylinux1 + - os: ubuntu-latest + python: 37 bitness: 32 platform_id: manylinux_i686 + manylinux_image: manylinux1 + - os: ubuntu-latest + python: 38 + bitness: 32 + platform_id: manylinux_i686 + manylinux_image: manylinux1 + - os: ubuntu-latest + python: 39 + bitness: 32 + platform_id: manylinux_i686 + manylinux_image: manylinux1 + + # Linux 32 bit manylinux2010 + - os: ubuntu-latest + python: 37 + bitness: 32 + platform_id: manylinux_i686 + manylinux_image: manylinux2010 + - os: ubuntu-latest + python: 38 + bitness: 32 + platform_id: manylinux_i686 + manylinux_image: manylinux2010 + - os: ubuntu-latest + python: 39 + bitness: 32 + platform_id: manylinux_i686 + manylinux_image: manylinux2010 + + # MacOS x86_64 - os: macos-latest bitness: 64 + python: 37 platform_id: macosx_x86_64 - exclude: + macosx_deployment_target: "10.13" - os: macos-latest - bitness: 32 - # Remove manylinux1 from the windows and osx build matrix since - # manylinux_image is not used for these platforms - - os: windows-latest - manylinux_image: manylinux1 + bitness: 64 + python: 38 + platform_id: macosx_x86_64 + macosx_deployment_target: "10.13" - os: macos-latest - manylinux_image: manylinux1 + bitness: 64 + python: 39 + platform_id: macosx_x86_64 + macosx_deployment_target: "10.13" + + # MacOS arm64 + - os: macos-latest + bitness: 64 + python: 38 + platform_id: macosx_arm64 + macosx_deployment_target: "12.0" + cibw_environment: "PYTHON_CROSSENV=1" + - os: macos-latest + bitness: 64 + python: 39 + platform_id: macosx_arm64 + macosx_deployment_target: "12.0" + cibw_environment: "PYTHON_CROSSENV=1" + - os: macos-latest + bitness: 64 + python: 310 + platform_id: macosx_arm64 + macosx_deployment_target: "12.0" + cibw_environment: "PYTHON_CROSSENV=1" steps: - name: Checkout scikit-learn @@ -95,10 +198,13 @@ jobs: OPENBLAS_NUM_THREADS=2 SKLEARN_SKIP_NETWORK_TESTS=1 SKLEARN_BUILD_PARALLEL=3 - MACOSX_DEPLOYMENT_TARGET=10.13 + ${{ matrix.cibw_environment }} + CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET=${{ matrix.macosx_deployment_target }} CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }} + CIBW_ARCHS: all CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux_image }} CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.manylinux_image }} + CIBW_TEST_SKIP: "*-macosx_arm64" CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: bash build_tools/github/repair_windows_wheels.sh {wheel} {dest_dir} ${{ matrix.bitness }} CIBW_BEFORE_TEST_WINDOWS: bash build_tools/github/build_minimal_windows_image.sh ${{ matrix.python }} ${{ matrix.bitness }} CIBW_TEST_REQUIRES: pytest pandas threadpoolctl diff --git a/build_tools/github/build_wheels.sh b/build_tools/github/build_wheels.sh index 2671c50f66bb3..11ba3f43decc5 100755 --- a/build_tools/github/build_wheels.sh +++ b/build_tools/github/build_wheels.sh @@ -12,7 +12,11 @@ if [[ "$RUNNER_OS" == "macOS" ]]; then # supported macos version is: High Sierra / 10.13. When upgrading this, be # sure to update the MACOSX_DEPLOYMENT_TARGET environment variable in # wheels.yml accordingly. Note that Darwin_17 == High Sierra / 10.13. - wget https://packages.macports.org/libomp/libomp-11.0.1_0+universal.darwin_17.i386-x86_64.tbz2 -O libomp.tbz2 + if [[ "$CIBW_BUILD" == *-macosx_arm64 ]]; then + wget https://packages.macports.org/libomp/libomp-11.0.1_0.darwin_20.arm64.tbz2 -O libomp.tbz2 + else + wget https://packages.macports.org/libomp/libomp-11.0.1_0+universal.darwin_17.i386-x86_64.tbz2 -O libomp.tbz2 + fi sudo tar -C / -xvjf libomp.tbz2 opt export CC=/usr/bin/clang diff --git a/build_tools/github/check_build_trigger.sh b/build_tools/github/check_build_trigger.sh index b80fe4674864d..4d9a6edb0d3ea 100755 --- a/build_tools/github/check_build_trigger.sh +++ b/build_tools/github/check_build_trigger.sh @@ -7,6 +7,7 @@ COMMIT_MSG=$(git log --no-merges -1 --oneline) # The commit marker "[cd build]" will trigger the build when required if [[ "$GITHUB_EVENT_NAME" == schedule || - "$COMMIT_MSG" =~ \[cd\ build\] ]]; then + "$COMMIT_MSG" =~ \[cd\ build\] || + "$COMMIT_MSG" =~ \[cd\ build\ gh\] ]]; then echo "::set-output name=build::true" fi diff --git a/build_tools/github/check_wheels.py b/build_tools/github/check_wheels.py index 4abd0c123df7a..ef9bd77254fb5 100644 --- a/build_tools/github/check_wheels.py +++ b/build_tools/github/check_wheels.py @@ -8,14 +8,8 @@ with gh_wheel_path.open("r") as f: wheel_config = yaml.safe_load(f) -build_matrix = wheel_config["jobs"]["build_wheels"]["strategy"]["matrix"] -n_python_versions = len(build_matrix["python"]) - -# For each python version we have: 7 wheels -# 1 osx wheel (x86_64) -# 4 linux wheel (i686 + x86_64) * (manylinux1 + manylinux2010) -# 2 windows wheel (win32 + wind_amd64) -n_wheels = 7 * n_python_versions +build_matrix = wheel_config["jobs"]["build_wheels"]["strategy"]["matrix"]["include"] +n_wheels = len(build_matrix) # plus one more for the sdist n_wheels += 1 diff --git a/doc/developers/contributing.rst b/doc/developers/contributing.rst index 54e7f66ffc3c9..03358342e3509 100644 --- a/doc/developers/contributing.rst +++ b/doc/developers/contributing.rst @@ -559,6 +559,7 @@ message, the following actions are taken. ---------------------- ------------------- [ci skip] CI is skipped completely [cd build] CD is run (wheels and source distribution are built) + [cd build gh] CD is run only for GitHub Actions [lint skip] Azure pipeline skips linting [scipy-dev] Build & test with our dependencies (numpy, scipy, etc ...) development builds [icc-build] Build & test with the Intel C compiler (ICC) diff --git a/sklearn/_build_utils/openmp_helpers.py b/sklearn/_build_utils/openmp_helpers.py index ebb3e67cd058f..192e96cd30765 100644 --- a/sklearn/_build_utils/openmp_helpers.py +++ b/sklearn/_build_utils/openmp_helpers.py @@ -49,6 +49,7 @@ def check_openmp_support(): if "PYODIDE_PACKAGE_ABI" in os.environ: # Pyodide doesn't support OpenMP return False + code = textwrap.dedent( """\ #include diff --git a/sklearn/_build_utils/pre_build_helpers.py b/sklearn/_build_utils/pre_build_helpers.py index 15bf2ba41dbc5..bf898a1b6639f 100644 --- a/sklearn/_build_utils/pre_build_helpers.py +++ b/sklearn/_build_utils/pre_build_helpers.py @@ -102,6 +102,7 @@ def basic_check_build(): if "PYODIDE_PACKAGE_ABI" in os.environ: # The following check won't work in pyodide return + code = textwrap.dedent( """\ #include From e449a573223de0225784bc96f1239a61534ff8ee Mon Sep 17 00:00:00 2001 From: "Thomas J. Fan" Date: Mon, 29 Nov 2021 22:45:04 -0500 Subject: [PATCH 2/4] CI Move env variables into build_wheel.sh [cd build gh] --- .github/workflows/wheels.yml | 11 ----------- build_tools/github/build_wheels.sh | 16 ++++++++++++---- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 850f29063810c..9f228fe8c73a8 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -149,37 +149,28 @@ jobs: bitness: 64 python: 37 platform_id: macosx_x86_64 - macosx_deployment_target: "10.13" - os: macos-latest bitness: 64 python: 38 platform_id: macosx_x86_64 - macosx_deployment_target: "10.13" - os: macos-latest bitness: 64 python: 39 platform_id: macosx_x86_64 - macosx_deployment_target: "10.13" # MacOS arm64 - os: macos-latest bitness: 64 python: 38 platform_id: macosx_arm64 - macosx_deployment_target: "12.0" - cibw_environment: "PYTHON_CROSSENV=1" - os: macos-latest bitness: 64 python: 39 platform_id: macosx_arm64 - macosx_deployment_target: "12.0" - cibw_environment: "PYTHON_CROSSENV=1" - os: macos-latest bitness: 64 python: 310 platform_id: macosx_arm64 - macosx_deployment_target: "12.0" - cibw_environment: "PYTHON_CROSSENV=1" steps: - name: Checkout scikit-learn @@ -198,8 +189,6 @@ jobs: OPENBLAS_NUM_THREADS=2 SKLEARN_SKIP_NETWORK_TESTS=1 SKLEARN_BUILD_PARALLEL=3 - ${{ matrix.cibw_environment }} - CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET=${{ matrix.macosx_deployment_target }} CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }} CIBW_ARCHS: all CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux_image }} diff --git a/build_tools/github/build_wheels.sh b/build_tools/github/build_wheels.sh index 11ba3f43decc5..cc20286854a9d 100755 --- a/build_tools/github/build_wheels.sh +++ b/build_tools/github/build_wheels.sh @@ -8,13 +8,21 @@ if [[ "$RUNNER_OS" == "macOS" ]]; then # Make sure to use a libomp version binary compatible with the oldest # supported version of the macos SDK as libomp will be vendored into the # scikit-learn wheels for macos. The list of binaries are in - # https://packages.macports.org/libomp/. Currently, the oldest - # supported macos version is: High Sierra / 10.13. When upgrading this, be - # sure to update the MACOSX_DEPLOYMENT_TARGET environment variable in - # wheels.yml accordingly. Note that Darwin_17 == High Sierra / 10.13. + # https://packages.macports.org/libomp/. if [[ "$CIBW_BUILD" == *-macosx_arm64 ]]; then + # arm64 builds must cross compile because CI is on x64 + export PYTHON_CROSSENV=1 + # SciPy requires 12.0 on arm to prevent kernel panics + # https://github.com/scipy/scipy/issues/14688 + # We use the same deployment target to match SciPy. + export MACOSX_DEPLOYMENT_TARGET=12.0 wget https://packages.macports.org/libomp/libomp-11.0.1_0.darwin_20.arm64.tbz2 -O libomp.tbz2 else + # Currently, the oldest supported macos version is: High Sierra / 10.13. + # When upgrading this, be sure to update the MACOSX_DEPLOYMENT_TARGET + # environment variable in wheels.yml accordingly. Note that Darwin_17 == + # High Sierra / 10.13. + export MACOSX_DEPLOYMENT_TARGET=10.13 wget https://packages.macports.org/libomp/libomp-11.0.1_0+universal.darwin_17.i386-x86_64.tbz2 -O libomp.tbz2 fi sudo tar -C / -xvjf libomp.tbz2 opt From 7c18ffa1be836c6b1d903b55ddf64cb1391be728 Mon Sep 17 00:00:00 2001 From: Olivier Grisel Date: Thu, 2 Dec 2021 10:40:12 +0100 Subject: [PATCH 3/4] [cd build gh] From cc0938b808a1d64bc2248f1d1f5a91829b6d6d8f Mon Sep 17 00:00:00 2001 From: Olivier Grisel Date: Thu, 2 Dec 2021 10:42:53 +0100 Subject: [PATCH 4/4] Update comment [cd build gh] --- build_tools/github/build_wheels.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/build_tools/github/build_wheels.sh b/build_tools/github/build_wheels.sh index cc20286854a9d..0a8f93e3d2c0b 100755 --- a/build_tools/github/build_wheels.sh +++ b/build_tools/github/build_wheels.sh @@ -19,9 +19,7 @@ if [[ "$RUNNER_OS" == "macOS" ]]; then wget https://packages.macports.org/libomp/libomp-11.0.1_0.darwin_20.arm64.tbz2 -O libomp.tbz2 else # Currently, the oldest supported macos version is: High Sierra / 10.13. - # When upgrading this, be sure to update the MACOSX_DEPLOYMENT_TARGET - # environment variable in wheels.yml accordingly. Note that Darwin_17 == - # High Sierra / 10.13. + # Note that Darwin_17 == High Sierra / 10.13. export MACOSX_DEPLOYMENT_TARGET=10.13 wget https://packages.macports.org/libomp/libomp-11.0.1_0+universal.darwin_17.i386-x86_64.tbz2 -O libomp.tbz2 fi