; Compile libc.c with the wasi-sdk (run via docker) and promote the result to
; ../libc.wasm. This directory is marked as vendored in ../dune so the rule is
; excluded from @all and only runs when explicitly requested through the
; recompile-libc alias; see ../dune.
(rule
 (target libc.wasm)
 ; Depend on (universe) so an explicit 'dune build @recompile-libc' always
 ; reruns docker, picking up an updated wasi-sdk image or wasm-opt even when
 ; libc.c is unchanged.
 (deps libc.c (universe))
 (mode (promote (into ..)))
 (action
  (with-stdout-to
   %{target}
   (pipe-stdout
    (run
     docker
     run
     -v
     .:/src
     -w
     /src
     ghcr.io/webassembly/wasi-sdk
     /opt/wasi-sdk/bin/clang
     -O2
     libc.c
     -flto
     -o
     -)
    (run wasm-opt -Oz --strip-debug --strip-dwarf - -o -)))))
