Skip to content
Permalink
Browse files

librdkafka: Use the right C++ standard library

Revbump because this changes the installed rdkafka++.pc file.
  • Loading branch information
ryandesign authored and kencu committed May 14, 2020
1 parent 837d1cf commit d9f8527fdcc3b5dccfa1e042acdc230178046e16
Showing with 133 additions and 0 deletions.
  1. +7 −0 net/librdkafka/Portfile
  2. +126 −0 net/librdkafka/files/CXX.patch
@@ -4,6 +4,7 @@ PortSystem 1.0
PortGroup github 1.0

github.setup edenhill librdkafka 1.4.2 v
revision 1
categories net
platforms darwin
license BSD-2-clause (Fold License)
@@ -15,6 +16,12 @@ checksums sha256 d6e553b1216b76de9e3a3c4b9c53fbecd87a5220aa5db2f3a8333
rmd160 99496ebe9eefa3d197bdd893baca273ad142b758 \
size 2733040

patchfiles CXX.patch

if {[string match *clang* ${configure.cxx}]} {
configure.ldflags-append -stdlib=${configure.cxx_stdlib}
}

configure.ldflags-prepend -L../src
configure.args --enable-ssl --enable-sasl

@@ -0,0 +1,126 @@
Use CXX instead of CC to link C++ libs/programs so that -lstdc++ is not needed.

It should be possible to remove this patch when updating the port to 1.5.0.

https://github.com/edenhill/librdkafka/issues/2878
https://github.com/edenhill/librdkafka/commit/e68ef8dc37db37c4682c95f79ad0af6dfc45bb56
--- examples/Makefile.orig
+++ examples/Makefile
@@ -35,7 +35,7 @@ producer: ../src/librdkafka.a producer.c

producer_cpp: ../src-cpp/librdkafka++.a ../src/librdkafka.a producer.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) producer.cpp -o $@ $(LDFLAGS) \
- ../src-cpp/librdkafka++.a ../src/librdkafka.a $(LIBS) -lstdc++
+ ../src-cpp/librdkafka++.a ../src/librdkafka.a $(LIBS)

consumer: ../src/librdkafka.a consumer.c
$(CC) $(CPPFLAGS) $(CFLAGS) $@.c -o $@ $(LDFLAGS) \
@@ -78,20 +78,20 @@ rdkafka_performance: ../src/librdkafka.a rdkafka_performance.c

rdkafka_example_cpp: ../src-cpp/librdkafka++.a ../src/librdkafka.a rdkafka_example.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) rdkafka_example.cpp -o $@ $(LDFLAGS) \
- ../src-cpp/librdkafka++.a ../src/librdkafka.a $(LIBS) -lstdc++
+ ../src-cpp/librdkafka++.a ../src/librdkafka.a $(LIBS)

kafkatest_verifiable_client: ../src-cpp/librdkafka++.a ../src/librdkafka.a kafkatest_verifiable_client.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) kafkatest_verifiable_client.cpp -o $@ $(LDFLAGS) \
- ../src-cpp/librdkafka++.a ../src/librdkafka.a $(LIBS) -lstdc++
+ ../src-cpp/librdkafka++.a ../src/librdkafka.a $(LIBS)


rdkafka_complex_consumer_example_cpp: ../src-cpp/librdkafka++.a ../src/librdkafka.a rdkafka_complex_consumer_example.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) rdkafka_complex_consumer_example.cpp -o $@ $(LDFLAGS) \
- ../src-cpp/librdkafka++.a ../src/librdkafka.a $(LIBS) -lstdc++
+ ../src-cpp/librdkafka++.a ../src/librdkafka.a $(LIBS)

rdkafka_consume_batch: ../src-cpp/librdkafka++.a ../src/librdkafka.a rdkafka_consume_batch.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) rdkafka_consume_batch.cpp -o $@ $(LDFLAGS) \
- ../src-cpp/librdkafka++.a ../src/librdkafka.a $(LIBS) -lstdc++
+ ../src-cpp/librdkafka++.a ../src/librdkafka.a $(LIBS)

