From 7be5fbf70fdc995034b2658bd814cfa45dfddc9a Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 3 Nov 2021 16:50:59 +0000 Subject: pkgsStatic.netbsd: fix nbtool_config.h conflicts In pkgsStatic, /all/ build inputs are propagated. This means that netbsd.compat was propagated, along with its setup hook, which broke static glib builds because glib defines a function with the same name as one in nbtool_config.h, and nbtool_config.h was being automatically included in every C file processed by the compiler, in any transitive dependent of netbsd.compat's setup hook. To fix this, rather than forcing nbtool_config.h to be included for _every_ C file in a derivation that depends on netbsd.compat, modify the NetBSD-specific mkDerivation to detect files that need the header, and patch it in there where appropriate. That way, only files that are part of NetBSD will be affected, not all transitive dependents. --- pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh | 1 - pkgs/os-specific/bsd/netbsd/default.nix | 12 +++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'pkgs/os-specific/bsd') diff --git a/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh b/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh index 3c49337a937ce..acd90b7aa2f0e 100644 --- a/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh +++ b/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh @@ -3,4 +3,3 @@ getHostRole export NIX_LDFLAGS${role_post}+=" -lnbcompat" export NIX_CFLAGS_COMPILE${role_post}+=" -DHAVE_NBTOOL_CONFIG_H" -export NIX_CFLAGS_COMPILE${role_post}+=" -include nbtool_config.h" diff --git a/pkgs/os-specific/bsd/netbsd/default.nix b/pkgs/os-specific/bsd/netbsd/default.nix index beaa176dae157..7a6604afe641e 100644 --- a/pkgs/os-specific/bsd/netbsd/default.nix +++ b/pkgs/os-specific/bsd/netbsd/default.nix @@ -120,7 +120,17 @@ in lib.makeScopeWithSplicing } // lib.optionalAttrs (attrs.headersOnly or false) { installPhase = "includesPhase"; dontBuild = true; - } // attrs)); + } // attrs // { + postPatch = lib.optionalString (!stdenv'.hostPlatform.isNetBSD) '' + # Files that use NetBSD-specific macros need to have nbtool_config.h + # included ahead of them on non-NetBSD platforms. + set +e + grep -Zlr "^__RCSID + ^__BEGIN_DECLS" | xargs -0r grep -FLZ nbtool_config.h | + xargs -0tr sed -i '0,/^#/s//#include \n\0/' + set -e + '' + attrs.postPatch or ""; + })); ## ## START BOOTSTRAPPING -- cgit 1.4.1