Skip to content

Commit 14a1d5a

Browse files
committed
pacman: build patched 7.1 client under MSYS
1 parent 76fbc8e commit 14a1d5a

3 files changed

Lines changed: 176 additions & 16 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Patched MSYS pacman source build
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- cmake/Components.cmake
7+
- patches/pacman/**
8+
- tests/pacman/msys-pacman-build.sh
9+
- tests/pacman/msys-runtime-smoke.ps1
10+
- .github/workflows/msys-pacman-source.yml
11+
push:
12+
branches:
13+
- next
14+
paths:
15+
- cmake/Components.cmake
16+
- patches/pacman/**
17+
- tests/pacman/msys-pacman-build.sh
18+
- tests/pacman/msys-runtime-smoke.ps1
19+
- .github/workflows/msys-pacman-source.yml
20+
workflow_dispatch:
21+
22+
jobs:
23+
build-and-transact:
24+
runs-on: windows-latest
25+
timeout-minutes: 20
26+
steps:
27+
- uses: actions/checkout@v4
28+
- uses: msys2/setup-msys2@v2
29+
with:
30+
msystem: MSYS
31+
update: true
32+
install: >-
33+
base-devel
34+
git
35+
gcc
36+
meson
37+
ninja
38+
pkgconf
39+
gettext-devel
40+
heimdal-devel
41+
libarchive-devel
42+
libcurl-devel
43+
libsqlite-devel
44+
libunistring-devel
45+
openssl-devel
46+
- name: Build patched pacman 7.1
47+
shell: msys2 {0}
48+
run: >-
49+
./tests/pacman/msys-pacman-build.sh
50+
"$(cygpath -u "$RUNNER_TEMP")/vitasdk-pacman"
51+
- name: Exercise the built two-file runtime
52+
shell: pwsh
53+
run: |
54+
./tests/pacman/msys-runtime-smoke.ps1 `
55+
-PacmanExecutable (Join-Path $env:RUNNER_TEMP "vitasdk-pacman/pacman.exe") `
56+
-RuntimeDll (Join-Path $env:RUNNER_TEMP "vitasdk-pacman/msys-2.0.dll")

tests/pacman/msys-pacman-build.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
if (( $# != 1 )); then
6+
printf 'usage: %s <output-directory>\n' "$0" >&2
7+
exit 2
8+
fi
9+
10+
script_directory=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)
11+
repository_root=$(cd "$script_directory/../.." && pwd -P)
12+
output_directory=$1
13+
work_directory=$(mktemp -d "${TMPDIR:-/tmp}/vitasdk-msys-pacman-build.XXXXXXXX")
14+
source_directory="$work_directory/pacman"
15+
build_directory="$work_directory/build"
16+
17+
cleanup() {
18+
rm -rf -- "$work_directory"
19+
}
20+
trap cleanup EXIT
21+
22+
git clone --depth 1 --branch v7.1.0 \
23+
https://gitlab.archlinux.org/pacman/pacman.git "$source_directory"
24+
25+
expected_revision=5683f8477a0afcc6b331766175a83445b2dcfe89
26+
actual_revision=$(git -C "$source_directory" rev-parse HEAD)
27+
[[ $actual_revision == "$expected_revision" ]] || {
28+
printf 'unexpected pacman revision: %s\n' "$actual_revision" >&2
29+
exit 1
30+
}
31+
32+
for patch in \
33+
"$repository_root/patches/pacman/0001-allow-writable-non-root-installation-roots.patch" \
34+
"$repository_root/patches/pacman/0002-embed-libalpm-in-static-clients.patch"
35+
do
36+
git -C "$source_directory" apply --check --whitespace=error-all "$patch"
37+
git -C "$source_directory" apply --whitespace=error-all "$patch"
38+
done
39+
40+
export CFLAGS="${CFLAGS:-} -O2 -fzero-init-padding-bits=unions"
41+
export LDFLAGS="${LDFLAGS:-} -static-libgcc"
42+
43+
meson setup "$build_directory" "$source_directory" \
44+
--buildtype=release \
45+
--prefix=/usr \
46+
--sysconfdir=/etc \
47+
--localstatedir=/var \
48+
--default-library=static \
49+
-Dbuildstatic=true \
50+
-Ddoc=disabled \
51+
-Ddoxygen=disabled \
52+
-Di18n=false \
53+
-Dgpgme=disabled \
54+
-Dcurl=enabled \
55+
-Dcrypto=openssl \
56+
-Duse-git-version=false \
57+
-Dpkg-ext=.pkg.tar.xz \
58+
-Dscriptlet-shell=/usr/bin/false
59+
meson compile -C "$build_directory"
60+
61+
mkdir -p "$output_directory"
62+
cp "$build_directory/pacman.exe" "$output_directory/pacman.exe"
63+
cp /usr/bin/msys-2.0.dll "$output_directory/msys-2.0.dll"
64+
65+
mapfile -t imports < <(
66+
objdump -p "$output_directory/pacman.exe" |
67+
sed -n 's/^[[:space:]]*DLL Name: //p' |
68+
sort -fu
69+
)
70+
printf 'pacman.exe imports:\n'
71+
printf ' %s\n' "${imports[@]}"
72+
73+
for import in "${imports[@]}"; do
74+
case ${import,,} in
75+
msys-2.0.dll|crypt32.dll|kernel32.dll) ;;
76+
*)
77+
printf 'unexpected pacman runtime import: %s\n' "$import" >&2
78+
exit 1
79+
;;
80+
esac
81+
done
82+
(( ${#imports[@]} == 3 )) || {
83+
printf 'pacman runtime import set is incomplete\n' >&2
84+
exit 1
85+
}
86+
87+
printf 'built patched pacman 7.1.0 with the two-file MSYS runtime contract\n'

tests/pacman/msys-runtime-smoke.ps1

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
param(
2-
[string]$WorkDirectory = (Join-Path $env:TEMP "vitasdk-msys-pacman-smoke")
2+
[string]$WorkDirectory = (Join-Path $env:TEMP "vitasdk-msys-pacman-smoke"),
3+
[string]$PacmanExecutable = "",
4+
[string]$RuntimeDll = ""
35
)
46

57
$ErrorActionPreference = "Stop"
@@ -54,21 +56,36 @@ $packagePath = Join-Path $WorkDirectory "vitasdk-msys-probe-1.0-1-any.pkg.tar.xz
5456
(Join-Path $packageRoot "arm-vita-eabi/include")
5557
) | ForEach-Object { New-Item -ItemType Directory -Force -Path $_ | Out-Null }
5658

57-
$pacmanArchive = Join-Path $downloads "pacman.pkg.tar.zst"
58-
$runtimeArchive = Join-Path $downloads "runtime.pkg.tar.zst"
59-
Invoke-WebRequest -Uri $pacmanUrl -OutFile $pacmanArchive
60-
Invoke-WebRequest -Uri $runtimeUrl -OutFile $runtimeArchive
61-
Assert-Sha256 $pacmanArchive $pacmanSha256
62-
Assert-Sha256 $runtimeArchive $runtimeSha256
63-
64-
Invoke-Checked "tar.exe" @(
65-
"-xf", $pacmanArchive, "-C", $extract, "usr/bin/pacman.exe"
66-
)
67-
Invoke-Checked "tar.exe" @(
68-
"-xf", $runtimeArchive, "-C", $extract, "usr/bin/msys-2.0.dll"
69-
)
70-
Copy-Item (Join-Path $extract "usr/bin/pacman.exe") $pacmanBin
71-
Copy-Item (Join-Path $extract "usr/bin/msys-2.0.dll") $pacmanBin
59+
if (($PacmanExecutable -eq "") -xor ($RuntimeDll -eq "")) {
60+
throw "PacmanExecutable and RuntimeDll must be supplied together"
61+
}
62+
if ($PacmanExecutable -ne "") {
63+
if (-not (Test-Path -PathType Leaf $PacmanExecutable)) {
64+
throw "built pacman executable is missing: ${PacmanExecutable}"
65+
}
66+
if (-not (Test-Path -PathType Leaf $RuntimeDll)) {
67+
throw "MSYS runtime DLL is missing: ${RuntimeDll}"
68+
}
69+
Copy-Item $PacmanExecutable (Join-Path $pacmanBin "pacman.exe")
70+
Copy-Item $RuntimeDll (Join-Path $pacmanBin "msys-2.0.dll")
71+
}
72+
else {
73+
$pacmanArchive = Join-Path $downloads "pacman.pkg.tar.zst"
74+
$runtimeArchive = Join-Path $downloads "runtime.pkg.tar.zst"
75+
Invoke-WebRequest -Uri $pacmanUrl -OutFile $pacmanArchive
76+
Invoke-WebRequest -Uri $runtimeUrl -OutFile $runtimeArchive
77+
Assert-Sha256 $pacmanArchive $pacmanSha256
78+
Assert-Sha256 $runtimeArchive $runtimeSha256
79+
80+
Invoke-Checked "tar.exe" @(
81+
"-xf", $pacmanArchive, "-C", $extract, "usr/bin/pacman.exe"
82+
)
83+
Invoke-Checked "tar.exe" @(
84+
"-xf", $runtimeArchive, "-C", $extract, "usr/bin/msys-2.0.dll"
85+
)
86+
Copy-Item (Join-Path $extract "usr/bin/pacman.exe") $pacmanBin
87+
Copy-Item (Join-Path $extract "usr/bin/msys-2.0.dll") $pacmanBin
88+
}
7289

7390
$runtimeFiles = @(Get-ChildItem -File $pacmanBin)
7491
if ($runtimeFiles.Count -ne 2) {

0 commit comments

Comments
 (0)