Skip to content
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

module和test在一起时报错 #4641

Closed
someview opened this issue Jan 22, 2024 · 10 comments
Closed

module和test在一起时报错 #4641

someview opened this issue Jan 22, 2024 · 10 comments
Labels

Comments

@someview
Copy link

Xmake Version

2.8.5

Operating System Version and Architecture

win11

Describe Bug

工具链使用msvc, 同时使用xmake和module特性,xmake build报错.

// xmake.lua
add_rules("mode.debug", "mode.release")
set_languages("c++20")
add_requires("doctest")

target("cinterview")
    set_kind("binary")
    add_files("src/*.cpp", "src/*.ixx")




target("doctest")
    set_kind("binary")
    add_files("src/*.cpp")
    for _, testfile in ipairs(os.files("tests/*.cpp")) do
        add_tests(path.basename(testfile), {
            files = testfile,
            remove_files = "src/main.cpp",
            languages = "c++20",
            packages = "doctest",
            defines = "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN"})
    end

target("doctest_shared")
    set_kind("shared")
    add_files("src/foo.cpp")
    for _, testfile in ipairs(os.files("tests/*.cpp")) do
        add_tests(path.basename(testfile), {
            kind = "binary",
            files = testfile,
            languages = "c++20",
            packages = "doctest",
            defines = "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN"})
    end

运行xmake build -v, 输出日志:

checking for zig ... no
checking for unzip ... no
checking for 7z ... E:\c\xmake\winenv\bin\7z
checking for git ... ok
checking for gzip ... no
git rev-parse HEAD
checking for xmake::doctest ... doctest 2.4.11
checking for cl.exe ... E:\ide\visualstudio\VC\Tools\MSVC\14.38.33130\bin\HostX64\x64\cl.exe
checking for the c++ compiler (cxx) ... cl.exe
checking for E:\ide\visualstudio\VC\Tools\MSVC\14.38.33130\bin\HostX64\x64\cl.exe ... ok
checking for flags (cl_experimental_module) ... ok
checking for link.exe ... E:\ide\visualstudio\VC\Tools\MSVC\14.38.33130\bin\HostX64\x64\link.exe
checking for the linker (ld) ... link.exe
checking for link.exe ... E:\ide\visualstudio\VC\Tools\MSVC\14.38.33130\bin\HostX64\x64\link.exe
checking for the shared library linker (sh) ... link.exe
checking for flags (cl_scan_dependencies) ... ok
checking for flags (cl_ifc_output) ... ok
checking for flags (cl_interface) ... ok
checking for flags (cl_reference) ... ok
checking for flags (cl_internal_partition) ... ok
checking for flags (-O2 -fp:fast) ... ok
checking for flags (-std:c++20) ... ok
checking for flags (-DNDEBUG) ... ok
[ 16%]: compiling.release src\foo.cpp
E:\ide\visualstudio\VC\Tools\MSVC\14.38.33130\bin\HostX64\x64\cl.exe -c -nologo -O2 -fp:fast -std:c++20 /EHsc -DNDEBUG -Fobuild\.objs\doctest\windows\x64\release\src\foo.cpp.obj src\foo.cpp
[ 16%]: compiling.release src\main.cpp
E:\ide\visualstudio\VC\Tools\MSVC\14.38.33130\bin\HostX64\x64\cl.exe -c -nologo -O2 -fp:fast -std:c++20 /EHsc -DNDEBUG -Fobuild\.objs\doctest\windows\x64\release\src\main.cpp.obj src\main.cpp
[ 22%]: compiling.release src\foo.cpp
E:\ide\visualstudio\VC\Tools\MSVC\14.38.33130\bin\HostX64\x64\cl.exe -c -nologo -O2 -fp:fast -std:c++20 /EHsc -DNDEBUG -Fobuild\.objs\doctest_shared\windows\x64\release\src\foo.cpp.obj src\foo.cpp
checking for flags (cl_sourceDependencies) ... ok
error: main.cpp
src\main.cpp(1): error C2230: 无法找到模块“hello”
src\main.cpp(4): error C2653: “hello”: 不是类或命名空间名称
src\main.cpp(4): error C3861: “say”: 找不到标识符

相当于,既有module,又有测试,看起来好像冲突了.

Expected Behavior

build的时候不报错.

Project Configuration

已给出

Additional Information and Error Logs

已给出

@someview someview added the bug label Jan 22, 2024
@someview
Copy link
Author

如果去掉test,运行是正常的

@Issues-translate-bot
Copy link

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


Title: module and test report an error together

@Issues-translate-bot
Copy link

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


If test is removed, the operation is normal.

@waruqi
Copy link
Member

waruqi commented Jan 24, 2024

最近 modules 在重构,都重构完,会统一看下相关的问题。

@Issues-translate-bot
Copy link

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


The modules are being refactored recently. After they are all refactored, we will take a look at the related issues together.

@waruqi
Copy link
Member

waruqi commented Feb 20, 2024

我这可以的么,给个完整可复现的例子 example ,或者试下最新 dev version。。xmake update -s dev

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

set_languages("c++latest")

target("stdmodules_cpp_only")
    set_kind("binary")
    add_files("src/*.cpp")
    set_policy("build.c++.modules", true)

    for _, testfile in ipairs(os.files("tests/*.cpp")) do
        add_tests(path.basename(testfile), {
            files = testfile,
            remove_files = "src/main.cpp",
            languages = "c++20",
            packages = "doctest",
            defines = "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN"})
    end
D:\projects\personal\xmake\tests\projects\c++\modules\stdmodules_cpp_only>xmake test
checking for Microsoft Visual Studio (x64) version ... 2022
[  0%]: <stdmodules_cpp_only_main> generating.module.deps tests\main.cpp
[  0%]: <stdmodules_cpp_only_main> generating.module.deps C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.38.33129\modules\std.ixx
[  0%]: <stdmodules_cpp_only_main> generating.module.deps C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.38.33129\modules\std.compat.ixx
[ 25%]: <stdmodules_cpp_only_main> compiling.module.release std
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.38.33129\include\chrono(2326): warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc
[ 37%]: <stdmodules_cpp_only_main> compiling.module.release std.compat
[ 62%]: compiling.release tests\main.cpp
cl: 命令行 warning D9025 :正在重写“/std:c++latest”(用“/std:c++20”)
tests\main.cpp(1): warning C5050: 导入模块“std”时可能不兼容的环境: mismatched C++ versions.  Current "202002" module version "202004"
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.38.33129\include\ostream(779): warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc
[ 75%]: linking.release stdmodules_cpp_only_main.exe
running tests ...
[100%]: stdmodules_cpp_only/main .................................... passed 0.110s

100% tests passed, 0 tests failed out of 1, spent 0.110s

@someview
Copy link
Author

someview commented Mar 5, 2024

我这可以的么,给个完整可复现的例子 example ,或者试下最新 dev version。。xmake update -s dev

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

set_languages("c++latest")

target("stdmodules_cpp_only")
    set_kind("binary")
    add_files("src/*.cpp")
    set_policy("build.c++.modules", true)

    for _, testfile in ipairs(os.files("tests/*.cpp")) do
        add_tests(path.basename(testfile), {
            files = testfile,
            remove_files = "src/main.cpp",
            languages = "c++20",
            packages = "doctest",
            defines = "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN"})
    end
D:\projects\personal\xmake\tests\projects\c++\modules\stdmodules_cpp_only>xmake test
checking for Microsoft Visual Studio (x64) version ... 2022
[  0%]: <stdmodules_cpp_only_main> generating.module.deps tests\main.cpp
[  0%]: <stdmodules_cpp_only_main> generating.module.deps C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.38.33129\modules\std.ixx
[  0%]: <stdmodules_cpp_only_main> generating.module.deps C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.38.33129\modules\std.compat.ixx
[ 25%]: <stdmodules_cpp_only_main> compiling.module.release std
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.38.33129\include\chrono(2326): warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc
[ 37%]: <stdmodules_cpp_only_main> compiling.module.release std.compat
[ 62%]: compiling.release tests\main.cpp
cl: 命令行 warning D9025 :正在重写“/std:c++latest”(用“/std:c++20”)
tests\main.cpp(1): warning C5050: 导入模块“std”时可能不兼容的环境: mismatched C++ versions.  Current "202002" module version "202004"
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.38.33129\include\ostream(779): warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc
[ 75%]: linking.release stdmodules_cpp_only_main.exe
running tests ...
[100%]: stdmodules_cpp_only/main .................................... passed 0.110s

100% tests passed, 0 tests failed out of 1, spent 0.110s

回去试试

@Issues-translate-bot
Copy link

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


Is this possible? Give me a complete and reproducible example, or try the latest dev version. . xmake update -s dev

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

set_languages("c++latest")

target("stdmodules_cpp_only")
set_kind("binary")
add_files("src/*.cpp")
set_policy("build.c++.modules", true)

for _, testfile in ipairs(os.files("tests/*.cpp")) do
add_tests(path.basename(testfile), {
files = testfile,
remove_files = "src/main.cpp",
languages ​​= "c++20",
packages = "doctest",
defines = "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN"})
end


D:\projects\personal\xmake\tests\projects\c++\modules\stdmodules_cpp_only>xmake test
checking for Microsoft Visual Studio (x64) version ... 2022
[ 0%]: <stdmodules_cpp_only_main> generating.module.deps tests\main.cpp
[ 0%]: <stdmodules_cpp_only_main> generating.module.deps C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.38.33129\modules\std.ixx
[ 0%]: <stdmodules_cpp_only_main> generating.module.deps C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.38.33129\modules\std.compat.ixx
[25%]: <stdmodules_cpp_only_main> compiling.module.release std
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.38.33129\include\chrono(2326): warning C4530: A C++ exception handler is used but unwind semantics are not enabled. Please specify /EHsc
[37%]: <stdmodules_cpp_only_main> compiling.module.release std.compat
[62%]: compiling.release tests\main.cpp
cl: Command line warning D9025: Rewriting "/std:c++latest" (with "/std:c++20")
tests\main.cpp(1): warning C5050: Possibly incompatible environments when importing module "std": mismatched C++ versions. Current "202002" module version "202004"
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.38.33129\include\ostream(779): warning C4530: A C++ exception handler is used but unwind semantics are not enabled. Please specify /EHsc
[75%]: linking.release stdmodules_cpp_only_main.exe
running tests ...
[100%]: stdmodules_cpp_only/main ............................. passed 0.110s

100% tests passed, 0 tests failed out of 1, spent 0.110s

Go back and try

@someview
Copy link
Author

someview commented Mar 5, 2024

升级一下版本就没这个问题了,已经解决,module里也可以有test了

@someview someview closed this as completed Mar 5, 2024
@Issues-translate-bot
Copy link

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


Upgrading the version will eliminate this problem. It has been solved. You can also have tests in the module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants