Skip to content

Commit

Permalink
feat: build macOS arm64 packages
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Dec 11, 2022
1 parent 6dd0b75 commit e1a6884
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
PLATFORMS:
description: 'Platforms for execution in "os" or "os_arch" format (arch is "x64" by default)'
required: true
default: 'ubuntu-18.04,ubuntu-20.04,ubuntu-22.04,macos-11,windows-2019_x64,windows-2019_x86'
default: 'ubuntu-18.04,ubuntu-20.04,ubuntu-22.04,macos-11_x64,macos-11_arm64,windows-2019_x64,windows-2019_x86'
pull_request:
paths-ignore:
- 'versions-manifest.json'
Expand Down
5 changes: 3 additions & 2 deletions builders/macos-python-builder.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class macOSPythonBuilder : NixPythonBuilder {
.DESCRIPTION
Contains methods that required to build macOS Python artifact from sources. Inherited from base NixPythonBuilder.
While python.org provides precompiled binaries for macOS, switching to them risks breaking existing customers.
If we wanted to start using the official binaries instead of building from source, we should avoid changing previous versions
so we remain backwards compatible.
Expand Down Expand Up @@ -143,6 +143,7 @@ class macOSPythonBuilder : NixPythonBuilder {
$variablesToReplace = @{
"{{__VERSION_FULL__}}" = $this.Version;
"{{__PKG_NAME__}}" = $this.GetPkgName();
"{{__ARCH__}}" = $this.Architecture;
}

$variablesToReplace.keys | ForEach-Object { $installationTemplateContent = $installationTemplateContent.Replace($_, $variablesToReplace[$_]) }
Expand All @@ -158,7 +159,7 @@ class macOSPythonBuilder : NixPythonBuilder {

$PkgVersion = [semver]"3.11.0-beta.1"

if ($this.Version -ge $PkgVersion) {
if (($this.Version -ge $PkgVersion) -or ($this.Architecture -eq "arm64")) {
Write-Host "Download Python $($this.Version) [$($this.Architecture)] package..."
$this.DownloadPkg()

Expand Down
15 changes: 8 additions & 7 deletions installers/macos-pkg-setup-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set -e

PYTHON_FULL_VERSION="{{__VERSION_FULL__}}"
PYTHON_PKG_NAME="{{__PKG_NAME__}}"
ARCH="{{__ARCH__}}"
MAJOR_VERSION=$(echo $PYTHON_FULL_VERSION | cut -d '.' -f 1)
MINOR_VERSION=$(echo $PYTHON_FULL_VERSION | cut -d '.' -f 2)

Expand All @@ -18,7 +19,7 @@ fi

PYTHON_TOOLCACHE_PATH=$TOOLCACHE_ROOT/Python
PYTHON_TOOLCACHE_VERSION_PATH=$PYTHON_TOOLCACHE_PATH/$PYTHON_FULL_VERSION
PYTHON_TOOLCACHE_VERSION_ARCH_PATH=$PYTHON_TOOLCACHE_VERSION_PATH/x64
PYTHON_TOOLCACHE_VERSION_ARCH_PATH=$PYTHON_TOOLCACHE_VERSION_PATH/$ARCH
PYTHON_FRAMEWORK_PATH="/Library/Frameworks/Python.framework/Versions/${MAJOR_VERSION}.${MINOR_VERSION}"
PYTHON_APPLICATION_PATH="/Applications/Python ${MAJOR_VERSION}.${MINOR_VERSION}"

Expand All @@ -29,10 +30,10 @@ if [ ! -d $PYTHON_TOOLCACHE_PATH ]; then
else
# remove ALL other directories for same major.minor python versions
find $PYTHON_TOOLCACHE_PATH -name "${MAJOR_VERSION}.${MINOR_VERSION}.*"|while read python_version;do
python_version_x64="$python_version/x64"
if [ -e "$python_version_x64" ];then
echo "Deleting Python $python_version_x64"
rm -rf "$python_version_x64"
python_version_arch="$python_version/$ARCH"
if [ -e "$python_version_arch" ];then
echo "Deleting Python $python_version_arch"
rm -rf "$python_version_arch"
fi
done
fi
Expand All @@ -55,7 +56,7 @@ ln -s ./bin/$PYTHON_MAJOR_DOT_MINOR python

cd bin/

# This symlink already exists if Python version with the same major.minor version is installed,
# This symlink already exists if Python version with the same major.minor version is installed,
# since we do not remove the framework folder
if [ ! -f $PYTHON_MAJOR_MINOR ]; then
ln -s $PYTHON_MAJOR_DOT_MINOR $PYTHON_MAJOR_MINOR
Expand All @@ -75,4 +76,4 @@ echo "Install OpenSSL certificates"
sh -e "${PYTHON_APPLICATION_PATH}/Install Certificates.command"

echo "Create complete file"
touch $PYTHON_TOOLCACHE_VERSION_PATH/x64.complete
touch $PYTHON_TOOLCACHE_VERSION_PATH/${ARCH}.complete

0 comments on commit e1a6884

Please sign in to comment.