Skip to content

Commit

Permalink
more robust llvm-config usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinafyi committed Feb 28, 2024
1 parent 53864ac commit 47e6aaf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
(name main)
(modules main)
(libraries gtirb_semantics base64 yojson asli.libASL llvm_disas)
(flags :standard -cclib (:include ../llvm-disas/llvmconf.sexp))
(flags :standard (:include ../llvm-disas/llvmconf.sexp))
)

21 changes: 16 additions & 5 deletions llvm-disas/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@
(name llvm_disas)

(libraries ctypes ctypes.foreign)
(library_flags :standard -cclib (:include llvmconf.sexp))
(library_flags :standard (:include llvmconf.sexp))
)

; use opam's detected llvm if present, otherwise fall back to 'llvm-config'
(rule
(target llvmconf.pth)
(action (with-stdout-to %{target}
(bash "if command -v opam &>/dev/null ; then opam var conf-llvm:config ; else command -v llvm-config ; fi"))))

; https://dune.readthedocs.io/en/latest/reference/actions/index.html
(rule
(targets llvmconf.sexp)
; use opam if present otherwise fall back to $LLVM_CONFIG
(action (bash "if command -v opam; then llvm_config=$(opam var conf-llvm:config); fi ; ${llvm_config:-$LLVM_CONFIG} --libs > llvmconf.sexp"))
)
(target llvmconf.sexp)
(action (with-stdout-to %{target}
(setenv conf "%{read:llvmconf.pth}"
(pipe-stdout
; (bash "printf 'llvm-config: %q\n' $conf >&2")
(bash "printf -- '-cclib %s\n' $($conf --libs)")
(bash "cat ; printf -- '-ccopt %s\n' $($conf --ldflags) $($conf --cflags)")
(bash "echo '(' ; cat ; echo ')'"))))))

0 comments on commit 47e6aaf

Please sign in to comment.