From 9e51269e4caf0044bea9cda587e2f7352f182045 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Sat, 1 Apr 2023 18:36:19 -0700 Subject: [PATCH] dune-configurator: respect $PKG_CONFIG Signed-off-by: Antonio Nuno Monteiro --- CHANGES.md | 3 +++ otherlibs/configurator/src/v1.ml | 7 ++++++- src/dune_rules/pkg_config.ml | 16 ++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d3a9dc56edb..544fc1429ce 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/otherlibs/configurator/src/v1.ml b/otherlibs/configurator/src/v1.ml index a0171fa8643..abe5201d6ee 100644 --- a/otherlibs/configurator/src/v1.ml +++ b/otherlibs/configurator/src/v1.ml @@ -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 = diff --git a/src/dune_rules/pkg_config.ml b/src/dune_rules/pkg_config.ml index 7b8f2b36891..44d91f7f602 100644 --- a/src/dune_rules/pkg_config.ml +++ b/src/dune_rules/pkg_config.ml @@ -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 @@ -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) @@ -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