Skip to content

Commit

Permalink
minimal setup for wasm ci
Browse files Browse the repository at this point in the history
  • Loading branch information
DerThorsten committed Sep 18, 2023
1 parent b9a6bcc commit df3b24e
Show file tree
Hide file tree
Showing 6 changed files with 388 additions and 151 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/emscripten.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Emscripten build
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- uses: mamba-org/setup-micromamba@v1
with:
environment-name: xsimd
create-args: >-
microsoft::playwright
python
- name: Build script
run: |
echo "Build script for wasm"
playwright install
./test/test_wasm/test_wasm.sh
317 changes: 166 additions & 151 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,175 +35,190 @@ OPTION(XSIMD_ENABLE_WERROR "Turn on -Werror" OFF)



################
# ARM SETTINGS #
################

OPTION(CROSS_COMPILE_ARM "cross compile for ARM targets" OFF)

# Note: to compile on ARM (or cross compile), you may need to add the following:
# -DTARGET_ARCH="armv8-a -mfpu=neon -mfloat-abi=softfp -target arm-linux-gnueabi"
set(TARGET_ARCH "native" CACHE STRING "Target architecture arguments")

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
if (NOT WIN32 AND NOT ANDROID)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-parameter -Wextra -Wreorder")
# Users may override the c++ standard:
if(NOT DEFINED CMAKE_CXX_STANDARD OR "${CMAKE_CXX_STANDARD}" STREQUAL "")
if (ENABLE_XTL_COMPLEX)
CHECK_CXX_COMPILER_FLAG("-std=c++14" HAS_CPP14_FLAG)
if (NOT HAS_CPP14_FLAG)
message(FATAL_ERROR "Unsupported compiler -- xsimd requires C++14 support when xtl complex support is enabled")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else()
CHECK_CXX_COMPILER_FLAG("-std=c++11" HAS_CPP11_FLAG)
if (NOT HAS_CPP11_FLAG)
message(FATAL_ERROR "Unsupported compiler -- xsimd requires C++11 support!")
if(NOT EMSCRIPTEN)
################
# ARM SETTINGS #
################

OPTION(CROSS_COMPILE_ARM "cross compile for ARM targets" OFF)

# Note: to compile on ARM (or cross compile), you may need to add the following:
# -DTARGET_ARCH="armv8-a -mfpu=neon -mfloat-abi=softfp -target arm-linux-gnueabi"
set(TARGET_ARCH "native" CACHE STRING "Target architecture arguments")

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
if (NOT WIN32 AND NOT ANDROID)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-parameter -Wextra -Wreorder")
# Users may override the c++ standard:
if(NOT DEFINED CMAKE_CXX_STANDARD OR "${CMAKE_CXX_STANDARD}" STREQUAL "")
if (ENABLE_XTL_COMPLEX)
CHECK_CXX_COMPILER_FLAG("-std=c++14" HAS_CPP14_FLAG)
if (NOT HAS_CPP14_FLAG)
message(FATAL_ERROR "Unsupported compiler -- xsimd requires C++14 support when xtl complex support is enabled")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
CHECK_CXX_COMPILER_FLAG("-std=c++11" HAS_CPP11_FLAG)
if (NOT HAS_CPP11_FLAG)
message(FATAL_ERROR "Unsupported compiler -- xsimd requires C++11 support!")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
endif()
endif()

if (NOT CROSS_COMPILE_ARM)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fPIC")
endif()
endif()

if (NOT CROSS_COMPILE_ARM)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fPIC")
if (ANDROID)
# Nothing to do here, we assume the cmake Android NDK toolchain sets the
# correct options for arm and neon.
elseif (CROSS_COMPILE_ARM)
# We're cross-compiling with clang++ on Azure Pipelines, this is all pretty specific and just for testing
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
set(CMAKE_THREAD_LIBS_INIT)

set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER_TARGET arm-linux-gnueabi)
set(CMAKE_CXX_COMPILER_TARGET arm-linux-gnueabi)

set(ARM_ARCH_DIRECTORY "arm-linux-gnueabi" CACHE STRING "ARM arch header dir")
set(ARM_GCC_VER "4.7.3" CACHE STRING "ARM GCC header dir")
include_directories(/usr/${ARM_ARCH_DIRECTORY}/include/c++/${ARM_GCC_VER}/${ARM_ARCH_DIRECTORY}/)
include_directories(/usr/${ARM_ARCH_DIRECTORY}/include/c++/${ARM_GCC_VER}/)
include_directories(/usr/${ARM_ARCH_DIRECTORY}/include/)
if(NOT CMAKE_CXX_FLAGS MATCHES "-march")
message(STATUS "SETTING ARCH TO ${TARGET_ARCH}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${TARGET_ARCH}")
endif()
if(ARM_ARCH_DIRECTORY MATCHES "arm-linux-gnueabi")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -mfloat-abi=softfp -target arm-linux-gnueabi")
else ()
# delegating to gcc here
endif()
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message(STATUS "CMAKE_CXX_LINK_EXECUTABLE: ${CMAKE_CXX_LINK_EXECUTABLE}")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^ppc64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=${TARGET_ARCH} -mtune=${TARGET_ARCH}")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "riscv64")
# Nothing specific
elseif(NOT WIN32)
if(NOT CMAKE_CXX_FLAGS MATCHES "-march" AND NOT CMAKE_CXX_FLAGS MATCHES "-arch" AND NOT CMAKE_OSX_ARCHITECTURES)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${TARGET_ARCH}")
endif()
endif()
endif()

