feat: build macOS arm64 packages

This commit is contained in:
mayeut 2022-12-11 16:35:04 +01:00
parent 256e6ddd57
commit fb2e761b1b
No known key found for this signature in database
GPG Key ID: 8B03CED67D3ABFBA
5 changed files with 24 additions and 18 deletions

View File

@ -15,7 +15,7 @@ on:
PLATFORMS: PLATFORMS:
description: 'Platforms for execution in "os" or "os_arch" format (arch is "x64" by default)' description: 'Platforms for execution in "os" or "os_arch" format (arch is "x64" by default)'
required: true required: true
default: 'ubuntu-20.04,ubuntu-22.04,macos-11,windows-2019_x64,windows-2019_x86' default: 'ubuntu-20.04,ubuntu-22.04,macos-11_x64,macos-11_arm64,windows-2019_x64,windows-2019_x86'
pull_request: pull_request:
paths-ignore: paths-ignore:
- 'versions-manifest.json' - 'versions-manifest.json'
@ -39,7 +39,7 @@ jobs:
- name: Generate execution matrix - name: Generate execution matrix
id: generate-matrix id: generate-matrix
run: | run: |
[String[]]$configurations = "${{ inputs.platforms || 'ubuntu-20.04,ubuntu-22.04,macos-11,windows-2019_x64,windows-2019_x86' }}".Split(",").Trim() [String[]]$configurations = "${{ inputs.platforms || 'ubuntu-20.04,ubuntu-22.04,macos-11,macos-11_arm64,windows-2019_x64,windows-2019_x86' }}".Split(",").Trim()
$matrix = @() $matrix = @()
foreach ($configuration in $configurations) { foreach ($configuration in $configurations) {
@ -155,6 +155,7 @@ jobs:
$pesterContainer = New-PesterContainer -Path './python-tests.ps1' -Data @{ $pesterContainer = New-PesterContainer -Path './python-tests.ps1' -Data @{
Version="${{ env.VERSION }}"; Version="${{ env.VERSION }}";
Platform="${{ matrix.platform }}"; Platform="${{ matrix.platform }}";
Architecture="${{ matrix.arch }}";
} }
$Result = Invoke-Pester -Container $pesterContainer -PassThru $Result = Invoke-Pester -Container $pesterContainer -PassThru
if ($Result.FailedCount -gt 0) { if ($Result.FailedCount -gt 0) {

View File

@ -7,7 +7,7 @@ class macOSPythonBuilder : NixPythonBuilder {
.DESCRIPTION .DESCRIPTION
Contains methods that required to build macOS Python artifact from sources. Inherited from base NixPythonBuilder. 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. 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 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. so we remain backwards compatible.
@ -151,6 +151,7 @@ class macOSPythonBuilder : NixPythonBuilder {
$variablesToReplace = @{ $variablesToReplace = @{
"{{__VERSION_FULL__}}" = $this.Version; "{{__VERSION_FULL__}}" = $this.Version;
"{{__PKG_NAME__}}" = $this.GetPkgName(); "{{__PKG_NAME__}}" = $this.GetPkgName();
"{{__ARCH__}}" = $this.Architecture;
} }
$variablesToReplace.keys | ForEach-Object { $installationTemplateContent = $installationTemplateContent.Replace($_, $variablesToReplace[$_]) } $variablesToReplace.keys | ForEach-Object { $installationTemplateContent = $installationTemplateContent.Replace($_, $variablesToReplace[$_]) }
@ -166,7 +167,7 @@ class macOSPythonBuilder : NixPythonBuilder {
$PkgVersion = [semver]"3.11.0-beta.1" $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..." Write-Host "Download Python $($this.Version) [$($this.Architecture)] package..."
$this.DownloadPkg() $this.DownloadPkg()

View File

@ -2,6 +2,7 @@ set -e
PYTHON_FULL_VERSION="{{__VERSION_FULL__}}" PYTHON_FULL_VERSION="{{__VERSION_FULL__}}"
PYTHON_PKG_NAME="{{__PKG_NAME__}}" PYTHON_PKG_NAME="{{__PKG_NAME__}}"
ARCH="{{__ARCH__}}"
MAJOR_VERSION=$(echo $PYTHON_FULL_VERSION | cut -d '.' -f 1) MAJOR_VERSION=$(echo $PYTHON_FULL_VERSION | cut -d '.' -f 1)
MINOR_VERSION=$(echo $PYTHON_FULL_VERSION | cut -d '.' -f 2) MINOR_VERSION=$(echo $PYTHON_FULL_VERSION | cut -d '.' -f 2)
@ -18,7 +19,7 @@ fi
PYTHON_TOOLCACHE_PATH=$TOOLCACHE_ROOT/Python PYTHON_TOOLCACHE_PATH=$TOOLCACHE_ROOT/Python
PYTHON_TOOLCACHE_VERSION_PATH=$PYTHON_TOOLCACHE_PATH/$PYTHON_FULL_VERSION 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_FRAMEWORK_PATH="/Library/Frameworks/Python.framework/Versions/${MAJOR_VERSION}.${MINOR_VERSION}"
PYTHON_APPLICATION_PATH="/Applications/Python ${MAJOR_VERSION}.${MINOR_VERSION}" PYTHON_APPLICATION_PATH="/Applications/Python ${MAJOR_VERSION}.${MINOR_VERSION}"
@ -29,10 +30,10 @@ if [ ! -d $PYTHON_TOOLCACHE_PATH ]; then
else else
# remove ALL other directories for same major.minor python versions # remove ALL other directories for same major.minor python versions
find $PYTHON_TOOLCACHE_PATH -name "${MAJOR_VERSION}.${MINOR_VERSION}.*"|while read python_version;do find $PYTHON_TOOLCACHE_PATH -name "${MAJOR_VERSION}.${MINOR_VERSION}.*"|while read python_version;do
python_version_x64="$python_version/x64" python_version_arch="$python_version/$ARCH"
if [ -e "$python_version_x64" ];then if [ -e "$python_version_arch" ];then
echo "Deleting Python $python_version_x64" echo "Deleting Python $python_version_arch"
rm -rf "$python_version_x64" rm -rf "$python_version_arch"
fi fi
done done
fi fi
@ -55,7 +56,7 @@ ln -s ./bin/$PYTHON_MAJOR_DOT_MINOR python
cd bin/ 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 # since we do not remove the framework folder
if [ ! -f $PYTHON_MAJOR_MINOR ]; then if [ ! -f $PYTHON_MAJOR_MINOR ]; then
ln -s $PYTHON_MAJOR_DOT_MINOR $PYTHON_MAJOR_MINOR ln -s $PYTHON_MAJOR_DOT_MINOR $PYTHON_MAJOR_MINOR
@ -75,4 +76,4 @@ echo "Install OpenSSL certificates"
sh -e "${PYTHON_APPLICATION_PATH}/Install Certificates.command" sh -e "${PYTHON_APPLICATION_PATH}/Install Certificates.command"
echo "Create complete file" echo "Create complete file"
touch $PYTHON_TOOLCACHE_VERSION_PATH/x64.complete touch $PYTHON_TOOLCACHE_VERSION_PATH/${ARCH}.complete

View File

@ -2,7 +2,9 @@ param (
[semver] [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [semver] [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()]
$Version, $Version,
[string] [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()]
$Platform $Platform,
[string] [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()]
$Architecture
) )
Import-Module (Join-Path $PSScriptRoot "../helpers/pester-extensions.psm1") Import-Module (Join-Path $PSScriptRoot "../helpers/pester-extensions.psm1")
@ -56,7 +58,7 @@ Describe "Tests" {
# } # }
# } # }
if (($Version -ge "3.2.0") -and ($Version -lt "3.11.0")) { if (($Version -ge "3.2.0") -and ($Version -lt "3.11.0") -and (($Platform -ne "darwin") -or ($Architecture -ne "arm64"))) {
It "Check if sqlite3 module is installed" { It "Check if sqlite3 module is installed" {
"python ./sources/python-sqlite3.py" | Should -ReturnZeroExitCode "python ./sources/python-sqlite3.py" | Should -ReturnZeroExitCode
} }
@ -80,7 +82,7 @@ Describe "Tests" {
It "Check if python configuration is correct" { It "Check if python configuration is correct" {
$nativeVersion = Convert-Version -version $Version $nativeVersion = Convert-Version -version $Version
"python ./sources/python-config-test.py $Version $nativeVersion" | Should -ReturnZeroExitCode "python ./sources/python-config-test.py $Version $nativeVersion $Architecture" | Should -ReturnZeroExitCode
} }
It "Check if shared libraries are linked correctly" { It "Check if shared libraries are linked correctly" {

View File

@ -9,12 +9,13 @@ import os
os_type = platform.system() os_type = platform.system()
version = sys.argv[1] version = sys.argv[1]
nativeVersion = sys.argv[2] nativeVersion = sys.argv[2]
architecture = sys.argv[3]
versions=version.split(".") versions=version.split(".")
version_major=int(versions[0]) version_major=int(versions[0])
version_minor=int(versions[1]) version_minor=int(versions[1])
pkg_installer = os_type == 'Darwin' and (version_major == 3 and version_minor >= 11) pkg_installer = os_type == 'Darwin' and ((version_major == 3 and version_minor >= 11) or (architecture == "arm64"))
lib_dir_path = sysconfig.get_config_var('LIBDIR') lib_dir_path = sysconfig.get_config_var('LIBDIR')
ld_library_name = sysconfig.get_config_var('LDLIBRARY') ld_library_name = sysconfig.get_config_var('LDLIBRARY')
@ -40,7 +41,7 @@ if lib_dir_path != expected_lib_dir_path:
### Validate shared libraries ### Validate shared libraries
if is_shared: if is_shared:
print('%s was built with shared extensions' % ld_library_name) print('%s was built with shared extensions' % ld_library_name)
### Validate libpython extension ### Validate libpython extension
ld_library_extension = ld_library_name.split('.')[-1] ld_library_extension = ld_library_name.split('.')[-1]
if ld_library_extension != expected_ld_library_extension: if ld_library_extension != expected_ld_library_extension:
@ -64,7 +65,7 @@ if os_type == 'Darwin':
else: else:
expected_openssl_includes = '-I/usr/local/opt/openssl@1.1/include' expected_openssl_includes = '-I/usr/local/opt/openssl@1.1/include'
expected_openssl_ldflags ='-L/usr/local/opt/openssl@1.1/lib' expected_openssl_ldflags ='-L/usr/local/opt/openssl@1.1/lib'
openssl_includes = sysconfig.get_config_var('OPENSSL_INCLUDES') openssl_includes = sysconfig.get_config_var('OPENSSL_INCLUDES')
openssl_ldflags = sysconfig.get_config_var('OPENSSL_LDFLAGS') openssl_ldflags = sysconfig.get_config_var('OPENSSL_LDFLAGS')
@ -81,4 +82,4 @@ if os_type == 'Darwin':
if sys.version_info < (3, 12): if sys.version_info < (3, 12):
if not have_libreadline: if not have_libreadline:
print('Missing libreadline') print('Missing libreadline')
exit(1) exit(1)