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

Using WASI SDK in CMake build on Windows #179

Closed
arrisde opened this issue Apr 17, 2021 · 5 comments
Closed

Using WASI SDK in CMake build on Windows #179

arrisde opened this issue Apr 17, 2021 · 5 comments

Comments

@arrisde
Copy link

arrisde commented Apr 17, 2021

I'm trying to use the Windows release of WASI SDK to build a WASI module using CMake, but I'm not quite able to wrap my head around this. Maybe someone can point out what I'm doing wrong here.

I have a simple CMakeLists.txt:

cmake_minimum_required(VERSION 3.10.0)
project(demo)
add_executable(MyDemo "demo.c")

And try to build as follows:

$ cmake .. -DCMAKE_TOOLCHAIN_FILE="C://wasi-sdk-12.0//share//cmake//wasi-sdk.cmake" -DWASI_SDK_PREFIX="C://wasi-sdk-12.0" -G "Ninja"

Which fails:

-- The C compiler identification is Clang 11.0.0
-- The CXX compiler identification is Clang 11.0.0
System is unknown to cmake, create:
Platform/WASI to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Detecting C compiler ABI info
System is unknown to cmake, create:
Platform/WASI to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C://wasi-sdk-12.0/bin/clang.exe
System is unknown to cmake, create:
Platform/WASI to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Check for working C compiler: C://wasi-sdk-12.0/bin/clang.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.19/Modules/CMakeTestCCompiler.cmake:66 (message):
  The C compiler

    "C://wasi-sdk-12.0/bin/clang.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/demo/build/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/ninja.exe cmTC_ba490 && [1/2] Building C object CMakeFiles/cmTC_ba490.dir/testCCompiler.c.obj
    [2/2] Linking C executable cmTC_ba490
    FAILED: cmTC_ba490
    cmd.exe /C "cd . && C:\\wasi-sdk-12.0\bin\clang.exe --target=wasm32-wasi   CMakeFiles/cmTC_ba490.dir/testCCompiler.c.obj -o cmTC_ba490   && cd ."
    wasm-ld: error: cannot open crt1.o: no such file or directory
    wasm-ld: error: unable to find library -lc
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!
See also "C:/demo/build/CMakeFiles/CMakeOutput.log".
See also "C:/demo/build/CMakeFiles/CMakeError.log".

So it seems clang isn't picking up the sysroot. I dug around a bit and found these settings in an older version of wasi-sdk.cmake:

set(CMAKE_C_COMPILER_WORKS ON)
set(CMAKE_CXX_COMPILER_WORKS ON)
set(CMAKE_SYSROOT ${WASI_SDK_PREFIX}/share/wasi-sysroot)

Adding these to my share\cmake\wasi-sdk.cmake makes the build succeed. But these settings were removed in #161, so presumably they shouldn't be necessary anymore?

@arrisde
Copy link
Author

arrisde commented Apr 17, 2021

Btw, is there a reason why the Windows release still has mingw in its name? If I understand #164 correctly, it is now built by MSVC instead of GCC.

@sbc100
Copy link
Member

sbc100 commented Apr 17, 2021

Indeed, it looks like it was mistake to remove the CMAKE_SYSROOT from the version of wasi-sdk.cmake that is shipped.

Interestingly enough the very latest change should remove the need for explicit sysroot: 14d7b78. If we wan't for that change then we would need to add it back, but since 14d7b78 landed, the next release won't need it.

@arrisde
Copy link
Author

arrisde commented Apr 17, 2021

Just tried 14d7b78 and indeed it fixes the issue. So I'm closing and hoping for a new release soon 😄

@arrisde arrisde closed this as completed Apr 17, 2021
@rajsite
Copy link

rajsite commented Sep 20, 2021

Do we know when a new release might have these changes @sbc100 ? Alternatively are there any docs / hints for making a windows build?

@sbc100
Copy link
Member

sbc100 commented Sep 20, 2021

A new llvm due to out tomorrow (Sept 21) so we should probably do wasi-sdk release as soon as that happens.

In them an time I think you should be able to add set(CMAKE_SYSROOT ${WASI_SDK_PREFIX}/share/wasi-sysroot) to the end of share/cmake/wasi-sdk.cmake as a workaround.

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

No branches or pull requests

3 participants