Skip to content
Merged
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
32 changes: 25 additions & 7 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

- name: Setup MacOS
if: startsWith(matrix.os, 'macOS')
run: brew install automake autoconf ninja cmake
run: brew upgrade && brew install automake autoconf ninja cmake emscripten wasi-libc wasi-runtimes llvm

- name: Setup Ubuntu
if: startsWith(matrix.os, 'ubuntu')
Expand All @@ -41,15 +41,33 @@ jobs:
uses: lukka/run-cmake@v10
id: runcmake-ninja
with:
configurePreset: 'ninja'
buildPreset: 'ninja-release'
testPreset: 'ninja-release'
configurePreset: "ninja"
buildPreset: "ninja-release"
testPreset: "ninja-release"

- name: Run CMake+MSVC+CTest to generate/build/test.
uses: lukka/run-cmake@v10
if: startsWith(matrix.os, 'win')
id: runcmake-msvc
with:
configurePreset: 'msvc'
buildPreset: 'msvc-release'
testPreset: 'msvc-release'
configurePreset: "msvc"
buildPreset: "msvc-release"
testPreset: "msvc-release"

- name: Build emscripten plugin template.
uses: lukka/run-cmake@v10
if: startsWith(matrix.os, 'macOS')
id: runcmake-emscripten
with:
configurePreset: "emscripten"
buildPreset: "emscripten-release"

# TODO: enable it, unfortunately it currently fails (only on github, not my on OS) with:
# clang: error: unable to execute command: posix_spawn failed: No such file or directory
# - name: Build wasi plugin template.
# uses: lukka/run-cmake@v10
# if: startsWith(matrix.os, 'macOS')
# id: runcmake-wasi
# with:
# configurePreset: "wasi"
# buildPreset: "wasi-release"
15 changes: 12 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,22 @@ if (${CLAP_BUILD_TESTS})
clap_compile_cpp(cpp11 cc 11 11)
clap_compile_cpp(cpp14 cc 11 14)
if(${CMAKE_VERSION} VERSION_LESS "3.21")
message(STATUS "Skipping C17 tests due to older CMAKE_VERSION ${CMAKE_VERSION}")
message(STATUS "Skipping C17 tests due to older CMAKE_VERSION ${CMAKE_VERSION}")
else()
clap_compile_cpp(c17 c 17 17)
clap_compile_cpp(c17 c 17 17)
endif()
clap_compile_cpp(cpp17 cc 17 17)
clap_compile_cpp(cpp20 cc 17 20)

check_include_file(threads.h CLAP_HAS_THREADS_H)

add_library(clap-plugin-template MODULE EXCLUDE_FROM_ALL src/plugin-template.c)
if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
set(CLAP_LIBRARY_TYPE STATIC)
else()
set(CLAP_LIBRARY_TYPE MODULE)
endif()

