Skip to content

fix[tools]: attach group LOCAL_CPPDEFINES to source files in Eclipse export - #11930

Open
AZE-BlackCore wants to merge 1 commit into
RT-Thread:masterfrom
AZE-BlackCore:dev
Open

AZE-BlackCore wants to merge 1 commit into
RT-Thread:masterfrom
AZE-BlackCore:dev

Conversation

@AZE-BlackCore

@AZE-BlackCore AZE-BlackCore commented Oct 25, 2026 •

Copy link
Copy Markdown

…pse/Studio builds

The rt_sched_* scheduler APIs in include/rtsched.h are guarded by RT_KERNEL_SOURCE / RT_IPC_SOURCE. The gcc/armclang branch of src/SConscript injects the macro via LOCAL_CPPDEFINES, which is honored by scons command-line builds but is NOT collected by the Eclipse project generator (tools/targets/eclipse.py) that RT-Thread Studio runs before each make build. As a result, Studio builds of dist-exported projects report 24 -Wimplicit-function-declaration warnings (clock.c 1, ipc.c 7, thread.c 12, timer.c 1, scheduler_comm.c 3).

Move RT_KERNEL_SOURCE into the global CPPDEFINES of the Kernel group, matching the existing msvc branch. The macro then lands in the generated rtconfig_preinc.h automatically and the warnings disappear, with no change to scons command-line build behavior or generated firmware.

Verified: Studio rebuild 0 errors / 0 warnings; firmware size unchanged.

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

通过 scons --dist-ide 导出的项目在 RT-Thread Studio / Eclipse(构建前运行 scons --target=eclipse)下使用 gcc/armclang 工具链编译时,内核 5 个源文件(src/clock.c、src/ipc.c、src/thread.c、src/timer.c、src/scheduler_comm.c)报 24 条 -Wimplicit-function-declaration 警告(rt_sched_* 内部调度 API 隐式声明)。

该问题在最新 master(a59e72fb5c)上已独立复现;且 GCC 14 起 -Wimplicit-function-declaration 默认升级为 error,同一问题在 GCC 14+/15 工具链下会导致编译失败,直接阻断构建。修复可同时消除警告并避免新工具链下的硬错误。

你的解决方案是什么 (what is your solution)

根因:include/rtsched.h 中 rt_sched_* 声明被 #if defined(__RT_KERNEL_SOURCE__) || defined(__RT_IPC_SOURCE__) 包裹;scons 命令行构建通过 src/SConscript 的 LOCAL_CPPDEFINES 注入该宏,但 Studio 构建链路的 Eclipse 工程生成器(tools/targets/eclipse.py)只收集全局 project['CPPDEFINES'] 写入 rtconfig_preinc.h,不收集 LOCAL_CPPDEFINES,导致 preinc 缺宏、声明不可见。

修复(按维护者评审意见调整为最终方案):保持 src/SConscript 的 LOCAL_CPPDEFINES 原样不动,修改 tools/targets/eclipse.py,让 Eclipse 导出器将各组的 LOCAL_CPPDEFINES 作为 CDT per-file Defined Symbols(fileInfo) 挂到该组对应的源文件上:

  • 宏作用域不扩大:rtconfig_preinc.h 仍只含全局宏,__RT_KERNEL_SOURCE__ 仅作用于 Kernel 组自身源文件(与 scons 命令行构建的 LOCAL 语义一致);
  • CDT 生成 makefile 时,带 fileInfo 的源文件编译命令自动追加各自的 -D,等价于命令行构建的效果;
  • 纯工程生成层修改(仅 tools/targets/eclipse.py,+76/-2),scons 命令行构建、rtconfig_preinc.h 内容、固件产物均无任何变化。

.cproject 生成效果示例:

<fileInfo id="...rttlocal.rt-thread.src.clock.c" name="/rt-thread/src/clock.c">
  <tool id="...rttlocal.rt-thread.src.clock.c.tool"
        superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler">
    <option id="...rttlocal.rt-thread.src.clock.c.defs"
            superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.defs">
      <listOptionValue builtIn="false" value="__RT_KERNEL_SOURCE__"/>
    </option>
  </tool>
</fileInfo>

