From cf0c9479deedcbfc0592ac6d207b22ebf3655567 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 27 Jun 2023 02:27:44 +0200 Subject: Add --cpu=baseline|native option, propagate sanitize setting to sub projects --- backend/ninja/Ninja.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'backend/ninja') 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 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; -- cgit v1.2.3