From 24ad909c6153a3752cc0ae62745ce1e41c1a9354 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Wed, 19 Mar 2025 17:56:49 -0700 Subject: [PATCH] capnproto: build shared libs, debuginfo, etc. This makes several improvements to the `capnproto` derivation: - Build shared libs - Build debuginfo See: https://git.lix.systems/lix-project/lix/issues/550 - Set the correct cmake build type - Set the correct cxxflags to build the coroutine library - Always build with clang - Work around a broken static build See: https://github.com/avdv/scalals/commit/a2de0eff59cb4c9be6f8a33b2957e31727f87b89 See: https://git.lix.systems/lix-project/lix/issues/527 This upstreams the fixes from https://gerrit.lix.systems/c/lix/+/2074 --- pkgs/by-name/ca/capnproto/package.nix | 46 +++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/pkgs/by-name/ca/capnproto/package.nix b/pkgs/by-name/ca/capnproto/package.nix index ee39c2207230..9334d336e364 100644 --- a/pkgs/by-name/ca/capnproto/package.nix +++ b/pkgs/by-name/ca/capnproto/package.nix @@ -1,13 +1,34 @@ { + binutils, lib, - stdenv, + clangStdenv, fetchFromGitHub, cmake, openssl, zlib, }: -stdenv.mkDerivation rec { +let + # HACK: work around https://github.com/NixOS/nixpkgs/issues/177129 + # Though this is an issue between Clang and GCC, + # so it may not get fixed anytime soon... + empty-libgcc_eh = clangStdenv.mkDerivation { + pname = "empty-libgcc_eh"; + version = "0"; + dontUnpack = true; + installPhase = '' + mkdir -p "$out"/lib + "${binutils}"/bin/ar r "$out"/lib/libgcc_eh.a + ''; + }; +in + +# NOTE: This must be `clang` because `gcc` is known to miscompile or ICE while +# compiling `capnproto` coroutines. +# +# See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102051 +# See: https://gerrit.lix.systems/c/lix/+/1874 +clangStdenv.mkDerivation rec { pname = "capnproto"; version = "1.1.0"; @@ -23,8 +44,27 @@ stdenv.mkDerivation rec { propagatedBuildInputs = [ openssl zlib + ] ++ lib.optional (clangStdenv.cc.isClang && clangStdenv.targetPlatform.isStatic) empty-libgcc_eh; + + # FIXME: separate the binaries from the stuff that user systems actually use + # This runs into a terrible UX issue in Lix and I just don't want to debug it + # right now for the couple MB of closure size: + # https://git.lix.systems/lix-project/lix/issues/551 + # outputs = [ "bin" "dev" "out" ]; + + cmakeFlags = [ + (lib.cmakeBool "BUILD_SHARED_LIBS" true) + # Take optimization flags from CXXFLAGS rather than cmake injecting them + (lib.cmakeFeature "CMAKE_BUILD_TYPE" "None") ]; + env = { + # Required to build the coroutine library + CXXFLAGS = "-std=c++20"; + }; + + separateDebugInfo = true; + meta = with lib; { homepage = "https://capnproto.org/"; description = "Cap'n Proto cerealization protocol"; @@ -35,6 +75,6 @@ stdenv.mkDerivation rec { ''; license = licenses.mit; platforms = platforms.all; - maintainers = [ ]; + maintainers = lib.teams.lix.members; }; }