Skip to content

fix\[kernel]: resolve rt\_sched\_\* implicit declaration warnings in Eclipse/Studio builds - #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 gcc/armclang 分支将 __RT_KERNEL_SOURCE__ 从 LOCAL_CPPDEFINES 移入 Kernel 组全局 CPPDEFINES(与既有 msvc 分支写法一致,一行改动):

--- a/src/SConscript
+++ b/src/SConscript
@@ -57,7 +57,7 @@ if rtconfig.CROSS_TOOL == 'msvc':
 else:
     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__'])

效果:scons --target=eclipse 每次生成的 rtconfig_preinc.h 自动包含 #define __RT_KERNEL_SOURCE__,Studio make 构建经 -include 可见声明,警告清零。宏仍只作用于 Kernel 组内文件,scons 命令行构建编译参数不变,固件逐字节一致,无 API/ABI/ 运行时影响

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

  • BSP:bsp/stm32/stm32l475-atk-pandora
  • .config: 本修复为内核构建系统(src/SConscript)纯构建层修改,不涉及任何配置项,验证使用 bsp/stm32/stm32l475-atk-pandora 默认配置即可复现(无需改动 .config)。复现 / 验证方式:scons --dist-ide --project-name=stm32l475-atk-pandora 导出后,在 RT-Thread Studio 中 Clean + 重新构建。
  • action: PR 已提交:RT-Thread/rt-thread #11930。官方仓库 Pull Request Labeler 工作流执行 Success:action 执行地址(Run #40179172456,总耗时 8s);含 2 条非阻断警告(pull_request_target 平台策略提示、Node.js 20 弃用提示)。编译类检查结果以 PR 页面 CI 状态为准

测试情况(已确认,板卡:stm32l475-atk-pandora):① 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 个内核文件:修复前 24 警告 → 修复后 0 警告;② RT-Thread Studio 实测:Clean 后重新构建 0 errors / 0 warnings,固件 96.64 KB Flash / 6.58 KB RAM,与修复前逐字节一致;③ scons 命令行构建回归通过;④ 最新 master 对照:问题独立复现(GCC 5.4.1 下 24 警告、GCC 15.2.1 下编译失败);⑤ dev 导出项目内 A/B 对照:仅切换 SConscript 一处,不带修复 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自查

…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.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@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.

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

Kernel PR has src relate code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants