aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-03-08 12:53:25 +0100
committerdec05eba <dec05eba@protonmail.com>2023-03-08 12:53:25 +0100
commit0697f410b05085cdaf767d5b6fd3fea056ec5bd3 (patch)
tree09c5a5c920b191edb0ceffe30ae0cc99de91b11d /src/main.cpp
parentcc0eb4651e4b204fb7926ddd84bb830f432aabd3 (diff)
Add support for mold, add optimization flags for linking step
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp22
1 files changed, 14 insertions, 8 deletions
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 <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 <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 <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 <filepath>...|--all-files]\n\n");
+ printf("Usage: sibs test [project_path] [--debug|--release] [--sanitize=(address|undefined|leak|thread|none)] [--linker=lld|gold|mold] [--file <filepath>...|--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 <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);