From 7e74ec53da20c288f9a45047e67e8227d95b2a55 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Thu, 8 Dec 2022 13:07:14 +0100 Subject: [PATCH 1/2] libwebsockets: use multiple outputs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This considerably lowers the closure size of packages that just need the libraries at runtime. The difference is roughly 60–70MiB. --- pkgs/development/libraries/libwebsockets/default.nix | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/libwebsockets/default.nix b/pkgs/development/libraries/libwebsockets/default.nix index 0b8d8d8e5817..b2839de387a2 100644 --- a/pkgs/development/libraries/libwebsockets/default.nix +++ b/pkgs/development/libraries/libwebsockets/default.nix @@ -20,6 +20,8 @@ stdenv.mkDerivation rec { hash = "sha256-why8LAcc4XN0JdTJ1JoNWijKENL5mOHBsi9K4wpYr2c="; }; + outputs = [ "out" "dev" ]; + buildInputs = [ openssl zlib libuv ]; nativeBuildInputs = [ cmake ]; @@ -34,7 +36,14 @@ stdenv.mkDerivation rec { ++ lib.optional withExternalPoll "-DLWS_WITH_EXTERNAL_POLL=ON"; postInstall = '' - rm -r ${placeholder "out"}/share/libwebsockets-test-server + # Fix path that will be incorrect on move to "dev" output. + substituteInPlace "$out/lib/cmake/libwebsockets/LibwebsocketsTargets-release.cmake" \ + --replace "\''${_IMPORT_PREFIX}" "$out" + + # The package builds a few test programs that are not usually necessary. + # Move those to the dev output. + moveToOutput "bin/libwebsockets-test-*" "$dev" + moveToOutput "share/libwebsockets-test-*" "$dev" ''; # $out/share/libwebsockets-test-server/plugins/libprotocol_*.so refers to crtbeginS.o From 7fb1be82f4e180da9b53fb06de4d91c43b605b0f Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Wed, 28 Dec 2022 16:34:01 +0100 Subject: [PATCH 2/2] libwebsockets: build static library only when necessary --- pkgs/development/libraries/libwebsockets/default.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/libwebsockets/default.nix b/pkgs/development/libraries/libwebsockets/default.nix index b2839de387a2..a535763b8c19 100644 --- a/pkgs/development/libraries/libwebsockets/default.nix +++ b/pkgs/development/libraries/libwebsockets/default.nix @@ -33,7 +33,13 @@ stdenv.mkDerivation rec { "-DDISABLE_WERROR=ON" "-DLWS_BUILD_HASH=no_hash" ] ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) "-DLWS_WITHOUT_TESTAPPS=ON" - ++ lib.optional withExternalPoll "-DLWS_WITH_EXTERNAL_POLL=ON"; + ++ lib.optional withExternalPoll "-DLWS_WITH_EXTERNAL_POLL=ON" + ++ ( + if stdenv.hostPlatform.isStatic then + [ "-DLWS_WITH_SHARED=OFF" ] + else + [ "-DLWS_WITH_STATIC=OFF" "-DLWS_LINK_TESTAPPS_DYNAMIC=ON" ] + ); postInstall = '' # Fix path that will be incorrect on move to "dev" output.