-
-
Notifications
You must be signed in to change notification settings - Fork 779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add module redeclaration check #4773
Conversation
刚发现有个测试用来确保模块重复声明时的链接顺序(tests/projects/c++/modules/link_order)。也许应该加一个 flag 来开启重复定义的检查?不过我好像想不出有什么场景下模块重复声明是有用的。 |
I just found a test to ensure the link order when modules are repeatedly declared ([tests/projects/c++/modules/link_order](https://github.com/xmake-io/xmake/blob/76af94c04ba55dfe7a5087ce76dfeba4a709ba46/tests/projects/ c%2B%2B/modules/link_order/xmake.lua)). Maybe add a flag to enable duplicate definition checking? But I can't seem to think of any scenario where repeated module declarations would be useful. |
我觉得这个不应该在 xmake 层面去检测,而是得让 linker 自己去检测和报错。。 既然你 issues 里面提到 cmake 能报错,说明它可能把两个 obj 都同时传给 linker 去 link 了,被 linker 检测出来了,而 xmake 里面可能仅仅是由于少传了一个 obj 给 linker ,导致没法被检测到,那可以改进下实现,让 xmake 把所有依赖的 obj 都传给 linker 才对,让 linker 去主动检测和报错。
首先,xmake 内置的 dependency_scanner 实现,仅仅是 编译器没有原生支持时候的 fallback 方案,如果编译器支持,也是优先用的编译器的实现。 毕竟 xmake 提供的扫描实现方案,并不是完全可靠的。 另外,在 xmake 层面去检测这些,也会影响编译效率,尤其是工程变得庞大,模块依赖层次结构复杂的时候,这种检测是非常耗时的,lua 层来回遍历这些非常慢。 |
I think this should not be detected at the xmake level, but the linker must detect and report errors by itself. . Since you mentioned in your issues that cmake can report an error, it means that it may have linked both of them at the same time and was detected by the linker. However, in xmake, it may just be that one less obj is passed to the linker, resulting in the failure to be detected. Then The implementation can be improved so that xmake passes all dependent objs to the linker.
First of all, xmake's built-in dependency_scanner implementation is just a fallback solution when the compiler does not have native support. If the compiler supports it, the compiler's implementation will be used. After all, the scanning implementation solution provided by xmake is not completely reliable. In addition, detecting these at the xmake level will also affect compilation efficiency. Especially when the project becomes large and the module dependency hierarchy is complex, this detection is very time-consuming. |
@Arthapz any idea? |
Oh sorry didn't saw the PR i'll Check very soon |
so after some tests, we can enable the CMake behavior by deleting this line
and changing this one
local job_name = cppfile to actually build the duplicated module so the objectfile passed to the linker exists but link_order test will not work anymore (and shall be removed as it doesn't test anything usefull ?)
|
@Arthapz Looks cool, do you think this could be the default behavior for xmake? |
Okay, I'll create a new PR for this. |
Add function
modules_support.dependency_scanner.check_module_redeclaration
to detect module interface / partition redeclaration before build.Fixes #4770.