Skip to content

Commit

Permalink
[C++] Add Wireshark cmake and fix build with latest Wireshark (apache…
Browse files Browse the repository at this point in the history
…#13236)

### Motivation
The Pulsar Wireshark dissector doesn't have a CMake file to build it, and in the latest Wireshark, the dissector API has changed. This PR is the minimizes support of Wireshark dissector, some behavior not right (include naming), I'll fix in next PRs.

I only test in macOS 12.1 (AArch64 and x64 architecture) with Wireshark 3.6.0, Linux support is in progress.

### Modifications
* Add Wireshark CMakefile
* Fix pulsarDissector.cc to let it build success.
* Use "%" G_GINT64_MODIFIER "u" instead %llu , since not all platforms support "%ll" for printing 64-bit integral data types

### Documentation

- [x] `doc-required`
  • Loading branch information
Demogorgon314 authored Dec 12, 2021
1 parent 342fb54 commit d4ed376
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 62 deletions.
2 changes: 1 addition & 1 deletion build/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ RUN apt-get update && \
libboost-dev libboost-program-options-dev libboost-system-dev libboost-python-dev \
libxml2-utils protobuf-compiler wget \
curl doxygen openjdk-8-jdk-headless openjdk-11-jdk-headless clang-format-5.0 \
gnupg2 golang-1.13-go zip unzip libzstd-dev libsnappy-dev python3-pip libpython-dev
gnupg2 golang-1.13-go zip unzip libzstd-dev libsnappy-dev python3-pip libpython-dev wireshark-dev

# Build protobuf 3.x.y from source since the default protobuf from Ubuntu's apt source is 2.x.y
RUN curl -O -L https://github.com/protocolbuffers/protobuf/releases/download/v3.17.3/protobuf-cpp-3.17.3.tar.gz && \
Expand Down
7 changes: 7 additions & 0 deletions pulsar-client-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ MESSAGE(STATUS "BUILD_TESTS: " ${BUILD_TESTS})
option(BUILD_PYTHON_WRAPPER "Build Pulsar Python wrapper" ON)
MESSAGE(STATUS "BUILD_PYTHON_WRAPPER: " ${BUILD_PYTHON_WRAPPER})

option(BUILD_WIRESHARK "Build Pulsar Wireshark dissector" OFF)
MESSAGE(STATUS "BUILD_WIRESHARK: " ${BUILD_WIRESHARK})

option(BUILD_PERF_TOOLS "Build Pulsar CLI perf producer/consumer" OFF)
MESSAGE(STATUS "BUILD_PERF_TOOLS: " ${BUILD_PERF_TOOLS})

Expand Down Expand Up @@ -429,6 +432,10 @@ if (BUILD_PYTHON_WRAPPER)
add_subdirectory(python)
endif ()

if (BUILD_WIRESHARK)
add_subdirectory(wireshark)
endif()

# `make format` option
if (NOT APPLE AND NOT WIN32)
set(CLANG_FORMAT_VERSION "5.0")
Expand Down
2 changes: 1 addition & 1 deletion pulsar-client-cpp/docker/build-client-lib-within-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ find . -name CMakeCache.txt | xargs -r rm
find . -name CMakeFiles | xargs -r rm -rf
rm -f lib/*.pb.*

cmake . -DBUILD_TESTS=OFF -DLINK_STATIC=ON \
cmake . -DBUILD_TESTS=OFF -DBUILD_WIRESHARK=OFF -DLINK_STATIC=ON \
-DPYTHON_INCLUDE_DIR=/opt/python/$PYTHON_SPEC/include/python$PYTHON_VERSION \
-DPYTHON_LIBRARY=/opt/python/$PYTHON_SPEC/lib \

Expand Down
3 changes: 2 additions & 1 deletion pulsar-client-cpp/docker/build-wheel-file-within-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ find . -name CMakeFiles | xargs -r rm -rf
cmake . -DPYTHON_INCLUDE_DIR=/opt/python/$PYTHON_SPEC/include/python$PYTHON_VERSION \
-DPYTHON_LIBRARY=/opt/python/$PYTHON_SPEC/lib \
-DLINK_STATIC=ON \
-DBUILD_TESTS=OFF
-DBUILD_TESTS=OFF \
-DBUILD_WIRESHARK=OFF

make clean
make _pulsar -j3 VERBOSE=1
Expand Down
77 changes: 77 additions & 0 deletions pulsar-client-cpp/wireshark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

set(CMAKE_CXX_FLAGS "-O3 -g ${CMAKE_CXX_FLAGS}")

# Wireshark dependency's
find_library(WIRESHARK_LIB wireshark)
find_library(WIRESHARK_UTIL_LIB wsutil)
find_path(WIRESHARK_INCLUDE_PATH wireshark/config.h)
find_library(GLIB_LIB glib)
include_directories(${GLIB_INCLUDE_DIRS})
include(FindPkgConfig)
pkg_check_modules(GLIB glib-2.0)
include_directories(${WIRESHARK_INCLUDE_PATH}/wireshark ${GLIB_INCLUDE_DIRS} ../lib )

MESSAGE(STATUS "Use WIRESHARK_LIB: ${WIRESHARK_LIB}")
MESSAGE(STATUS "Use WIRESHARK_UTIL_LIB: ${WIRESHARK_UTIL_LIB}")
MESSAGE(STATUS "Use WIRESHARK_INCLUDE_PATH: ${WIRESHARK_INCLUDE_PATH}")
MESSAGE(STATUS "Use GLIB_INCLUDE_DIRS: ${GLIB_INCLUDE_DIRS}")

# Protobuf libs
if (NOT PROTOC_PATH)
set(PROTOC_PATH protoc)
endif()

include_directories(${Protobuf_INCLUDE_DIRS})
find_library(Protobuf_LIBRARIES protobuf libprotobuf)
find_path(Protobuf_INCLUDE_DIRS google/protobuf/stubs/common.h)

set(AUTOGEN_DIR ${CMAKE_BINARY_DIR}/generated)
file(MAKE_DIRECTORY ${AUTOGEN_DIR})
set(LIB_AUTOGEN_DIR ${AUTOGEN_DIR}/lib)
file(MAKE_DIRECTORY ${LIB_AUTOGEN_DIR})
include_directories(${LIB_AUTOGEN_DIR})

# Protobuf generation is only supported natively starting from CMake 3.8
# Using custom command for now
set(PROTO_SOURCES ${LIB_AUTOGEN_DIR}/PulsarApi.pb.cc ${LIB_AUTOGEN_DIR}/PulsarApi.pb.h)
ADD_CUSTOM_COMMAND(
OUTPUT ${PROTO_SOURCES}
COMMAND ${PROTOC_PATH} -I ../../pulsar-common/src/main/proto ../../pulsar-common/src/main/proto/PulsarApi.proto --cpp_out=${LIB_AUTOGEN_DIR}
DEPENDS
../../pulsar-common/src/main/proto/PulsarApi.proto
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
link_libraries(${Protobuf_LIBRARIES})

# Build wireshark shared lib
add_library(pulsar-dissector SHARED pulsarDissector.cc ${PROTO_SOURCES})
SET(CMAKE_SHARED_LIBRARY_PREFIX )
SET(CMAKE_SHARED_LIBRARY_SUFFIX .so)
set_target_properties(pulsar-dissector PROPERTIES PREFIX "" DEFINE_SYMBOL "")

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS} -undefined dynamic_lookup")
endif()

if (APPLE)
target_link_libraries(pulsar-dissector -Wl,-all_load ${PROTO_LIBRARIES})
else ()
target_link_libraries(pulsar-dissector ${PROTOBUF_LIBRARIES})
endif ()
34 changes: 0 additions & 34 deletions pulsar-client-cpp/wireshark/moduleinfo.h

This file was deleted.

Loading

0 comments on commit d4ed376

Please sign in to comment.