Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions builders/nix-python-builder.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,48 @@ class NixPythonBuilder : PythonBuilder {
return $expandedSourceLocation
}

[string] BuildLibmpdec() {
<#
.SYNOPSIS
Build a static libmpdec for the _decimal module. Returns installation location path.
#>

$mpdecimalVersion = "4.0.1"
$mpdecimalSha256 = "96d33abb4bb0070c7be0fed4246cd38416188325f820468214471938545b1ac8"
$mpdecimalUri = "https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-${mpdecimalVersion}.tar.gz"
Write-Host "libmpdec sources URI: $mpdecimalUri"

$archiveFilepath = Download-File -Uri $mpdecimalUri -OutputFolder $this.TempFolderLocation
$actualSha256 = (Get-FileHash -Path $archiveFilepath -Algorithm SHA256).Hash
if ($actualSha256 -ne $mpdecimalSha256) {
Write-Host "SHA256 mismatch for ${archiveFilepath}: expected $mpdecimalSha256, got $actualSha256"
exit 1
}

$sourceLocation = Join-Path -Path $this.TempFolderLocation -ChildPath "mpdecimal-source"
$installLocation = Join-Path -Path $this.TempFolderLocation -ChildPath "mpdecimal"
New-Item -Path $sourceLocation -ItemType Directory
Extract-TarArchive -ArchivePath $archiveFilepath -OutputDirectory $sourceLocation

Push-Location -Path $sourceLocation
### _decimal is a shared extension module, so the static library has to be position independent.
### -O3 and -fvisibility=hidden match how CPython compiled its bundled libmpdec in the 3.14 builds:
### libmpdec's symbols stay private to _decimal, and big-number arithmetic doesn't get slower.
Execute-Command -Command "./configure --prefix=$installLocation --disable-cxx --disable-shared CFLAGS='-fPIC -O3 -fvisibility=hidden'"
Execute-Command -Command "make"
Execute-Command -Command "make install"
Pop-Location

### Execute-Command doesn't stop on failure, and without the library _decimal would silently be left out
$libmpdecArchive = Join-Path -Path $installLocation -ChildPath "lib/libmpdec.a"
if (-not (Test-Path $libmpdecArchive)) {
Write-Host "libmpdec build failed, $libmpdecArchive is missing"
exit 1
}

return $installLocation
}

[void] CreateInstallationScript() {
<#
.SYNOPSIS
Expand Down
8 changes: 8 additions & 0 deletions builders/rhel-python-builder.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class RhelPythonBuilder : NixPythonBuilder {
$configureString += " --disable-gil"
}

### Python 3.15+ skips _decimal unless it finds a system libmpdec, and the RHEL builder doesn't install mpdecimal.
### Linking a static copy also keeps the artifact from needing libmpdec on the runner.
if ([semver]"$($this.Version.Major).$($this.Version.Minor)" -ge [semver]"3.15") {
$libmpdecLocation = $this.BuildLibmpdec()
$configureString += " LIBMPDEC_CFLAGS='-I$libmpdecLocation/include'"
$configureString += " LIBMPDEC_LIBS='$libmpdecLocation/lib/libmpdec.a -lm'"
}

### Compile with support of loadable sqlite extensions.
### Link to documentation (https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.enable_load_extension)
$configureString += " --enable-loadable-sqlite-extensions"
Expand Down
8 changes: 8 additions & 0 deletions builders/ubuntu-python-builder.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class UbuntuPythonBuilder : NixPythonBuilder {
$configureString += " --disable-gil"
}

### Python 3.15+ skips _decimal unless it finds a system libmpdec, and Ubuntu 24.04 doesn't package mpdecimal.
### Linking a static copy also keeps the artifact from needing libmpdec on the runner.
if ([semver]"$($this.Version.Major).$($this.Version.Minor)" -ge [semver]"3.15") {
$libmpdecLocation = $this.BuildLibmpdec()
$configureString += " LIBMPDEC_CFLAGS='-I$libmpdecLocation/include'"
$configureString += " LIBMPDEC_LIBS='$libmpdecLocation/lib/libmpdec.a -lm'"
}

### Compile with support of loadable sqlite extensions.
### Link to documentation (https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.enable_load_extension)
$configureString += " --enable-loadable-sqlite-extensions"
Expand Down
1 change: 1 addition & 0 deletions tests/sources/python-modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
'datetime',
'dbm',
'decimal',
'_decimal',
'difflib',
'dis',
'distutils',
Expand Down