name: Check Wasm Exports

on:
  pull_request:
    paths:
      - lib/include/tree_sitter/api.h
      - lib/binding_web/**
      - xtask/src/**
  push:
    branches: [master]
    paths:
      - lib/include/tree_sitter/api.h
      - lib/binding_rust/bindings.rs
      - CMakeLists.txt

jobs:
  check-wasm-exports:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Set up stable Rust toolchain
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: stable

      - name: Install wasm-objdump
        run: sudo apt-get update -y && sudo apt-get install -y wabt

      - name: Build C library (make)
        run: make -j CFLAGS="$CFLAGS"
        env:
          CFLAGS: -g -Werror -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types

      - name: Build Wasm Library
        working-directory: lib/binding_web
        run: npm ci && npm run build:debug

      - name: Check Wasm exports
        run: cargo xtask check-wasm-exports
