Skip to content

Preserve the inherited pkg-config environment on macOS - #17078

Merged
rgrinberg merged 5 commits into
ocaml:mainfrom
aikhanjum:fix-configurator-brew-env
Nov 22, 2026
Merged

rgrinberg merged 5 commits into
ocaml:mainfrom
aikhanjum:fix-configurator-brew-env

Conversation

@aikhanjum

Copy link
Copy Markdown
Contributor

When Homebrew adds a pkg-config search path, configurator passes an explicit
PKG_CONFIG_PATH binding to Unix.create_process_env. That replaces the inherited
environment and drops settings such as PKG_CONFIG_LIBDIR and
PKG_CONFIG_SYSROOT_DIR, causing a package that depends on those settings to be
reported as missing.

Merge the explicit bindings with the inherited environment, with explicit
bindings taking precedence. The macOS regression uses controlled brew and
pkg-config executables to cover inherited variables, existing search-path
precedence, and packages without a Homebrew directory.

Related to #10805. The original vcpkg setup in that issue has not been reproduced.

Validation performed against main at 5a68b1910384be91a56b8f99046b00db6b87b8ab.

  • ./dune.exe build --cache=disabled @check @fmt passed on macOS.
  • ./dune.exe runtest --cache=disabled otherlibs/configurator/test/blackbox-tests
    passed on macOS. The saved before-fix regression reports package missing.
  • ./dune.exe build --cache=disabled @check @fmt @runtest was run on Linux
    arm64 with OCaml 5.5.2 in the repository's pinned Nix development shell. The
    final fresh run failed in pkg/opam-package-with-build-env.t and
    pkg/pkg-extract-fail.t with Lock directory is not active for context "default". Earlier runs hit the same error in other package-lock cases.
    A separate clean upstream checkout reproduced the same error in
    pkg/pin-stanza/opam-template.t. No expectations were changed or promoted.
  • The macOS full suite hit an fsevents_tests.ml expectation failure also
    reproduced on clean upstream.

AI assistance was used to prepare and validate this change.

@aikhanjum
aikhanjum marked this pull request as ready for review November 17, 2026 05:59
@Alizter Alizter added the configurator `(configurator)` stanza and the `dune-configurator` library for build-time C config label Nov 17, 2026
@Alizter
Alizter requested a review from rgrinberg November 17, 2026 11:32
@rgrinberg
rgrinberg force-pushed the fix-configurator-brew-env branch from f9ceab5 to a2280cf Compare November 22, 2026 14:50
aikhanjum and others added 5 commits November 22, 2026 14:55
Add a macOS regression for inherited variables when a Homebrew pkg-config
search path is present, including existing path precedence and the case
without a Homebrew package directory.

Signed-off-by: Aikhan Jumashukurov <[email protected]>
Merge explicit environment bindings with the inherited environment before
Unix.create_process_env, allowing explicit bindings to override matching
variables. This preserves settings used by pkg-config and wrappers.

Related to ocaml#10805.

Signed-off-by: Aikhan Jumashukurov <[email protected]>
Stub the compiler system so the Homebrew path is testable on Linux. Check that query_variable inherits PKG_CONFIG_LIBDIR as well as the search path.

Signed-off-by: Rudi Grinberg <[email protected]>
Precompute override names before filtering inherited bindings. Keep override precedence and environment ordering unchanged.

Signed-off-by: Rudi Grinberg <[email protected]>
@rgrinberg
rgrinberg force-pushed the fix-configurator-brew-env branch from a2280cf to cb9030c Compare November 22, 2026 14:57
@rgrinberg
rgrinberg merged commit bfd55a2 into ocaml:main Nov 22, 2026
36 of 37 checks passed
@rgrinberg

Copy link
Copy Markdown
Member

Thanks

@Alizter Alizter added this to the 3.26.0 milestone Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

configurator `(configurator)` stanza and the `dune-configurator` library for build-time C config

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants