(executables
 (names Main)
 (flags
  (:standard
   (:include flags.sexp))
  )
 (libraries
  TCB
  semgrep.core_cli
  semgrep.osemgrep_cli
  ; implementations of dune virtual modules
  lwt_platform.unix
  semgrep.legacy_language_server
  telemetry.unix)
 (preprocess
  (pps ppx_profiling))
 ; 'byte' is for ocamldebug
 (modes native byte))

; use flags.sh to generate the OS specific build flags

(rule
 (targets flags.sexp)
 (deps
  (:langs tree-sitter-langs.dat))
 (enabled_if
  (<> %{os_type} Win32))
 (action
  (with-stdout-to
   flags.sexp
   (run ./flags.sh %{ocaml-config:system} %{langs}))))

; flags.sh won't run properly in Windows, so simply hardcode to ( :standard )
; todo: is there an easy way to do static compilation in Windows?
; todo: is there a way we could make flags.sh more portable?

(rule
 (targets flags.sexp)
 (enabled_if
  (= %{os_type} Win32))
 (action
  (write-file %{targets} "( )")))

(rule
 (deps
  (source_tree %{project_root}/languages))
 (targets tree-sitter-langs.dat)
 (action
  (with-stdout-to
   tree-sitter-langs.dat
   (chdir
    %{project_root}
    (run src/main/list-tree-sitter-langs.sh)))))

(install
 (package semgrep)
 (section bin)
 (files
  (Main.exe as semgrep-core)
  (Main.exe as osemgrep)
  ; in the long term (and in the short term on windows) we want to ship
  ; osemgrep as "semgrep"
  (Main.exe as semgrep)
  ; useful to debug semgrep, see ../../debug and ocamldebug
  (Main.bc as semgrep-core.bc)
  (Main.bc as osemgrep.bc)))
