~mro/geohash

b40cea6a36b688fff098e55fbbdd8a0c55bac6c1 — Marcus Rohrmoser 3 years ago fbd81a1
statically link but not on macOS.

Thanks https://discuss.ocaml.org/t/dune-how-to-link-statically-on-linux-not-on-others/8537/6?u=mro
2 files changed, 17 insertions(+), 1 deletions(-)

M bin/dune
A bin/gen_link_flags.sh
M bin/dune => bin/dune +4 -1
@@ 1,3 1,6 @@
;; https://discuss.ocaml.org/t/dune-how-to-link-statically-on-linux-not-on-others/8537/4?u=mro
(rule (with-stdout-to link_flags.sexp (run sh %{dep:gen_link_flags.sh})))

; https://stackoverflow.com/a/53325230/349514
(executable
  (name geohash)


@@ 30,5 33,5 @@
; $ make clean build
; $ file _build/default/bin/*.exe 
; _build/default/bin/meta.exe: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
  (link_flags (-ccopt "-static"))
  (link_flags (:include link_flags.sexp))
)

A bin/gen_link_flags.sh => bin/gen_link_flags.sh +13 -0
@@ 0,0 1,13 @@
#!/bin/sh
# https://discuss.ocaml.org/t/dune-how-to-link-statically-on-linux-not-on-others/8537/4?u=mro

case "$(uname -s)" in
  Darwin)
    # do not link statically on macos.
    echo "()"
    ;;
  *)
    echo '(-ccopt "-static")'
    ;;
esac