Merge topic 'emscripten-try_run'

a308ea38f3 Emscripten: Fix try_run to run the `.js` file and not the adjacent `.wasm`
ad91bc558a ci: Make node available to Emscripten tests
27cc5d58bf Tests/RunCMake/Emscripten: Add tests covering try_compile COPY_FILE

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11451
This commit is contained in:
Brad King
2025-11-26 14:59:19 +00:00
committed by Kitware Robot
11 changed files with 66 additions and 13 deletions

View File

@@ -4,7 +4,8 @@ set(CMake_TEST_CXX_STANDARDS "98;11;14;17;20;23" CACHE STRING "")
if (NOT "$ENV{CMAKE_CI_NIGHTLY}" STREQUAL "")
set(CMake_TEST_IAR_TOOLCHAINS "/opt/iarsystems" CACHE PATH "")
set(CMake_TEST_TICLANG_TOOLCHAINS "$ENV{CI_PROJECT_DIR}/.gitlab/ticlang" CACHE PATH "")
set(CMake_TEST_Emscripten_TOOLCHAINS "$ENV{CI_PROJECT_DIR}/.gitlab/emsdk/upstream/emscripten" CACHE PATH "")
set(CMake_TEST_Emscripten_TOOLCHAINS "$ENV{EMSDK}/upstream/emscripten" CACHE PATH "")
set(CMake_TEST_Emscripten_NODE "$ENV{EMSDK_NODE}" CACHE PATH "")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/configure_external_test.cmake")

View File

@@ -1,7 +1,8 @@
if (NOT "$ENV{CMAKE_CI_NIGHTLY}" STREQUAL "")
set(CMake_TEST_IAR_TOOLCHAINS "/opt/iarsystems" CACHE PATH "")
set(CMake_TEST_TICLANG_TOOLCHAINS "$ENV{CI_PROJECT_DIR}/.gitlab/ticlang" CACHE PATH "")
set(CMake_TEST_Emscripten_TOOLCHAINS "$ENV{CI_PROJECT_DIR}/.gitlab/emsdk/upstream/emscripten" CACHE PATH "")
set(CMake_TEST_Emscripten_TOOLCHAINS "$ENV{EMSDK}/upstream/emscripten" CACHE PATH "")
set(CMake_TEST_Emscripten_NODE "$ENV{EMSDK_NODE}" CACHE PATH "")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/configure_external_test.cmake")

View File

