3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #214304 from obsidiansystems/pkg-config-meta

meta.pkgConfigModules: Init convention
This commit is contained in:
John Ericson 2023-02-06 11:44:29 -05:00 committed by GitHub
commit 6d0b3086f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 6 deletions

View file

@ -4,6 +4,48 @@
Nixpkgs provides a couple of facilities for working with this tool. Nixpkgs provides a couple of facilities for working with this tool.
- A [setup hook](#setup-hook-pkg-config) bundled with in the `pkg-config` package, to bring a derivation's declared build inputs into the environment. ## Writing packages providing pkg-config modules
- The [`validatePkgConfig` setup hook](https://nixos.org/manual/nixpkgs/stable/#validatepkgconfig), for packages that provide pkg-config modules.
- The `defaultPkgConfigPackages` package set: a set of aliases, named after the modules they provide. This is meant to be used by language-to-nix integrations. Hand-written packages should use the normal Nixpkgs attribute name instead. Packages should set `meta.pkgConfigProvides` with the list of package config modules they provide.
They should also use `testers.testMetaPkgConfig` to check that the final built package matches that list.
Additionally, the [`validatePkgConfig` setup hook](https://nixos.org/manual/nixpkgs/stable/#validatepkgconfig), will do extra checks on to-be-installed pkg-config modules.
A good example of all these things is zlib:
```
{ pkg-config, testers, ... }:
stdenv.mkDerivation (finalAttrs: {
...
nativeBuildInputs = [ pkg-config validatePkgConfig ];
passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
meta = {
...
pkgConfigModules = [ "zlib" ];
};
})
```
## Accessing packages via pkg-config module name
### Within Nixpkgs
A [setup hook](#setup-hook-pkg-config) is bundled in the `pkg-config` package to bring a derivation's declared build inputs into the environment.
This will populate environment variables like `PKG_CONFIG_PATH`, `PKG_CONFIG_PATH_FOR_BUILD`, and `PKG_CONFIG_PATH_HOST` based on:
- how `pkg-config` itself is depended upon
- how other dependencies are depended upon
For more details see the section on [specifying dependencies in general](#ssec-stdenv-dependencies).
Normal pkg-config commands to look up dependencies by name will then work with those environment variables defined by the hook.
### Externally
The `defaultPkgConfigPackages` package set is a set of aliases, named after the modules they provide.
This is meant to be used by language-to-nix integrations.
Hand-written packages should use the normal Nixpkgs attribute name instead.

View file

@ -123,4 +123,5 @@
hasPkgConfigModule = callPackage ./hasPkgConfigModule/tester.nix { }; hasPkgConfigModule = callPackage ./hasPkgConfigModule/tester.nix { };
testMetaPkgConfig = callPackage ./testMetaPkgConfig/tester.nix { };
} }

View file

@ -0,0 +1,14 @@
{ lib, runCommand, testers }:
package:
runCommand "check-meta-pkg-config-modules-for-${package.name}" {
meta = {
description = "Test whether ${package.name} exposes all pkg-config modules ${toString package.meta.pkgConfigModules}";
};
dependsOn = map
(moduleName: testers.hasPkgConfigModule { inherit package moduleName; })
package.meta.pkgConfigModules;
} ''
echo "found all of ${toString package.meta.pkgConfigModules}" > "$out"
''

View file

@ -8,6 +8,7 @@
# the `.pc` file lists only the main output's lib dir. # the `.pc` file lists only the main output's lib dir.
# If false, and if `{ static = true; }`, the .a stays in the main output. # If false, and if `{ static = true; }`, the .a stays in the main output.
, splitStaticOutput ? shared && static , splitStaticOutput ? shared && static
, testers
}: }:
# Without either the build will actually still succeed because the build # Without either the build will actually still succeed because the build
@ -21,11 +22,13 @@ assert shared || static;
assert splitStaticOutput -> static; assert splitStaticOutput -> static;
stdenv.mkDerivation rec { stdenv.mkDerivation (finalAttrs: {
pname = "zlib"; pname = "zlib";
version = "1.2.13"; version = "1.2.13";
src = fetchurl { src = let
inherit (finalAttrs) version;
in fetchurl {
urls = [ urls = [
# This URL works for 1.2.13 only; hopefully also for future releases. # This URL works for 1.2.13 only; hopefully also for future releases.
"https://github.com/madler/zlib/releases/download/v${version}/zlib-${version}.tar.gz" "https://github.com/madler/zlib/releases/download/v${version}/zlib-${version}.tar.gz"
@ -125,10 +128,13 @@ stdenv.mkDerivation rec {
"SHARED_MODE=1" "SHARED_MODE=1"
]; ];
passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
meta = with lib; { meta = with lib; {
homepage = "https://zlib.net"; homepage = "https://zlib.net";
description = "Lossless data-compression library"; description = "Lossless data-compression library";
license = licenses.zlib; license = licenses.zlib;
platforms = platforms.all; platforms = platforms.all;
pkgConfigModules = [ "zlib" ];
}; };
} })

View file

@ -271,6 +271,7 @@ let
sourceProvenance = listOf lib.types.attrs; sourceProvenance = listOf lib.types.attrs;
maintainers = listOf (attrsOf anything); # TODO use the maintainer type from lib/tests/maintainer-module.nix maintainers = listOf (attrsOf anything); # TODO use the maintainer type from lib/tests/maintainer-module.nix
priority = int; priority = int;
pkgConfigModules = listOf str;
platforms = listOf (either str (attrsOf anything)); # see lib.meta.platformMatch platforms = listOf (either str (attrsOf anything)); # see lib.meta.platformMatch
hydraPlatforms = listOf str; hydraPlatforms = listOf str;
broken = bool; broken = bool;