ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.6k stars 395 forks source link

pkg-config not resolved on windows with dune configurator #4130

Open dmtrKovalenko opened 3 years ago

dmtrKovalenko commented 3 years ago

Expected Behavior

Once pkg-config --libs libpng returns the value get it and return from C.Pkg_config.get

Actual Behavior

C.Pkg_config.get on windows always return None

Reproduction

  1. Use windows server for example in GitHub actions
jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [windows-latest]
        # os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
      - uses: actions/setup-node@v2
        with:
          node-version: '13'
      - uses: actions/checkout@v2.3.2

      - name: Install libpng
        run: |
          C:\vcpkg\vcpkg install libpng
          ls C:\vcpkg\packages\libpng_x86-windows\lib\pkgconfig
          $env:PKG_CONFIG_PATH += 'C:\vcpkg\packages\libpng_x86-windows\lib\pkgconfig'
          pkg-config --libs libpng # returns correct flags
        #..prepare your env 
       - name: Run dune
         run: |
          dune build -p myprojec

With a simple dune configurator executable

(executable
 (name discover)
 (libraries dune-configurator))

And discover.ml code

module C = Configurator.V1

let () =
C.main ~name:"odiff-c-lib-package-resolver" (fun c ->
let default : C.Pkg_config.package_conf =
  { libs   = ["libpng"]
  ; cflags = []
  }
in
let conf =
  match C.Pkg_config.get c with
  | None -> default
  | Some pc ->
     match (C.Pkg_config.query pc ~package:"libpng") with
     | None -> default
     | Some deps -> deps
in

Printf.printf "Resolved c flags %s" (String.concat "" conf.cflags);
Printf.printf "\nResolved c libs %s" (String.concat "" conf.libs);

C.Flags.write_sexp "c_flags.sexp"         conf.cflags;
C.Flags.write_sexp "c_library_flags.sexp" conf.libs) 

Observe that conf.cflags and conf.libs are always empty

Specifications

rgrinberg commented 3 years ago

In your github action, you're setting the pkg config path correctly with PKG_CONFIG_PATH += 'C:\vcpkg\packages\libpng_x86-windows\lib\pkgconfig'

Are you doing the same when invoking the configurator script?

dmtrKovalenko commented 3 years ago

Sorry my bad my eyes are not reading anymore after 18 hours debugging windows CI :) I`ll triple check the env var and put the updates

dmtrKovalenko commented 3 years ago

image No, it's not still no result when having correct PNG_CONFIG_PATH. BTW here is the link right to the github action https://github.com/dmtrKovalenko/odiff/pull/16/checks?check_run_id=1717472847

rgrinberg commented 2 years ago

@nojb if you use pkg-config on windows, perhaps you know off the top of your head what the issue might be?

nojb commented 2 years ago

@nojb if you use pkg-config on windows, perhaps you know off the top of your head what the issue might be?

Sorry, I never use dune-configurator, so I don't have a lot of experience here. Just by looking at the screenshot I see that the output of pkg-config does not include any -I flag. Can this be because under Unix, the header is in some default include path, but that path may not be included by default by the mingw64 compilers? Just a guess, maybe completely off the mark.

image