Skip to content

Conversation

@MisterDA
Copy link
Contributor

@MisterDA MisterDA commented Apr 8, 2025

pkgconf uses the personality to locate the correct library when the library can be found with multiple toolchains. For instance, on Cygwin, pkgconf could detect libcurl (built with cygwin1.dll), licurl (built with x86_64-w64-mingw32), or libcurl (built with i686-w64-mingw32). It needs the right --personality flag to select between these libraries, which we pass when asking for the --cflags or --libs. We also need it when validating the expression, or pkgconf returns an error:

$ (cd _build/default && config/discover.exe)
which: pkgconf
-> found: C:\Users\Antonin\AppData\Local\opam\default-2\bin\pkgconf.exe
run: C:\Users\Antonin\AppData\Local\opam\default-2\bin\pkgconf.exe --print-errors "libcurl >= 7.28.0"
-> process exited with code 1
-> stdout:
-> stderr:
| Package libcurl was not found in the pkg-config search path.
| Perhaps you should add the directory containing `libcurl.pc'
| to the PKG_CONFIG_PATH environment variable
| Package 'libcurl' not found
Error: Package libcurl was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcurl.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libcurl' not found
$ ~/AppData/Local/opam/default-2/bin/pkgconf.exe --personality x86_64-w64-mingw32 --print-errors "libcurl >= 7.28.0

This is a nasty bug for me, as there's no way of passing the personality flag to pkgconf outsite of Dune: the PKG_CONFIG_ARGN is just exposed by Dune and CMake and isn't actually recognized by pkgconf.

cf #10937

@maiste maiste added bug config Everything related to dune configuration (workspace, project, dune, env) labels Apr 8, 2025
@maiste
Copy link
Collaborator

maiste commented Apr 8, 2025

(Once the CI passes the test 😄)

@MisterDA MisterDA force-pushed the dune-configurator-args branch from de1f417 to 8da4dfa Compare April 8, 2025 23:49
Copy link
Collaborator

@Leonidas-from-XIV Leonidas-from-XIV left a comment

Choose a reason for hiding this comment

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

It's most likely ok, I'd just want to understand where the --personality change comes from.

-> process exited with code 0
-> stdout:
| --personality
| $TARGET
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just so I understand the issue: we always had the --personality $TARGET flag in t.pkg_config_args (which I guess is partly populated from PKG_CONFIG_ARGN), we just forgot to pass it to pkgconf?

Copy link
Contributor Author

@MisterDA MisterDA Apr 9, 2025

Choose a reason for hiding this comment

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

Say we're looking for libcurl. Then, C.Pkg_config.query_expr_err pc ~package:"libcurl" ~expr:"libcurl >= 7.28.0" will do three invocations:

$ pkgconf "libcurl >= 7.28.0"
$ pkgconf $PKG_CONFIG_ARGN --libs libcurl
-lcurl
$ pkgconf $PKG_CONFIG_ARGN --cflags libcurl

I just found out that if we're not passing $PKG_CONFIG_ARGN to the first invocation, then it might fail because pkgconf would be looking for libcurl in the "default" personality, which may not be the one the current ocaml install is using. So, yes, we forgot to pass it to the first invocation.

Note that PKG_CONFIG_ARG isn't a variable that's understood by pkgconf or pkg-config, it's an escape hatch from the build systems (CMake and Dune) to allow users to pass extra variables to pkgconf/pkg-config invocations—provided the build system doesn't forget to pass the variable!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I get that, but from what I understand there were two bugs being fixed in this PR:

  1. PKG_CONFIG_ARGN wasn't respected when doing the call (thus -static wasn't passed in the test) and now it is. That much makes sense to me.
  2. Somehow --personality was not passed either and now it is. It did not come from PKG_CONFIG_ARGN (since the first dune build invocation in the test does not have it set) so I assume it was another bug that also existed and is being fixed by this PR.

Am I right in this interpretation?

Please add a changelog entry however since it would be nice for people to learn about this fix when we cut the next Dune release.

Copy link
Contributor Author

@MisterDA MisterDA Apr 9, 2025

Choose a reason for hiding this comment

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

I think the bug was rather that Dune forgot to pass the personality flag to the first invocation of pkgconf.

Reading about --static:

Compute a deeper dependency graph and use compiler/linker flags intended for static linking.

I don't think it matters much in the first invocation (just to detect whether the package is available).

The mechanism Dune uses to pass extra flags to pkgconf, whether auto-detected, or from the user through PKG_CONFIG_ARGN, works when requesting --libs and --cflags.

Dune might even be overzealous in doing that first invocation. If we don't get rid of it, maybe just passing the personality flag is enough and we don't need to pass the full PKG_CONFIG_ARGN. I'm not sure if that would be surprising to users.

Copy link
Contributor Author

@MisterDA MisterDA Apr 9, 2025

Choose a reason for hiding this comment

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

Sorry, I wasn't very clear. t.pkg_config_args is either the content of PKG_CONFIG_ARGN if set, or --personality=$target (set by Dune). Either way it wasn't passed to the first invocation. I don't think the first invocation need the --static flag anyway, but the user might be willing to pass additional flags. Thinking about it, I'd be surprised if this first invocation is needed at all, meaning that we can pass the content of the expression to when we look for flags.

@MisterDA MisterDA force-pushed the dune-configurator-args branch from 8da4dfa to 1deb104 Compare April 9, 2025 15:35
pkgconf uses the personality to locate the correct library when the
library can be found with multiple toolchains. For instance, on
Cygwin, pkgconf could detect libcurl (built with cygwin1.dll), libcurl
(built with x86_64-w64-mingw32), or libcurl (built with
i686-w64-mingw32). It needs the right `--personality` flag to select
between these libraries, which we pass when asking for the `--cflags`
or `--libs`. We also need it when validating the expression, or
pkgconf returns an error:

    $ (cd _build/default && config/discover.exe)
    which: pkgconf
    -> found: C:\Users\Antonin\AppData\Local\opam\default-2\bin\pkgconf.exe
    run: C:\Users\Antonin\AppData\Local\opam\default-2\bin\pkgconf.exe --print-errors "libcurl >= 7.28.0"
    -> process exited with code 1
    -> stdout:
    -> stderr:
     | Package libcurl was not found in the pkg-config search path.
     | Perhaps you should add the directory containing `libcurl.pc'
     | to the PKG_CONFIG_PATH environment variable
     | Package 'libcurl' not found
    Error: Package libcurl was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libcurl.pc'
    to the PKG_CONFIG_PATH environment variable
    Package 'libcurl' not found

