Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dune-configurator: respect $PKG_CONFIG #7469

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably allow overriding this variable. I recommend fetching the environment from Super_context.env_node

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, env_node makes sense. I changed to that.

| 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