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

[Modules] xmake uses inconsistent STL for different targets #3373

Closed
ChuanqiXu9 opened this issue Feb 16, 2023 · 8 comments
Closed

[Modules] xmake uses inconsistent STL for different targets #3373

ChuanqiXu9 opened this issue Feb 16, 2023 · 8 comments

Comments

@ChuanqiXu9
Copy link

Xmake Version

xmake v2.7.6+master.7f8eefb8a

Operating System Version and Architecture

linux

Describe Bug

I am trying to compile https://github.com/alibaba/async_simple/tree/CXX20Modules with xmake.

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

set_languages("c++20")

target("std")
    set_kind("static")
    add_files("third_party_module/stdmodules/*.cppm")
    add_includedirs("third_party_module/stdmodules")
    set_languages("c++20")

target("asio")
    set_kind("static")
    add_files("third_party_module/asio/asio.cppm")
    add_includedirs("third_party_module/asio")
    set_languages("c++20")

target("async_simple")
    set_kind("static")
    add_files("async_simple_module/*.cppm",
              "async_simple_module/coro/*.cppm",
              "async_simple_module/executors/*.cppm",
              "async_simple_module/uthread/*.cppm",
              "async_simple_module/uthread/internal/*.cppm",
              "async_simple_module/util/*.cppm")
    add_deps("std")
    set_languages("c++20")

Bug I meet a surprising error message:

error: In module 'async_simple:Common' imported from async_simple_module/util/Condition.cppm:27:
In module 'std' imported from /home/chuanqi.xcq/async_simple_module/async_simple_module/Common.cppm:17:
In module 'std:cstdint' imported from /home/chuanqi.xcq/async_simple_module/third_party_module/stdmodules/std.cppm:23:
/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/cstddef:138:18: error: 'std::operator&' has different definitions in different modules; definition in module 'std:cstdint.<global>' first difference is 1st parameter with name '__l'
  operator&(byte __l, byte __r) noexcept
            ~~~~~^~~
/home/chuanqi.xcq/llvm-project-for-work/build/bin/../include/c++/v1/cstddef:107:34: note: but in '' found 1st parameter with name '__lhs'
constexpr byte  operator& (byte  __lhs, byte __rhs) noexcept
                           ~~~~~~^~~~~
1 error generated.

Look carefully into the error message, I found the first one uses libstdc++ while the second one uses libc++. So here is the problem. Then I find that xmake wouldn't append -stdlib=libc++ for module units of std but xmake would append -stdlib=libc++ for module units under async_simple.

Here is the command for std:utility:

/home/chuanqi.xcq/llvm-project-for-work/build/bin/clang++ -c -x c++-module -fmodule-output=build/.gens/std/linux/x86_64/release/rules/modules/cache/b8e837a8/std:utility.pcm -Qunused-arguments -m64 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -std=c++20 -Ithird_party_module/stdmodules -DNDEBUG -fmodules-cache-path=build/.gens/std/linux/x86_64/release/rules/modules/cache -o build/.objs/std/linux/x86_64/release/third_party_module/stdmodules/utility.cppm.o third_party_module/stdmodules/utility.cppm

Here is the command for async_simple:Unit

/home/chuanqi.xcq/llvm-project-for-work/build/bin/clang++ -c -x c++-module -fmodule-output=build/.gens/async_simple/linux/x86_64/release/rules/modules/cache/321e8fd9/async_simple:Unit.pcm -Qunused-arguments -m64 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -std=c++20 -stdlib=libc++ -DNDEBUG -fmodules-cache-path=build/.gens/async_simple/linux/x86_64/release/rules/modules/cache -o build/.objs/async_simple/linux/x86_64/release/async_simple_module/Unit.cppm.o async_simple_module/Unit.cppm

Expected Behavior

The targets in the same project should use the same configuration for STL.

Project Configuration

No response

Additional Information and Error Logs

No response

@ChuanqiXu9 ChuanqiXu9 added the bug label Feb 16, 2023
@waruqi
Copy link
Member

waruqi commented Feb 16, 2023

I have improved it, try it again. 9e8183b

@Arthapz

And I need remove std::ignore

diff --git a/third_party_module/stdmodules/tuple.cppm b/third_party_module/stdmodules/tuple.cppm
index e4bd882..9226d0b 100644
--- a/third_party_module/stdmodules/tuple.cppm
+++ b/third_party_module/stdmodules/tuple.cppm
@@ -7,5 +7,5 @@ export namespace std {
     using std::get;
     using std::tie;
     using std::make_tuple;
-    using std::ignore;
+//    using std::ignore;
 }