请提供验证的bsp和config (provide the config and bsp)

  • BSP:bsp/stm32/stm32l475-atk-pandora
  • .config: 本修复为 Eclipse 工程导出器(tools/targets/eclipse.py)纯生成层修改,不涉及任何配置项,验证使用 bsp/stm32/stm32l475-atk-pandora 默认配置即可复现(无需改动 .config)。复现 / 验证方式:scons --dist-ide --project-name=stm32l475-atk-pandora 导出后,在 RT-Thread Studio 中 Clean + 重新构建。

测试情况(已确认,板卡:stm32l475-atk-pandora):① 导出工程静态验证:.cproject 为 Kernel 组 15 个源文件生成 per-file fileInfo(含 __RT_KERNEL_SOURCE__),rtconfig_preinc.h 不含该宏(作用域不扩大),重复生成幂等;② 模拟 CDT 编译(Studio 同参 -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O0 -Wall -std=gnu99 -include rtconfig_preinc.h + 完整包含路径,GCC 5.4.1):5 个内核文件带 per-file -D 编译 0 警告,applications/main.c 不带 -D 编译 0 警告(作用域对照);③ scons 命令行构建回归通过(src/SConscript 未改动);④ 最新 master 对照:问题独立复现(GCC 5.4.1 下 24 警告、GCC 15.2.1 下编译失败);⑤ dev 导出项目内 A/B 对照:不带修复 24 警告 → 带修复 0 警告。
]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用clang-format 源码格式化工具确保格式符合RT-Thread代码规范 This PR has been formatted with clang-format and complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

@CLAassistant

CLAassistant commented Oct 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

Copy link
Copy Markdown

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • Use workflow from 保持默认分支(通常为 master)
    Keep the default branch (usually master) in Use workflow from
  • 在 branch 输入框填写 PR 分支 dev
    Enter PR branch dev in the branch field
  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将作为独立提交推送至你的分支。
    The formatting changes will be pushed to your branch as a separate commit.

完成后,提交将自动更新至 dev 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the dev branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions github-actions Bot added the Kernel PR has src relate code label Oct 25, 2026
@github-actions

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: kernel

Reviewers: @GorrayLi @ReviewSun @hamburger-os @lianux-mm @wdfk-prog @xu18838022837

Changed Files (Click to expand)
  • src/SConscript

📊 Current Review Status (Last Updated: 2026-10-25 17:04 CST)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

Comment thread src/SConscript Outdated
group = DefineGroup('Kernel', src, depend=[''], CPPPATH=inc,
LINKFLAGS=LINKFLAGS, LOCAL_CFLAGS=LOCAL_CFLAGS,
CPPDEFINES=['__RTTHREAD__'], LOCAL_CPPDEFINES=['__RT_KERNEL_SOURCE__'])
CPPDEFINES=['__RTTHREAD__', '__RT_KERNEL_SOURCE__'])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议保留原来的配置,让 Eclipse 导出器将各组的 LOCAL_CPPDEFINES 配置到对应源文件上。不要直接汇总到全局 rtconfig_preinc.h,否则仍会扩大作用域。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢您的评审意见!已按建议调整方案:

  • src/SConscript 保持原配置不变(LOCAL_CPPDEFINES=['RT_KERNEL_SOURCE'],与 master 无差异),不再改动内核构建脚本;

  • 修改落在 tools/targets/eclipse.py:新增 CollectLocalDefines / UpdateLocalDefinesFileInfo,导出时收集各组的 LOCAL_CPPDEFINES,作为 CDT per-file Defined Symbols(fileInfo) 挂到该组对应的源文件上(Kernel 组 15 个源文件),不再汇总进全局 preinc;

  • 验证结果:生成的 .cproject 含 Kernel 组 15 个 per-file fileInfo(含 RT_KERNEL_SOURCE),rtconfig_preinc.h 不含该宏(宏作用域不扩大);以 Studio 同参(GCC 5.4.1 + per-file -D)编译 5 个内核文件 0 警告,main.c(不带 -D)0 警告;scons 命令行构建行为不变。

PR 已更新(commit 1613695,仅 eclipse.py,+76/-2),请再帮忙看一下,谢谢!

@Rbb666 Rbb666 added the -1 No vote label Oct 26, 2026
@github-actions github-actions Bot added the tools label Oct 26, 2026
@AZE-BlackCore AZE-BlackCore changed the title fix\[kernel]: resolve rt\_sched\_\* implicit declaration warnings in Eclipse/Studio builds fix[tools]: attach group LOCAL_CPPDEFINES to source files in Eclipse export Oct 26, 2026