rdkafka_zookeeper_example: ../src/librdkafka.a rdkafka_zookeeper_example.c
$(CC) $(CPPFLAGS) $(CFLAGS) -I/usr/include/zookeeper rdkafka_zookeeper_example.c -o $@ $(LDFLAGS) \
--- mklove/Makefile.base.orig
+++ mklove/Makefile.base
@@ -25,6 +25,10 @@ ifndef MKL_MAKEFILE_CONFIG
-include $(TOPDIR)/Makefile.config
endif

+# Use C compiler as default linker.
+# C++ libraries will need to override this CXX after including Makefile.base
+CC_LD?=$(CC)
+
_UNAME_S := $(shell uname -s)
ifeq ($(_UNAME_S),Darwin)
LIBFILENAME=$(LIBNAME).$(LIBVER)$(SOLIB_EXT)
@@ -100,7 +104,7 @@ $(LIBNAME_LDS):

$(LIBFILENAME): $(OBJS) $(LIBNAME_LDS)
@printf "$(MKL_YELLOW)Creating shared library $@$(MKL_CLR_RESET)\n"
- $(CC) $(LDFLAGS) $(LIB_LDFLAGS) $(OBJS) -o $@ $(LIBS)
+ $(CC_LD) $(LDFLAGS) $(LIB_LDFLAGS) $(OBJS) -o $@ $(LIBS)

$(LIBNAME).a: $(OBJS)
@printf "$(MKL_YELLOW)Creating static library $@$(MKL_CLR_RESET)\n"
@@ -196,7 +200,7 @@ endif

$(BIN): $(OBJS)
@printf "$(MKL_YELLOW)Creating program $@$(MKL_CLR_RESET)\n"
- $(CC) $(CPPFLAGS) $(LDFLAGS) $(OBJS) -o $@ $(LIBS)
+ $(CC_LD) $(CPPFLAGS) $(LDFLAGS) $(OBJS) -o $@ $(LIBS)


file-check:
--- src-cpp/CMakeLists.txt.orig
+++ src-cpp/CMakeLists.txt
@@ -54,7 +54,7 @@ set(PKG_CONFIG_LIBS
"-L\${libdir} -lrdkafka++"
)
set(PKG_CONFIG_LIBS_PRIVATE
- "-lrdkafka -lstdc++"
+ "-lrdkafka"
)
configure_file(
"../packaging/cmake/rdkafka.pc.in"
--- src-cpp/Makefile.orig
+++ src-cpp/Makefile
@@ -21,6 +21,9 @@ DISABLE_LDS=y
MKL_NO_SELFCONTAINED_STATIC_LIB=y
include ../mklove/Makefile.base

+# Use C++ compiler as linker rather than the default C compiler
+CC_LD=$(CXX)
+
# OSX and Cygwin requires linking required libraries
ifeq ($(_UNAME_S),Darwin)
FWD_LINKING_REQ=y
@@ -34,7 +37,7 @@ endif

# Ignore previously defined library dependencies for the C library,
# we'll get those dependencies through the C library linkage.
-LIBS := -L../src -lrdkafka -lstdc++
+LIBS := -L../src -lrdkafka

CHECK_FILES+= $(LIBFILENAME) $(LIBNAME).a

--- tests/Makefile.orig
+++ tests/Makefile
@@ -3,7 +3,7 @@ TESTSRCS_CXX= $(wildcard [08]*-*.cpp)
OBJS = $(TESTSRCS_C:%.c=%.o) $(TESTSRCS_CXX:%.cpp=%.o)

BIN = test-runner
-LIBS += -lrdkafka++ -lrdkafka -lstdc++
+LIBS += -lrdkafka++ -lrdkafka
OBJS += test.o rusage.o testcpp.o \
tinycthread.o tinycthread_extra.o rdlist.o sockem.o \
sockem_ctrl.o
@@ -21,6 +21,9 @@ SCENARIOS?=noautocreate

-include ../Makefile.config

+# Use C++ compiler as linker
+CC_LD=$(CXX)
+
all: $(BIN) run_par

#

0 comments on commit d9f8527

Please sign in to comment.
You can’t perform that action at this time.