Signed-off-by: Antonin Décimo <[email protected]>
@maiste maiste force-pushed the dune-configurator-args branch from 1deb104 to a77373c Compare April 10, 2025 06:29
@Leonidas-from-XIV Leonidas-from-XIV merged commit 897bd78 into ocaml:main Apr 10, 2025
24 of 25 checks passed
@MisterDA MisterDA deleted the dune-configurator-args branch April 11, 2025 12:40
@maiste maiste mentioned this pull request Apr 14, 2025
8 tasks
maiste pushed a commit to maiste/dune that referenced this pull request Apr 14, 2025
…l#11619)

pkgconf uses the personality to locate the correct library when the
library can be found with multiple toolchains. For instance, on
Cygwin, pkgconf could detect libcurl (built with cygwin1.dll), libcurl
(built with x86_64-w64-mingw32), or libcurl (built with
i686-w64-mingw32). It needs the right `--personality` flag to select
between these libraries, which we pass when asking for the `--cflags`
or `--libs`. We also need it when validating the expression, or
pkgconf returns an error:

    $ (cd _build/default && config/discover.exe)
    which: pkgconf
    -> found: C:\Users\Antonin\AppData\Local\opam\default-2\bin\pkgconf.exe
    run: C:\Users\Antonin\AppData\Local\opam\default-2\bin\pkgconf.exe --print-errors "libcurl >= 7.28.0"
    -> process exited with code 1
    -> stdout:
    -> stderr:
     | Package libcurl was not found in the pkg-config search path.
     | Perhaps you should add the directory containing `libcurl.pc'
     | to the PKG_CONFIG_PATH environment variable
     | Package 'libcurl' not found
    Error: Package libcurl was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libcurl.pc'
    to the PKG_CONFIG_PATH environment variable
    Package 'libcurl' not found

Signed-off-by: Antonin Décimo <[email protected]>
maiste added a commit that referenced this pull request Apr 15, 2025
…) (#11626)

pkgconf uses the personality to locate the correct library when the
library can be found with multiple toolchains. For instance, on
Cygwin, pkgconf could detect libcurl (built with cygwin1.dll), libcurl
(built with x86_64-w64-mingw32), or libcurl (built with
i686-w64-mingw32). It needs the right `--personality` flag to select
between these libraries, which we pass when asking for the `--cflags`
or `--libs`. We also need it when validating the expression, or
pkgconf returns an error:

    $ (cd _build/default && config/discover.exe)
    which: pkgconf
    -> found: C:\Users\Antonin\AppData\Local\opam\default-2\bin\pkgconf.exe
    run: C:\Users\Antonin\AppData\Local\opam\default-2\bin\pkgconf.exe --print-errors "libcurl >= 7.28.0"
    -> process exited with code 1
    -> stdout:
    -> stderr:
     | Package libcurl was not found in the pkg-config search path.
     | Perhaps you should add the directory containing `libcurl.pc'
     | to the PKG_CONFIG_PATH environment variable
     | Package 'libcurl' not found
    Error: Package libcurl was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libcurl.pc'
    to the PKG_CONFIG_PATH environment variable
    Package 'libcurl' not found

