From 0b539dea4a380235696db6265215a8cca0f33821 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 27 Jun 2024 17:28:31 -0400 Subject: [PATCH] Improve boost hacks --- flake.nix | 6 +++--- package.nix | 29 +-------------------------- packaging/components.nix | 17 ---------------- packaging/dependencies.nix | 13 +++++++++++++ src/libcmd/network-proxy.cc | 5 +++-- src/libexpr/package.nix | 15 +------------- src/libstore/meson.build | 2 +- src/libstore/package.nix | 10 ---------- src/libutil/meson.build | 7 +------ src/libutil/package.nix | 39 ++----------------------------------- src/perl/package.nix | 14 +------------ 11 files changed, 26 insertions(+), 131 deletions(-) diff --git a/flake.nix b/flake.nix index 582a946c4..04fc94a55 100644 --- a/flake.nix +++ b/flake.nix @@ -207,7 +207,7 @@ # https://github.com/NixOS/nixpkgs/issues/320448 "static-" = nixpkgsFor.${system}.static; }) - (nixpkgsPrefix: nixpkgs: + (nixpkgsPrefix: nixpkgs: flatMapAttrs nixpkgs.nixComponents (pkgName: pkg: flatMapAttrs pkg.tests or {} @@ -304,8 +304,8 @@ env = { # Needed for Meson to find Boost. # https://github.com/NixOS/nixpkgs/issues/86131. - BOOST_INCLUDEDIR = "${lib.getDev pkgs.boost}/include"; - BOOST_LIBRARYDIR = "${lib.getLib pkgs.boost}/lib"; + BOOST_INCLUDEDIR = "${lib.getDev pkgs.nixDependencies.boost}/include"; + BOOST_LIBRARYDIR = "${lib.getLib pkgs.nixDependencies.boost}/lib"; # For `make format`, to work without installing pre-commit _NIX_PRE_COMMIT_HOOKS_CONFIG = "${(pkgs.formats.yaml { }).generate "pre-commit-config.yaml" modular.pre-commit.settings.rawConfig}"; diff --git a/package.nix b/package.nix index 0661dc080..28d7e788f 100644 --- a/package.nix +++ b/package.nix @@ -199,7 +199,6 @@ in { ; buildInputs = lib.optionals doBuild [ - boost brotli bzip2 curl @@ -227,33 +226,12 @@ in { ; propagatedBuildInputs = [ + boost nlohmann_json ] ++ lib.optional enableGC boehmgc; dontBuild = !attrs.doBuild; - disallowedReferences = [ boost ]; - - preConfigure = lib.optionalString (doBuild && ! stdenv.hostPlatform.isStatic) ( - '' - # Copy libboost_context so we don't get all of Boost in our closure. - # https://github.com/NixOS/nixpkgs/issues/45462 - mkdir -p $out/lib - cp -pd ${boost}/lib/{libboost_context*,libboost_thread*,libboost_system*} $out/lib - rm -f $out/lib/*.a - '' + lib.optionalString stdenv.hostPlatform.isLinux '' - chmod u+w $out/lib/*.so.* - patchelf --set-rpath $out/lib:${stdenv.cc.cc.lib}/lib $out/lib/libboost_thread.so.* - '' + lib.optionalString stdenv.hostPlatform.isDarwin '' - for LIB in $out/lib/*.dylib; do - chmod u+w $LIB - install_name_tool -id $LIB $LIB - install_name_tool -delete_rpath ${boost}/lib/ $LIB || true - done - install_name_tool -change ${boost}/lib/libboost_system.dylib $out/lib/libboost_system.dylib $out/lib/libboost_thread.dylib - '' - ); - configureFlags = [ (lib.enableFeature doBuild "build") (lib.enableFeature doInstallCheck "functional-tests") @@ -295,11 +273,6 @@ in { lib.optionalString stdenv.hostPlatform.isStatic '' mkdir -p $out/nix-support echo "file binary-dist $out/bin/nix" >> $out/nix-support/hydra-build-products - '' + lib.optionalString stdenv.isDarwin '' - install_name_tool \ - -change ${boost}/lib/libboost_context.dylib \ - $out/lib/libboost_context.dylib \ - $out/lib/libnixutil.dylib '' ) + lib.optionalString enableManual '' mkdir -p ''${!outputDoc}/nix-support diff --git a/packaging/components.nix b/packaging/components.nix index 0189f4ca3..97b989f1f 100644 --- a/packaging/components.nix +++ b/packaging/components.nix @@ -26,23 +26,6 @@ in nix-expr-test = callPackage ../src/libexpr-test/package.nix { }; nix-expr-c = callPackage ../src/libexpr-c/package.nix { }; - nix-flake = callPackage ../src/libflake/package.nix { }; - nix-flake-c = callPackage ../src/libflake-c/package.nix { }; - - nix-store = callPackage ../src/libstore/package.nix { }; - nix-store-test-support = callPackage ../src/libstore-test-support/package.nix { }; - nix-store-test = callPackage ../src/libstore-test/package.nix { }; - nix-store-c = callPackage ../src/libstore-c/package.nix { }; - - nix-fetchers = callPackage ../src/libfetchers/package.nix { }; - nix-fetchers-test = callPackage ../src/libfetchers-test/package.nix { }; - nix-fetchers-c = callPackage ../src/libfetchers-c/package.nix { }; - - nix-expr = callPackage ../src/libexpr/package.nix { }; - nix-expr-test-support = callPackage ../src/libexpr-test-support/package.nix { }; - nix-expr-test = callPackage ../src/libexpr-test/package.nix { }; - nix-expr-c = callPackage ../src/libexpr-c/package.nix { }; - nix-flake = callPackage ../src/libflake/package.nix { }; nix-internal-api-docs = callPackage ../src/internal-api-docs/package.nix { }; diff --git a/packaging/dependencies.nix b/packaging/dependencies.nix index 484385128..b2349f02c 100644 --- a/packaging/dependencies.nix +++ b/packaging/dependencies.nix @@ -52,6 +52,19 @@ scope: { enableLargeConfig = true; }; + # Hack until https://github.com/NixOS/nixpkgs/issues/45462 is fixed. + boost = (pkgs.boost.override { + extraB2Args = [ + "--with-container" + "--with-context" + "--with-coroutine" + ]; + }).overrideAttrs (old: { + # Need to remove `--with-*` to use `--with-libraries=...` + buildPhase = pkgs.lib.replaceStrings [ "--without-python" ] [ "" ] old.buildPhase; + installPhase = pkgs.lib.replaceStrings [ "--without-python" ] [ "" ] old.installPhase; + }); + libgit2 = pkgs.libgit2.overrideAttrs (attrs: { src = inputs.libgit2; version = inputs.libgit2.lastModifiedDate; diff --git a/src/libcmd/network-proxy.cc b/src/libcmd/network-proxy.cc index 4b7d2441f..47be311cd 100644 --- a/src/libcmd/network-proxy.cc +++ b/src/libcmd/network-proxy.cc @@ -1,7 +1,6 @@ #include "network-proxy.hh" #include -#include #include "environment-variables.hh" @@ -13,7 +12,9 @@ static StringSet getAllVariables() { StringSet variables = lowercaseVariables; for (const auto & variable : lowercaseVariables) { - variables.insert(boost::to_upper_copy(variable)); + std::string upperVariable; + std::transform(variable.begin(), variable.end(), upperVariable.begin(), [](unsigned char c) { return std::toupper(c); }); + variables.insert(std::move(upperVariable)); } return variables; } diff --git a/src/libexpr/package.nix b/src/libexpr/package.nix index 223b04042..799368ee9 100644 --- a/src/libexpr/package.nix +++ b/src/libexpr/package.nix @@ -70,19 +70,14 @@ mkDerivation (finalAttrs: { pkg-config ]; - buildInputs = [ - boost - ]; - propagatedBuildInputs = [ nix-util nix-store nix-fetchers + boost nlohmann_json ] ++ lib.optional enableGC boehmgc; - disallowedReferences = [ boost ]; - preConfigure = # "Inline" .version so it's not a symlink, and includes the suffix '' @@ -104,14 +99,6 @@ mkDerivation (finalAttrs: { enableParallelBuilding = true; - postInstall = - # Remove absolute path to boost libs that ends up in `Libs.private` - # by default, and would clash with out `disallowedReferences`. Part - # of the https://github.com/NixOS/nixpkgs/issues/45462 workaround. - '' - sed -i "$out/lib/pkgconfig/nix-expr.pc" -e 's, ${lib.getLib boost}[^ ]*,,g' - ''; - separateDebugInfo = !stdenv.hostPlatform.isStatic; # TODO Always true after https://github.com/NixOS/nixpkgs/issues/318564 diff --git a/src/libstore/meson.build b/src/libstore/meson.build index d2a5acb18..2bc3f27e4 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -400,6 +400,6 @@ this_library = library( install_headers(headers, subdir : 'nix', preserve_path : true) -libraries_private = ['-lboost_container'] +libraries_private = [] subdir('meson-utils/export') diff --git a/src/libstore/package.nix b/src/libstore/package.nix index f27dac2f6..5af1a7815 100644 --- a/src/libstore/package.nix +++ b/src/libstore/package.nix @@ -86,8 +86,6 @@ mkDerivation (finalAttrs: { nlohmann_json ]; - disallowedReferences = [ boost ]; - preConfigure = # "Inline" .version so it's not a symlink, and includes the suffix '' @@ -112,14 +110,6 @@ mkDerivation (finalAttrs: { enableParallelBuilding = true; - postInstall = - # Remove absolute path to boost libs that ends up in `Libs.private` - # by default, and would clash with out `disallowedReferences`. Part - # of the https://github.com/NixOS/nixpkgs/issues/45462 workaround. - '' - sed -i "$out/lib/pkgconfig/nix-store.pc" -e 's, ${lib.getLib boost}[^ ]*,,g' - ''; - separateDebugInfo = !stdenv.hostPlatform.isStatic; # TODO Always true after https://github.com/NixOS/nixpkgs/issues/318564 diff --git a/src/libutil/meson.build b/src/libutil/meson.build index 7a4dfaf50..5eee8b3b2 100644 --- a/src/libutil/meson.build +++ b/src/libutil/meson.build @@ -254,12 +254,7 @@ this_library = library( install_headers(headers, subdir : 'nix', preserve_path : true) -# Part of how we copy boost libraries to a separate installation to -# reduce closure size. These libraries will be copied to our `$out/bin`, -# and these `-l` flags will pick them up there. -# -# https://github.com/NixOS/nixpkgs/issues/45462 -libraries_private = ['-lboost_context', '-lboost_coroutine'] +libraries_private = [] if host_machine.system() == 'windows' # `libraries_private` cannot contain ad-hoc dependencies (from # `find_library), so we need to do this manually diff --git a/src/libutil/package.nix b/src/libutil/package.nix index 8ba6daa2a..ef5e251fb 100644 --- a/src/libutil/package.nix +++ b/src/libutil/package.nix @@ -65,7 +65,6 @@ mkMesonDerivation (finalAttrs: { ]; buildInputs = [ - boost brotli libsodium openssl @@ -73,37 +72,17 @@ mkMesonDerivation (finalAttrs: { ; propagatedBuildInputs = [ - boost.dev + boost libarchive nlohmann_json ]; - disallowedReferences = [ boost ]; - preConfigure = # TODO: change release process to add `pre` in `.version`, remove it before tagging, and restore after. '' chmod u+w ./.version echo ${version} > ../../.version - '' - # Copy some boost libraries so we don't get all of Boost in our - # closure. https://github.com/NixOS/nixpkgs/issues/45462 - + lib.optionalString (!stdenv.hostPlatform.isStatic) ('' - mkdir -p $out/lib - cp -pd ${boost}/lib/{libboost_context*,libboost_thread*,libboost_system*} $out/lib - rm -f $out/lib/*.a - '' + lib.optionalString stdenv.hostPlatform.isLinux '' - chmod u+w $out/lib/*.so.* - patchelf --set-rpath $out/lib:${stdenv.cc.cc.lib}/lib $out/lib/libboost_thread.so.* - '' + lib.optionalString stdenv.hostPlatform.isDarwin '' - for LIB in $out/lib/*.dylib; do - chmod u+w $LIB - install_name_tool -id $LIB $LIB - install_name_tool -delete_rpath ${boost}/lib/ $LIB || true - done - install_name_tool -change ${boost}/lib/libboost_system.dylib $out/lib/libboost_system.dylib $out/lib/libboost_thread.dylib - '' - ); + ''; mesonFlags = [ (lib.mesonEnable "cpuid" stdenv.hostPlatform.isx86_64) @@ -120,20 +99,6 @@ mkMesonDerivation (finalAttrs: { enableParallelBuilding = true; - postInstall = - # Remove absolute path to boost libs that ends up in `Libs.private` - # by default, and would clash with out `disallowedReferences`. Part - # of the https://github.com/NixOS/nixpkgs/issues/45462 workaround. - '' - sed -i "$out/lib/pkgconfig/nix-util.pc" -e 's, ${lib.getLib boost}[^ ]*,,g' - '' - + lib.optionalString stdenv.isDarwin '' - install_name_tool \ - -change ${boost}/lib/libboost_context.dylib \ - $out/lib/libboost_context.dylib \ - $out/lib/libnixutil.dylib - ''; - separateDebugInfo = !stdenv.hostPlatform.isStatic; # TODO Always true after https://github.com/NixOS/nixpkgs/issues/318564 diff --git a/src/perl/package.nix b/src/perl/package.nix index e1a84924c..6b8487148 100644 --- a/src/perl/package.nix +++ b/src/perl/package.nix @@ -6,11 +6,6 @@ , ninja , pkg-config , nix-store -, curl -, bzip2 -, xz -, boost -, libsodium , darwin , versionSuffix ? "" }: @@ -45,14 +40,7 @@ perl.pkgs.toPerlModule (stdenv.mkDerivation (finalAttrs: { buildInputs = [ nix-store - curl - bzip2 - xz - perl - boost - ] - ++ lib.optional (stdenv.isLinux || stdenv.isDarwin) libsodium - ++ lib.optional stdenv.isDarwin darwin.apple_sdk.frameworks.Security; + ]; # `perlPackages.Test2Harness` is marked broken for Darwin doCheck = !stdenv.isDarwin;