Skip to content

Commit 62fc94d

Browse files
jaredramirezclaude
andcommitted
fix(nix): build kcov in the dev shell on macOS
`zig build build-ci` builds the custom kcov coverage tool from source on every platform, but the dev shell only provided kcov's link dependencies on Linux, so on macOS the build failed with "unable to find dynamic system library 'z'/'curl'". Provide curl/zlib/pkg-config on all platforms, and on macOS add libdwarf (kcov links it as "dwarf"). kcov resolves system libraries through pkg-config but asks for the module names "z"/"dwarf", which nixpkgs ships as "zlib"/"libdwarf"; add alias .pc files so those resolve (the nix pkg-config wrapper only reads .pc dirs from buildInputs, not an exported PKG_CONFIG_PATH). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 116746c commit 62fc94d

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

src/flake.nix

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,32 @@
3737
pkgs = import nixpkgs { inherit system; };
3838
isLinux = pkgs.stdenv.isLinux;
3939

40-
# kcov build dependencies for Linux (coverage uses custom kcov fork built from source)
40+
# kcov (built from source for coverage on every platform) links system
41+
# libs via pkg-config, but asks for "z"/"curl"/"dwarf" while nixpkgs
42+
# ships "zlib"/"libcurl"/"libdwarf". Provide alias .pc files so those
43+
# resolve; they must be packages since the nix pkg-config wrapper only
44+
# reads .pc dirs from buildInputs. On macOS the bare "-l" fallback only
45+
# searches the SDK (which has neither libz nor libcurl), so every lib
46+
# must resolve through pkg-config here.
47+
pcConfigAlias = name: pkg: pcName: pkgs.runCommand "pkgconfig-alias-${name}" { } ''
48+
mkdir -p "$out/lib/pkgconfig"
49+
cp "$(find ${pkg} -name '${pcName}.pc' | head -n1)" "$out/lib/pkgconfig/${name}.pc"
50+
'';
4151
kcovBuildDeps = with pkgs; [
42-
elfutils
4352
pkg-config
4453
curl
4554
zlib
55+
(pcConfigAlias "z" zlib.dev "zlib")
56+
(pcConfigAlias "curl" curl.dev "libcurl")
57+
];
58+
# elfutils (libdw/libelf for DWARF parsing) is used by kcov on Linux.
59+
kcovLinuxOnlyDeps = with pkgs; [
60+
elfutils
61+
];
62+
# macOS kcov uses libdwarf (linked as "dwarf") instead of elfutils.
63+
kcovDarwinOnlyDeps = with pkgs; [
64+
libdwarf
65+
(pcConfigAlias "dwarf" libdwarf.dev "libdwarf")
4666
];
4767
zig = pkgs.zig_0_16;
4868
dependencies = [
@@ -53,7 +73,9 @@
5373
pkgs.jq # see ci/benchmarks_zig.sh
5474
(pkgs.writeShellScriptBin "zon2nix" "nix run github:Cloudef/zig2nix -- zon2nix")
5575
]
56-
++ pkgs.lib.optionals isLinux kcovBuildDeps;
76+
++ kcovBuildDeps
77+
++ pkgs.lib.optionals isLinux kcovLinuxOnlyDeps
78+
++ pkgs.lib.optionals (!isLinux) kcovDarwinOnlyDeps;
5779

5880
shellFunctions = ''
5981
buildcmd() {

0 commit comments

Comments
 (0)