Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2556,13 +2556,15 @@ configurePkgconfigPackages verbosity pkg_descr progdb enabled
traverse_ requirePkg allpkgs
mlib' <- traverse addPkgConfigBILib (library pkg_descr)
libs' <- traverse addPkgConfigBILib (subLibraries pkg_descr)
flibs' <- traverse addPkgConfigBIFLib (foreignLibs pkg_descr)
exes' <- traverse addPkgConfigBIExe (executables pkg_descr)
tests' <- traverse addPkgConfigBITest (testSuites pkg_descr)
benches' <- traverse addPkgConfigBIBench (benchmarks pkg_descr)
let pkg_descr' =
pkg_descr
{ library = mlib'
, subLibraries = libs'
, foreignLibs = flibs'
, executables = exes'
, testSuites = tests'
, benchmarks = benches'
Expand Down Expand Up @@ -2607,6 +2609,10 @@ configurePkgconfigPackages verbosity pkg_descr progdb enabled
addPkgConfigBILib = addPkgConfigBI libBuildInfo $
\lib bi -> lib{libBuildInfo = bi}

-- Adds pkgconfig dependencies to the build info for a foreign library
addPkgConfigBIFLib = addPkgConfigBI foreignLibBuildInfo $
\flib bi -> flib{foreignLibBuildInfo = bi}

-- Adds pkgconfig dependencies to the build info for an executable
addPkgConfigBIExe = addPkgConfigBI buildInfo $
\exe bi -> exe{buildInfo = bi}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: *.cabal
5 changes: 5 additions & 0 deletions cabal-testsuite/PackageTests/PkgConfigForeignLib/csrc/foo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <mylib.h>

int mylib_value(void) {
return MYLIB_VALUE;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef MYLIB_H
#define MYLIB_H

#define MYLIB_VALUE 42

#endif
16 changes: 16 additions & 0 deletions cabal-testsuite/PackageTests/PkgConfigForeignLib/my.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: PkgConfigForeignLib
version: 0.1
license: BSD3
synopsis: Test that pkgconfig-depends cflags reach foreign-library c-sources
category: PackageTests
build-type: Simple
cabal-version: 2.0

foreign-library myforeignlib
type: native-shared
pkgconfig-depends: mypkg
other-modules: MyForeignLib
hs-source-dirs: src
c-sources: csrc/foo.c
build-depends: base
default-language: Haskell2010
40 changes: 40 additions & 0 deletions cabal-testsuite/PackageTests/PkgConfigForeignLib/pkg-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh

set -eu

# Resolve the directory containing this shim so we can point pkg-config's
# --cflags at the header shipped next to it.
dir="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"

case "$*" in
'--version')
echo 0.29.2
;;

'--variable pc_path pkg-config')
echo '.'
;;

'--list-all')
printf 'mypkg mypkg - my test package\n'
;;

'--modversion mypkg')
echo 1.0
;;

'--cflags mypkg')
echo "-I$dir/include"
;;

'--libs mypkg')
;;

'--libs --static mypkg')
;;

*)
echo >&2 "pkg-config: unrecognised arguments $* (this is an incomplete shim)"
exit 1
;;
esac
8 changes: 8 additions & 0 deletions cabal-testsuite/PackageTests/PkgConfigForeignLib/setup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- PkgConfigForeignLib-0.1 (flib:myforeignlib) (first run)
Configuring foreign library 'myforeignlib' for PkgConfigForeignLib-0.1...
Preprocessing foreign library 'myforeignlib' for PkgConfigForeignLib-0.1...
Building foreign library 'myforeignlib' for PkgConfigForeignLib-0.1...
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Test.Cabal.Prelude

-- Test that pkgconfig-depends cflags are propagated to the C compiler
-- when compiling the c-sources of a foreign-library (see #11297).
main = cabalTest $ do
when isWindows $ skip "pkg-config shim requires sh"
cdir <- testCurrentDir <$> getTestEnv
cabal "v2-build" ["--extra-prog-path=" ++ cdir]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{-# LANGUAGE ForeignFunctionInterface #-}

module MyForeignLib (mylibValue) where

foreign import ccall "mylib_value" mylibValue :: IO Int
12 changes: 12 additions & 0 deletions changelog.d/12265.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
synopsis: Apply pkgconfig-depends flags to foreign-library c-sources
packages: [Cabal]
prs: 12265
issues: 11297
---

The `pkgconfig-depends` flags (e.g. `--cflags` include directories) were not
propagated to the C compiler when compiling the `c-sources` of a
`foreign-library`, unlike for `library` and `executable` components. This is now
fixed so that C sources in foreign libraries can use headers provided by
pkg-config dependencies.
Loading