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

zig c++: fix libcxx build and add support for wasm32-wasi target. #9113

Merged
merged 6 commits into from
Jun 15, 2021

Conversation

mathetake
Copy link
Contributor

@mathetake mathetake commented Jun 14, 2021

This is basically following wasi-sdk's Makefile, and notably I emulated the behavior of LIBCXX_ENABLE_FILESYSTEM:BOOL CMake flag, and completely disabled the threading APIs. This resolves #9044 without modifying libcxx. Ref: WebAssembly/wasi-sdk#125

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
@mathetake
Copy link
Contributor Author

Now we can compile

#include <string>

int main(int argc, char **argv) {
    printf("test: %s", std::string("my-string").c_str());
    return 0;
}

but we got some strange imports inside the binary:

Import[9]:
 - func[0] sig=2 <__imported_wasi_snapshot_preview1_args_get> <- wasi_snapshot_preview1.args_get
 - func[1] sig=2 <__imported_wasi_snapshot_preview1_args_sizes_get> <- wasi_snapshot_preview1.args_sizes_get
 - func[2] sig=3 <__imported_wasi_snapshot_preview1_fd_close> <- wasi_snapshot_preview1.fd_close
 - func[3] sig=2 <__imported_wasi_snapshot_preview1_fd_fdstat_get> <- wasi_snapshot_preview1.fd_fdstat_get
 - func[4] sig=4 <__imported_wasi_snapshot_preview1_fd_seek> <- wasi_snapshot_preview1.fd_seek
 - func[5] sig=5 <__imported_wasi_snapshot_preview1_fd_write> <- wasi_snapshot_preview1.fd_write
 - func[6] sig=6 <__imported_wasi_snapshot_preview1_proc_exit> <- wasi_snapshot_preview1.proc_exit
 - func[7] sig=3 <std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()> <- env._ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev
 - func[8] sig=7 <std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)> <- env._ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcm

will look into this now.

@mathetake
Copy link
Contributor Author

OK looks like just libcxx isn't hooked up into linker well.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
src/libcxx.zig Outdated Show resolved Hide resolved
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
@mathetake
Copy link
Contributor Author

Yeah finally it's started working! yay! @kubkon PTAL!

mathetake@mathetake ~/zig/build cpp-wasi
<< cat ~/zigcctest/test.cc
#include <cstdio>
#include <iostream>
#include <string>

int main() {
    std::string str = "hello wasi-sdk!";
    std::cout << str << std::endl;
    std::printf("%s\n", str.c_str());

    return 0;
}

mathetake@mathetake ~/zig/build cpp-wasi
>> /home/mathetake/zig-bootstrap/out/host/bin/zig c++ -target wasm32-wasi ~/zigcctest/test.cc

mathetake@mathetake ~/zig/build cpp-wasi 7s
>> wasmtime a.out       
hello wasi-sdk!
hello wasi-sdk!

@mathetake mathetake marked this pull request as ready for review June 15, 2021 00:30
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
@mathetake mathetake changed the title c++,wasi: enable libcxx build. zig c++: fix libcxx build and add support for wasm32-wasi target. Jun 15, 2021
@kubkon kubkon merged commit 0063f64 into ziglang:master Jun 15, 2021
@kubkon
Copy link
Member

kubkon commented Jun 15, 2021

Excellent work! Thank you @mathetake!

@mathetake mathetake deleted the cpp-wasi branch June 15, 2021 10:36
@mathetake
Copy link
Contributor Author

Thanks @kubkon for taking a look! 🥇 😄

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

Successfully merging this pull request may close these issues.

Support libc++ on the target wasm32-wasi-musl
2 participants