if (ANDROID)
# Nothing to do here, we assume the cmake Android NDK toolchain sets the
# correct options for arm and neon.
elseif (CROSS_COMPILE_ARM)
# We're cross-compiling with clang++ on Azure Pipelines, this is all pretty specific and just for testing
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
set(CMAKE_THREAD_LIBS_INIT)

set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER_TARGET arm-linux-gnueabi)
set(CMAKE_CXX_COMPILER_TARGET arm-linux-gnueabi)

set(ARM_ARCH_DIRECTORY "arm-linux-gnueabi" CACHE STRING "ARM arch header dir")
set(ARM_GCC_VER "4.7.3" CACHE STRING "ARM GCC header dir")
include_directories(/usr/${ARM_ARCH_DIRECTORY}/include/c++/${ARM_GCC_VER}/${ARM_ARCH_DIRECTORY}/)
include_directories(/usr/${ARM_ARCH_DIRECTORY}/include/c++/${ARM_GCC_VER}/)
include_directories(/usr/${ARM_ARCH_DIRECTORY}/include/)
if(NOT CMAKE_CXX_FLAGS MATCHES "-march")
message(STATUS "SETTING ARCH TO ${TARGET_ARCH}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${TARGET_ARCH}")
endif()
if(ARM_ARCH_DIRECTORY MATCHES "arm-linux-gnueabi")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -mfloat-abi=softfp -target arm-linux-gnueabi")
else ()
# delegating to gcc here
endif()
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message(STATUS "CMAKE_CXX_LINK_EXECUTABLE: ${CMAKE_CXX_LINK_EXECUTABLE}")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^ppc64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=${TARGET_ARCH} -mtune=${TARGET_ARCH}")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "riscv64")
# Nothing specific
elseif(NOT WIN32)
if(NOT CMAKE_CXX_FLAGS MATCHES "-march" AND NOT CMAKE_CXX_FLAGS MATCHES "-arch" AND NOT CMAKE_OSX_ARCHITECTURES)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${TARGET_ARCH}")
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /bigobj")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4267 /wd4005 /wd4146 /wd4800")
set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
endif()
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /bigobj")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4267 /wd4005 /wd4146 /wd4800")
set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES Clang AND MSVC AND WIN32) # We are using clang-cl
add_compile_options(/EHsc /bigobj)
set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES Clang AND MSVC AND WIN32) # We are using clang-cl
add_compile_options(/EHsc /bigobj)
set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
endif()
set(XSIMD_TESTS
main.cpp
test_api.cpp
test_arch.cpp
test_basic_math.cpp
test_batch.cpp
test_batch_bool.cpp
test_batch_cast.cpp
test_batch_complex.cpp
test_batch_float.cpp
test_batch_int.cpp
test_bitwise_cast.cpp
test_batch_constant.cpp
test_batch_manip.cpp
test_complex_exponential.cpp
test_complex_hyperbolic.cpp
test_complex_power.cpp
test_complex_trigonometric.cpp
test_conversion.cpp
test_custom_default_arch.cpp
test_error_gamma.cpp
test_explicit_batch_instantiation.cpp
test_exponential.cpp
test_extract_pair.cpp
test_fp_manipulation.cpp
test_hyperbolic.cpp
test_load_store.cpp
test_memory.cpp
test_poly_evaluation.cpp
test_power.cpp
test_rounding.cpp
test_select.cpp
test_shuffle.cpp
test_sum.cpp
test_traits.cpp
test_trigonometric.cpp
test_xsimd_api.cpp
test_utils.hpp
)

if(NOT MSVC)
list(APPEND XSIMD_TESTS test_gnu_source.cpp)
endif()

set(XSIMD_TESTS
main.cpp
test_api.cpp
test_arch.cpp
test_basic_math.cpp
test_batch.cpp
test_batch_bool.cpp
test_batch_cast.cpp
test_batch_complex.cpp
test_batch_float.cpp
test_batch_int.cpp
test_bitwise_cast.cpp
test_batch_constant.cpp
test_batch_manip.cpp
test_complex_exponential.cpp
test_complex_hyperbolic.cpp
test_complex_power.cpp
test_complex_trigonometric.cpp
test_conversion.cpp
test_custom_default_arch.cpp
test_error_gamma.cpp
test_explicit_batch_instantiation.cpp
test_exponential.cpp
test_extract_pair.cpp
test_fp_manipulation.cpp
test_hyperbolic.cpp
test_load_store.cpp
test_memory.cpp
test_poly_evaluation.cpp
test_power.cpp
test_rounding.cpp
test_select.cpp
test_shuffle.cpp
test_sum.cpp
test_traits.cpp
test_trigonometric.cpp
test_xsimd_api.cpp
test_utils.hpp
)

