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/ninja/Ninja.cpp | |
parent | 0697f410b05085cdaf767d5b6fd3fea056ec5bd3 (diff) |
Diffstat (limited to 'backend/ninja/Ninja.cpp')
-rw-r--r-- | backend/ninja/Ninja.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
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; |