Skip to content

Commit

Permalink
dune-configurator: respect $PKG_CONFIG
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Nuno Monteiro <anmonteiro@gmail.com>
  • Loading branch information
anmonteiro committed Apr 4, 2023
1 parent 7bed96d commit 9e51269
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Unreleased
----------

- Use `$PKG_CONFIG`, when set, to find the `pkg-config` binary (#7469, fixes
#2572, @anmonteiro)

- Preliminary support for Coq compiled intefaces (`.vos` files) enabled via
`(mode vos)` in `coq.theory` stanzas. This can be used in combination with
`dune coq top` to obtain fast re-building of dependencies (with no checking
Expand Down
7 changes: 6 additions & 1 deletion otherlibs/configurator/src/v1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,12 @@ module Pkg_config = struct
}

let get c =
Option.map (which c "pkg-config") ~f:(fun pkg_config ->
let pkg_config_exe_name =
match Sys.getenv "PKG_CONFIG" with
| s -> s
| exception Not_found -> "pkg-config"
in
Option.map (which c pkg_config_exe_name) ~f:(fun pkg_config ->
{ pkg_config; configurator = c })

type package_conf =
Expand Down
16 changes: 14 additions & 2 deletions src/dune_rules/pkg_config.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
open Import

let pkg_config_binary sctx ~dir =
let open Memo.O in
let+ env = Super_context.env_node sctx ~dir >>= Env_node.external_env in
match Env.get env "PKG_CONFIG" with
| None -> "pkg-config"
| Some s -> s

module Query = struct
type t =
| Libs of string
Expand Down Expand Up @@ -28,7 +35,9 @@ module Query = struct
let open Action_builder.O in
let* bin =
Action_builder.of_memo
@@ Super_context.resolve_program sctx ~loc:None ~dir "pkg-config"
(let open Memo.O in
let* pkg_config = pkg_config_binary sctx ~dir in
Super_context.resolve_program sctx ~loc:None ~dir pkg_config)
in
match bin with
| Error _ -> Action_builder.return (default t)
Expand All @@ -42,7 +51,10 @@ end
let gen_rule sctx ~loc ~dir query =
let open Memo.O in
let* bin =
Super_context.resolve_program sctx ~loc:(Some loc) ~dir "pkg-config"
let open Memo.O in
let* pkg_config = pkg_config_binary sctx ~dir in

Super_context.resolve_program sctx ~loc:(Some loc) ~dir pkg_config
in
match bin with
| Error _ -> Memo.return @@ Error `Not_found
Expand Down

0 comments on commit 9e51269

Please sign in to comment.