From 58bfad16f6311ab91202dbb389dce9634429ac74 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Wed, 20 Nov 2024 17:58:07 -0500 Subject: [PATCH 1/4] support cmake LINK_LIBRARY:WHOLE_ARCHIVE --- cmake/Modules/Platform/Emscripten.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/Modules/Platform/Emscripten.cmake b/cmake/Modules/Platform/Emscripten.cmake index 0922fb856bcc3..0036d4c564c0b 100644 --- a/cmake/Modules/Platform/Emscripten.cmake +++ b/cmake/Modules/Platform/Emscripten.cmake @@ -279,6 +279,10 @@ set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 1) set(CMAKE_C_RESPONSE_FILE_LINK_FLAG "@") set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG "@") +# Enable $ for CMake 3.24+ +set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "-Wl,--whole-archive" "" "-Wl,--no-whole-archive") +set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED True) + # Set a global EMSCRIPTEN variable that can be used in client CMakeLists.txt to # detect when building using Emscripten. set(EMSCRIPTEN 1 CACHE INTERNAL "If true, we are targeting Emscripten output.") From c17d2b3409b47a912f5a2e3aaecd9c2f1472cfc8 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Fri, 22 Nov 2024 22:57:38 -0500 Subject: [PATCH 2/4] add test --- test/cmake/whole_archive/CMakeLists.txt | 7 +++++++ test/cmake/whole_archive/lib.cpp | 6 ++++++ test/cmake/whole_archive/main.cpp | 5 +++++ test/cmake/whole_archive/out.txt | 2 ++ test/test_other.py | 13 +++++++------ 5 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 test/cmake/whole_archive/CMakeLists.txt create mode 100644 test/cmake/whole_archive/lib.cpp create mode 100644 test/cmake/whole_archive/main.cpp create mode 100644 test/cmake/whole_archive/out.txt diff --git a/test/cmake/whole_archive/CMakeLists.txt b/test/cmake/whole_archive/CMakeLists.txt new file mode 100644 index 0000000000000..bfca4abf77568 --- /dev/null +++ b/test/cmake/whole_archive/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.24) + +project(whole) + +add_library(whole_lib STATIC lib.cpp) +add_executable(whole main.cpp) +target_link_libraries(whole $) diff --git a/test/cmake/whole_archive/lib.cpp b/test/cmake/whole_archive/lib.cpp new file mode 100644 index 0000000000000..d100a2a91f640 --- /dev/null +++ b/test/cmake/whole_archive/lib.cpp @@ -0,0 +1,6 @@ +#include + +static void init(void) __attribute__((constructor)); +static void init(void) { + std::cout << "init" << std::endl; +} diff --git a/test/cmake/whole_archive/main.cpp b/test/cmake/whole_archive/main.cpp new file mode 100644 index 0000000000000..335a966bd88a6 --- /dev/null +++ b/test/cmake/whole_archive/main.cpp @@ -0,0 +1,5 @@ +#include + +int main() { + std::cout << "main" << std::endl; +} diff --git a/test/cmake/whole_archive/out.txt b/test/cmake/whole_archive/out.txt new file mode 100644 index 0000000000000..9ac7e01535b94 --- /dev/null +++ b/test/cmake/whole_archive/out.txt @@ -0,0 +1,2 @@ +init +main diff --git a/test/test_other.py b/test/test_other.py index c0c6f33c3d1f0..f40901e4dffbf 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -909,12 +909,13 @@ def test_emstrip(self): # would take 10 minutes+ to finish (CMake feature detection is slow), so # combine multiple features into one to try to cover as much as possible # while still keeping this test in sensible time limit. - 'js': ('target_js', 'test_cmake.js', ['-DCMAKE_BUILD_TYPE=Debug']), - 'html': ('target_html', 'hello_world_gles.html', ['-DCMAKE_BUILD_TYPE=Release']), - 'library': ('target_library', 'libtest_cmake.a', ['-DCMAKE_BUILD_TYPE=MinSizeRel']), - 'static_cpp': ('target_library', 'libtest_cmake.a', ['-DCMAKE_BUILD_TYPE=RelWithDebInfo', '-DCPP_LIBRARY_TYPE=STATIC']), - 'stdproperty': ('stdproperty', 'helloworld.js', []), - 'post_build': ('post_build', 'hello.js', []), + 'js': ('target_js', 'test_cmake.js', ['-DCMAKE_BUILD_TYPE=Debug']), + 'html': ('target_html', 'hello_world_gles.html', ['-DCMAKE_BUILD_TYPE=Release']), + 'library': ('target_library', 'libtest_cmake.a', ['-DCMAKE_BUILD_TYPE=MinSizeRel']), + 'static_cpp': ('target_library', 'libtest_cmake.a', ['-DCMAKE_BUILD_TYPE=RelWithDebInfo', '-DCPP_LIBRARY_TYPE=STATIC']), + 'whole_archive': ('whole_archive', 'whole.js', []), + 'stdproperty': ('stdproperty', 'helloworld.js', []), + 'post_build': ('post_build', 'hello.js', []), }) def test_cmake(self, test_dir, output_file, cmake_args): # Test all supported generators. From b16e887a0da110ad5ea9facd4ce90451dfa3cd6f Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Sun, 24 Nov 2024 18:01:40 -0500 Subject: [PATCH 3/4] address review comments --- test/cmake/whole_archive/CMakeLists.txt | 4 ++-- test/cmake/whole_archive/lib.c | 5 +++++ test/cmake/whole_archive/lib.cpp | 6 ------ test/cmake/whole_archive/main.c | 5 +++++ test/cmake/whole_archive/main.cpp | 5 ----- 5 files changed, 12 insertions(+), 13 deletions(-) create mode 100644 test/cmake/whole_archive/lib.c delete mode 100644 test/cmake/whole_archive/lib.cpp create mode 100644 test/cmake/whole_archive/main.c delete mode 100644 test/cmake/whole_archive/main.cpp diff --git a/test/cmake/whole_archive/CMakeLists.txt b/test/cmake/whole_archive/CMakeLists.txt index bfca4abf77568..92b07b985eb66 100644 --- a/test/cmake/whole_archive/CMakeLists.txt +++ b/test/cmake/whole_archive/CMakeLists.txt @@ -2,6 +2,6 @@ cmake_minimum_required(VERSION 3.24) project(whole) -add_library(whole_lib STATIC lib.cpp) -add_executable(whole main.cpp) +add_library(whole_lib STATIC lib.c) +add_executable(whole main.c) target_link_libraries(whole $) diff --git a/test/cmake/whole_archive/lib.c b/test/cmake/whole_archive/lib.c new file mode 100644 index 0000000000000..f68845002a080 --- /dev/null +++ b/test/cmake/whole_archive/lib.c @@ -0,0 +1,5 @@ +#include + +__attribute__((constructor)) void init(void) { + printf("init\n"); +} diff --git a/test/cmake/whole_archive/lib.cpp b/test/cmake/whole_archive/lib.cpp deleted file mode 100644 index d100a2a91f640..0000000000000 --- a/test/cmake/whole_archive/lib.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -static void init(void) __attribute__((constructor)); -static void init(void) { - std::cout << "init" << std::endl; -} diff --git a/test/cmake/whole_archive/main.c b/test/cmake/whole_archive/main.c new file mode 100644 index 0000000000000..76929edbaa08e --- /dev/null +++ b/test/cmake/whole_archive/main.c @@ -0,0 +1,5 @@ +#include + +int main() { + printf("main\n"); +} diff --git a/test/cmake/whole_archive/main.cpp b/test/cmake/whole_archive/main.cpp deleted file mode 100644 index 335a966bd88a6..0000000000000 --- a/test/cmake/whole_archive/main.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include - -int main() { - std::cout << "main" << std::endl; -} From c4961819c3acb524baf93c78cf6bae6f83017bea Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Wed, 27 Nov 2024 22:14:46 -0500 Subject: [PATCH 4/4] skip test in test-other job --- .circleci/config.yml | 1 + test/test_other.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 92d3d1e352277..c0536063facaa 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -799,6 +799,7 @@ jobs: EMTEST_SKIP_NODE_CANARY: "1" EMTEST_SKIP_RUST: "1" EMTEST_SKIP_WASM64: "1" + EMTEST_SKIP_NEW_CMAKE: "1" steps: - install-rust - run: apt-get install -q -y ninja-build scons ccache diff --git a/test/test_other.py b/test/test_other.py index cc7cbbe287caa..36d1ca40d26b8 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -922,6 +922,9 @@ def test_emstrip(self): 'post_build': ('post_build', 'hello.js', []), }) def test_cmake(self, test_dir, output_file, cmake_args): + if test_dir == 'whole_archive' and 'EMTEST_SKIP_NEW_CMAKE' in os.environ: + self.skipTest('EMTEST_SKIP_NEW_CMAKE set') + # Test all supported generators. if WINDOWS: generators = ['MinGW Makefiles', 'NMake Makefiles']