This is an automated email from the ASF dual-hosted git repository. sjanc pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git
commit 733af491ac082062648ee25ac1975453fc9da791 Author: Szymon Janc <[email protected]> AuthorDate: Tue Oct 20 00:51:28 2026 +0200 newt/toolchain: Add compiler.c.flags for C-only flags compiler.flags are passed to C, C++ and assembler invocations, so there is no way for a compiler package to set flags that are valid for C only. For example -std=c11 makes g++ fail with -Werror: cc1plus: error: command-line option '-std=c11' is valid for C/ObjC but not for C++ [-Werror] Add compiler.c.flags which are used only when compiling C files. They have the lowest priority: a C-only flag is dropped if the common flags already contain one with the same base, so a package setting e.g. -std=gnu99 in pkg.cflags keeps its own language standard. Assisted-by: Claude:claude-opus-5-5 --- newt/builder/cmake.go | 2 ++ newt/toolchain/compiler.go | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/newt/builder/cmake.go b/newt/builder/cmake.go index 05940e6d..af95634e 100644 --- a/newt/builder/cmake.go +++ b/newt/builder/cmake.go @@ -122,6 +122,8 @@ func CmakeSourceObjectWrite(w io.Writer, cj toolchain.CompilerJob, case toolchain.COMPILER_TYPE_C: flags = append(flags, c.GetCompilerInfo().Cflags...) flags = append(flags, c.GetLocalCompilerInfo().Cflags...) + flags = append(flags, c.GetCompilerInfo().CCflags...) + flags = append(flags, c.GetLocalCompilerInfo().CCflags...) case toolchain.COMPILER_TYPE_ASM: flags = append(flags, c.GetCompilerInfo().Cflags...) flags = append(flags, c.GetLocalCompilerInfo().Cflags...) diff --git a/newt/toolchain/compiler.go b/newt/toolchain/compiler.go index f920fc05..80855c04 100644 --- a/newt/toolchain/compiler.go +++ b/newt/toolchain/compiler.go @@ -58,6 +58,7 @@ const ( type CompilerInfo struct { Includes []string Cflags []string + CCflags []string CXXflags []string Lflags []string Aflags []string @@ -243,6 +244,7 @@ func NewCompilerInfo() *CompilerInfo { ci := &CompilerInfo{} ci.Includes = []string{} ci.Cflags = []string{} + ci.CCflags = []string{} ci.CXXflags = []string{} ci.Lflags = []string{} ci.Aflags = []string{} @@ -335,6 +337,7 @@ func (ci *CompilerInfo) AddCflags(cflags []string) { func (ci *CompilerInfo) AddCompilerInfo(newCi *CompilerInfo) { ci.Includes = append(ci.Includes, newCi.Includes...) ci.Cflags = addFlags("cflag", ci.Cflags, newCi.Cflags) + ci.CCflags = addFlags("ccflag", ci.CCflags, newCi.CCflags) ci.CXXflags = addFlags("cxxflag", ci.CXXflags, newCi.CXXflags) ci.Lflags = addFlags("lflag", ci.Lflags, newCi.Lflags) ci.Aflags = addFlags("aflag", ci.Aflags, newCi.Aflags) @@ -498,6 +501,7 @@ func (c *Compiler) load(compilerDir string, buildProfile string, cfg *cfgv.Setti } c.lclInfo.Cflags = loadFlags(yc, settings, "compiler.flags", cfg) + c.lclInfo.CCflags = loadFlags(yc, settings, "compiler.c.flags", cfg) c.lclInfo.CXXflags = loadFlags(yc, settings, "compiler.cxx.flags", cfg) c.lclInfo.Lflags = loadFlags(yc, settings, "compiler.ld.flags", cfg) c.lclInfo.Aflags = loadFlags(yc, settings, "compiler.as.flags", cfg) @@ -603,6 +607,14 @@ func (c *Compiler) cflagsStrings() []string { return cflags } +// Returns flags for compiling C files: common flags followed by C-only flags. +// A C-only flag is dropped if a common flag with the same base is already +// present (e.g., -std from a package overrides -std from the compiler). +func (c *Compiler) ccflagsStrings() []string { + return addFlags("ccflag", c.cflagsStrings(), + SortFlags(c.info.CCflags...)) +} + func (c *Compiler) cxxflagsStrings() []string { cxxflags := SortFlags(c.info.CXXflags...) return cxxflags @@ -653,7 +665,7 @@ func (c *Compiler) CompileFileCmd(file string, compilerType int) ( case COMPILER_TYPE_C: cmdName = c.ccPath toolKey = "compiler.path.cc" - flags = c.cflagsStrings() + flags = c.ccflagsStrings() case COMPILER_TYPE_ASM: cmdName = c.asPath toolKey = "compiler.path.as" @@ -704,7 +716,7 @@ func (c *Compiler) GenDepsForFile(file string, compilerType int) error { case COMPILER_TYPE_C: cmdName = c.ccPath toolKey = "compiler.path.cc" - flags = c.cflagsStrings() + flags = c.ccflagsStrings() case COMPILER_TYPE_ASM: cmdName = c.asPath toolKey = "compiler.path.as"
