; required to install tree_sitter/parser.h
(include_subdirs qualified)

(library
  (public_name tree-sitter-lang.r)
  (name tree_sitter_r)
  (libraries atdgen-runtime tree-sitter.run)

  ; A copy of the C headers for the tree-sitter library is found locally.
  ; This is because it's important to use the right version of 'parser.h'.
  ;
  (foreign_stubs
    (language c)
    (names scanner parser bindings)
    (flags -std=c11
           -fPIC
           -I %{env:TREESITTER_INCDIR=/usr/local/include}
           -I .)
  )

  ; TREESITTER_LIBDIR is meant to be some nonstandard location containing the
  ; desired version of the tree-sitter library.
  ; The -rpath option tells the linker to hardcode this search location
  ; in the binary.
  ;
  ; Including the c_library_flags.sexp allows customizing the linker arguments
  ; based on the platform we build on.
  ;
  (c_library_flags
    (
      -L%{env:TREESITTER_LIBDIR=/usr/local/lib}
      -ltree-sitter
      (:include c_library_flags.sexp)
    )
  )
)

(rule
 (targets c_library_flags.sexp)
 (action (run ../config/discover.exe)))