@@ -1232,8 +1232,20 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
if ((res == 0) && arguments.CopyFileTo) {
std::string const& copyFile = *arguments.CopyFileTo;
std::string outputFile = this->OutputFile;
// Emscripten `.js` executables have an adjacent `.wasm` file with the
// actual compiled binary. Our COPY_FILE clients need the latter.
if (cmHasLiteralSuffix(outputFile, ".js")) {
std::string wasmOutput =
cmStrCat(outputFile.substr(0, outputFile.length() - 3), ".wasm");
if (cmSystemTools::FileExists(wasmOutput)) {
outputFile = std::move(wasmOutput);
}
}
cmsys::SystemTools::CopyStatus status =
cmSystemTools::CopyFileAlways(this->OutputFile, copyFile);
cmSystemTools::CopyFileAlways(outputFile, copyFile);
if (!status) {
std::string err = status.GetString();
switch (status.Path) {
@@ -1249,7 +1261,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
/* clang-format off */
err = cmStrCat(
"Cannot copy output executable\n"
" '", this->OutputFile, "'\n"
" '", outputFile, "'\n"
"to destination specified by COPY_FILE:\n"
" '", copyFile, "'\n"
"because:\n"
@@ -1388,14 +1400,6 @@ void cmCoreTryCompile::FindOutputFile(std::string const& targetName)
return;
}
if (cmHasLiteralSuffix(outputFileLocation, ".js")) {
std::string wasmOutputLocation = cmStrCat(
outputFileLocation.substr(0, outputFileLocation.length() - 3), ".wasm");
if (cmSystemTools::FileExists(wasmOutputLocation)) {
outputFileLocation = wasmOutputLocation;
}
}
this->OutputFile = cmSystemTools::CollapseFullPath(outputFileLocation);
}

View File

@@ -1447,7 +1447,8 @@ if (CMake_TEST_Renesas_TOOLCHAINS)
set_property(TEST RunCMake.Renesas APPEND PROPERTY LABELS "Renesas")
endif()
if(CMake_TEST_Emscripten_TOOLCHAINS)
add_RunCMake_test(Emscripten -DCMake_TEST_Emscripten_TOOLCHAINS=${CMake_TEST_Emscripten_TOOLCHAINS})
add_RunCMake_test(Emscripten -DCMake_TEST_Emscripten_TOOLCHAINS=${CMake_TEST_Emscripten_TOOLCHAINS}
-DCMake_TEST_Emscripten_NODE=${CMake_TEST_Emscripten_NODE})
set_property(TEST RunCMake.Emscripten APPEND PROPERTY LABELS "Emscripten")
endif()

View File

@@ -0,0 +1,2 @@
-- SIZEOF_INT='[1-9][0-9]*'
-- HAVE_SIZEOF_INT='TRUE'

View File

@@ -0,0 +1,6 @@
enable_language(C)
include(CheckTypeSize)
check_type_size(int SIZEOF_INT)
message(STATUS "SIZEOF_INT='${SIZEOF_INT}'")
message(STATUS "HAVE_SIZEOF_INT='${HAVE_SIZEOF_INT}'")

View File

@@ -0,0 +1,2 @@
-- CMAKE_C_BYTE_ORDER='LITTLE_ENDIAN'
-- CMAKE_C_SIZEOF_DATA_PTR='[1-9][0-9]*'

View File

@@ -0,0 +1,7 @@
enable_language(C)
foreach(var IN ITEMS
CMAKE_C_BYTE_ORDER
CMAKE_C_SIZEOF_DATA_PTR
)
message(STATUS "${var}='${${var}}'")
endforeach()

View File

@@ -0,0 +1,2 @@
-- COMPILE_RESULT='TRUE'
-- RUN_RESULT='12'

View File

@@ -0,0 +1,8 @@
enable_language(C)
try_run(RUN_RESULT
COMPILE_RESULT
SOURCE_FROM_CONTENT main.c "int main(void) { return 12; }\n"
NO_CACHE
)
message(STATUS "COMPILE_RESULT='${COMPILE_RESULT}'")
message(STATUS "RUN_RESULT='${RUN_RESULT}'")

View File

@@ -40,6 +40,12 @@ foreach(_emscripten_toolchain IN LISTS _emscripten_toolchains)
set(cxx_comp ${BIN_DIR}/em++${EMCC_SUFFIX})
set(comp_ar ${BIN_DIR}/emar${EMCC_SUFFIX})
# Compiler inspection.
run_cmake_with_options(C-enable
-DCMAKE_SYSTEM_NAME=Emscripten
-DCMAKE_C_COMPILER=${c_comp}
)
# Create an executable from .c sources only.
run_toolchain(C-exe
-DCMAKE_SYSTEM_NAME=Emscripten
@@ -76,4 +82,17 @@ foreach(_emscripten_toolchain IN LISTS _emscripten_toolchains)
)
run_cmake_target(C-WHOLE_ARCHIVE link-exe main)
run_cmake_target(C-WHOLE_ARCHIVE circular-exe main_circular)
run_cmake_with_options(C-CheckTypeSize
-DCMAKE_SYSTEM_NAME=Emscripten
-DCMAKE_C_COMPILER=${c_comp}
)
if(CMake_TEST_Emscripten_NODE)
run_cmake_with_options(C-try_run
-DCMAKE_SYSTEM_NAME=Emscripten
-DCMAKE_CROSSCOMPILING_EMULATOR=${CMake_TEST_Emscripten_NODE}
-DCMAKE_C_COMPILER=${c_comp}
)
endif()
endforeach()