From 39a2e166dd316cf3bf248cb109dde3a95d753541 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 6 Nov 2019 16:53:02 +0100 Subject: [PATCH 1/5] Cleanup --- src/libstore/build.cc | 2 +- src/libutil/util.cc | 2 +- src/libutil/xml-writer.cc | 4 ++-- src/nix-daemon/nix-daemon.cc | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libstore/build.cc b/src/libstore/build.cc index ada1cf8ec..c82f60748 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -23,8 +23,8 @@ #include #include #include +#include -#include #include #include #include diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 34c1d96dc..79716c5a7 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -17,7 +18,6 @@ #include #include -#include #include #include #include diff --git a/src/libutil/xml-writer.cc b/src/libutil/xml-writer.cc index e5cc2e9fc..68857e34d 100644 --- a/src/libutil/xml-writer.cc +++ b/src/libutil/xml-writer.cc @@ -1,10 +1,10 @@ -#include +#include #include "xml-writer.hh" namespace nix { - + XMLWriter::XMLWriter(bool indent, std::ostream & output) : output(output), indent(indent) diff --git a/src/nix-daemon/nix-daemon.cc b/src/nix-daemon/nix-daemon.cc index da17ddcba..65ae88faf 100644 --- a/src/nix-daemon/nix-daemon.cc +++ b/src/nix-daemon/nix-daemon.cc @@ -10,8 +10,9 @@ #include "daemon.hh" #include - +#include #include + #include #include #include @@ -23,7 +24,6 @@ #include #include #include -#include #if __APPLE__ || __FreeBSD__ #include From 5ff4d77f5585f9aad068fcc473393095e0640ae4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 6 Nov 2019 16:54:18 +0100 Subject: [PATCH 2/5] Precompile headers This cuts 'make install -j6' on my laptop from 170s to 134s. --- Makefile | 4 +-- configure.ac | 1 - mk/lib.mk | 1 + mk/patterns.mk | 4 +-- mk/precompiled-headers.mk | 42 +++++++++++++++++++++++ precompiled-headers.h | 71 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 118 insertions(+), 5 deletions(-) create mode 100644 mk/precompiled-headers.mk create mode 100644 precompiled-headers.h diff --git a/Makefile b/Makefile index 9ac82fda6..c441a933e 100644 --- a/Makefile +++ b/Makefile @@ -15,8 +15,8 @@ makefiles = \ tests/local.mk \ tests/plugins/local.mk -GLOBAL_CXXFLAGS += -g -Wall -include config.h - -include Makefile.config include mk/lib.mk + +GLOBAL_CXXFLAGS += -g -Wall -include config.h -std=c++17 diff --git a/configure.ac b/configure.ac index 4a6eaac8a..c67f1e739 100644 --- a/configure.ac +++ b/configure.ac @@ -57,7 +57,6 @@ test "$localstatedir" = '${prefix}/var' && localstatedir=/nix/var AC_PROG_CC AC_PROG_CXX AC_PROG_CPP -AX_CXX_COMPILE_STDCXX_17([noext], [mandatory]) AC_CHECK_TOOL([AR], [ar]) diff --git a/mk/lib.mk b/mk/lib.mk index 1da51d879..b0a36cf8d 100644 --- a/mk/lib.mk +++ b/mk/lib.mk @@ -89,6 +89,7 @@ include mk/jars.mk include mk/patterns.mk include mk/templates.mk include mk/tests.mk +include mk/precompiled-headers.mk # Include all sub-Makefiles. diff --git a/mk/patterns.mk b/mk/patterns.mk index 3219d9629..7319f4cdd 100644 --- a/mk/patterns.mk +++ b/mk/patterns.mk @@ -1,10 +1,10 @@ $(buildprefix)%.o: %.cc @mkdir -p "$(dir $@)" - $(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(GLOBAL_CXXFLAGS_PCH) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(call filename-to-dep, $@) -MP + $(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS_PCH) $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(call filename-to-dep, $@) -MP $(buildprefix)%.o: %.cpp @mkdir -p "$(dir $@)" - $(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(GLOBAL_CXXFLAGS_PCH) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(call filename-to-dep, $@) -MP + $(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS_PCH) $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(call filename-to-dep, $@) -MP $(buildprefix)%.o: %.c @mkdir -p "$(dir $@)" diff --git a/mk/precompiled-headers.mk b/mk/precompiled-headers.mk new file mode 100644 index 000000000..779389b26 --- /dev/null +++ b/mk/precompiled-headers.mk @@ -0,0 +1,42 @@ +PRECOMPILE_HEADERS ?= 1 + +print-var-help += \ + echo " PRECOMPILE_HEADERS ($(PRECOMPILE_HEADERS)): Whether to use precompiled headers to speed up the build"; + +GCH = $(buildprefix)precompiled-headers.h.gch + +$(GCH): precompiled-headers.h + @rm -f $@ + @mkdir -p "$(dir $@)" + $(trace-gen) $(CXX) -x c++-header -o $@ $^ $(GLOBAL_CXXFLAGS) + +PCH = $(buildprefix)precompiled-headers.h.pch + +$(PCH): precompiled-headers.h + @rm -f $@ + @mkdir -p "$(dir $@)" + $(trace-gen) $(CXX) -x c++-header -o $@ $^ $(GLOBAL_CXXFLAGS) + +clean-files += $(GCH) $(PCH) + +ifeq ($(PRECOMPILE_HEADERS), 1) + + ifeq ($(CXX), g++) + + GLOBAL_CXXFLAGS_PCH += -include $(buildprefix)precompiled-headers.h -Winvalid-pch + + GLOBAL_ORDER_AFTER += $(GCH) + + else ifeq ($(CXX), clang++) + + GLOBAL_CXXFLAGS_PCH += -include-pch $(PCH) -Winvalid-pch + + GLOBAL_ORDER_AFTER += $(PCH) + + else + + $(error Don't know how to precompile headers on $(CXX)) + + endif + +endif diff --git a/precompiled-headers.h b/precompiled-headers.h new file mode 100644 index 000000000..c5790bec4 --- /dev/null +++ b/precompiled-headers.h @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "util.hh" +#include "args.hh" From f5b7991e59d8c9ae38fb4c9074a5847942caab73 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 6 Nov 2019 16:55:37 +0100 Subject: [PATCH 3/5] Revert "autoconf: Allow overriding CFLAGS/CXXFLAGS from outside." This reverts commit 717e821b99797845e1bef47d862f8cb0fb69cfc9. It's much more convenient to do 'make OPTIMIZE=0'. --- Makefile | 8 ++++++++ configure.ac | 6 ++---- perl/Makefile | 7 +++++++ perl/configure.ac | 6 ++---- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index c441a933e..fe397e018 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,14 @@ makefiles = \ -include Makefile.config +OPTIMIZE = 1 + +ifeq ($(OPTIMIZE), 1) + GLOBAL_CXXFLAGS += -O3 +else + GLOBAL_CXXFLAGS += -O0 +endif + include mk/lib.mk GLOBAL_CXXFLAGS += -g -Wall -include config.h -std=c++17 diff --git a/configure.ac b/configure.ac index c67f1e739..26f16b846 100644 --- a/configure.ac +++ b/configure.ac @@ -50,10 +50,8 @@ AC_DEFINE_UNQUOTED(SYSTEM, ["$system"], [platform identifier ('cpu-os')]) test "$localstatedir" = '${prefix}/var' && localstatedir=/nix/var -# Set default flags for nix (as per AC_PROG_CC/CXX docs), -# while still allowing the user to override them from the command line. -: ${CFLAGS="-O3"} -: ${CXXFLAGS="-O3"} +CFLAGS= +CXXFLAGS= AC_PROG_CC AC_PROG_CXX AC_PROG_CPP diff --git a/perl/Makefile b/perl/Makefile index f36f5d0e9..284c75022 100644 --- a/perl/Makefile +++ b/perl/Makefile @@ -4,4 +4,11 @@ GLOBAL_CXXFLAGS += -g -Wall -include Makefile.config +OPTIMIZE = 1 + +ifeq ($(OPTIMIZE), 1) + GLOBAL_CFLAGS += -O3 + GLOBAL_CXXFLAGS += -O3 +endif + include mk/lib.mk diff --git a/perl/configure.ac b/perl/configure.ac index e8e3610a8..966700695 100644 --- a/perl/configure.ac +++ b/perl/configure.ac @@ -2,10 +2,8 @@ AC_INIT(nix-perl, m4_esyscmd([bash -c "echo -n $(cat ../.version)$VERSION_SUFFIX AC_CONFIG_SRCDIR(MANIFEST) AC_CONFIG_AUX_DIR(../config) -# Set default flags for nix (as per AC_PROG_CC/CXX docs), -# while still allowing the user to override them from the command line. -: ${CFLAGS="-O3"} -: ${CXXFLAGS="-O3"} +CFLAGS= +CXXFLAGS= AC_PROG_CC AC_PROG_CXX AX_CXX_COMPILE_STDCXX_11 From 04bf9acd22c5e3f399f66d7edb0863e8394e542e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 6 Nov 2019 17:30:48 +0100 Subject: [PATCH 4/5] Remove #include --- src/libstore/download.cc | 4 ++++ src/libstore/download.hh | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libstore/download.cc b/src/libstore/download.cc index cdf56e09d..8fe278d02 100644 --- a/src/libstore/download.cc +++ b/src/libstore/download.cc @@ -34,6 +34,10 @@ DownloadSettings downloadSettings; static GlobalConfig::Register r1(&downloadSettings); +CachedDownloadRequest::CachedDownloadRequest(const std::string & uri) + : uri(uri), ttl(settings.tarballTtl) +{ } + std::string resolveUri(const std::string & uri) { if (uri.compare(0, 8, "channel:") == 0) diff --git a/src/libstore/download.hh b/src/libstore/download.hh index 68565bf46..5a131c704 100644 --- a/src/libstore/download.hh +++ b/src/libstore/download.hh @@ -2,7 +2,7 @@ #include "types.hh" #include "hash.hh" -#include "globals.hh" +#include "config.hh" #include #include @@ -71,10 +71,10 @@ struct CachedDownloadRequest bool unpack = false; std::string name; Hash expectedHash; - unsigned int ttl = settings.tarballTtl; + unsigned int ttl; - CachedDownloadRequest(const std::string & uri) - : uri(uri) { } + CachedDownloadRequest(const std::string & uri); + CachedDownloadRequest() = delete; }; struct CachedDownloadResult From 99af822004418b25b6d04eca67949c62e770c16b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 7 Nov 2019 10:14:00 +0100 Subject: [PATCH 5/5] Disable the evalNixOS test It also OOMs. https://hydra.nixos.org/build/105942679 --- release.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/release.nix b/release.nix index b137f1d2d..61ca4323c 100644 --- a/release.nix +++ b/release.nix @@ -277,7 +277,6 @@ let nix = build.x86_64-linux; officialRelease = false; }; - */ tests.evalNixOS = pkgs.runCommand "eval-nixos" { buildInputs = [ build.x86_64-linux ]; } @@ -289,6 +288,7 @@ let touch $out ''; + */ installerScript = @@ -327,7 +327,7 @@ let tests.nix-copy-closure tests.binaryTarball #tests.evalNixpkgs - tests.evalNixOS + #tests.evalNixOS installerScript ]; };