- name: Install Rust toolchain
  uses: dtolnay/rust-toolchain@stable
- name: Install Sccache
  uses: mozilla-actions/sccache-action@v0.0.9
  env:
    SCCACHE_GHA_ENABLED: "true"
    RUSTC_WRAPPER: "sccache"
- name: Enable sccache
  run: |
    echo "RUSTC_WRAPPER=sccache" >> "$GITHUB_ENV"
    echo "SCCACHE_GHA_ENABLED=true" >> "$GITHUB_ENV"
- name: Add gettid shim for glibc < 2.30 (manylinux_2_28)
  # gettid() glibc wrapper was added in glibc 2.30; recent Rust stdlib references it directly.
  # Compile a shim so lld can resolve the symbol when building on old glibc.
  run: |
    if ! nm -D /lib64/libc.so.6 2>/dev/null | grep -qw gettid; then
      printf '#define _GNU_SOURCE\n#include <unistd.h>\n#include <sys/syscall.h>\npid_t gettid(void){return (pid_t)syscall(SYS_gettid);}\n' \
        | gcc -x c - -c -o /tmp/gettid_shim.o
      ar rcs /tmp/libgettid_shim.a /tmp/gettid_shim.o
      echo "RUSTFLAGS=${RUSTFLAGS} -C link-arg=-L/tmp -C link-arg=-lgettid_shim" >> "$GITHUB_ENV"
    fi
