bb15b750fb
复用现有 Docker 和 Nuitka 流程,隔离架构镜像并支持 aarch64 标签。已通过 47 项测试、代码及文档门禁,并完成 Python 3.10 ARM64 wheel 构建、隔离导入与内容审计。
120 lines
4.1 KiB
PowerShell
120 lines
4.1 KiB
PowerShell
# Build x86_64 or aarch64 manylinux wheels using Docker Desktop.
|
|
#
|
|
# Usage (from repo root, PowerShell):
|
|
# .\build\wheel\docker\run.ps1
|
|
# .\build\wheel\docker\run.ps1 -Architecture aarch64 -PythonVersions 3.10
|
|
#
|
|
# From cmd.exe:
|
|
# powershell -ExecutionPolicy Bypass -File .\build\wheel\docker\run.ps1
|
|
|
|
param(
|
|
[ValidateSet("pypi-linux", "internal")]
|
|
[string]$Target = "pypi-linux",
|
|
[string]$PythonVersions = "3.10,3.11,3.12",
|
|
[ValidateSet("x86_64", "aarch64")]
|
|
[string]$Architecture = "x86_64",
|
|
[switch]$SkipImageBuild,
|
|
[string]$ImageName = ""
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$Architecture = $Architecture.ToLowerInvariant()
|
|
|
|
function Convert-ToManylinuxTag {
|
|
param([string]$Version)
|
|
$v = $Version.Trim()
|
|
switch ($v) {
|
|
"3.10" { return "cp310-cp310" }
|
|
"3.11" { return "cp311-cp311" }
|
|
"3.12" { return "cp312-cp312" }
|
|
"cp310-cp310" { return "cp310-cp310" }
|
|
"cp311-cp311" { return "cp311-cp311" }
|
|
"cp312-cp312" { return "cp312-cp312" }
|
|
default {
|
|
throw "Unsupported Python version '$Version'. Use 3.10, 3.11, and/or 3.12."
|
|
}
|
|
}
|
|
}
|
|
|
|
$RepoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..\..")).Path
|
|
Set-Location $RepoRoot
|
|
|
|
$tags = @()
|
|
foreach ($part in ($PythonVersions -split ",")) {
|
|
if ([string]::IsNullOrWhiteSpace($part)) { continue }
|
|
$tags += (Convert-ToManylinuxTag $part)
|
|
}
|
|
if ($tags.Count -eq 0) {
|
|
throw "No Python versions specified."
|
|
}
|
|
$pythonTags = [string]::Join(",", $tags)
|
|
$dockerArchitecture = if ($Architecture -eq "aarch64") { "arm64" } else { "amd64" }
|
|
$dockerPlatform = "linux/$dockerArchitecture"
|
|
if ([string]::IsNullOrWhiteSpace($ImageName)) {
|
|
$ImageName = if ($Architecture -eq "aarch64") { "orisys-manylinux-aarch64" } else { "orisys-manylinux" }
|
|
}
|
|
|
|
Write-Host "=== Orisys manylinux Docker build ==="
|
|
Write-Host "Repo: $RepoRoot"
|
|
Write-Host "Target: $Target"
|
|
Write-Host "Image: $ImageName"
|
|
Write-Host "Architecture: $Architecture ($dockerPlatform)"
|
|
Write-Host "Python tags: $pythonTags"
|
|
|
|
# Docker Desktop must be in Linux container mode for manylinux.
|
|
$dockerInfo = docker version --format "{{.Server.Os}}" 2>$null
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Docker is not available. Start Docker Desktop and retry."
|
|
}
|
|
if ($dockerInfo -ne "linux") {
|
|
throw "Docker server OS is '$dockerInfo'. Switch Docker Desktop to Linux containers."
|
|
}
|
|
|
|
$entrypoint = Join-Path $RepoRoot "build\wheel\docker\entrypoint.sh"
|
|
# Normalize CRLF -> LF so bash in the container can execute the script.
|
|
$raw = [System.IO.File]::ReadAllText($entrypoint)
|
|
$normalized = $raw -replace "`r`n", "`n" -replace "`r", "`n"
|
|
[System.IO.File]::WriteAllText($entrypoint, $normalized)
|
|
|
|
$dockerfile = "build/wheel/docker/Dockerfile.manylinux"
|
|
|
|
if (-not $SkipImageBuild) {
|
|
Write-Host "`n=== Building Docker image ==="
|
|
docker build --platform $dockerPlatform --build-arg "MANYLINUX_ARCH=$Architecture" -f $dockerfile -t $ImageName .
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "docker build failed"
|
|
}
|
|
}
|
|
|
|
# A custom or reused image must contain the requested architecture.
|
|
$imageArchitecture = docker image inspect --format "{{.Architecture}}" $ImageName
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Cannot inspect image '$ImageName'. Rebuild without -SkipImageBuild."
|
|
}
|
|
if ($imageArchitecture -ne $dockerArchitecture) {
|
|
throw "Image '$ImageName' architecture is '$imageArchitecture'; expected '$dockerArchitecture'. Rebuild without -SkipImageBuild."
|
|
}
|
|
|
|
Write-Host "`n=== Running manylinux container ==="
|
|
# Mount the repo so artifacts land under dist/repaired and SDK/<version>/ on the host.
|
|
docker run --rm `
|
|
--platform $dockerPlatform `
|
|
-e "ORISYS_BUILD_TARGET=$Target" `
|
|
-e "ORISYS_PYTHON_TAGS=$pythonTags" `
|
|
-v "${RepoRoot}:/src" `
|
|
$ImageName
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "manylinux container build failed"
|
|
}
|
|
|
|
Write-Host "`n=== Host artifacts ==="
|
|
$repaired = Join-Path $RepoRoot "dist\repaired"
|
|
if (Test-Path $repaired) {
|
|
Get-ChildItem $repaired -Filter *.whl | ForEach-Object { Write-Host $_.FullName }
|
|
} else {
|
|
Write-Warning "No dist/repaired directory found."
|
|
}
|
|
|
|
Write-Host "`nNext steps: see docs/publishing.md (TestPyPI then PyPI)."
|