From e59d08b33daca53a53e44e0705db3e5d2fcc2817 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 10 Feb 2021 14:17:09 +0100 Subject: Disable flto by default and add --flto to enable it --- README.md | 2 +- backend/ninja/Ninja.cpp | 11 ++++++----- include/Conf.hpp | 4 +++- project.conf | 1 - src/main.cpp | 8 ++++++++ 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 785540e..4b16ecc 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ and run the binary under `sibs-build//debug/`. Linux is the primary platform, the platform which master branch is guaranteed to compile on. # Dependencies -`libcurl, libarchive, libgit2, ninja, cmake, pkg-config, ccache` +`libcurl, libarchive, ninja, cmake, pkg-config, ccache` # Installation ## Posix (Linux, MacOS, OpenBSD, Haiku) diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index fad1d35..34fe6e7 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -458,9 +458,10 @@ namespace backend } case OPT_LEV_RELEASE: { - return { - ninja::NinjaArg::createRaw("-O3 -g0 -DNDEBUG -flto") - }; + if(config.use_flto) + return { ninja::NinjaArg::createRaw("-O3 -g0 -DNDEBUG -flto") }; + else + return {}; } } break; @@ -1410,7 +1411,7 @@ namespace backend buildExeArgs.push_back(ninja::NinjaArg::createRaw("-s")); } - if(config.getOptimizationLevel() == OPT_LEV_RELEASE) + if(config.getOptimizationLevel() == OPT_LEV_RELEASE && config.use_flto) { buildExeArgs.push_back(ninja::NinjaArg::createRaw("-flto")); } @@ -1638,7 +1639,7 @@ namespace backend if(sanitizeFlag.type != ninja::NinjaArg::Type::NONE) buildDynamicArgs.push_back(std::move(sanitizeFlag)); - if(config.getOptimizationLevel() == OPT_LEV_RELEASE) + if(config.getOptimizationLevel() == OPT_LEV_RELEASE && config.use_flto) { buildDynamicArgs.push_back(ninja::NinjaArg::createRaw("-flto")); } diff --git a/include/Conf.hpp b/include/Conf.hpp index 12164ea..eb922bc 100644 --- a/include/Conf.hpp +++ b/include/Conf.hpp @@ -230,7 +230,8 @@ namespace sibs zigTestAllFiles(false), packaging(false), bundling(false), - platform(SYSTEM_PLATFORM) + platform(SYSTEM_PLATFORM), + use_flto(false) { cmakeDirGlobal = projectPath; switch(optimizationLevel) @@ -430,6 +431,7 @@ namespace sibs std::string versionStr; PackageVersion version; Platform platform; + bool use_flto; std::vector includeDirs; std::vector exposeIncludeDirs; std::vector ignoreDirs; diff --git a/project.conf b/project.conf index ecf6f54..7257a62 100644 --- a/project.conf +++ b/project.conf @@ -11,4 +11,3 @@ ignore_dirs = ["cmake", "cmake-build-debug", "build", "distribute", "examples", [dependencies] libcurl = ">=7" libarchive = ">=3" -libgit2 = ">=0.24.0" diff --git a/src/main.cpp b/src/main.cpp index 8282889..a812b8a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -137,6 +137,7 @@ static void usageBuild(bool run) printf(" --debug|--release Optimization level to build project and dependencies with (if not a system package) - Optional (default: --debug)\n"); printf(" --sanitize Add runtime address/undefined behavior sanitization. Program can be up to 3 times slower and use 10 times as much RAM. Ignored if compiler doesn't support sanitization - Optional (default: none)\n"); printf(" --platform The platform to build for - Optional (default: the running platform)\n"); + printf(" --flto Use link-time optimization. May increase compile times - Optional (default: false)\n"); printf("Examples:\n"); printf(" sibs %s\n", run ? "run" : "build"); if(run) @@ -515,6 +516,7 @@ static int buildProject(int argc, const _tinydir_char_t **argv, bool run) FileString projectPath; Sanitize sanitize = Sanitize::NONE; FileString platformName; + bool use_flto = false; std::vector run_args; for(int i = 0; i < argc; ++i) @@ -538,6 +540,10 @@ static int buildProject(int argc, const _tinydir_char_t **argv, bool run) } optimizationLevel = OPT_LEV_RELEASE; } + else if(_tinydir_strcmp(arg, TINYDIR_STRING("--flto")) == 0) + { + use_flto = true; + } else if(_tinydir_strncmp(arg, TINYDIR_STRING("--sanitize="), 11) == 0) { sanitize = sanitize_string_to_type(arg + 11); @@ -645,6 +651,7 @@ static int buildProject(int argc, const _tinydir_char_t **argv, bool run) sibsConfig.showWarnings = true; sibsConfig.platform = platform; sibsConfig.setSanitize(sanitize); + sibsConfig.use_flto = use_flto; return buildProject(projectPath, projectConfFilePath, sibsConfig, run, escape_args(run_args)); } @@ -1228,6 +1235,7 @@ static int packageProject(int argc, const _tinydir_char_t **argv) sibsConfig.showWarnings = true; sibsConfig.packaging = packagingType == PackagingType::STATIC; sibsConfig.bundling = (packagingType == PackagingType::BUNDLE) || (packagingType == PackagingType::BUNDLE_INSTALL); + sibsConfig.use_flto = true; int result = buildProject(projectPath, projectConfFilePath, sibsConfig, false, TINYDIR_STRING("")); if(result != 0) return result; -- cgit v1.2.3