Skip to content

Truly independent web browser

2.4 KB
Raw Blame
#
# Download and compile the WebAssembly testsuite into the WebAssembly binary format
#

if(INCLUDE_WASM_SPEC_TESTS)
    set(WASM_SPEC_TEST_COMMIT 4b24564c844e3d34bf46dfcb3c774ee5163e31cc) # 2025-09-10
    set(WASM_SPEC_TEST_GZ_URL https://github.com/WebAssembly/testsuite/archive/${WASM_SPEC_TEST_COMMIT}.tar.gz)
    set(WASM_SPEC_TEST_GZ_PATH ${LADYBIRD_CACHE_DIR}/WasmSpecTests/wasm-spec-testsuite-${WASM_SPEC_TEST_COMMIT}.tar.gz CACHE PATH "")
    set(WASM_SPEC_TEST_PATH ${CMAKE_CURRENT_BINARY_DIR}/Tests/Fixtures/SpecTests CACHE PATH "")

    download_file(${WASM_SPEC_TEST_GZ_URL} ${WASM_SPEC_TEST_GZ_PATH})

    set(SKIP_PRETTIER false)
    if (WASM_SPEC_TEST_SKIP_FORMATTING)
        set(SKIP_PRETTIER true)
    endif()

    find_program(WASMTOOLS wasm-tools REQUIRED)
    find_program(PRETTIER prettier OPTIONAL)
    if (NOT SKIP_PRETTIER AND PRETTIER EQUAL "PRETTIER-NOTFOUND")
       message(FATAL_ERROR "Prettier required to format Wasm spec tests! Install prettier or set WASM_SPEC_TEST_SKIP_FORMATTING to ON")
    endif()

    if(EXISTS ${WASM_SPEC_TEST_GZ_PATH} AND NOT EXISTS ${WASM_SPEC_TEST_PATH}/const.0.wasm)
        message(STATUS "Extracting the WebAssembly testsuite from ${WASM_SPEC_TEST_GZ_PATH}...")
        extract_path("${CMAKE_CURRENT_BINARY_DIR}" "${WASM_SPEC_TEST_GZ_PATH}" "testsuite-${WASM_SPEC_TEST_COMMIT}/*.wast" "${WASM_SPEC_TEST_PATH}")
        file(MAKE_DIRECTORY ${WASM_SPEC_TEST_PATH})
        file(GLOB WASM_TESTS "${CMAKE_CURRENT_BINARY_DIR}/testsuite-${WASM_SPEC_TEST_COMMIT}/*.wast")
        # The tests of the legacy exception handling instructions are in a directory of their own, and share names with
        # the current ones.
        file(GLOB WASM_LEGACY_TESTS "${CMAKE_CURRENT_BINARY_DIR}/testsuite-${WASM_SPEC_TEST_COMMIT}/legacy/*.wast")
        foreach(PATH ${WASM_TESTS} ${WASM_LEGACY_TESTS})
            get_filename_component(NAME ${PATH} NAME_WLE)
            if (PATH IN_LIST WASM_LEGACY_TESTS)
                set(NAME "legacy_${NAME}")
            endif()
            message(STATUS "Generating test cases for WebAssembly test ${NAME}...")
            execute_process(
                COMMAND env SKIP_PRETTIER=${SKIP_PRETTIER} bash ${LADYBIRD_SOURCE_DIR}/Meta/Generators/generate_libwasm_spec_test.sh "${PATH}" "${CMAKE_CURRENT_BINARY_DIR}/Tests/Spec" "${NAME}" "${WASM_SPEC_TEST_PATH}")
        endforeach()
        file(REMOVE testsuite-${WASM_SPEC_TEST_COMMIT})
    endif()
endif()