From d35486cb74175b1e598e829d6307d2d1dd695813 Mon Sep 17 00:00:00 2001 From: ayeteadoe Date: Mon, 12 May 2025 07:11:19 -0700 Subject: [PATCH] LibTest: Explicitly export symbols --- Libraries/LibTest/CMakeLists.txt | 1 + Libraries/LibTest/CrashTest.h | 3 ++- Libraries/LibTest/Macros.h | 15 ++++++++------- Libraries/LibTest/TestCase.h | 8 ++++---- Libraries/LibTest/TestResult.h | 4 +++- Libraries/LibTest/TestSuite.h | 3 ++- Meta/Lagom/CMakeLists.txt | 24 +++++++++++++----------- 7 files changed, 33 insertions(+), 25 deletions(-) diff --git a/Libraries/LibTest/CMakeLists.txt b/Libraries/LibTest/CMakeLists.txt index f0974e4e520..59c288c3614 100644 --- a/Libraries/LibTest/CMakeLists.txt +++ b/Libraries/LibTest/CMakeLists.txt @@ -9,5 +9,6 @@ set(SOURCES ) add_library(LibTest ${SOURCES}) +lagom_generate_export_header(LibTest test) target_link_libraries(LibTest PRIVATE AK LibCore LibFileSystem) set_target_properties(LibTest PROPERTIES OUTPUT_NAME lagom-test) diff --git a/Libraries/LibTest/CrashTest.h b/Libraries/LibTest/CrashTest.h index 1de2d793e96..b5d94733f0a 100644 --- a/Libraries/LibTest/CrashTest.h +++ b/Libraries/LibTest/CrashTest.h @@ -11,10 +11,11 @@ #include #include #include +#include namespace Test { -class Crash { +class TEST_API Crash { public: enum class RunType { UsingChildProcess, diff --git a/Libraries/LibTest/Macros.h b/Libraries/LibTest/Macros.h index d656bbb0312..0a088abcae6 100644 --- a/Libraries/LibTest/Macros.h +++ b/Libraries/LibTest/Macros.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -19,16 +20,16 @@ namespace Test { // Declare helpers so that we can call them from VERIFY in included headers // the setter for TestResult is already declared in TestResult.h -TestResult current_test_result(); +TEST_API TestResult current_test_result(); -Randomized::RandomnessSource& randomness_source(); -void set_randomness_source(Randomized::RandomnessSource); +TEST_API Randomized::RandomnessSource& randomness_source(); +TEST_API void set_randomness_source(Randomized::RandomnessSource); -bool is_reporting_enabled(); -void enable_reporting(); -void disable_reporting(); +TEST_API bool is_reporting_enabled(); +TEST_API void enable_reporting(); +TEST_API void disable_reporting(); -u64 randomized_runs(); +TEST_API u64 randomized_runs(); template void expect(T const& expression, StringView expression_string, SourceLocation location = SourceLocation::current()) diff --git a/Libraries/LibTest/TestCase.h b/Libraries/LibTest/TestCase.h index 275c9336461..26f3934cb0f 100644 --- a/Libraries/LibTest/TestCase.h +++ b/Libraries/LibTest/TestCase.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -29,7 +30,7 @@ inline void run_with_randomness_source(Randomized::RandomnessSource source, Test } } -class TestCase : public RefCounted { +class TEST_API TestCase : public RefCounted { public: TestCase(ByteString const& name, TestFunction&& fn, bool is_benchmark) : m_name(name) @@ -107,9 +108,8 @@ private: }; // Helper to hide implementation of TestSuite from users -void add_test_case_to_suite(NonnullRefPtr const& test_case); -void set_suite_setup_function(Function setup); - +TEST_API void add_test_case_to_suite(NonnullRefPtr const& test_case); +TEST_API void set_suite_setup_function(Function setup); } #define TEST_SETUP \ diff --git a/Libraries/LibTest/TestResult.h b/Libraries/LibTest/TestResult.h index 513a60e5d57..71c8a33e5ff 100644 --- a/Libraries/LibTest/TestResult.h +++ b/Libraries/LibTest/TestResult.h @@ -6,6 +6,8 @@ #pragma once +#include + namespace Test { // TestResult signals to the TestSuite how the TestCase execution went. @@ -30,6 +32,6 @@ enum class TestResult { // Used eg. to signal we've ran out of prerecorded random bits. // Defined in TestSuite.cpp -void set_current_test_result(TestResult); +void TEST_API set_current_test_result(TestResult); } // namespace Test diff --git a/Libraries/LibTest/TestSuite.h b/Libraries/LibTest/TestSuite.h index c293a771826..0264b6088ee 100644 --- a/Libraries/LibTest/TestSuite.h +++ b/Libraries/LibTest/TestSuite.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -18,7 +19,7 @@ namespace Test { -class TestSuite { +class TEST_API TestSuite { public: static TestSuite& the() { diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index bee87202368..458432bf226 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -178,6 +178,18 @@ if (WIN32) find_package(mman REQUIRED) endif() +function(lagom_generate_export_header name fs_name) + # Temporary helper to allow libraries to opt-in to using X_API macros + # to export symbols required by external consumers. This allows the codebase + # to gradually slowly migrate instead of an all-or-nothing approach. + if (NOT WIN32) + target_compile_options(${name} PRIVATE -fvisibility=hidden) + endif() + include(GenerateExportHeader) + string(TOUPPER ${fs_name} fs_name_upper) + generate_export_header(${name} EXPORT_MACRO_NAME ${fs_name_upper}_API EXPORT_FILE_NAME "Export.h") +endfunction() + function(lagom_lib target_name fs_name) cmake_parse_arguments(LAGOM_LIBRARY "EXPLICIT_SYMBOL_EXPORT" "LIBRARY_TYPE" "SOURCES;LIBS" ${ARGN}) string(REPLACE "Lib" "" library ${target_name}) @@ -225,18 +237,8 @@ function(lagom_lib target_name fs_name) ) endif() serenity_generated_sources(${target_name}) - if (LAGOM_LIBRARY_EXPLICIT_SYMBOL_EXPORT) - # Temporary helper to allow libraries to opt-in to using X_API macros - # to export symbols required by external consumers. This allows the codebase - # to gradually slowly migrate instead of an all-or-nothing approach. - if (NOT WIN32) - target_compile_options(${target_name} PRIVATE -fvisibility=hidden) - endif() - include(GenerateExportHeader) - string(TOUPPER ${fs_name} fs_name_upper) - generate_export_header(${target_name} EXPORT_MACRO_NAME "${fs_name_upper}_API" EXPORT_FILE_NAME "Export.h") - target_sources(${target_name} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/Export.h") + lagom_generate_export_header(${target_name} ${fs_name}) endif() endfunction()