xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
9.98k stars 780 forks source link

SDCC 头文件依赖没有做好 #5711

Closed WG12 closed 6 days ago

WG12 commented 1 week ago

Xmake 版本

xmake v2.9.5+HEAD.d30de52e9, A cross-platform build utility based on Lua

操作系统版本和架构

windows10 21H2,操作系统内部版本 19044.5011

描述问题

使用SDCC工具链,正确编译一次之后,更改任意一个头文件,依赖该头文件的源文件不会重新编译。且build文件夹下的.d文件,没有记录源文件的依赖关系。GCC工具链没有此问题

期待的结果

修复

工程配置

add_rules("mode.debug", "mode.release")

-- set_config("toolchain", "sdcc") -- 指定编译器 -- set_config("arch", "mcs51") -- 指定芯片架构 -- set_config("sdk", "C:\Program Files (x86)\SDCC") -- 指定SDK路径,根据自身实际情况选择 -- set_config("plat", "cross") -- 设置编译平台 -- set_languages("c17") -- 设置C语言标准为C17

set_config("toolchain", "gcc") -- 指定编译器

-- 添加源文件路径
target("main") add_files("0-bsp/.c") add_files("1-middle/.c") add_files("2-app/*.c")

target("main") add_files("main.c") -- set_filename("main.ihx") -- set_kind("binary") -- after_link(function (target) -- os.cd("$(buildir)/cross/mcs51/release/") -- os.runv(os.shell(), {"packihx main.ihx > main.hex"}) -- os.cp("main.hex", "$(scriptdir)/main.hex") -- os.cd("$(scriptdir)") -- end)

-- 删除除缓存文件和配置文件 target("rm") set_default(false) on_build(function (target) os.tryrm("$(configdir)/cache/") os.tryrm("$(configdir)") os.tryrm("$(buildir)") os.tryrm("main.hex") end)

附加信息和错误日志

使用SDCC编译文件时,《.deps》文件夹内关于main.c的分析文件内容记录《main.c.rel.d》 { files = { "main.c" }, values = { [[C:\Program Files (x86)\SDCC\bin\sdcc]], { "-mmcs51", "--opt-code-speed", "-DNDEBUG" } } } 使用SDCC分析main.c文件的依赖关系,发现依赖分析工具正确输出,但依赖关系没有记录到《main.c.rel.d》文件中 其中sdcc出现了一个显示bug,sdcc的中间文件拓展名为《.rel》,而本测试显示的中间文件为《main.o》 PS D:\002-project\005-STC-DAP\ttt> sdcc -M main.c main.o: main.c 0-bsp/bsp.h 1-middle/middle.h 2-app/app.h PS D:\002-project\005-STC-DAP\ttt>

使用gcc编译时(编译为exe文件),《.deps》文件夹内关于main.c的分析文件内容记录《main.c.obj.d》 { depfiles_gcc = "main.o: main.c 0-bsp/bsp.h 1-middle/middle.h 2-app/app.h\ ", files = { "main.c" }, values = { "gcc", { "-m64", "-fvisibility=hidden", "-O3", "-DNDEBUG" } } } 使用gcc分析main.c文件的依赖关系,发现与上述文件中记录的值相同 PS D:\002-project\005-STC-DAP\ttt> gcc -M main.c main.o: main.c 0-bsp/bsp.h 1-middle/middle.h 2-app/app.h PS D:\002-project\005-STC-DAP\ttt>

综上所述,应该时使用sdcc工具链时,分析文件依关系的功能运行异常,请求修复

Issues-translate-bot commented 1 week ago

Bot detected the issue body's language is not English, translate it automatically.


Title: SDCC header file dependency is not done well

waruqi commented 1 week ago

目前不支持

Issues-translate-bot commented 1 week ago

Bot detected the issue body's language is not English, translate it automatically.


Not currently supported

WG12 commented 1 week ago

好吧。

当你准备实现这个功能的时候,可以参考一下GCC工具链的实现方式。SDCC对于指令基本上是照抄GCC的。仅作建议。

Issues-translate-bot commented 1 week ago

Bot detected the issue body's language is not English, translate it automatically.


All right.

When you are ready to implement this function, you can refer to the implementation of the GCC tool chain. SDCC basically copies GCC's instructions. Suggestions only.

waruqi commented 1 week ago

其中sdcc出现了一个显示bug,sdcc的中间文件拓展名为《.rel》,而本测试显示的中间文件为《main.o》

不是 bug,这边统一 .o ,只要 link 正常,无所谓哪个后缀。

另外,gcc 使用 "-MMD", "-MF" 去 dump 头文件依赖关系,sdcc 用的啥,怎么 dump ,我不知道,没找到相关 flags

Issues-translate-bot commented 1 week ago

Bot detected the issue body's language is not English, translate it automatically.


There is a display bug in sdcc. The extension of the intermediate file of sdcc is ".rel", while the intermediate file displayed in this test is "main.o"

It's not a bug. The .o is unified here. As long as the link is normal, it doesn't matter which suffix is ​​used.

In addition, gcc uses "-MMD" and "-MF" to dump header file dependencies. What does sdcc use? How to dump? I don't know. I didn't find the relevant flags.

waruqi commented 1 week ago

其中sdcc出现了一个显示bug,sdcc的中间文件拓展名为《.rel》,而本测试显示的中间文件为《main.o》

切 cross 平台,用的就是 .rel ,没啥问题

ruki@1da901d26bee:/tmp/test$ xmake f -p cross --toolchain=sdcc -c
checking for architecture ... none
ruki@1da901d26bee:/tmp/test$ xmake -rv
checking for sdcc ... /usr/bin/sdcc
checking for the c compiler (cc) ... sdcc
checking for /usr/bin/sdcc ... ok
checking for flags (--opt-code-speed) ... ok
checking for flags (-DNDEBUG) ... ok
[ 50%]: cache compiling.release src/main.c
/usr/bin/sdcc -c --opt-code-speed -DNDEBUG -o build/.objs/test/cross/none/release/src/main.c.rel src/main.c
a
waruqi commented 1 week ago

试下这个 patch,头文件解析应该可以了。。

xmake update -s github:xmake-io/xmake#sdcc
Issues-translate-bot commented 1 week ago

Bot detected the issue body's language is not English, translate it automatically.


Try this patch, header file parsing should be OK. .

xmake update -s github:xmake-io/xmake#sdcc
WG12 commented 6 days ago

试下这个 patch,头文件解析应该可以了。。

xmake update -s github:xmake-io/xmake#sdcc

老哥,我试了这样可以了,依赖的问题解决了。感谢!!!

Issues-translate-bot commented 6 days ago

Bot detected the issue body's language is not English, translate it automatically.


Try this patch, the header file should be parsed. .

xmake update -s github:xmake-io/xmake#sdcc

Brother, I tried this and it worked. The dependency problem was solved. grateful! ! !

waruqi commented 6 days ago

merge 了

Issues-translate-bot commented 6 days ago

Bot detected the issue body's language is not English, translate it automatically.


Merged