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/BackendUtils.cpp | 2 ++ backend/ninja/Ninja.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) (limited to 'backend') 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 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