diff --git a/otherlibs/configurator/src/v1.ml b/otherlibs/configurator/src/v1.ml index abe5201d6ee3..b8d3721daf7d 100644 --- a/otherlibs/configurator/src/v1.ml +++ b/otherlibs/configurator/src/v1.ml @@ -616,6 +616,7 @@ let which t prog = module Pkg_config = struct type nonrec t = { pkg_config : string + ; pkg_config_args : string list ; configurator : t } @@ -625,8 +626,13 @@ module Pkg_config = struct | s -> s | exception Not_found -> "pkg-config" in + let pkg_config_args = + match Sys.getenv "PKG_CONFIG_ARGN" with + | s -> String.split ~on:' ' s + | exception Not_found -> [] + in Option.map (which c pkg_config_exe_name) ~f:(fun pkg_config -> - { pkg_config; configurator = c }) + { pkg_config; pkg_config_args; configurator = c }) type package_conf = { libs : string list @@ -688,7 +694,8 @@ module Pkg_config = struct let run what = match String.trim - (Process.run_capture_exn c ~dir ?env t.pkg_config [ what; package ]) + (Process.run_capture_exn c ~dir ?env t.pkg_config + (t.pkg_config_args @ [ what; package ])) with | "" -> [] | s -> String.extract_blank_separated_words s diff --git a/src/dune_rules/pkg_config.ml b/src/dune_rules/pkg_config.ml index 44d91f7f6025..f1eb72326b90 100644 --- a/src/dune_rules/pkg_config.ml +++ b/src/dune_rules/pkg_config.ml @@ -20,12 +20,18 @@ module Query = struct | Libs s -> sprintf "%s.libs" s | Cflags s -> sprintf "%s.cflags" s - let to_args t : _ Command.Args.t list = + let to_args t ~env : _ Command.Args.t list = + let env_args : _ Command.Args.t list = + match Env.get env "PKG_CONFIG_ARGN" with + | Some s -> [ As (String.split_on_char ~sep:' ' s) ] + | None -> [] + in Hidden_deps Dep.(Set.singleton universe) - :: - (match t with - | Libs lib -> [ A "--libs"; A lib ] - | Cflags lib -> [ A "--cflags"; A lib ]) + :: (env_args + @ + match t with + | Libs lib -> [ A "--libs"; A lib ] + | Cflags lib -> [ A "--cflags"; A lib ]) let default = function | Libs lib -> [ sprintf "-l%s" lib ] @@ -60,8 +66,9 @@ let gen_rule sctx ~loc ~dir query = | Error _ -> Memo.return @@ Error `Not_found | Ok _ as bin -> let command = + let env = Super_context.context_env sctx in Command.run ~dir:(Path.build dir) ~stdout_to:(Query.file ~dir query) bin - (Query.to_args query) + (Query.to_args ~env query) in let+ () = Super_context.add_rule sctx ~loc ~dir command in Ok ()