if(NOT MSVC)
list(APPEND XSIMD_TESTS test_gnu_source.cpp)
endif()
add_executable(test_xsimd ${XSIMD_TESTS} ${XSIMD_HEADERS})
target_include_directories(test_xsimd PRIVATE ${XSIMD_INCLUDE_DIR})

add_executable(test_xsimd ${XSIMD_TESTS} ${XSIMD_HEADERS})
target_include_directories(test_xsimd PRIVATE ${XSIMD_INCLUDE_DIR})
option(XSIMD_DOWNLOAD_DOCTEST OFF)
find_package(doctest QUIET)
if (doctest_FOUND)
set(DOCTEST_MINIMAL_VERSION 2.4.9)
if (doctest_VERSION VERSION_LESS DOCTEST_MINIMAL_VERSION)
message(FATAL_ERROR "Requires doctest >= ${DOCTEST_MINIMAL_VERSION}")
endif()
target_link_libraries(test_xsimd PRIVATE doctest::doctest)
elseif(DOWNLOAD_DOCTEST)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doctest")
file(DOWNLOAD
"https://github.com/doctest/doctest/releases/download/v2.4.9/doctest.h"
"${CMAKE_CURRENT_BINARY_DIR}/doctest/doctest.h")
target_include_directories(test_xsimd PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
else()
message(FATAL_ERROR "
Cannot find required doctest component.
Please either set CMAKE_PREFIX_PATH to the location of doctestConfig.cmake,
or set DOWNLOAD_DOCTEST=ON")
endif()

option(XSIMD_DOWNLOAD_DOCTEST OFF)
find_package(doctest QUIET)
if (doctest_FOUND)
set(DOCTEST_MINIMAL_VERSION 2.4.9)
if (doctest_VERSION VERSION_LESS DOCTEST_MINIMAL_VERSION)
message(FATAL_ERROR "Requires doctest >= ${DOCTEST_MINIMAL_VERSION}")
if(ENABLE_XTL_COMPLEX)
target_include_directories(test_xsimd PRIVATE ${xtl_INCLUDE_DIRS})
endif()
target_link_libraries(test_xsimd PRIVATE doctest::doctest)
elseif(DOWNLOAD_DOCTEST)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doctest")
file(DOWNLOAD
"https://github.com/doctest/doctest/releases/download/v2.4.9/doctest.h"
"${CMAKE_CURRENT_BINARY_DIR}/doctest/doctest.h")
target_include_directories(test_xsimd PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
else()
message(FATAL_ERROR "
Cannot find required doctest component.
Please either set CMAKE_PREFIX_PATH to the location of doctestConfig.cmake,
or set DOWNLOAD_DOCTEST=ON")
endif()
add_test(NAME test_xsimd COMMAND test_xsimd)

if(ENABLE_XTL_COMPLEX)
target_include_directories(test_xsimd PRIVATE ${xtl_INCLUDE_DIRS})
endif()
add_test(NAME test_xsimd COMMAND test_xsimd)
if (CROSS_COMPILE_ARM)
add_custom_target(xtest COMMAND qemu-arm -L /usr/arm-linux-gnueabi/ test_xsimd DEPENDS test_xsimd)
else()
add_executable(test_xsimd_wasm xsimd_wasm.cpp)
endif()

if (XSIMD_ENABLE_WERROR)
target_compile_options(test_xsimd PRIVATE -Werror -Wall -DXSIMD_SKIP_ON_WERROR)
endif()

if (CROSS_COMPILE_ARM)
add_custom_target(xtest COMMAND qemu-arm -L /usr/arm-linux-gnueabi/ test_xsimd DEPENDS test_xsimd)
add_subdirectory(doc)
else()
add_custom_target(xtest COMMAND test_xsimd DEPENDS test_xsimd)
endif()
add_executable(test_xsimd_wasm test_wasm/test_wasm.cpp)
target_include_directories(test_xsimd_wasm PRIVATE ${XSIMD_INCLUDE_DIR})

if (XSIMD_ENABLE_WERROR)
target_compile_options(test_xsimd PRIVATE -Werror -Wall -DXSIMD_SKIP_ON_WERROR)
endif()
# set compile flgs -msimd128

add_subdirectory(doc)
target_compile_options(test_xsimd_wasm
PUBLIC --std=c++17
PUBLIC "SHELL: -msimd128"
)
# add flags embind, modularize


set_target_properties(test_xsimd_wasm PROPERTIES LINK_FLAGS "-s MODULARIZE=1 -s EXPORT_NAME=test_xsimd_wasm -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -lembind")
endif()
12 changes: 12 additions & 0 deletions test/test_wasm/browser_main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>TEST_TITLE</title>
<link rel="stylesheet" href="style.css">
<script src="test_xsimd_wasm.js"></script>
</head>
<body>
<!-- page content -->
</body>
</html>
Loading

0 comments on commit df3b24e

Please sign in to comment.