okami.mom/ultraviolet

git clone https://git.nkp.pet/okami.mom/ultraviolet

Kieran Klukasci: build the conformance oracle for a portable CPUbbf040a

main
4.0 KiB87 linesraw
1name: libghostty-vt
2description: Build or restore libghostty-vt and point pkg-config at it.
3
4# libghostty-vt is the C library go-libghostty links against, and the
5# conformance module needs it to build at all. Three jobs across two workflows
6# need the same thing, so it lives here once rather than being copied into each
7# of them and drifting.
8
9runs:
10  using: composite
11  steps:
12    # The library has to be built from the go-libghostty commit the module
13    # already depends on. That commit's CMakeLists pins the ghostty revision it
14    # fetches, and a different revision exports a different set of symbols than
15    # these bindings call, so a mismatch fails at link time with undefined
16    # symbols. Reading the commit out of go.mod is what keeps the two in step:
17    # bumping the dependency moves the build with it, and there is no second
18    # place to remember to update.
19    - name: Resolve the go-libghostty pin
20      id: pin
21      shell: bash
22      run: |
23        mod=internal/conformance/go.mod
24
25        # Exactly one line may mention the module. A replace directive, in
26        # either spelling, adds another, and picking one silently builds a
27        # revision the module does not use.
28        matches=$(grep -c 'go\.mitchellh\.com/libghostty' "$mod" || true)
29        if [ "$matches" -ne 1 ]; then
30          echo "::error::expected one go.mitchellh.com/libghostty line in $mod, found $matches"
31          exit 1
32        fi
33        version=$(awk '$1 == "go.mitchellh.com/libghostty" { print $2 }' "$mod")
34
35        # A pseudo-version ends in the twelve-digit commit it was built from,
36        # and that commit is the ref. Anything else is a tag, already a ref.
37        rev=${version%+incompatible}
38        if [[ $rev =~ -([0-9a-f]{12})$ ]]; then
39          rev=${BASH_REMATCH[1]}
40        fi
41        echo "rev=$rev" >> "$GITHUB_OUTPUT"
42
43    - uses: mlugg/setup-zig@v2
44      with:
45        version: "0.16.0"
46
47    # Building from source takes a couple of minutes, so cache the result. The
48    # key carries the pin, so the build happens again exactly when the
49    # dependency moves and not otherwise.
50    #
51    # The cpu suffix is in the key so entries cached before the build below
52    # pinned a baseline CPU are not reused. Those were tuned for whichever
53    # runner produced them, and crash on a runner that lacks the instructions.
54    - name: Cache libghostty-vt
55      id: cache
56      uses: actions/cache@v6
57      with:
58        path: ${{ github.workspace }}/.cache/libghostty-vt
59        key: libghostty-vt-${{ steps.pin.outputs.rev }}-${{ runner.os }}-${{ runner.arch }}-cpu-baseline
60
61    - name: Build libghostty-vt
62      if: steps.cache.outputs.cache-hit != 'true'
63      shell: bash
64      run: |
65        git clone https://github.com/mitchellh/go-libghostty /tmp/go-libghostty
66        git -C /tmp/go-libghostty checkout --detach "${{ steps.pin.outputs.rev }}"
67        # Zig builds for the host CPU unless told otherwise, so the library
68        # picks up whatever instructions the runner that built it happened to
69        # support. Every runner then shares that binary through the cache, and
70        # one without those instructions dies on the first call into it. A
71        # baseline CPU is what makes the artifact portable enough to cache.
72        cmake -B /tmp/go-libghostty/build -S /tmp/go-libghostty \
73          -DCMAKE_BUILD_TYPE=Release \
74          -DGHOSTTY_ZIG_BUILD_FLAGS=-Dcpu=baseline
75        cmake --build /tmp/go-libghostty/build
76        mkdir -p .cache
77        cp -r /tmp/go-libghostty/build/_deps/ghostty-src/zig-out .cache/libghostty-vt
78
79    # The .pc file records the absolute path it was built at. Rewrite it to
80    # point at this workspace so a restored cache resolves correctly, then put
81    # it on PKG_CONFIG_PATH for every step that follows.
82    - name: Configure pkg-config
83      shell: bash
84      run: |
85        prefix="${{ github.workspace }}/.cache/libghostty-vt"
86        sed -i "s|^prefix=.*|prefix=$prefix|" "$prefix/share/pkgconfig/libghostty-vt-static.pc"
87        echo "PKG_CONFIG_PATH=$prefix/share/pkgconfig" >> "$GITHUB_ENV"