Skip to content

Commit 6d04944

Browse files
authored
feat: build macOS arm64 packages (actions#214)
1 parent 256e6dd commit 6d04944

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

.github/workflows/build-python-packages.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
PLATFORMS:
1616
description: 'Platforms for execution in "os" or "os_arch" format (arch is "x64" by default)'
1717
required: true
18-
default: 'ubuntu-20.04,ubuntu-22.04,macos-11,windows-2019_x64,windows-2019_x86'
18+
default: 'ubuntu-20.04,ubuntu-22.04,macos-11_x64,macos-11_arm64,windows-2019_x64,windows-2019_x86'
1919
pull_request:
2020
paths-ignore:
2121
- 'versions-manifest.json'
@@ -39,7 +39,7 @@ jobs:
3939
- name: Generate execution matrix
4040
id: generate-matrix
4141
run: |
42-
[String[]]$configurations = "${{ inputs.platforms || 'ubuntu-20.04,ubuntu-22.04,macos-11,windows-2019_x64,windows-2019_x86' }}".Split(",").Trim()
42+
[String[]]$configurations = "${{ inputs.platforms || 'ubuntu-20.04,ubuntu-22.04,macos-11,macos-11_arm64,windows-2019_x64,windows-2019_x86' }}".Split(",").Trim()
4343
$matrix = @()
4444
4545
foreach ($configuration in $configurations) {
@@ -155,6 +155,7 @@ jobs:
155155
$pesterContainer = New-PesterContainer -Path './python-tests.ps1' -Data @{
156156
Version="${{ env.VERSION }}";
157157
Platform="${{ matrix.platform }}";
158+
Architecture="${{ matrix.arch }}";
158159
}
159160
$Result = Invoke-Pester -Container $pesterContainer -PassThru
160161
if ($Result.FailedCount -gt 0) {

builders/macos-python-builder.psm1

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class macOSPythonBuilder : NixPythonBuilder {
77
88
.DESCRIPTION
99
Contains methods that required to build macOS Python artifact from sources. Inherited from base NixPythonBuilder.
10-
10+
1111
While python.org provides precompiled binaries for macOS, switching to them risks breaking existing customers.
1212
If we wanted to start using the official binaries instead of building from source, we should avoid changing previous versions
1313
so we remain backwards compatible.
@@ -151,6 +151,7 @@ class macOSPythonBuilder : NixPythonBuilder {
151151
$variablesToReplace = @{
152152
"{{__VERSION_FULL__}}" = $this.Version;
153153
"{{__PKG_NAME__}}" = $this.GetPkgName();
154+
"{{__ARCH__}}" = $this.Architecture;
154155
}
155156

156157
$variablesToReplace.keys | ForEach-Object { $installationTemplateContent = $installationTemplateContent.Replace($_, $variablesToReplace[$_]) }
@@ -166,7 +167,7 @@ class macOSPythonBuilder : NixPythonBuilder {
166167

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

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

installers/macos-pkg-setup-template.sh

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ set -e
22

33
PYTHON_FULL_VERSION="{{__VERSION_FULL__}}"
44
PYTHON_PKG_NAME="{{__PKG_NAME__}}"
5+
ARCH="{{__ARCH__}}"
56
MAJOR_VERSION=$(echo $PYTHON_FULL_VERSION | cut -d '.' -f 1)
67
MINOR_VERSION=$(echo $PYTHON_FULL_VERSION | cut -d '.' -f 2)
78

@@ -18,7 +19,7 @@ fi
1819

1920
PYTHON_TOOLCACHE_PATH=$TOOLCACHE_ROOT/Python
2021
PYTHON_TOOLCACHE_VERSION_PATH=$PYTHON_TOOLCACHE_PATH/$PYTHON_FULL_VERSION
21-
PYTHON_TOOLCACHE_VERSION_ARCH_PATH=$PYTHON_TOOLCACHE_VERSION_PATH/x64
22+
PYTHON_TOOLCACHE_VERSION_ARCH_PATH=$PYTHON_TOOLCACHE_VERSION_PATH/$ARCH
2223
PYTHON_FRAMEWORK_PATH="/Library/Frameworks/Python.framework/Versions/${MAJOR_VERSION}.${MINOR_VERSION}"
2324
PYTHON_APPLICATION_PATH="/Applications/Python ${MAJOR_VERSION}.${MINOR_VERSION}"
2425

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

5657
cd bin/
5758

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

7778
echo "Create complete file"
78-
touch $PYTHON_TOOLCACHE_VERSION_PATH/x64.complete
79+
touch $PYTHON_TOOLCACHE_VERSION_PATH/${ARCH}.complete

tests/python-tests.ps1

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ param (
22
[semver] [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()]
33
$Version,
44
[string] [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()]
5-
$Platform
5+
$Platform,
6+
[string] [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()]
7+
$Architecture
68
)
79

810
Import-Module (Join-Path $PSScriptRoot "../helpers/pester-extensions.psm1")
@@ -56,7 +58,7 @@ Describe "Tests" {
5658
# }
5759
# }
5860

59-
if (($Version -ge "3.2.0") -and ($Version -lt "3.11.0")) {
61+
if (($Version -ge "3.2.0") -and ($Version -lt "3.11.0") -and (($Platform -ne "darwin") -or ($Architecture -ne "arm64"))) {
6062
It "Check if sqlite3 module is installed" {
6163
"python ./sources/python-sqlite3.py" | Should -ReturnZeroExitCode
6264
}
@@ -80,7 +82,7 @@ Describe "Tests" {
8082

8183
It "Check if python configuration is correct" {
8284
$nativeVersion = Convert-Version -version $Version
83-
"python ./sources/python-config-test.py $Version $nativeVersion" | Should -ReturnZeroExitCode
85+
"python ./sources/python-config-test.py $Version $nativeVersion $Architecture" | Should -ReturnZeroExitCode
8486
}
8587

8688
It "Check if shared libraries are linked correctly" {

tests/sources/python-config-test.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
os_type = platform.system()
1010
version = sys.argv[1]
1111
nativeVersion = sys.argv[2]
12+
architecture = sys.argv[3]
1213

1314
versions=version.split(".")
1415
version_major=int(versions[0])
1516
version_minor=int(versions[1])
1617

17-
pkg_installer = os_type == 'Darwin' and (version_major == 3 and version_minor >= 11)
18+
pkg_installer = os_type == 'Darwin' and ((version_major == 3 and version_minor >= 11) or (architecture == "arm64"))
1819

1920
lib_dir_path = sysconfig.get_config_var('LIBDIR')
2021
ld_library_name = sysconfig.get_config_var('LDLIBRARY')
@@ -40,7 +41,7 @@
4041
### Validate shared libraries
4142
if is_shared:
4243
print('%s was built with shared extensions' % ld_library_name)
43-
44+
4445
### Validate libpython extension
4546
ld_library_extension = ld_library_name.split('.')[-1]
4647
if ld_library_extension != expected_ld_library_extension:
@@ -64,7 +65,7 @@
6465
else:
6566
expected_openssl_includes = '-I/usr/local/opt/[email protected]/include'
6667
expected_openssl_ldflags ='-L/usr/local/opt/[email protected]/lib'
67-
68+
6869
openssl_includes = sysconfig.get_config_var('OPENSSL_INCLUDES')
6970
openssl_ldflags = sysconfig.get_config_var('OPENSSL_LDFLAGS')
7071

@@ -81,4 +82,4 @@
8182
if sys.version_info < (3, 12):
8283
if not have_libreadline:
8384
print('Missing libreadline')
84-
exit(1)
85+
exit(1)

0 commit comments

Comments
 (0)