Repository navigation
455 lines (427 loc) · 19.7 KB
/
Copy pathmacos-json.yml
File metadata and controls
455 lines (427 loc) · 19.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
name: macOS arm64 JSON portability
on:
push:
# Packaging and release-metadata branches are built by release-dry.yml
# through workflow_call; a standalone push run would duplicate macOS on the
# same commit. The branches filter also keeps this workflow off tag pushes,
# where release.yml calls it explicitly.
branches-ignore:
- "p71*-packaging*"
- "p72*"
paths:
- .github/workflows/macos-json.yml
- CMakeLists.txt
- cmake/**
- include/**
- src/**
- tests/**
- td
pull_request:
branches:
- master
- v0.5.1-consolidated
paths:
- .github/workflows/macos-json.yml
- CMakeLists.txt
- cmake/**
- include/**
- src/**
- tests/**
- td
workflow_call:
permissions:
contents: read
concurrency:
group: macos-json-${{ github.ref }}
cancel-in-progress: true
jobs:
json-arm64:
name: pinned TDLib, JSON, Lua 5.4
runs-on: macos-26
timeout-minutes: 120
steps:
- name: Check out pinned TDLib submodule
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
submodules: recursive
- name: Record runner, toolchain, and source provenance
shell: bash
run: |
set -euo pipefail
mkdir -p "$RUNNER_TEMP/tdlua-artifacts"
{
sw_vers
uname -a
test "$(uname -m)" = arm64
xcodebuild -version
xcode-select -p
xcrun --sdk macosx --show-sdk-version
xcrun --sdk macosx clang++ --version
cmake --version
ninja --version
git rev-parse HEAD
git -C td rev-parse HEAD
git -C td status --short
git ls-tree HEAD td
shasum -a 256 td/td/generate/scheme/td_api.tl
} 2>&1 | tee "$RUNNER_TEMP/tdlua-artifacts/provenance.log"
test "$(git -C td rev-parse HEAD)" = c15d3f5a5de6e3ba5839822c451152e5e18bb700
test -z "$(git -C td status --porcelain)"
- name: Install macOS build dependencies
shell: bash
run: |
set -euo pipefail
brew install cmake gperf lua@5.4 ninja openssl@3
lua_prefix="$(brew --prefix lua@5.4)"
openssl_prefix="$(brew --prefix openssl@3)"
lua_header="$(find "$lua_prefix/include" -name lua.h -print -quit)"
lua_library="$(find "$lua_prefix/lib" -maxdepth 1 -name 'liblua*.dylib' -print -quit)"
# Select the interpreter explicitly. A glob can pick luac first (or
# because lua is a symlink, skip it), which accepts neither -e nor
# script execution.
lua_executable="$lua_prefix/bin/lua"
test -n "$lua_header" && test -n "$lua_library" && test -x "$lua_executable"
{
brew list --versions cmake gperf lua@5.4 ninja openssl@3
printf 'LUA_INCLUDE_DIR=%s\nLUA_LIBRARY=%s\nLUA_EXECUTABLE=%s\nOPENSSL_ROOT_DIR=%s\n' \
"$(dirname "$lua_header")" "$lua_library" "$lua_executable" "$openssl_prefix"
} 2>&1 | tee "$RUNNER_TEMP/tdlua-artifacts/dependencies.log"
echo "LUA_INCLUDE_DIR=$(dirname "$lua_header")" >> "$GITHUB_ENV"
echo "LUA_LIBRARY=$lua_library" >> "$GITHUB_ENV"
echo "LUA_EXECUTABLE=$lua_executable" >> "$GITHUB_ENV"
echo "OPENSSL_ROOT_DIR=$openssl_prefix" >> "$GITHUB_ENV"
# Explicit floor for the distributed module. The cache key includes
# it, otherwise a TDLib built against the runner's default (the
# current macOS SDK, e.g. minos 26) would be reused silently.
deployment_target="13.0"
echo "DEPLOYMENT_TARGET=$deployment_target" >> "$GITHUB_ENV"
tdlib_cache_key="$( {
git -C td rev-parse HEAD
shasum -a 256 td/td/generate/scheme/td_api.tl
uname -m
xcrun --sdk macosx --show-sdk-version
xcrun --sdk macosx clang++ --version
cmake --version
brew list --versions openssl@3
printf 'deployment_target=%s\n' "$deployment_target"
printf '%s\n' 'Release;arm64;JSON;shared;parallel=3'
} | shasum -a 256 | cut -d ' ' -f 1)"
echo "TDLIB_CACHE_KEY=tdlib-macos-json-v1-$tdlib_cache_key" >> "$GITHUB_ENV"
- name: Restore the pinned TDLib installation
id: tdlib-cache
uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
key: ${{ env.TDLIB_CACHE_KEY }}
path: |
${{ runner.temp }}/tdlua-stage/include/td
${{ runner.temp }}/tdlua-stage/lib/libtdjson*.dylib
${{ runner.temp }}/tdlua-stage/lib/cmake/Td
- name: Build and install TDLua with pinned TDLib
shell: bash
run: |
set -euo pipefail
stage="$RUNNER_TEMP/tdlua-stage"
bundled=ON
if [ '${{ steps.tdlib-cache.outputs.cache-hit }}' = true ]; then
bundled=OFF
fi
printf 'TDLib bundled build=%s, dependency cache=%s\n' "$bundled" "$TDLIB_CACHE_KEY" \
| tee "$RUNNER_TEMP/tdlua-artifacts/tdlib-cache.log"
cmake -S . -B "$RUNNER_TEMP/tdlua-package-build" -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-DCMAKE_OSX_DEPLOYMENT_TARGET="$DEPLOYMENT_TARGET" \
-DCMAKE_OSX_SYSROOT="$(xcrun --sdk macosx --show-sdk-path)" \
-DCMAKE_INSTALL_PREFIX="$stage" \
-DCMAKE_INSTALL_RPATH='@loader_path;@loader_path/../..' \
-DCMAKE_PREFIX_PATH="$stage" \
-DTDLUA_BACKEND=json \
-DTDLUA_BUNDLED_TDLIB="$bundled" \
-DTDLUA_BUILD_TESTS=OFF \
-DTDLUA_LUA_VERSION=5.4 \
-DLUA_INCLUDE_DIR="$LUA_INCLUDE_DIR" \
-DLUA_LIBRARY="$LUA_LIBRARY" \
-DLUA_EXECUTABLE="$LUA_EXECUTABLE" \
-DTDLUA_LUA_EXECUTABLE="$LUA_EXECUTABLE" \
-DOPENSSL_ROOT_DIR="$OPENSSL_ROOT_DIR" \
2>&1 | tee "$RUNNER_TEMP/tdlua-artifacts/package-configure.log"
cmake --build "$RUNNER_TEMP/tdlua-package-build" --target tdlua --parallel 3 \
2>&1 | tee "$RUNNER_TEMP/tdlua-artifacts/package-build.log"
cmake --install "$RUNNER_TEMP/tdlua-package-build" \
2>&1 | tee "$RUNNER_TEMP/tdlua-artifacts/install.log"
cp "$RUNNER_TEMP/tdlua-package-build/CMakeCache.txt" \
"$RUNNER_TEMP/tdlua-artifacts/package-CMakeCache.txt"
cp "$stage/lib/lua/5.4/tdlua.so" "$RUNNER_TEMP/tdlua-artifacts/installed-tdlua.so"
cp "$stage/lib/libtdjson.dylib" "$RUNNER_TEMP/tdlua-artifacts/installed-libtdjson.dylib"
{
file "$stage/lib/lua/5.4/tdlua.so" "$stage/lib/libtdjson.dylib"
lipo -archs "$stage/lib/lua/5.4/tdlua.so"
lipo -archs "$stage/lib/libtdjson.dylib"
otool -L "$stage/lib/lua/5.4/tdlua.so"
otool -l "$stage/lib/lua/5.4/tdlua.so"
otool -L "$stage/lib/libtdjson.dylib"
nm -gU "$stage/lib/lua/5.4/tdlua.so" \
> "$RUNNER_TEMP/tdlua-artifacts/installed-exports.log"
grep '_luaopen_tdlua$' "$RUNNER_TEMP/tdlua-artifacts/installed-exports.log"
if grep -q '_tdlua_test_live_scheduler_cores$' "$RUNNER_TEMP/tdlua-artifacts/installed-exports.log"; then
echo 'test instrumentation leaked into the installed module' >&2
exit 1
fi
shasum -a 256 "$stage/lib/lua/5.4/tdlua.so" "$stage/lib/libtdjson.dylib"
} 2>&1 | tee "$RUNNER_TEMP/tdlua-artifacts/installed-linking.log"
- name: Save the verified TDLib installation
if: steps.tdlib-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
key: ${{ env.TDLIB_CACHE_KEY }}
path: |
${{ runner.temp }}/tdlua-stage/include/td
${{ runner.temp }}/tdlua-stage/lib/libtdjson*.dylib
${{ runner.temp }}/tdlua-stage/lib/cmake/Td
- name: Load installed module and exercise real TDLib client
shell: bash
run: |
set -euo pipefail
stage="$RUNNER_TEMP/tdlua-stage"
export LUA_CPATH="$stage/lib/lua/5.4/?.so;;"
"$LUA_EXECUTABLE" -e 'local t = require("tdlua"); assert(type(t.version) == "string"); print("installed require and version PASS", t.version)'
"$LUA_EXECUTABLE" tests/e2e_smoke.lua "$stage/lib/lua/5.4" \
2>&1 | tee "$RUNNER_TEMP/tdlua-artifacts/installed-e2e.log"
- name: Package the macOS arm64 JSON module
shell: bash
run: |
set -euo pipefail
stage="$RUNNER_TEMP/tdlua-stage"
source_module="$stage/lib/lua/5.4/tdlua.so"
test -f "$source_module"
version_le() {
awk -v a="$1" -v b="$2" 'BEGIN {
n = split(a, A, "."); m = split(b, B, ".");
for (i = 1; i <= 3; i++) {
ai = (i <= n ? A[i] : 0) + 0;
bi = (i <= m ? B[i] : 0) + 0;
if (ai < bi) exit 0;
if (ai > bi) exit 1;
}
exit 0
}'
}
minos() {
otool -l "$1" | awk '
/LC_BUILD_VERSION/ { seen = 1; next }
seen && $1 == "minos" && !printed { print $2; printed = 1 }'
}
# Ship the exact TDLib dylib the module records, not just the name
# that happens to be a symlink in the stage.
tdjson_ref="$(otool -L "$source_module" | awk '/libtdjson/ && !found { print $1; found = 1 }')"
test -n "$tdjson_ref"
tdjson_name="$(basename "$tdjson_ref")"
tdjson_source="$stage/lib/$tdjson_name"
if [ ! -f "$tdjson_source" ]; then
tdjson_source="$(find "$stage/lib" -maxdepth 1 -name 'libtdjson*.dylib' ! -type l -print -quit)"
test -n "$tdjson_source"
tdjson_name="$(basename "$tdjson_source")"
fi
name="tdlua-5.4-macos-arm64-json"
packages="$RUNNER_TEMP/tdlua-packages"
root="$packages/$name"
rm -rf "$root"
mkdir -p "$root/lib/lua/5.4" "$root/share/licenses/tdlua" "$packages"
cp "$source_module" "$root/lib/lua/5.4/tdlua.so"
cp "$tdjson_source" "$root/lib/$tdjson_name"
for license in LICENSE TDLib-LICENSE_1_0.txt; do
test -f "$stage/share/licenses/tdlua/$license"
cp "$stage/share/licenses/tdlua/$license" \
"$root/share/licenses/tdlua/$license"
done
module="$root/lib/lua/5.4/tdlua.so"
lua_ref="$(otool -L "$module" | awk '/liblua/ && !found { print $1; found = 1 }')"
test -n "$lua_ref"
if [ "$lua_ref" != "@rpath/liblua.5.4.dylib" ]; then
# Homebrew's absolute path would tie the package to this runner.
# Keep the dynamic dependency, but resolve it through the host's
# Lua 5.4 (@rpath: the module directory or DYLD_LIBRARY_PATH).
install_name_tool -change "$lua_ref" "@rpath/liblua.5.4.dylib" "$module"
codesign --force --sign - "$module"
fi
if ! otool -l "$module" \
| awk '$1 == "path" && $2 == "@loader_path" { found = 1 } END { exit !found }'; then
install_name_tool -add_rpath "@loader_path" "$module"
codesign --force --sign - "$module"
fi
module_minos="$(minos "$module")"
tdjson_minos="$(minos "$root/lib/$tdjson_name")"
test -n "$module_minos"
test -n "$tdjson_minos"
for built in "$module_minos" "$tdjson_minos"; do
if ! version_le "$built" "$DEPLOYMENT_TARGET"; then
echo "::error::binary requires macOS $built, target is $DEPLOYMENT_TARGET"
exit 1
fi
done
# Record the effective floor: the declared target, or a dependency
# that already requires a newer macOS.
dependency_minos_max="$module_minos"
for dep in \
$(otool -L "$module" | tail -n +2 | awk '{print $1}') \
$(otool -L "$root/lib/$tdjson_name" | tail -n +2 | awk '{print $1}'); do
case "$dep" in
@rpath/*) candidate="$root/lib/${dep#@rpath/}" ;;
@loader_path/*) candidate="$root/lib/lua/5.4/${dep#@loader_path/}" ;;
/usr/lib/*|/System/*) continue ;;
*) candidate="$dep" ;;
esac
[ -f "$candidate" ] || continue
dep_minos="$(minos "$candidate")"
[ -n "$dep_minos" ] || continue
if version_le "$dependency_minos_max" "$dep_minos"; then
dependency_minos_max="$dep_minos"
fi
done
version="$(cat "$RUNNER_TEMP/tdlua-package-build/tdlua-version.txt")"
tdlib_version="$(sed -n 's/^set(PACKAGE_VERSION "\([^"]*\)")/\1/p' \
"$stage/lib/cmake/Td/TdConfigVersion.cmake")"
test -n "$tdlib_version"
module_sha="$(shasum -a 256 "$module" | cut -d ' ' -f 1)"
{
echo 'package=tdlua'
echo "version=$version"
echo 'platform=macos-arm64'
echo 'os=macos'
echo 'arch=arm64'
echo 'lua_implementation=Lua'
echo 'lua_version=5.4'
echo 'backend=json'
echo "tdlib_version=$tdlib_version"
echo "source_sha=$GITHUB_SHA"
echo 'module=lib/lua/5.4/tdlua.so'
echo "module_sha256=$module_sha"
echo "module_minos=$module_minos"
echo "tdlib_dylib=lib/$tdjson_name"
echo "dependency_minos_max=$dependency_minos_max"
echo 'external_runtime=lua5.4 (host), openssl@3 via libtdjson'
} > "$root/MANIFEST.txt"
tar -C "$packages" -czf "$packages/$name.tar.gz" "$name"
# Verify the archive from an extracted directory, not the stage.
extract="$RUNNER_TEMP/tdlua-pkg-verify-json"
rm -rf "$extract"
mkdir -p "$extract"
tar -xzf "$packages/$name.tar.gz" -C "$extract"
extracted="$extract/$name"
extracted_module="$extracted/lib/lua/5.4/tdlua.so"
test -f "$extracted_module"
if otool -L "$extracted_module" | grep '/opt/homebrew' >/dev/null; then
echo '::error::package still links an absolute Homebrew library'
exit 1
fi
otool -L "$extracted/lib/$tdjson_name" \
| tee "$packages/tdjson-dependencies.log"
if otool -L "$extracted/lib/$tdjson_name" | grep '/opt/homebrew' >/dev/null; then
echo 'note: libtdjson keeps Homebrew OpenSSL references; documented as a host prerequisite' \
| tee -a "$packages/tdjson-dependencies.log"
fi
lipo -archs "$extracted_module" | grep -x arm64 >/dev/null
nm -gU "$extracted_module" | grep '_luaopen_tdlua$' >/dev/null
if nm -gU "$extracted_module" | grep -E '_tdlua_(test_|json_test_)'; then
echo '::error::package exports test hooks'
exit 1
fi
# The host provides Lua 5.4; put its dylib next to the module so the
# @rpath reference resolves from the extracted tree alone.
cat "$LUA_LIBRARY" > "$extracted/lib/lua/5.4/liblua.5.4.dylib"
TDLIB_VERSION="$tdlib_version" \
LUA_CPATH="$extracted/lib/lua/5.4/?.so;;" "$LUA_EXECUTABLE" -e '
local tdlua = require("tdlua")
assert(type(tdlua.version) == "string", "missing version")
assert(type(tdlua.api_version) == "string", "missing api_version")
assert(tdlua.tdlib_version == os.getenv("TDLIB_VERSION"),
"wrong TDLib version")
print("extracted package", tdlua.version, tdlua.api_version,
tdlua.tdlib_version)
'
{
echo "archive=$packages/$name.tar.gz"
shasum -a 256 "$packages/$name.tar.gz"
tar -tzf "$packages/$name.tar.gz"
otool -L "$extracted_module"
} | tee "$packages/json-verification.log"
- name: Configure CTest build against the staged TDLib package
shell: bash
run: |
set -euo pipefail
cmake -S . -B "$RUNNER_TEMP/tdlua-test-build" -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-DCMAKE_OSX_DEPLOYMENT_TARGET="$DEPLOYMENT_TARGET" \
-DCMAKE_OSX_SYSROOT="$(xcrun --sdk macosx --show-sdk-path)" \
-DCMAKE_PREFIX_PATH="$RUNNER_TEMP/tdlua-stage" \
-DTDLUA_BACKEND=json \
-DTDLUA_BUNDLED_TDLIB=OFF \
-DTDLUA_BUILD_TESTS=ON \
-DTDLUA_LUA_VERSION=5.4 \
-DLUA_INCLUDE_DIR="$LUA_INCLUDE_DIR" \
-DLUA_LIBRARY="$LUA_LIBRARY" \
-DLUA_EXECUTABLE="$LUA_EXECUTABLE" \
-DTDLUA_LUA_EXECUTABLE="$LUA_EXECUTABLE" \
2>&1 | tee "$RUNNER_TEMP/tdlua-artifacts/test-configure.log"
cmake -LA -N "$RUNNER_TEMP/tdlua-test-build" \
> "$RUNNER_TEMP/tdlua-artifacts/test-CMakeCache-summary.log"
ctest --test-dir "$RUNNER_TEMP/tdlua-test-build" -N -V \
> "$RUNNER_TEMP/tdlua-artifacts/ctest-list.log" 2>&1
- name: Build TDLua and tests without rebuilding TDLib
id: test-build
shell: bash
run: |
set -euo pipefail
cmake --build "$RUNNER_TEMP/tdlua-test-build" --parallel 3 \
2>&1 | tee "$RUNNER_TEMP/tdlua-artifacts/test-build.log"
module="$RUNNER_TEMP/tdlua-test-build/tdlua.so"
test -f "$module"
{
file "$module"
lipo -archs "$module"
otool -L "$module"
shasum -a 256 "$module"
} 2>&1 | tee "$RUNNER_TEMP/tdlua-artifacts/test-module-linking.log"
lipo -archs "$module" | grep -qx arm64
- name: Run complete JSON CTest suite
shell: bash
run: |
set -euo pipefail
ctest --test-dir "$RUNNER_TEMP/tdlua-test-build" --output-on-failure -j2 \
2>&1 | tee "$RUNNER_TEMP/tdlua-artifacts/ctest.log"
- name: Repeat receiver, lifecycle, and module residency
if: always() && steps.test-build.outcome == 'success'
shell: bash
run: |
set -euo pipefail
ctest --test-dir "$RUNNER_TEMP/tdlua-test-build" --output-on-failure \
-R '^tdlua_receiver_runtime$' --repeat until-fail:100 \
2>&1 | tee "$RUNNER_TEMP/tdlua-artifacts/receiver-repeat.log"
ctest --test-dir "$RUNNER_TEMP/tdlua-test-build" --output-on-failure -j2 \
-R '^(tdlua_lifecycle|tdlua_shutdown_admission|tdlua_vm_threads|tdlua_macos_residency|tdlua_release)$' \
--repeat until-fail:20 \
2>&1 | tee "$RUNNER_TEMP/tdlua-artifacts/lifetime-repeat.log"
- name: Preserve detailed CTest output
if: always()
shell: bash
run: |
if [ -f "$RUNNER_TEMP/tdlua-test-build/Testing/Temporary/LastTest.log" ]; then
cp "$RUNNER_TEMP/tdlua-test-build/Testing/Temporary/LastTest.log" \
"$RUNNER_TEMP/tdlua-artifacts/LastTest.log"
fi
- name: Upload macOS JSON package
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: tdlua-macos-arm64-json-package
path: ${{ runner.temp }}/tdlua-packages/*.tar.gz
if-no-files-found: error
retention-days: 30
- name: Upload build, install, and test evidence
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: macos-arm64-json-${{ github.run_id }}
path: ${{ runner.temp }}/tdlua-artifacts/
if-no-files-found: warn
retention-days: 30