Merge pull request #87705 from Ericson2314/wrap-pkg-config

Wrap pkg-config
This commit is contained in:
John Ericson 2020-05-15 21:00:02 -04:00 committed by GitHub
commit 75c55c4fe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 221 additions and 26 deletions

View File

@ -13,7 +13,7 @@ stdenv.mkDerivation rec {
enableParallelBuilding = true;
makeFlags = [ "PKG_CONFIG=${buildPackages.pkgconfig}/bin/pkg-config" ];
makeFlags = [ "PKG_CONFIG=${buildPackages.pkgconfig}/bin/${buildPackages.pkgconfig.targetPrefix}pkg-config" ];
installPhase = ''
install -m 555 -Dt $out/bin mg

View File

@ -71,7 +71,7 @@ stdenv.mkDerivation {
moveToOutput "lib/ImageMagick-*/config-Q16HDRI" "$dev" # includes configure params
for file in "$dev"/bin/*-config; do
substituteInPlace "$file" --replace pkg-config \
"PKG_CONFIG_PATH='$dev/lib/pkgconfig' '${pkgconfig}/bin/pkg-config'"
"PKG_CONFIG_PATH='$dev/lib/pkgconfig' '${pkgconfig}/bin/${pkgconfig.targetPrefix}pkg-config'"
done
'' + lib.optionalString (ghostscript != null) ''
for la in $out/lib/*.la; do

View File

@ -85,9 +85,9 @@ stdenv.mkDerivation {
moveToOutput "lib/ImageMagick-*/config-Q16" "$dev" # includes configure params
for file in "$dev"/bin/*-config; do
substituteInPlace "$file" --replace "${pkgconfig}/bin/pkg-config -config" \
${pkgconfig}/bin/pkg-config
${pkgconfig}/bin/${pkgconfig.targetPrefix}pkg-config
substituteInPlace "$file" --replace ${pkgconfig}/bin/pkg-config \
"PKG_CONFIG_PATH='$dev/lib/pkgconfig' '${pkgconfig}/bin/pkg-config'"
"PKG_CONFIG_PATH='$dev/lib/pkgconfig' '${pkgconfig}/bin/${pkgconfig.targetPrefix}pkg-config'"
done
'' + lib.optionalString (ghostscript != null) ''
for la in $out/lib/*.la; do

View File

@ -15,7 +15,7 @@ stdenv.mkDerivation {
sha256 = "1f73wvqqvj5pr3fvb7jjc4bi1iwgkkknz24k8n69mdb75jnfjipp";
};
makeFlags = [ "PKGCONFIG=${pkgconfig}/bin/pkg-config" "binary=stupidterm" ];
makeFlags = [ "PKGCONFIG=${pkgconfig}/bin/${pkgconfig.targetPrefix}pkg-config" "binary=stupidterm" ];
installPhase = ''
install -D stupidterm $out/bin/stupidterm

View File

@ -12,7 +12,7 @@
cp -v "$script" "$target"/"$scriptName"
chmod 755 "$target"/"$scriptName"
patchShebangs "$target"/"$scriptName"
substituteInPlace "$target"/"$scriptName" --replace pkg-config ${pkgconfig}/bin/pkg-config
substituteInPlace "$target"/"$scriptName" --replace pkg-config ${pkgconfig}/bin/${pkgconfig.targetPrefix}pkg-config
substituteInPlace "$target"/"$scriptName" --replace monodis ${mono}/bin/monodis
done
''

View File

@ -0,0 +1,12 @@
# See cc-wrapper for comments.
var_templates_list=(
PKG_CONFIG_PATH
)
accumulateRoles
for var in "${var_templates_list[@]}"; do
mangleVarList "$var" ${role_suffixes[@]+"${role_suffixes[@]}"}
done
export NIX_PKG_CONFIG_WRAPPER_FLAGS_SET_@suffixSalt@=1

View File

@ -0,0 +1,117 @@
# The wrapper script ensures variables like PKG_CONFIG_PATH and
# PKG_CONFIG_PATH_FOR_BUILD work properly.
{ stdenvNoCC
, buildPackages
, pkg-config
, propagateDoc ? pkg-config != null && pkg-config ? man
, extraPackages ? [], extraBuildCommands ? ""
}:
with stdenvNoCC.lib;
let
stdenv = stdenvNoCC;
inherit (stdenv) hostPlatform targetPlatform;
# Prefix for binaries. Customarily ends with a dash separator.
#
# TODO(@Ericson2314) Make unconditional, or optional but always true by
# default.
targetPrefix = stdenv.lib.optionalString (targetPlatform != hostPlatform)
(targetPlatform.config + "-");
# See description in cc-wrapper.
suffixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config;
in
stdenv.mkDerivation {
pname = targetPrefix + pkg-config.pname + "-wrapper";
inherit (pkg-config) version;
preferLocalBuild = true;
shell = getBin stdenvNoCC.shell + stdenvNoCC.shell.shellPath or "";
inherit targetPrefix suffixSalt;
outputs = [ "out" ] ++ optionals propagateDoc [ "man" ];
passthru = {
inherit pkg-config;
};
dontBuild = true;
dontConfigure = true;
unpackPhase = ''
src=$PWD
'';
installPhase =
''
mkdir -p $out/bin $out/nix-support
wrap() {
local dst="$1"
local wrapper="$2"
export prog="$3"
substituteAll "$wrapper" "$out/bin/$dst"
chmod +x "$out/bin/$dst"
}
echo $pkg-config > $out/nix-support/orig-pkg-config
wrap ${targetPrefix}pkg-config ${./pkg-config-wrapper.sh} "${getBin pkg-config}/bin/pkg-config"
'';
strictDeps = true;
wrapperName = "PKG_CONFIG_WRAPPER";
setupHooks = [
../setup-hooks/role.bash
./setup-hook.sh
];
postFixup =
''
##
## User env support
##
# Propagate the underling unwrapped pkg-config so that if you
# install the wrapper, you get anything else it might provide.
printWords ${pkg-config} > $out/nix-support/propagated-user-env-packages
''
+ optionalString propagateDoc ''
##
## Man page and info support
##
ln -s ${pkg-config.man} $man
''
+ ''
substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash
##
## Extra custom steps
##
''
+ extraBuildCommands;
meta =
let pkg-config_ = if pkg-config != null then pkg-config else {}; in
(if pkg-config_ ? meta then removeAttrs pkg-config.meta ["priority"] else {}) //
{ description =
stdenv.lib.attrByPath ["meta" "description"] "pkg-config" pkg-config_
+ " (wrapper script)";
priority = 10;
};
}

View File

@ -0,0 +1,21 @@
#! @shell@
set -eu -o pipefail +o posix
shopt -s nullglob
if (( "${NIX_DEBUG:-0}" >= 7 )); then
set -x
fi
source @out@/nix-support/utils.bash
if [ -z "${NIX_PKG_CONFIG_WRAPPER_FLAGS_SET_@suffixSalt@:-}" ]; then
source @out@/nix-support/add-flags.sh
fi
if (( ${#role_suffixes[@]} > 0 )); then
# replace env var with nix-modified one
PKG_CONFIG_PATH=$PKG_CONFIG_PATH_@suffixSalt@ exec @prog@ "$@"
else
# pkg-config isn't a bonafied dependency so ignore setup hook entirely
exec @prog@ "$@"
fi

View File

@ -0,0 +1,29 @@
# pkg-config Wrapper hygiene
#
# See comments in cc-wrapper's setup hook. This works exactly the same way.
# Skip setup hook if we're neither a build-time dep, nor, temporarily, doing a
# native compile.
#
# TODO(@Ericson2314): No native exception
[[ -z ${strictDeps-} ]] || (( "$hostOffset" < 0 )) || return 0
pkgConfigWrapper_addPkgConfigPath () {
# See ../setup-hooks/role.bash
local role_post
getHostRoleEnvHook
addToSearchPath "PKG_CONFIG_PATH${role_post}" "$1/lib/pkgconfig"
addToSearchPath "PKG_CONFIG_PATH${role_post}" "$1/share/pkgconfig"
}
# See ../setup-hooks/role.bash
getTargetRole
getTargetRoleWrapper
addEnvHooks "$targetOffset" pkgConfigWrapper_addPkgConfigPath
export PKG_CONFIG${role_post}=@targetPrefix@pkg-config
# No local scope in sourced file
unset -v role_post

View File

@ -163,7 +163,6 @@ stdenv.mkDerivation rec {
] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"--cross-prefix=${stdenv.cc.targetPrefix}"
"--enable-cross-compile"
"--pkg-config=pkg-config" # Override ffmpeg's ./configure assumption that pkg-config is prefixed by the architecture. (e.g. aarch64-unknown-linux-gnu-pkg-config)
] ++ optional stdenv.cc.isClang "--cc=clang");
depsBuildBuild = [ buildPackages.stdenv.cc ];

View File

@ -117,7 +117,7 @@ in stdenv.mkDerivation rec {
makeFlags = [
"prefix=${placeholder "out"}"
"PKG_CONFIG=${pkgconfig}/bin/pkg-config"
"PKG_CONFIG=${pkgconfig}/bin/${pkgconfig.targetPrefix}pkg-config"
];
# The .pc files does not declare an `includedir=`, so the multiple

View File

@ -4,7 +4,7 @@ buildPythonPackage rec {
pname = "pkgconfig";
version = "1.5.1";
setupHook = pkgconfig.setupHook;
setupHooks = pkgconfig.setupHooks;
src = fetchPypi {
inherit pname version;
@ -21,7 +21,7 @@ buildPythonPackage rec {
patches = [ ./executable.patch ];
postPatch = ''
substituteInPlace pkgconfig/pkgconfig.py --replace 'PKG_CONFIG_EXE = "pkg-config"' 'PKG_CONFIG_EXE = "${pkgconfig}/bin/pkg-config"'
substituteInPlace pkgconfig/pkgconfig.py --replace 'PKG_CONFIG_EXE = "pkg-config"' 'PKG_CONFIG_EXE = "${pkgconfig}/bin/${pkgconfig.targetPrefix}pkg-config"'
'';
meta = with lib; {

View File

@ -12,7 +12,7 @@ buildPythonPackage rec {
postPatch = ''
substituteInPlace setup.py \
--replace "/usr/bin/pkg-config" "${pkgconfig}/bin/pkg-config"
--replace "/usr/bin/pkg-config" "${pkgconfig}/bin/${pkgconfig.targetPrefix}pkg-config"
'';
nativeBuildInputs = [ pkgconfig ];

View File

@ -6,8 +6,6 @@ stdenv.mkDerivation rec {
pname = "pkg-config";
version = "0.29.2";
setupHook = ./setup-hook.sh;
src = fetchurl {
url = "https://pkgconfig.freedesktop.org/releases/${pname}-${version}.tar.gz";
sha256 = "14fmwzki1rlz8bs2p810lk6jqdxsk966d8drgsjmi54cd00rrikg";

View File

@ -1,6 +0,0 @@
addPkgConfigPath () {
addToSearchPath PKG_CONFIG_PATH $1/lib/pkgconfig
addToSearchPath PKG_CONFIG_PATH $1/share/pkgconfig
}
addEnvHooks "$targetOffset" addPkgConfigPath

View File

@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
buildInputs = [ gpsd libcap libnl ];
preBuild = ''
makeFlags="PREFIX=$out PKG_CONFIG=${pkgconfig}/bin/pkg-config"
makeFlags="PREFIX=$out PKG_CONFIG=${pkgconfig}/bin/${pkgconfig.targetPrefix}pkg-config"
'';
meta = {

View File

@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
buildInputs = [ libnl ];
preBuild = ''
makeFlags="PREFIX=$out PKG_CONFIG=${pkgconfig}/bin/pkg-config"
makeFlags="PREFIX=$out PKG_CONFIG=${pkgconfig}/bin/${pkgconfig.targetPrefix}pkg-config"
'';
meta = {

View File

@ -13,7 +13,7 @@ let
compareTest = { emulator, pkgFun, hostPkgs, crossPkgs, exec, args ? [] }: let
pkgName = (pkgFun hostPkgs).name;
args' = lib.concatStringsSep " " args;
in pkgs.runCommand "test-${pkgName}-${crossPkgs.hostPlatform.config}" {
in crossPkgs.runCommand "test-${pkgName}-${crossPkgs.hostPlatform.config}" {
nativeBuildInputs = [ pkgs.dos2unix ];
} ''
# Just in case we are using wine, get rid of that annoying extra
@ -91,6 +91,20 @@ let
pkgFun = pkgs: pkgs.hello;
};
pkg-config = {platformFun, crossPkgs, emulator}: crossPkgs.runCommand
"test-pkg-config-${crossPkgs.hostPlatform.config}"
{
depsBuildBuild = [ crossPkgs.pkgsBuildBuild.pkg-config ];
nativeBuildInputs = [ crossPkgs.pkgsBuildHost.pkg-config crossPkgs.buildPackages.zlib ];
depsBuildTarget = [ crossPkgs.pkgsBuildTarget.pkg-config ];
buildInputs = [ crossPkgs.zlib ];
NIX_DEBUG = 7;
} ''
mkdir $out
${crossPkgs.pkgsBuildBuild.pkg-config.targetPrefix}pkg-config --cflags zlib > "$out/for-build"
${crossPkgs.pkgsBuildHost.pkg-config.targetPrefix}pkg-config --cflags zlib > "$out/for-host"
! diff "$out/for-build" "$out/for-host"
'';
};
in {

View File

@ -16,7 +16,7 @@ stdenv.mkDerivation {
};
preConfigure = ''
export PKG_CONFIG=${pkgconfig}/bin/pkg-config
export PKG_CONFIG=${pkgconfig}/bin/${pkgconfig.targetPrefix}pkg-config
export LIBXML2_CFLAGS="-I ${libxml2.dev}/include/libxml2"
export LIBXML2_LIBS="-L${libxml2.out}/lib -lxml2"
'';

View File

@ -329,7 +329,11 @@ in
# break dependency cycles
fetchurl = stdenv.fetchurlBoot;
zlib = buildPackages.zlib.override { fetchurl = stdenv.fetchurlBoot; };
pkgconfig = buildPackages.pkgconfig.override { fetchurl = stdenv.fetchurlBoot; };
pkgconfig = buildPackages.pkgconfig.override (old: {
pkg-config = old.pkg-config.override {
fetchurl = stdenv.fetchurlBoot;
};
});
perl = buildPackages.perl.override { fetchurl = stdenv.fetchurlBoot; };
openssl = buildPackages.openssl.override {
fetchurl = stdenv.fetchurlBoot;
@ -10737,10 +10741,17 @@ in
pkgconf = callPackage ../development/tools/misc/pkgconf {};
pkg-config = callPackage ../development/tools/misc/pkg-config { };
pkg-config-unwrapped = callPackage ../development/tools/misc/pkg-config { };
pkg-config = callPackage ../build-support/pkg-config-wrapper {
pkg-config = pkg-config-unwrapped;
};
pkgconfig = pkg-config; # added 2018-02-02
pkg-configUpstream = lowPrio (pkg-config.override { vanilla = true; });
pkg-configUpstream = lowPrio (pkg-config.override (old: {
pkg-config = old.pkg-config.override {
vanilla = true;
};
}));
pkgconfigUpstream = pkg-configUpstream; # added 2018-02-02
inherit (nodePackages) postcss-cli;