And I got errors.

.o async_simple_module/uthread/Await.cppm
error: async_simple_module/uthread/Await.cppm:85:23: error: no type named 'result_of_t' in namespace 'std'
        typename std::result_of_t<decltype(fn)(C, Ts && ...)>::ValueType;
        ~~~~~~~~~~~~~~^~~~~~~~~~~
async_simple_module/uthread/Await.cppm:85:34: error: expected ';' after alias declaration
        typename std::result_of_t<decltype(fn)(C, Ts && ...)>::ValueType;
                                 ^
                                 ;
async_simple_module/uthread/Await.cppm:86:13: error: use of undeclared identifier 'ValueType'
    Promise<ValueType> p;
            ^
async_simple_module/uthread/Await.cppm:110:23: error: no type named 'result_of_t' in namespace 'std'
        typename std::result_of_t<decltype(fn)(Ts && ...)>::ValueType;
        ~~~~~~~~~~~~~~^~~~~~~~~~~
async_simple_module/uthread/Await.cppm:110:34: error: expected ';' after alias declaration
        typename std::result_of_t<decltype(fn)(Ts && ...)>::ValueType;
                                 ^
                                 ;
async_simple_module/uthread/Await.cppm:111:13: error: use of undeclared identifier 'ValueType'
    Promise<ValueType> p;
            ^
6 errors generated.

@ChuanqiXu9

@waruqi waruqi added this to the v2.7.7 milestone Feb 16, 2023
@ChuanqiXu9
Copy link
Author

Thanks. The implementation of async_simple is based on libstdc++10 and it is not surprise to me that it can't compile in other versions. Now I see it would use libc++ by default. How can I force it to use libstdc++?

@waruqi
Copy link
Member

waruqi commented Feb 16, 2023

Currently there is no configuration to explicitly switch to libstdc++, I will improve the configuration to support it, but it may take a while.

@ChuanqiXu9
Copy link
Author

Thanks.

@waruqi
Copy link
Member

waruqi commented Feb 16, 2023

you can try after updating.

add_cxxflags("-stdlib=libstdc++")
[ 76%]: compiling.module.release async_simple:FutureState
[ 76%]: compiling.module.release async_simple:coro.CoAwait
[ 76%]: compiling.module.release async_simple:executors.SimpleExecutor
[ 81%]: compiling.module.release async_simple:Future
[ 81%]: compiling.module.release async_simple:coro.Lazy
[ 84%]: compiling.module.release async_simple:uthread.thread
[ 84%]: compiling.module.release async_simple:coro.Sleep
[ 84%]: compiling.module.release async_simple:coro.Collect
[ 88%]: compiling.module.release async_simple:uthread.Await
[ 88%]: compiling.module.release async_simple:uthread.Uthread
[ 90%]: compiling.module.release async_simple:uthread.Latch
[ 90%]: compiling.module.release async_simple:uthread.Async
[ 93%]: compiling.module.release async_simple:uthread.Collect
[ 94%]: compiling.module.release async_simple
[ 97%]: linking.release libasync_simple.so
[100%]: build ok!

@ChuanqiXu9
Copy link
Author

Thanks. It solves my problem.

@waruqi
Copy link
Member

waruqi commented Feb 16, 2023

and I added libaio package in xmake-repo, we can use it directly.

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

set_languages("c++20")
add_cxxflags("-stdlib=libstdc++")

add_requires("libaio")

target("std")
    set_kind("static")
    add_files("third_party_module/stdmodules/*.cppm")
    add_includedirs("third_party_module/stdmodules")

target("asio")
    set_kind("static")
    add_files("third_party_module/asio/asio.cppm")
    add_includedirs("third_party_module/asio")

target("async_simple")
    set_kind("static")
    add_files("async_simple_module/*.cppm",
              "async_simple_module/coro/*.cppm",
              "async_simple_module/executors/*.cppm",
              "async_simple_module/uthread/*.cppm",
              "async_simple_module/uthread/internal/*.cppm",
              "async_simple_module/util/*.cppm")
    add_deps("std")
    add_packages("libaio")

@Arthapz
Copy link
Member

Arthapz commented Feb 16, 2023

(you can switch your -stdlib on commandline too xmake f --cxxflags="-stdlib=libstdc++")

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

No branches or pull requests

3 participants