Signed-off-by: Antonin Décimo <[email protected]>
Co-authored-by: Antonin Décimo <[email protected]>
maiste added a commit to maiste/opam-repository that referenced this pull request Apr 15, 2025
CHANGES:

- fix: pass pkg-config (extra) args in all pkgconfig invocations. A missing
  `--personality` flag would result in pkgconf not finding libraries in some
  contexts. (ocaml/dune#11619, @MisterDA)
maiste added a commit to maiste/opam-repository that referenced this pull request Apr 15, 2025
CHANGES:

- fix: pass pkg-config (extra) args in all pkgconfig invocations. A missing
  `--personality` flag would result in pkgconf not finding libraries in some
  contexts. (ocaml/dune#11619, @MisterDA)
anmonteiro pushed a commit to anmonteiro/dune that referenced this pull request Apr 22, 2025
…l#11619)

pkgconf uses the personality to locate the correct library when the
library can be found with multiple toolchains. For instance, on
Cygwin, pkgconf could detect libcurl (built with cygwin1.dll), libcurl
(built with x86_64-w64-mingw32), or libcurl (built with
i686-w64-mingw32). It needs the right `--personality` flag to select
between these libraries, which we pass when asking for the `--cflags`
or `--libs`. We also need it when validating the expression, or
pkgconf returns an error:

    $ (cd _build/default && config/discover.exe)
    which: pkgconf
    -> found: C:\Users\Antonin\AppData\Local\opam\default-2\bin\pkgconf.exe
    run: C:\Users\Antonin\AppData\Local\opam\default-2\bin\pkgconf.exe --print-errors "libcurl >= 7.28.0"
    -> process exited with code 1
    -> stdout:
    -> stderr:
     | Package libcurl was not found in the pkg-config search path.
     | Perhaps you should add the directory containing `libcurl.pc'
     | to the PKG_CONFIG_PATH environment variable
     | Package 'libcurl' not found
    Error: Package libcurl was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libcurl.pc'
    to the PKG_CONFIG_PATH environment variable
    Package 'libcurl' not found

Signed-off-by: Antonin Décimo <[email protected]>
maiste added a commit to maiste/opam-repository that referenced this pull request May 20, 2025
CHANGES:

### Fixed

- Fixed a bug that was causing cram tests attached to multiple aliases to be run multiple
  times. (ocaml/dune#11547, @Alizter)

- Fix: pass pkg-config (extra) args in all pkgconfig invocations. A missing --personality
  flag would result in pkgconf not finding libraries in some contexts. (ocaml/dune#11619, @MisterDA)

- Fix: Evaluate `enabled_if` when computing the stubs for stanzas such as
  `foreign_library` (ocaml/dune#11707, @Alizter, @rgrinberg)

- Fix $ dune describe pp for libraries in the presence of `(include_subdirs
  unqualified)` (ocaml/dune#11729, fixes ocaml/dune#10999, @rgrinberg)

- Fix `$ dune subst` in sub directories of a git repository (ocaml/dune#11760, fixes
  ocaml/dune#11045, @Richard-Degenne)

- Fix a crash involving `Path.drop_prefix` when using Melange on Windows
  (ocaml/dune#11767, @nojb)

### Added

- Added detection and warning for common typos in package dependency
  constraints (ocaml/dune#11600, fixes ocaml/dune#11575, @kemsguy7)

- Added `(extra_objects)` field to `(foreign_library)` stanza with `(:include)` support.
  (ocaml/dune#11683, @Alizter)

### Changed

- Allow build RPC messages to be handled by dune's RPC server in eager watch
  mode (ocaml/dune#11622, @gridbugs)

- Allow concurrent build with RPC server (ocaml/dune#11712, @gridbugs)
maiste added a commit to maiste/opam-repository that referenced this pull request May 21, 2025
CHANGES:

### Fixed

- Fixed a bug that was causing cram tests attached to multiple aliases to be run multiple
  times. (ocaml/dune#11547, @Alizter)

- Fix: pass pkg-config (extra) args in all pkgconfig invocations. A missing --personality
  flag would result in pkgconf not finding libraries in some contexts. (ocaml/dune#11619, @MisterDA)

- Fix: Evaluate `enabled_if` when computing the stubs for stanzas such as
  `foreign_library` (ocaml/dune#11707, @Alizter, @rgrinberg)

- Fix $ dune describe pp for libraries in the presence of `(include_subdirs
  unqualified)` (ocaml/dune#11729, fixes ocaml/dune#10999, @rgrinberg)

- Fix `$ dune subst` in sub directories of a git repository (ocaml/dune#11760, fixes
  ocaml/dune#11045, @Richard-Degenne)

- Fix a crash involving `Path.drop_prefix` when using Melange on Windows
  (ocaml/dune#11767, @nojb)

### Added

- Added detection and warning for common typos in package dependency
  constraints (ocaml/dune#11600, fixes ocaml/dune#11575, @kemsguy7)

- Added `(extra_objects)` field to `(foreign_library)` stanza with `(:include)` support.
  (ocaml/dune#11683, @Alizter)

### Changed

- Allow build RPC messages to be handled by dune's RPC server in eager watch
  mode (ocaml/dune#11622, @gridbugs)

- Allow concurrent build with RPC server (ocaml/dune#11712, @gridbugs)
Sudha247 pushed a commit to Sudha247/dune that referenced this pull request Jul 23, 2025
…l#11619)

pkgconf uses the personality to locate the correct library when the
library can be found with multiple toolchains. For instance, on
Cygwin, pkgconf could detect libcurl (built with cygwin1.dll), libcurl
(built with x86_64-w64-mingw32), or libcurl (built with
i686-w64-mingw32). It needs the right `--personality` flag to select
between these libraries, which we pass when asking for the `--cflags`
or `--libs`. We also need it when validating the expression, or
pkgconf returns an error:

    $ (cd _build/default && config/discover.exe)
    which: pkgconf
    -> found: C:\Users\Antonin\AppData\Local\opam\default-2\bin\pkgconf.exe
    run: C:\Users\Antonin\AppData\Local\opam\default-2\bin\pkgconf.exe --print-errors "libcurl >= 7.28.0"
    -> process exited with code 1
    -> stdout:
    -> stderr:
     | Package libcurl was not found in the pkg-config search path.
     | Perhaps you should add the directory containing `libcurl.pc'
     | to the PKG_CONFIG_PATH environment variable
     | Package 'libcurl' not found
    Error: Package libcurl was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libcurl.pc'
    to the PKG_CONFIG_PATH environment variable
    Package 'libcurl' not found

Signed-off-by: Antonin Décimo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug config Everything related to dune configuration (workspace, project, dune, env)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants