From 0697f410b05085cdaf767d5b6fd3fea056ec5bd3 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 8 Mar 2023 12:53:25 +0100 Subject: Add support for mold, add optimization flags for linking step --- src/main.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index c67ac68..aa06549 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -129,7 +129,7 @@ static void usage() static void usageBuild(bool run) { - printf("Usage: sibs %s [project_path] [--debug|--release] [--sanitize=(address|undefined|leak|thread|none)] [--linker=linker] [--platform ]\n\n", run ? "run" : "build"); + printf("Usage: sibs %s [project_path] [--debug|--release] [--sanitize=(address|undefined|leak|thread|none)] [--linker=lld|gold|mold] [--platform ]\n\n", run ? "run" : "build"); printf("%s a sibs project\n\n", run ? "Build and run" : "Build"); printf("Options:\n"); printf(" project_path The directory containing a project.conf file - Optional (default: current directory)\n"); @@ -138,7 +138,7 @@ static void usageBuild(bool run) printf(" --platform The platform to build for - Optional (default: the running platform)\n"); printf(" --lto Use link-time optimization. May increase compile times - Optional (default: not used)\n"); printf(" --debug-symbols Include debug symbols in release mode - Optional (default: not used)\n"); - printf(" --linker=linker The linker to use. \"lld\" or \"gold\" is the default linker when using gcc\n"); + printf(" --linker=linker The linker to use. \"lld\", \"gold\" or \"mold\". \"gold\" - Optional (the compile automatically chooses best option)\n"); if(run) { printf(" --args A list of arguments to run the program with\n"); } else { @@ -173,7 +173,7 @@ static void usageNew() static void usageTest() { - printf("Usage: sibs test [project_path] [--debug|--release] [--sanitize=(address|undefined|leak|thread|none)] [--linker=linker] [--file ...|--all-files]\n\n"); + printf("Usage: sibs test [project_path] [--debug|--release] [--sanitize=(address|undefined|leak|thread|none)] [--linker=lld|gold|mold] [--file ...|--all-files]\n\n"); printf("Build and run tests for a sibs project\n\n"); printf("Options:\n"); printf(" project_path The directory containing a project.conf file - Optional (default: current directory)\n"); @@ -182,7 +182,7 @@ static void usageTest() printf(" --sanitize=option 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(" --file Specify file to test, path to test file should be defined after this. Can be defined multiple times to test multiple files - Optional (default: not used), Only applicable for Zig\n"); printf(" --all-files Test all files - Optional (default: not used), Only applicable for Zig\n"); - printf(" --linker=linker The linker to use. \"lld\" or \"gold\" is the default linker when using gcc\n"); + printf(" --linker=linker The linker to use. \"lld\", \"gold\" or \"mold\". \"gold\" - Optional (the compile automatically chooses best option)\n"); printf(" --skip-compile Skip compilation. This can be used to generate a compile_commands.json file without compiling. Note that the compile_commands.json can miss files that are generated when this option is used. This option also skips running the tests\n"); printf(" --args A list of arguments to run the program with\n"); printf("Examples:\n"); @@ -664,16 +664,22 @@ static int buildProject(int argc, const _tinydir_char_t **argv, bool run) Compiler compiler = Compiler::MSVC; #endif - // TODO: Make mold the default linker if it's installed and the installed gcc version supports it with -fuse-ld= option if(linker.empty()) { // Static object files compiled with gcc are not compatible with lld (llvm linker) // and we dont know which compiler was used to compile to code so we disable automatic // use of lld by default. The user can still force lld with --linker=lld, if they are // sure that they used clang to compile the code. - if(!use_lto && optimizationLevel != OPT_LEV_DEBUG && !include_debug_symbols_in_release && is_lld_linker_installed()) - linker = "lld"; - else if(is_gold_linker_installed()) + // TODO: Detect if linker has change and recompile everything (that was compiled with a different linker). + if(!use_lto && optimizationLevel != OPT_LEV_DEBUG && !include_debug_symbols_in_release) { + if(is_mold_linker_installed()) + linker = "mold"; + else if(is_lld_linker_installed()) + linker = "lld"; + else if(is_gold_linker_installed()) + linker = "gold"; + } else if(is_gold_linker_installed()) { linker = "gold"; + } } SibsConfig sibsConfig(compiler, projectPath, optimizationLevel, false); -- cgit v1.2.3