add_library(clap-plugin-template ${CLAP_LIBRARY_TYPE} EXCLUDE_FROM_ALL src/plugin-template.c)
target_link_libraries(clap-plugin-template PRIVATE clap)
set_target_properties(clap-plugin-template PROPERTIES C_STANDARD 11)
add_dependencies(clap-tests clap-plugin-template)
Expand All @@ -114,5 +120,8 @@ if (${CLAP_BUILD_TESTS})
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set_target_properties(clap-plugin-template PROPERTIES SUFFIX ".clap" PREFIX "")
elseif(CMAKE_SYSTEM_NAME STREQUAL "WASI" OR CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
target_link_options(clap-plugin-template PRIVATE --no-entry)
endif()

endif()
58 changes: 55 additions & 3 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,42 @@
"value": true
}
}
},
{
"name": "wasi",
"displayName": "Ninja Clang WASM32/WASI",
"description": "Configure and generate Ninja project files for all configurations, using clang and targetting wasm32 and wasi",
"binaryDir": "${sourceDir}/builds/${presetName}",
"generator": "Ninja Multi-Config",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": {
"type": "boolean",
"value": true
},
"CLAP_BUILD_TESTS": {
"type": "boolean",
"value": true
},
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/clang-wasm32-wasi.cmake"
}
},
{
"name": "emscripten",
"displayName": "emscripten",
"description": "Configure and generate Ninja project files for all configurations, using emscripten",
"binaryDir": "${sourceDir}/builds/${presetName}",
"generator": "Ninja Multi-Config",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": {
"type": "boolean",
"value": true
},
"CLAP_BUILD_TESTS": {
"type": "boolean",
"value": true
},
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/emscripten.cmake"
}
}
],
"buildPresets": [
Expand All @@ -48,15 +84,31 @@
"displayName": "Build ninja-release",
"description": "Build ninja Release configuration",
"configuration": "RelWithDebInfo",
"targets": ["clap-tests"]
"targets": ["clap-tests", "clap-plugin-template"]
},
{
"name": "msvc-release",
"configurePreset": "msvc",
"displayName": "Build msvc-release",
"description": "Build msvc Release configuration",
"configuration": "RelWithDebInfo",
"targets": ["clap-tests"]
"targets": ["clap-tests", "clap-plugin-template"]
},
{
"name": "wasi-release",
"configurePreset": "wasi",
"displayName": "Build wasi-release",
"description": "Build wasi Release configuration",
"configuration": "RelWithDebInfo",
"targets": ["clap-tests", "clap-plugin-template"]
},
{
"name": "emscripten-release",
"configurePreset": "emscripten",
"displayName": "Build emscripten-release",
"description": "Build emscripten Release configuration",
"configuration": "RelWithDebInfo",
"targets": ["clap-tests", "clap-plugin-template"]
}
],
"testPresets": [
Expand All @@ -71,4 +123,4 @@
"configuration": "RelWithDebInfo"
}
]
}
}
31 changes: 31 additions & 0 deletions cmake/toolchains/clang-wasm32-wasi.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Simple toolchain example that targets wasm32 using wasi
# On archlinux:
# pacman -S clang wasi-compiler-rt wasi-libc wasi-libc++ wasi-libc++abi
# On macOS:
# homebrew install wasi-libc wasi-runtimes llvm
#
# For other OSes, make a copy of this file and do the necessary adjustments.

set(CMAKE_SYSTEM_NAME "WASI")
set(CMAKE_CROSSCOMPILING TRUE)

set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")

if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux)
set(CMAKE_SYSROOT "/usr/share/wasi-sysroot")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)
set(CMAKE_SYSROOT "/opt/homebrew/share/wasi-sysroot")
set(CMAKE_C_COMPILER "/opt/homebrew/opt/llvm/bin/clang")
set(CMAKE_CXX_COMPILER "/opt/homebrew/opt/llvm/bin/clang++")
set(CMAKE_RANLIB "/opt/homebrew/opt/llvm/bin/llvm-ranlib")
endif()

# -nostdlib
set(CMAKE_C_FLAGS_INIT "--target=wasm32-wasi")
set(CMAKE_CXX_FLAGS_INIT "--target=wasm32-wasi")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,--export-all -Wl,--no-entry -lpthread")
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-Wl,--export-all -Wl,--no-entry -lpthread")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-Wl,--export-all -Wl,--no-entry -lpthread")

set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
21 changes: 21 additions & 0 deletions cmake/toolchains/emscripten.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Simple toolchain example that targets wasm32 using emscripten
# On archlinux:
# pacman -S clang emscripten
# On macOS:
# brew install emscripten
#
# For other OSes, make a copy of this file and do the necessary adjustments.

set(CMAKE_SYSTEM_NAME "Emscripten")
set(CMAKE_CROSSCOMPILING TRUE)

if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux)
set(CMAKE_C_COMPILER "/usr/lib/emscripten/emcc")
set(CMAKE_CXX_COMPILER "/usr/lib/emscripten/em++")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)
set(CMAKE_C_COMPILER "/opt/homebrew/bin/emcc")
set(CMAKE_CXX_COMPILER "/opt/homebrew/bin/em++")
else()
set(CMAKE_C_COMPILER "emcc")
set(CMAKE_CXX_COMPILER "em++")
endif()
2 changes: 1 addition & 1 deletion src/plugin-template.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdio.h>
#include <assert.h>

#if __STDC_VERSION__ >= 201112L && !defined (__STDC_NO_THREADS__) && defined (CLAP_HAS_THREADS_H)
#if __STDC_VERSION__ >= 201112L && !defined (__STDC_NO_THREADS__) && defined (CLAP_HAS_THREADS_H) && !defined (__wasi__)
# define CLAP_HAS_THREAD
# include <threads.h>
#endif
Expand Down
Loading