Skip to content

Commit

Permalink
refactor: Tolerate BUILD_SHARED_LIBS=On
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Apr 11, 2024
1 parent 438e7c5 commit b8119f4
Show file tree
Hide file tree
Showing 22 changed files with 75 additions and 104 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ option(WITH_STATIC_CRT "(Visual C++) Enable to statically link CRT, which avoids
option(DISCOVER_TESTS "Enables CTest by executing tests and discovering test cases. To disable with: -DDISCOVER_TESTS=Off" On)
option(BUILD_VSIX "When disabled, the VS Code client is not built and it is not packaged into vsix." On)
option(BUILD_FUZZER "Enable building of the fuzzer. Tested with clang and libstdc++ (enable with -DWITH_LIBCXX=Off)" Off)
option(USE_STATIC_ANTLR "Always use static ANTLR library." On)

set(USE_PRE_GENERATED_GRAMMAR "" CACHE PATH "Directory with pre-generated grammar files")
set(LANGUAGE_SERVER_BIN_SUBDIR "" CACHE STRING "Subdirectory for the language server binary in the client project")
Expand Down
25 changes: 18 additions & 7 deletions cmake/antlr_patch.diff
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
diff --git a/runtime/Cpp/runtime/CMakeLists.txt b/runtime/Cpp/runtime/CMakeLists.txt
index 86fdab97f..97486fb1a 100644
--- a/runtime/Cpp/runtime/CMakeLists.txt
+++ b/runtime/Cpp/runtime/CMakeLists.txt
@@ -120,7 +120,7 @@ set(static_lib_suffix "")
if (WIN32)
set(static_lib_suffix "-static")
if (TARGET antlr4_shared)
- target_compile_definitions(antlr4_shared PUBLIC ANTLR4CPP_EXPORTS)
+ target_compile_definitions(antlr4_shared PRIVATE ANTLR4CPP_EXPORTS)
endif()
if (TARGET antlr4_static)
target_compile_definitions(antlr4_static PUBLIC ANTLR4CPP_STATIC)
diff --git a/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp b/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp
index 54d35ee3b..f7d033e3f 100755
--- a/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp
Expand Down Expand Up @@ -76,7 +89,7 @@ index 337bcba17..391a8ce05 100755
for (size_t d = 0; d < simulator->decisionToDFA.size(); d++) {
dfa::DFA &dfa = simulator->decisionToDFA[d];
diff --git a/runtime/Cpp/runtime/src/Recognizer.cpp b/runtime/Cpp/runtime/src/Recognizer.cpp
index c8a183324..15c6bb98d 100755
index c8a183324..0a2251787 100755
--- a/runtime/Cpp/runtime/src/Recognizer.cpp
+++ b/runtime/Cpp/runtime/src/Recognizer.cpp
@@ -20,8 +20,8 @@ using namespace antlr4;
Expand All @@ -85,8 +98,8 @@ index c8a183324..15c6bb98d 100755

-std::map<const dfa::Vocabulary*, std::map<std::string_view, size_t>> Recognizer::_tokenTypeMapCache;
-std::map<std::vector<std::string>, std::map<std::string, size_t>> Recognizer::_ruleIndexMapCache;
+thread_local std::map<const dfa::Vocabulary*, std::map<std::string_view, size_t>> Recognizer::_tokenTypeMapCache;
+thread_local std::map<std::vector<std::string>, std::map<std::string, size_t>> Recognizer::_ruleIndexMapCache;
+thread_local std::map<const dfa::Vocabulary*, std::map<std::string_view, size_t>> _tokenTypeMapCache;
+thread_local std::map<std::vector<std::string>, std::map<std::string, size_t>> _ruleIndexMapCache;

Recognizer::Recognizer() {
InitializeInstanceFields();
Expand All @@ -107,10 +120,10 @@ index c8a183324..15c6bb98d 100755
auto iterator = _ruleIndexMapCache.find(ruleNames);
if (iterator != _ruleIndexMapCache.end()) {
diff --git a/runtime/Cpp/runtime/src/Recognizer.h b/runtime/Cpp/runtime/src/Recognizer.h
index bc62aea23..34abbc5e4 100755
index bc62aea23..2b2157883 100755
--- a/runtime/Cpp/runtime/src/Recognizer.h
+++ b/runtime/Cpp/runtime/src/Recognizer.h
@@ -142,12 +142,9 @@ namespace antlr4 {
@@ -142,12 +142,7 @@ namespace antlr4 {
protected:
atn::ATNSimulator *_interpreter; // Set and deleted in descendants (or the profiler).

Expand All @@ -120,8 +133,6 @@ index bc62aea23..34abbc5e4 100755
private:
- static std::map<const dfa::Vocabulary*, std::map<std::string_view, size_t>> _tokenTypeMapCache;
- static std::map<std::vector<std::string>, std::map<std::string, size_t>> _ruleIndexMapCache;
+ static thread_local std::map<const dfa::Vocabulary*, std::map<std::string_view, size_t>> _tokenTypeMapCache;
+ static thread_local std::map<std::vector<std::string>, std::map<std::string, size_t>> _ruleIndexMapCache;

ProxyErrorListener _proxListener; // Manages a collection of listeners.

Expand Down
2 changes: 1 addition & 1 deletion cmake/external_antlr4cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if(NOT antlr4cpp_POPULATED)
endif()
endif()

if(BUILD_SHARED_LIBS AND NOT EMSCRIPTEN)
if(BUILD_SHARED_LIBS AND NOT EMSCRIPTEN AND NOT USE_STATIC_ANTLR)
set(ANTLR4_RUNTIME antlr4_shared)
else()
set(ANTLR4_RUNTIME antlr4_static)
Expand Down
1 change: 0 additions & 1 deletion cmake/external_gtest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ FetchContent_GetProperties(googletest)

function(add_googletest)
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE BOOL "")
set(BUILD_SHARED_LIBS Off)
set(gtest_force_shared_crt ${WITH_STATIC_CRT} CACHE BOOL "" FORCE)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
unset(CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
Expand Down
13 changes: 13 additions & 0 deletions cmake/uri_patch.diff
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ index 8ff7a5e..a482a51 100644
}

constexpr int compare(size_type pos1, size_type n1,
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d7f387c..5b3f189 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -14,7 +14,7 @@ set(Uri_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/detail/uri_resolve.cpp
)

-add_library(network-uri ${Uri_SRCS})
+add_library(network-uri STATIC ${Uri_SRCS})
target_link_libraries(network-uri)
if(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
if (NOT Uri_DISABLE_LIBCXX)
diff --git a/src/detail/uri_parse.cpp b/src/detail/uri_parse.cpp
index 7f77148..73f581e 100644
--- a/src/detail/uri_parse.cpp
Expand Down
3 changes: 3 additions & 0 deletions language_server/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ target_link_libraries(server_test boost-asio)
target_link_libraries(server_test hlasm_language_server_base)

target_link_libraries(server_test gmock_main)
if (BUILD_SHARED_LIBS)
set_target_properties(server_test PROPERTIES COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
endif()
target_link_libraries(server_test network-uri)
target_link_libraries(server_test parser_library)

Expand Down
11 changes: 1 addition & 10 deletions parser_library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,11 @@ else()
set(GENERATED_GRAMMER_FOLDER ${USE_PRE_GENERATED_GRAMMAR})
endif()

add_library(parser_library)
add_library(parser_library STATIC)

add_subdirectory(src)
add_subdirectory(include)

if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(parser_library PUBLIC PARSER_LIBRARY_STATIC_DEFINE=1)
endif()

generate_export_header(parser_library
EXPORT_FILE_NAME ${GENERATED_FOLDER}/parser_library_export.h)

target_sources(parser_library PUBLIC ${GENERATED_FOLDER}/parser_library_export.h)

target_include_directories(parser_library PUBLIC
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/src
Expand Down
2 changes: 1 addition & 1 deletion parser_library/fuzzer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if(BUILD_FUZZER)
set_target_properties(library_fuzzer PROPERTIES LINK_FLAGS "-fsanitize=fuzzer")
generate_emscripten_node_runner(library_fuzzer)
else()
add_library(library_fuzzer)
add_library(library_fuzzer STATIC)
endif()

target_sources(library_fuzzer PRIVATE
Expand Down
2 changes: 0 additions & 2 deletions parser_library/include/branch_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

#include <cstddef>

#include "parser_library_export.h"

namespace hlasm_plugin::parser_library {

enum class branch_direction : unsigned char
Expand Down
1 change: 0 additions & 1 deletion parser_library/include/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include <span>

#include "parser_library_export.h"
#include "protocol.h"
#include "range.h"
#include "sequence.h"
Expand Down
3 changes: 1 addition & 2 deletions parser_library/include/lib_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
#include <optional>

#include "nlohmann/json_fwd.hpp"
#include "parser_library_export.h"

namespace hlasm_plugin::parser_library {
namespace config {
struct pgm_conf;
}

// Encapsulates user defined settings of library and individual workspaces
class PARSER_LIBRARY_EXPORT lib_config
class lib_config
{
public:
// Creates an instance of lib_config with values from input json.
Expand Down
Loading

0 comments on commit b8119f4

Please sign in to comment.