From 515626b540b56586c2329b5373da11a978801459 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 28 May 2022 10:40:34 -0700 Subject: [PATCH] move dot_builtins.c into C++ MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This looks like a bit of a strange change, when we now wrap the entire file in `extern "C"`. However this has two key benefits: 1. `dot_builtins` and `dot_static` that include this source needed an Autotools hack¹ to force compilation to use the C++ front end (`c++`) instead of the C front end (`cc`) in order to link against the C++ standard library. By moving this source into C++ we can remove this hack. 2. When trying to integrate `dot_builtins` into the CMake build system, MSVC complains (correctly) that the initializers to the array in this file are not compile-time constants. GCC and Clang apparently allow this by a non-standard extension. By moving this into C++, we get more relaxed initialization semantics that allow this on all compilers. Gitlab: #1836 ¹ https://www.gnu.org/software/automake/manual/automake.html#Libtool-Convenience-Libraries --- ci/clang_format.py | 2 +- cmd/dot/Makefile.am | 9 ++------- cmd/dot/{dot_builtins.c => dot_builtins.cpp} | 4 ++++ tests/CMakeLists.txt | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) rename cmd/dot/{dot_builtins.c => dot_builtins.cpp} (98%) diff --git a/ci/clang_format.py b/ci/clang_format.py index 512a2a596..133ea99c7 100644 --- a/ci/clang_format.py +++ b/ci/clang_format.py @@ -16,7 +16,7 @@ import sys # TODO: files that are not yet compliant EXCLUDE = ( "cmd/dot/dot.c", - "cmd/dot/dot_builtins.c", + "cmd/dot/dot_builtins.cpp", "cmd/dot/no_builtins.c", "cmd/dotty/mswin32/dotty.c", "cmd/edgepaint/edgepaintmain.c", diff --git a/cmd/dot/Makefile.am b/cmd/dot/Makefile.am index f835aa0cb..7842928ef 100644 --- a/cmd/dot/Makefile.am +++ b/cmd/dot/Makefile.am @@ -78,7 +78,7 @@ uninstall-hook: $(PS2PDF) $$psfile && rm -f $$psfile || { rm -f $$psfile; exit 1; } SUFFIXES = .1 .1.pdf -dot_static_SOURCES = dot.c dot_builtins.c +dot_static_SOURCES = dot.c dot_builtins.cpp dot_static_CPPFLAGS = $(AM_CPPFLAGS) -DDEMAND_LOADING=0 dot_static_LDADD = \ $(top_builddir)/plugin/dot_layout/libgvplugin_dot_layout_C.la \ @@ -91,7 +91,7 @@ dot_static_LDADD = \ $(top_builddir)/lib/cdt/libcdt_C.la \ $(PANGOCAIRO_LIBS) $(PANGOFT2_LIBS) $(GTS_LIBS) $(EXPAT_LIBS) $(Z_LIBS) $(SOCKET_LIBS) $(IPSEPCOLA_LIBS) $(MATH_LIBS) -dot_builtins_SOURCES = dot.c dot_builtins.c +dot_builtins_SOURCES = dot.c dot_builtins.cpp dot_builtins_CPPFLAGS = $(AM_CPPFLAGS) -DDEMAND_LOADING=1 dot_builtins_LDADD = \ $(top_builddir)/plugin/dot_layout/libgvplugin_dot_layout.la \ @@ -123,11 +123,6 @@ dot_static_LDADD += $(top_builddir)/plugin/lasi/.libs/libgvplugin_lasi_C.a $(LAS dot_builtins_LDADD += $(top_builddir)/plugin/lasi/libgvplugin_lasi.la $(LASI_LIBS) endif -# add a non-existent C++ source to force the C++ compiler to be used for -# linking, so the C++ standard library is included for our C++ dependencies -nodist_EXTRA_dot_static_SOURCES = fake.cxx -nodist_EXTRA_dot_builtins_SOURCES = fake.cxx - EXTRA_DIST = dot.vcxproj* DISTCLEANFILES = $(pdf_DATA) diff --git a/cmd/dot/dot_builtins.c b/cmd/dot/dot_builtins.cpp similarity index 98% rename from cmd/dot/dot_builtins.c rename to cmd/dot/dot_builtins.cpp index f71acf610..58b885f6d 100644 --- a/cmd/dot/dot_builtins.c +++ b/cmd/dot/dot_builtins.cpp @@ -18,6 +18,8 @@ #define IMPORT /* nothing */ #endif +extern "C" { + IMPORT extern gvplugin_library_t gvplugin_dot_layout_LTX_library; IMPORT extern gvplugin_library_t gvplugin_neato_layout_LTX_library; #ifdef HAVE_LIBGD @@ -47,3 +49,5 @@ lt_symlist_t lt_preloaded_symbols[] = { { "gvplugin_core_LTX_library", &gvplugin_core_LTX_library }, { 0, 0 } }; + +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8ce8b339a..5f65cc4ce 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -18,7 +18,7 @@ add_library(test_common STATIC svg_analyzer.cpp svg_analyzer.h svg_analyzer_interface.h - ../cmd/dot/dot_builtins.c + ../cmd/dot/dot_builtins.cpp ) set_target_properties(test_common PROPERTIES CXX_STANDARD 20) set_target_properties(test_common PROPERTIES CXX_STANDARD_REQUIRED ON) -- 2.40.0