Improve boost hacks

This commit is contained in:
John Ericson 2024-06-27 17:28:31 -04:00
parent 8399bd6b8f
commit 0b539dea4a
11 changed files with 26 additions and 131 deletions

View file

@ -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}";

View file

@ -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

View file

@ -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 { };

View file

@ -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;

View file

@ -1,7 +1,6 @@
#include "network-proxy.hh"
#include <algorithm>
#include <boost/algorithm/string.hpp>
#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;
}

View file

@ -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

View file

@ -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')

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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;