@Rbb666 Rbb666 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当前实现存在两处影响 Eclipse/RT-Thread Studio 工程加载和编译的问题,详见行内评论。请修复后重新验证 Studio 工程加载及完整构建,确认局部宏与原有编译选项均进入实际编译命令。此次检查已执行 Python/XML 最小重现并核对 CDT 源码,未执行 Studio 完整构建。

Comment thread tools/targets/eclipse.py Outdated

for rp, defines in local_defines.items():
fi_id = ccfg_id + _rtt_local_marker + rp.replace('/', '.').strip('.')
fi = SubElement(configuration, 'fileInfo', {'id': fi_id, 'name': '/' + rp})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 为 fileInfo 添加 resourcePath

这里生成的 fileInfo 只有 id 和 name,但 CDT 使用 resourcePath 关联源文件,name 不能替代该属性。对于包含 LOCAL_CPPDEFINES 的工程(例如默认 Kernel 组),这些节点加载后 getPath() 为 null,Configuration.addResourceConfiguration() 调用 getPath().segmentCount() 时会触发异常,导致工程配置无法正常加载。请添加 resourcePath=rp,使用相对于工程根目录的源文件路径,并验证生成的 .cproject 能被 Studio 正常重新加载。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

收到,感谢指正!已废弃原方案(将 RT_KERNEL_SOURCE 并入 Kernel 组全局 CPPDEFINES),按您的建议修改:保持 src/SConscript 的 LOCAL_CPPDEFINES 配置原样不动,改在 tools/targets/eclipse.py 中收集各组的 LOCAL_CPPDEFINES,作为 CDT per-file Defined Symbols(fileInfo) 挂到该组对应的源文件上。
这样宏作用域不扩大:rtconfig_preinc.h 仍只含全局宏,RT_KERNEL_SOURCE 仅作用于 Kernel 组自身源文件(与 scons 命令行构建的 LOCAL 语义一致);CDT 生成 makefile 时,带 fileInfo 的文件编译命令会自动追加 -D。
已验证:导出工程 .cproject 为 Kernel 组 15 个源文件生成 per-file fileInfo(含 RT_KERNEL_SOURCE);rtconfig_preinc.h 不含该宏;模拟 CDT 编译(Studio 同参,GCC 5.4.1)5 个内核文件 0 警告、main.c 无 -D 0 警告;scons 命令行构建行为不变。PR 已更新,请再帮忙看一下,谢谢!

Comment thread tools/targets/eclipse.py Outdated
fi_id = ccfg_id + _rtt_local_marker + rp.replace('/', '.').strip('.')
fi = SubElement(configuration, 'fileInfo', {'id': fi_id, 'name': '/' + rp})
tool = SubElement(fi, 'tool', {'id': fi_id + '.tool',
'superClass': 'ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler'})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 继承当前工程已配置的编译器实例

这里的 superClass 指向插件的基础 C 编译器,绕过了当前工程 folderInfo/toolChain 中已经配置的编译器实例。即使补齐 resourcePath,生成的文件级工具仍无法继承 HandleToolOption() 写入工程编译器的头文件搜索路径和 -include rtconfig_preinc.h 等选项,内核源文件会因缺少头文件路径或全局宏而编译失败。请根据源文件所属目录选择实际编译器,将文件级工具的 superClass 指向该实例的完整 ID,再添加局部宏;验证实际编译命令同时保留原有 -I、-include 和新增 -D。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已按两条意见修复并完成 Studio 实测:
① fileInfo 现携带 resourcePath(相对工程根路径),CDT 可正常关联源文件,工程在 RT-Thread Studio 中正常加载;
② 文件级 的 superClass 由基础插件类改为实际编译器实例 id(GetCompilerInstanceId 按源文件所属目录前缀匹配 folderInfo/toolChain 中的编译器实例),per-file -D 叠加在原有选项之上。
Studio 实测(stm32l475-atk-pandora,2026-10-26):工程正常加载,Clean 后完整构建 0 errors / 0 warnings(Flash 96.66 KB / RAM 6.58 KB)。核对 CDT 生成的 Debug/rt-thread/src/subdir.mk:Kernel 组 15 个源文件编译规则均含 -D__RT_KERNEL_SOURCE
_,并保留 -include rtconfig_preinc.h 与全部 -I 路径;klibc/drivers/applications 规则不含该宏 ——局部宏与原有编译选项均进入实际编译命令,宏作用域未扩大。
PR 已更新(commit 57c7318,仅 eclipse.py,+143/-2),请再帮忙看一下,谢谢!

