Skip to content

Commit

Permalink
pypy 4
Browse files Browse the repository at this point in the history
  • Loading branch information
ameli committed Dec 21, 2023
1 parent ffbc836 commit fbce934
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 8 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ jobs:
fail-fast: false
matrix:
# python-version: ['3.9', '3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12', 'pypy3.8', 'pypy3.9', 'pypy3.10']
# python-version: ['3.9', '3.10', '3.11', '3.12', 'pypy3.8', 'pypy3.9', 'pypy3.10']
python-version: ['pypy3.8', 'pypy3.9', 'pypy3.10']

steps:
- name: Checkout
Expand Down Expand Up @@ -57,7 +58,9 @@ jobs:
if: (contains(matrix.python-version, 'pypy'))
run: |
brew install openblas
brew install gfortran
brew install libomp
bash ./tools/wheels/install_openblas.sh "${{ matrix.python-version }}"
bash ./tools/wheels/install_gfortran.sh "."
# - name: Install CUDA
# uses: Jimver/[email protected]
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: deploy-pypi

on:
push:
branches:
- main
# push:
# branches:
# - main
release:
types:
- published
Expand Down
2 changes: 1 addition & 1 deletion tools/ci/cirrus_deploy_pypi_linux_aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pypi_build_wheels_linux_aarch64_task:
USE_CUDA=1
CUDA_DYNAMIC_LOADING=1
CUDA_HOME=/usr/local/cuda
CIBW_BEFORE_BUILD: bash ./tools/wheels/install_openblas.sh "${{ matrix.python-version }}"
CIBW_BEFORE_BUILD: bash {project}/tools/wheels/install_openblas.sh "${CIBW_BUILD}"

build_script: |
apt update
Expand Down
6 changes: 5 additions & 1 deletion tools/ci/cirrus_deploy_pypi_macosx_arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ pypi_build_wheels_macosx_arm64_task:
CIBW_SKIP: "pp37-* cp36-* cp37-* cp38-*"
CIBW_BUILD_VERBOSITY: "3"
# CIBW_BEFORE_BUILD: "pip install delocate; brew install libomp"
CIBW_BEFORE_BUILD: "pip install delocate; brew install libomp; brew install openblas"
CIBW_BEFORE_BUILD: >
pip install delocate
brew install libomp
bash {project}/tools/wheels/install_openblas.sh "${CIBW_BUILD}"
bash {project}/tools/wheels/install_gfortran.sh {project}
CIBW_TEST_SKIP: "*_universal2:arm64"

build_script:
Expand Down
193 changes: 193 additions & 0 deletions tools/wheels/gfortran_utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# This file is vendored from github.com/MacPython/gfortran-install It is
# licensed under BSD-2 which is copied as a comment below

# Copyright 2016-2021 Matthew Brett, Isuru Fernando, Matti Picus

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:

# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.

# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

# Bash utilities for use with gfortran

ARCHIVE_SDIR="${ARCHIVE_SDIR:-archives}"

GF_UTIL_DIR=$(dirname "${BASH_SOURCE[0]}")

function get_distutils_platform {
# Report platform as in form of distutils get_platform.
# This is like the platform tag that pip will use.
# Modify fat architecture tags on macOS to reflect compiled architecture

# Deprecate this function once get_distutils_platform_ex is used in all
# downstream projects
local plat=$1
case $plat in
i686|x86_64|arm64|universal2|intel|aarch64|s390x|ppc64le) ;;
*) echo Did not recognize plat $plat; return 1 ;;
esac
local uname=${2:-$(uname)}
if [ "$uname" != "Darwin" ]; then
if [ "$plat" == "intel" ]; then
echo plat=intel not allowed for Manylinux
return 1
fi
echo "manylinux1_$plat"
return
fi
# The gfortran downloads build for macos 10.9
local target="10_9"
echo "macosx_${target}_${plat}"
}

function get_distutils_platform_ex {
# Report platform as in form of distutils get_platform.
# This is like the platform tag that pip will use.
# Modify fat architecture tags on macOS to reflect compiled architecture
# For non-darwin, report manylinux version
local plat=$1
local mb_ml_ver=${MB_ML_VER:-1}
case $plat in
i686|x86_64|arm64|universal2|intel|aarch64|s390x|ppc64le) ;;
*) echo Did not recognize plat $plat; return 1 ;;
esac
local uname=${2:-$(uname)}
if [ "$uname" != "Darwin" ]; then
if [ "$plat" == "intel" ]; then
echo plat=intel not allowed for Manylinux
return 1
fi
echo "manylinux${mb_ml_ver}_${plat}"
return
fi
# The gfortran downloads build for macos 10.9
local target="10_9"
echo "macosx_${target}_${plat}"
}

function get_macosx_target {
# Report MACOSX_DEPLOYMENT_TARGET as given by distutils get_platform.
python3 -c "import sysconfig as s; print(s.get_config_vars()['MACOSX_DEPLOYMENT_TARGET'])"
}

function check_gfortran {
# Check that gfortran exists on the path
if [ -z "$(which gfortran)" ]; then
echo Missing gfortran
exit 1
fi
}

