Skip to content

Commit

Permalink
Enhancement of WASI_SDK_PREFIX in toolchain files (#349)
Browse files Browse the repository at this point in the history
No need to pass `WASI_SDK_PREFIX` value from the command line. Use
`CMAKE_CURRENT_LIST_DIR` to assemble the value of `WASI_SDK_PREFIX`
now.
  • Loading branch information
lum1n0us authored Sep 12, 2023
1 parent 8d4dbb1 commit 9b9708e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ includes/libraries/etc. The `--sysroot=...` option is not necessary if
`WASI_SDK_PATH` is `/opt/wasi-sdk`. For troubleshooting, one can replace the
`--sysroot` path with a manual build of [wasi-libc].

### Integrating with a CMake build system

Use a toolchain file to setup the *wasi-sdk* platform.

```
$ cmake -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_PATH}/share/cmake/wasi-sdk.cmake ...
```

or the *wasi-sdk-thread* platform

```
$ cmake -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_PATH}/share/cmake/wasi-sdk-pthread.cmake ...
```

## Notes for Autoconf

[Autoconf] 2.70 now [recognizes WASI].
Expand Down
5 changes: 5 additions & 0 deletions wasi-sdk-pthread.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ else()
set(WASI_HOST_EXE_SUFFIX "")
endif()

# When building from source, WASI_SDK_PREFIX represents the generated directory
if(NOT WASI_SDK_PREFIX)
set(WASI_SDK_PREFIX ${CMAKE_CURRENT_LIST_DIR}/../../)
endif()

set(CMAKE_C_COMPILER ${WASI_SDK_PREFIX}/bin/clang${WASI_HOST_EXE_SUFFIX})
set(CMAKE_CXX_COMPILER ${WASI_SDK_PREFIX}/bin/clang++${WASI_HOST_EXE_SUFFIX})
set(CMAKE_ASM_COMPILER ${WASI_SDK_PREFIX}/bin/clang${WASI_HOST_EXE_SUFFIX})
Expand Down
5 changes: 5 additions & 0 deletions wasi-sdk.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ else()
set(WASI_HOST_EXE_SUFFIX "")
endif()

# When building from source, WASI_SDK_PREFIX represents the generated directory
if(NOT WASI_SDK_PREFIX)
set(WASI_SDK_PREFIX ${CMAKE_CURRENT_LIST_DIR}/../../)
endif()

set(CMAKE_C_COMPILER ${WASI_SDK_PREFIX}/bin/clang${WASI_HOST_EXE_SUFFIX})
set(CMAKE_CXX_COMPILER ${WASI_SDK_PREFIX}/bin/clang++${WASI_HOST_EXE_SUFFIX})
set(CMAKE_ASM_COMPILER ${WASI_SDK_PREFIX}/bin/clang${WASI_HOST_EXE_SUFFIX})
Expand Down

0 comments on commit 9b9708e

Please sign in to comment.