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

discover: read $PKG_CONFIG to fix cross-compilation #51

Merged
merged 1 commit into from
Dec 9, 2024
Merged
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
39 changes: 28 additions & 11 deletions src/config/discover.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,34 @@ let major_minor_from_pgconfig () =
in
Fun.protect ~finally:(fun () -> close_in ic) (fun () -> pg_major_minor ic)

let major_minor_from_pkg_config () =
let ic = Unix.open_process_in "pkg-config --modversion libpq" in
Fun.protect ~finally:(fun () -> close_in ic) @@ fun () ->
let version_line = input_line ic in
(* Typically something like "14.1" *)
match String.split_on_char '.' version_line with
| major :: minor :: _ ->
("-DPG_OCAML_MAJOR_VERSION=" ^ major, "-DPG_OCAML_MINOR_VERSION=" ^ minor)
| _ ->
eprintf "Unable to parse libpq version: %s" version_line;
exit 1
let major_minor_from_pkg_config =
let pkg_config_prefix () =
let pkg_config_args =
match Sys.getenv "PKG_CONFIG_ARGN" with
| s -> String.split_on_char ' ' s
| exception Not_found -> []
in
let bin =
match Sys.getenv "PKG_CONFIG" with
| s -> s
| exception Not_found -> "pkg-config"
in
Format.asprintf "%s %s " bin (String.concat " " pkg_config_args)
in
fun () ->
let ic =
Unix.open_process_in (pkg_config_prefix () ^ " --modversion libpq")
in
Fun.protect ~finally:(fun () -> close_in ic) @@ fun () ->
let version_line = input_line ic in
(* Typically something like "14.1" *)
match String.split_on_char '.' version_line with
| major :: minor :: _ ->
( "-DPG_OCAML_MAJOR_VERSION=" ^ major,
"-DPG_OCAML_MINOR_VERSION=" ^ minor )
| _ ->
eprintf "Unable to parse libpq version: %s" version_line;
exit 1

let from_pgconfig () =
let cmd = "pg_config --includedir --libdir --version" in
Expand Down
Loading