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

[WIP] Add CMake build system #330

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,27 @@ jobs:

- name: Build libc
shell: bash
run: make -j4
run: |
cmake -DCMAKE_INSTALL_PREFIX=install-sysroot .
cmake --build . --target install
ctest

- uses: actions/upload-artifact@v1
with:
# Upload the sysroot folder. Give it a name according to the OS it was built for.
name: ${{ format( 'sysroot-{0}.tgz', matrix.os) }}
path: sysroot
path: install-sysroot

- name: Build libc + threads
# Only build the thread-capable wasi-libc in the latest supported Clang
# version; the earliest version does not have all necessary builtins
# (e.g., `__builtin_wasm_memory_atomic_notify`).
if: matrix.clang_version != '10.0.0'
shell: bash
run: make -j4 THREAD_MODEL=posix
run: |
cmake -DCMAKE_INSTALL_PREFIX=install-sysroot -DTHREAD_MODEL=posix .
cmake --build . --target install
ctest

# Disable the headerstest job for now, while WASI transitions from the
# witx snapshots to wit proposals, and we have a few manual edits to the
Expand Down
32 changes: 32 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
cmake_minimum_required(VERSION 3.16.3)

project(wasi-libc LANGUAGES C)

enable_testing()

if("${CMAKE_C_COMPILER}" MATCHES "(.*)clang(-[0-9]+)?$")
set(CMAKE_NM "${CMAKE_MATCH_1}llvm-nm${CMAKE_MATCH_2}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend against this. This prevents the user from specifying the name tool to use.

endif()

find_package(Python COMPONENTS Interpreter REQUIRED)

set(TARGET_TRIPLE wasm32-wasi)
set(MULTIARCH_TRIPLE wasm32-wasi)

set(CMAKE_C_COMPILER_TARGET ${TARGET_TRIPLE} CACHE STRING "The target to compile for")

# note that pthread support is still a work-in-progress.
set(THREAD_MODEL "single" CACHE STRING "single or posix")

set(MALLOC_IMPL "dlmalloc" CACHE STRING "dlmalloc or none")

option(BUILD_LIBC_TOP_HALF "Build libc top half" ON)

# When the length is no larger than this threshold, we consider the
# overhead of bulk memory opcodes to outweigh the performance benefit,
# and fall back to the original musl implementation. See
# https://github.com/WebAssembly/wasi-libc/pull/263 for relevant
# discussion
set(BULK_MEMORY_THRESHOLD "32" CACHE STRING "bulk memory threshold")

add_subdirectory(cmake)
Loading