muntjac 0.2.0

Translate uv.lock into Buck2 build rules
Documentation
name: CI

on:
  push:
    branches: [main]
  pull_request:

jobs:
  test:
    name: ${{ matrix.runner }}
    strategy:
      fail-fast: false
      matrix:
        runner: [ubuntu-latest, ubuntu-24.04-arm, macos-latest]
    runs-on: ${{ matrix.runner }}
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: recursive

      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - uses: Swatinem/rust-cache@v2

      - name: cargo fmt --check
        run: cargo fmt --all -- --check

      - name: cargo clippy
        run: cargo clippy --all-targets --locked -- -D warnings

      - name: cargo build
        run: cargo build --locked

      - name: cargo test
        run: cargo test --locked

      - name: install cp312 python
        run: |
          set -euo pipefail
          # uv ships a known-good cp312 across runners.
          if ! command -v uv >/dev/null 2>&1; then
            python3 -m pip install --user uv || pipx install uv
          fi
          uv python install 3.12
          UV_PY_BIN="$(uv python find 3.12)"
          # Symlink so the prelude's system_python_toolchain finds `python3.12`.
          if [ "${{ runner.os }}" = "macOS" ]; then
            ln -sf "$UV_PY_BIN" /usr/local/bin/python3.12
          else
            sudo ln -sf "$UV_PY_BIN" /usr/local/bin/python3.12
          fi
          python3.12 --version

      - name: install buck2
        run: |
          set -euo pipefail
          BUCK2_RELEASE="2026-05-18"
          case "${{ matrix.runner }}" in
            ubuntu-latest)       ASSET="buck2-x86_64-unknown-linux-gnu.zst"   ;;
            ubuntu-24.04-arm)    ASSET="buck2-aarch64-unknown-linux-gnu.zst"  ;;
            macos-latest)        ASSET="buck2-aarch64-apple-darwin.zst"       ;;
            *) echo "unknown runner ${{ matrix.runner }}"; exit 1 ;;
          esac
          mkdir -p "$HOME/.local/bin"
          curl -L "https://github.com/facebook/buck2/releases/download/${BUCK2_RELEASE}/${ASSET}" \
              -o /tmp/buck2.zst
          # zstd may not be pre-installed on macOS GH runners; install if needed
          if ! command -v zstd >/dev/null 2>&1; then
            if [ "${{ runner.os }}" = "macOS" ]; then
              brew install zstd
            else
              sudo apt-get update && sudo apt-get install -y zstd
            fi
          fi
          zstd -d /tmp/buck2.zst -o "$HOME/.local/bin/buck2"
          chmod +x "$HOME/.local/bin/buck2"
          echo "$HOME/.local/bin" >> "$GITHUB_PATH"
          "$HOME/.local/bin/buck2" --version

      - name: muntjac buckify (02-numpy-pandas fixture)
        run: |
          set -euo pipefail
          cd tests/fixtures/buck/02-numpy-pandas
          # Initialize prelude submodule in case checkout step didn't.
          git submodule update --init --recursive --depth 1
          cargo run --release --manifest-path ../../../../Cargo.toml -- buckify
          # Verify the four files exist (no PACKAGE — wiring.bzl replaces it).
          test -f third-party/python/BUCK
          test -f third-party/python/muntjac.bzl
          test -f third-party/python/wiring.bzl
          test -f third-party/python/config/BUCK
          test ! -e third-party/python/PACKAGE

      - name: buck2 build + run numpy demo
        run: |
          set -euo pipefail
          cd tests/fixtures/buck/02-numpy-pandas
          buck2 run //tests/smoke:numpy_demo 2>&1 | tee /tmp/numpy-out.txt
          # Sanity-check the output contains the expected array.
          grep -F "[0. 0. 0.]" /tmp/numpy-out.txt

      - name: muntjac buckify (10-multi-tree fixture)
        run: |
          set -euo pipefail
          cd tests/fixtures/buck/10-multi-tree
          # Initialize prelude submodule in case checkout step didn't.
          git submodule update --init --recursive --depth 1
          cargo run --release --manifest-path ../../../../Cargo.toml -- buckify
          # Shared cfg emitted once at the common-ancestor cfg_dir.
          test -f third-party/python/config/BUCK
          test -f third-party/python/wiring.bzl
          # Per-tree packages.
          test -f third-party/python/modern/BUCK
          test -f third-party/python/modern/muntjac.bzl
          test -f third-party/python/legacy/BUCK
          test -f third-party/python/legacy/muntjac.bzl

      - name: buck2 build + run both trees (10-multi-tree)
        run: |
          set -euo pipefail
          cd tests/fixtures/buck/10-multi-tree
          buck2 run //tests/smoke:modern_demo 2>&1 | tee /tmp/modern-out.txt
          grep -E "MODERN numpy 2\." /tmp/modern-out.txt
          buck2 run //tests/smoke:legacy_demo 2>&1 | tee /tmp/legacy-out.txt
          grep -E "LEGACY numpy 1\." /tmp/legacy-out.txt

      - name: muntjac buckify (04-pure-python-sdist fixture)
        if: matrix.runner == 'ubuntu-latest'
        run: |
          set -euo pipefail
          cd tests/fixtures/buck/04-pure-python-sdist
          # Initialize prelude submodule in case checkout step didn't.
          git submodule update --init --recursive --depth 1
          # Buckify only consumes the committed manifest + wheel, no uv shellout.
          cargo run --release --manifest-path ../../../../Cargo.toml -- buckify

      - name: buck2 run prebake_demo
        if: matrix.runner == 'ubuntu-latest'
        run: |
          set -euo pipefail
          cd tests/fixtures/buck/04-pure-python-sdist
          buck2 run //tests/smoke:prebake_demo

      - name: muntjac buckify (05-local-fixup fixture)
        if: matrix.runner == 'ubuntu-latest'
        run: |
          set -euo pipefail
          cd tests/fixtures/buck/05-local-fixup
          # Initialize prelude submodule in case checkout step didn't.
          git submodule update --init --recursive --depth 1
          cargo run --release --manifest-path ../../../../Cargo.toml -- buckify

      - name: buck2 run overlay_demo
        if: matrix.runner == 'ubuntu-latest'
        run: |
          set -euo pipefail
          cd tests/fixtures/buck/05-local-fixup
          # zip + unzip must be on PATH for the overlay genrule.
          sudo apt-get update && sudo apt-get install -y zip unzip
          buck2 run //tests/smoke:overlay_demo 2>&1 | tee /tmp/overlay-out.txt
          grep -F "OVERLAY_APPLIED: True" /tmp/overlay-out.txt