diff --git a/Makefile b/Makefile index 9ac82fda6..fe397e018 100644 --- a/Makefile +++ b/Makefile @@ -15,8 +15,16 @@ makefiles = \ tests/local.mk \ tests/plugins/local.mk -GLOBAL_CXXFLAGS += -g -Wall -include config.h - -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 8c0f0f26d..9f29a7734 100644 --- a/configure.ac +++ b/configure.ac @@ -50,14 +50,11 @@ 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 -AX_CXX_COMPILE_STDCXX_17([noext], [mandatory]) AC_CHECK_TOOL([AR], [ar]) diff --git a/flake.nix b/flake.nix index b3a7ea535..b3a06bdd0 100644 --- a/flake.nix +++ b/flake.nix @@ -386,7 +386,6 @@ pkgs = nixpkgsFor.x86_64-linux; officialRelease = false; }; - */ # Check whether we can still evaluate NixOS. tests.evalNixOS = @@ -400,6 +399,7 @@ touch $out ''; + */ # Aggregate job containing the release-critical jobs. release = @@ -421,7 +421,7 @@ tests.nix-copy-closure tests.binaryTarball #tests.evalNixpkgs - tests.evalNixOS + #tests.evalNixOS installerScript ]; }; 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/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 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" diff --git a/src/libstore/build.cc b/src/libstore/build.cc index fe861e629..bf259e0b6 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -24,8 +24,8 @@ #include #include #include +#include -#include #include #include #include diff --git a/src/libstore/download.cc b/src/libstore/download.cc index a5165773a..d49d63912 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 c5dd893b5..487036833 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,12 +71,12 @@ struct CachedDownloadRequest bool unpack = false; std::string name; Hash expectedHash; - unsigned int ttl = settings.tarballTtl; + unsigned int ttl; bool gcRoot = false; bool getLastModified = false; - CachedDownloadRequest(const std::string & uri) - : uri(uri) { } + CachedDownloadRequest(const std::string & uri); + CachedDownloadRequest() = delete; }; struct CachedDownloadResult diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 0902c3783..998037337 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