function get_gf_lib_for_suf {
local suffix=$1
local prefix=$2
local plat=${3:-$PLAT}
local uname=${4:-$(uname)}
if [ -z "$prefix" ]; then echo Prefix not defined; exit 1; fi
local plat_tag=$(get_distutils_platform_ex $plat $uname)
if [ -n "$suffix" ]; then suffix="-$suffix"; fi
local fname="$prefix-${plat_tag}${suffix}.tar.gz"
local out_fname="${ARCHIVE_SDIR}/$fname"
[ -s $out_fname ] || (echo "$out_fname is empty"; exit 24)
echo "$out_fname"
}

if [ "$(uname)" == "Darwin" ]; then
mac_target=${MACOSX_DEPLOYMENT_TARGET:-$(get_macosx_target)}
export MACOSX_DEPLOYMENT_TARGET=$mac_target
# Keep this for now as some builds might depend on this being
# available before install_gfortran is called
export GFORTRAN_SHA=c469a420d2d003112749dcdcbe3c684eef42127e
# Set SDKROOT env variable if not set
export SDKROOT=${SDKROOT:-$(xcrun --show-sdk-path)}

function download_and_unpack_gfortran {
local arch=$1
local type=$2
curl -L -O https://github.com/isuruf/gcc/releases/download/gcc-11.3.0-2/gfortran-darwin-${arch}-${type}.tar.gz
case ${arch}-${type} in
arm64-native)
export GFORTRAN_SHA=0d5c118e5966d0fb9e7ddb49321f63cac1397ce8
;;
arm64-cross)
export GFORTRAN_SHA=527232845abc5af21f21ceacc46fb19c190fe804
;;
x86_64-native)
export GFORTRAN_SHA=c469a420d2d003112749dcdcbe3c684eef42127e
;;
x86_64-cross)
export GFORTRAN_SHA=107604e57db97a0ae3e7ca7f5dd722959752f0b3
;;
esac
if [[ "$(shasum gfortran-darwin-${arch}-${type}.tar.gz)" != "${GFORTRAN_SHA} gfortran-darwin-${arch}-${type}.tar.gz" ]]; then
echo "shasum mismatch for gfortran-darwin-${arch}-${type}"
exit 1
fi
sudo mkdir -p /opt/
sudo cp "gfortran-darwin-${arch}-${type}.tar.gz" /opt/gfortran-darwin-${arch}-${type}.tar.gz
pushd /opt
sudo tar -xvf gfortran-darwin-${arch}-${type}.tar.gz
sudo rm gfortran-darwin-${arch}-${type}.tar.gz
popd
if [[ "${type}" == "native" ]]; then
# Link these into /usr/local so that there's no need to add rpath or -L
sudo mkdir -p /usr/local/lib
for f in libgfortran.dylib libgfortran.5.dylib libgcc_s.1.dylib libgcc_s.1.1.dylib libquadmath.dylib libquadmath.0.dylib; do
sudo ln -sf /opt/gfortran-darwin-${arch}-${type}/lib/$f /usr/local/lib/$f
done
# Add it to PATH
sudo ln -sf /opt/gfortran-darwin-${arch}-${type}/bin/gfortran /usr/local/bin/gfortran
fi
}

function install_arm64_cross_gfortran {
download_and_unpack_gfortran arm64 cross
export FC_ARM64="$(find /opt/gfortran-darwin-arm64-cross/bin -name "*-gfortran")"
local libgfortran="$(find /opt/gfortran-darwin-arm64-cross/lib -name libgfortran.dylib)"
local libdir=$(dirname $libgfortran)

export FC_ARM64_LDFLAGS="-L$libdir -Wl,-rpath,$libdir"
if [[ "${PLAT:-}" == "arm64" ]]; then
export FC=$FC_ARM64
fi
}
function install_gfortran {
download_and_unpack_gfortran $(uname -m) native
check_gfortran
if [[ "${PLAT:-}" == "universal2" || "${PLAT:-}" == "arm64" ]]; then
install_arm64_cross_gfortran
fi
}

function get_gf_lib {
# Get lib with gfortran suffix
get_gf_lib_for_suf "gf_${GFORTRAN_SHA:0:7}" $@
}
else
function install_gfortran {
# No-op - already installed on manylinux image
check_gfortran
}

function get_gf_lib {
# Get library with no suffix
get_gf_lib_for_suf "" $@
}
fi
16 changes: 16 additions & 0 deletions tools/wheels/install_gfortran.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: Copyright 2021, Siavash Ameli <[email protected]>
# SPDX-License-Identifier: BSD-3-Clause
# SPDX-FileType: SOURCE
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the license found in the LICENSE.txt file in the root
# directory of this source tree.


set -xe
PROJECT_DIR="$1"
PLATFORM="macosx-arm64"
PLAT="arm64"
source $PROJECT_DIR/tools/wheels/gfortran_utils.sh
install_gfortran
pip install "delocate==0.10.4"
1 change: 0 additions & 1 deletion tools/wheels/install_openblas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ then
export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"
# export LDFLAGS="-L/usr/local/opt/openblas/lib"
# export CPPFLAGS="-I/usr/local/opt/openblas/include"

fi

else
Expand Down
4 changes: 4 additions & 0 deletions tools/wheels/upload_wheels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ install_anaconda() {
# Export PATH
export PATH=${CONDA_BASE_DIR}:$PATH
export PATH=${CONDA_BIN_DIR}:$PATH

# Initialize conda
# ${CONDA_BIN_DIR}/conda init bash
# source ${CONDA_BIN_DIR}/activate
}


Expand Down

0 comments on commit fbce934

Please sign in to comment.