diff options
author | dec05eba <dec05eba@protonmail.com> | 2023-06-27 02:27:44 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2023-06-27 02:28:47 +0200 |
commit | cf0c9479deedcbfc0592ac6d207b22ebf3655567 (patch) | |
tree | 008982a234f0a5ea7d1021dc151278dd143e669f /backend | |
parent | 0697f410b05085cdaf767d5b6fd3fea056ec5bd3 (diff) |
Add --cpu=baseline|native option, propagate sanitize setting to sub projects
Diffstat (limited to 'backend')
-rw-r--r-- | backend/BackendUtils.cpp | 2 | ||||
-rw-r--r-- | backend/ninja/Ninja.cpp | 42 |
2 files changed, 43 insertions, 1 deletions
diff --git a/backend/BackendUtils.cpp b/backend/BackendUtils.cpp index caeea3c..1109bf1 100644 --- a/backend/BackendUtils.cpp +++ b/backend/BackendUtils.cpp @@ -113,6 +113,8 @@ namespace backend backend::Ninja *subProject = new backend::Ninja(); SibsConfig *subProjectConfig = new SibsConfig(sibsConfig.getCompiler(), file->path, sibsConfig.getOptimizationLevel(), false); + subProjectConfig->setSanitize(sibsConfig.getSanitize()); + subProjectConfig->cpu = sibsConfig.cpu; subProjectConfig->packaging = sibsConfig.packaging; subProjectConfig->platform = sibsConfig.platform; subProjectConfig->bundling = sibsConfig.bundling; diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index c66907c..802ffd8 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -379,6 +379,37 @@ namespace backend return {}; } + static ninja::NinjaArg getCompilerCpuFlag(const SibsConfig &config) + { + // TODO: Also use -mcpu=native on non x86 systems + switch(config.getCompiler()) { + case Compiler::GCC: + case Compiler::MINGW_W64: { + switch(config.cpu) { + case sibs::CPU_INVALID: + case sibs::CPU_BASELINE: + return {}; + case sibs::CPU_NATIVE: + return ninja::NinjaArg::createRaw("-march=native"); + } + break; + } + case Compiler::MSVC: { + // msvc doesn't have any equivalent to gcc -march=native. + // TODO: Detect features at runtime here to manually add the cpu feature flags instead + switch(config.cpu) { + case sibs::CPU_INVALID: + case sibs::CPU_BASELINE: + return {}; + case sibs::CPU_NATIVE: + return ninja::NinjaArg::createRaw("-march=native"); + } + break; + } + } + return {}; + } + static vector<ninja::NinjaArg> getCompilerOptimizationFlags(const SibsConfig &config) { switch (config.getCompiler()) @@ -1017,6 +1048,10 @@ namespace backend allLinkerFlags += " " + optFlag.arg; } + ninja::NinjaArg cpuFlag = getCompilerCpuFlag(config); + if(cpuFlag.type != ninja::NinjaArg::Type::NONE) + compileCCommand.push_back(std::move(cpuFlag)); + ninja::NinjaArg sanitizerFlag = getCompilerSanitizerFlag(config); if(sanitizerFlag.type != ninja::NinjaArg::Type::NONE) compileCCommand.push_back(std::move(sanitizerFlag)); @@ -1075,6 +1110,10 @@ namespace backend allLinkerFlags += " " + optFlag.arg; } + ninja::NinjaArg cpuFlag = getCompilerCpuFlag(config); + if(cpuFlag.type != ninja::NinjaArg::Type::NONE) + compileCCommand.push_back(std::move(cpuFlag)); + ninja::NinjaArg sanitizerFlag = getCompilerSanitizerFlag(config); if(sanitizerFlag.type != ninja::NinjaArg::Type::NONE) compileCCommand.push_back(std::move(sanitizerFlag)); @@ -1764,7 +1803,8 @@ namespace backend SibsTestConfig sibsTestConfig(config.getCompiler(), testSourceDirNative.data, config.getOptimizationLevel()); sibsTestConfig.platform = config.platform; sibsTestConfig.setSanitize(config.getSanitize()); - sibsTestConfig.zigTestFiles = move(config.zigTestFiles); + sibsTestConfig.cpu = config.cpu; + sibsTestConfig.zigTestFiles = config.zigTestFiles; sibsTestConfig.zigTestAllFiles = config.zigTestAllFiles; sibsTestConfig.cVersion = config.cVersion; sibsTestConfig.cppVersion = config.cppVersion; |