@Rbb666 Rbb666 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审提交 57c7318:fileInfo 的 resourcePath 已补齐,默认 Studio 模板的编译器继承也已修复;但目录级配置仍使用 name 而非 resourcePath 匹配源文件,可能跳过所属目录的自定义编译选项,详见行内评论。该问题已通过 Python/XML 最小复现确认,修复前继续保持 Request changes。

Comment thread tools/targets/eclipse.py Outdated
# per-folder compiler instances: folder name -> tool instance id
folders = []
for fi in configuration.findall('folderInfo'):
name = fi.get('name', '/')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 使用 resourcePath 匹配源文件所属目录

folderInfo.name 不是相对于工程根目录的路径,目录级配置可能沿用根配置的显示名称 /。例如同时存在根配置 name="/" resourcePath="" 和子目录配置 name="/" resourcePath="rt-thread/src" 时,这里把两者都当成空目录前缀,后续最长前缀比较无法区分它们。已复现 rt-thread/src/clock.c 仍选择根目录编译器,导致子目录编译器上的自定义选项(例如 -fno-builtin)被跳过。

请改为读取 fi.get('resourcePath', ''),按实际目录路径进行最长前缀匹配。建议覆盖根目录、嵌套目录及目录外文件三种情况;在最小复现中改用 resourcePath 后,内核文件选中子目录编译器,applications/main.c 仍选中根目录编译器。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已按 [P2] 意见修复:GetCompilerInstanceId 不再用 folderInfo.name(显示名可能均为 "/"),改读 fi.get('resourcePath', '') 按真实目录路径做最长前缀匹配。
验证:① 最小复现(根 + 子目录 rt-thread/src + 嵌套 rt-thread/src/klibc,name 均为 "/"):rt-thread/src/clock.c 正确选中子目录编译器、嵌套文件选中嵌套编译器、applications/main.c 与目录外文件选中根编译器、.cpp 选 cpp 编译器 —— 全部通过;② RT-Thread Studio 实测(2026-10-26):工程正常加载、完整构建 0 errors / 0 warnings;CDT makefile 核对 Kernel 15 条规则含 -D__RT_KERNEL_SOURCE
_ 且保留 -I/-include,klibc/drivers/applications 无宏;③ 固件尺寸与修复前一致(Flash 96.66 KB / RAM 6.58 KB)。
PR 已更新(commit cd78b54,仅 eclipse.py),请再帮忙看一下,谢谢!

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

…export

The Eclipse project generator (tools/targets/eclipse.py) only writes the
global CPPDEFINES into rtconfig_preinc.h, while per-group
LOCAL_CPPDEFINES (e.g. __RT_KERNEL_SOURCE__ for the Kernel group in
src/SConscript) are not collected. As a result, Eclipse/RT-Thread Studio
builds of dist-exported projects report 24 -Wimplicit-function-declaration
warnings for the rt_sched_* internal scheduler APIs, and GCC 14+ turns the
same warnings into hard errors.

Keep the original LOCAL_CPPDEFINES scoping and let the Eclipse exporter
attach each group's LOCAL_CPPDEFINES to the corresponding source files as
CDT per-file defined symbols (fileInfo). Each fileInfo carries
'resourcePath' (required by CDT to associate the file) and its tool
inherits the real folder/toolchain compiler instance id, so the per-file
-D is applied on top of the existing -I / '-include rtconfig_preinc.h'
options. The compiler instance is selected by the longest matching
folderInfo 'resourcePath' (not the display 'name', which is often '/' for
every folder), so kernel sources pick up their directory-level compiler
options while root and outside-folder files fall back to the root
compiler.

Verified: .cproject carries 15 per-file fileInfo for the Kernel group with
resourcePath and the real compiler instance id; the generated
rtconfig_preinc.h has no __RT_KERNEL_SOURCE__ (macro scope unchanged);
compiling the 5 kernel files with the full Studio flags plus the per-file
-D yields 0 warnings (GCC 5.4.1), while non-kernel files compile without
it; Studio build of the exported stm32l475-atk-pandora project: 0 errors /
0 warnings, and the CDT-generated makefile keeps -I / '-include' and adds
the per-file -D only for the Kernel group (15 rules).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

-1 No vote Kernel PR has src relate code tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants