Skip to content

Commit 49e5b93

Browse files
james94szaszm
authored andcommitted
MINIFICPP-2346-P1: Integrated Conan2 for OpenSSL, CURL, ZLIB & Build MiNiFi
Closes #1793 Signed-off-by: Marton Szasz <[email protected]>
1 parent 6c0979f commit 49e5b93

34 files changed

+884
-42
lines changed

CMakeLists.txt

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,15 @@ else()
221221
message(VERBOSE "No custom malloc implementation")
222222
endif()
223223

224+
# OpenSSL
225+
include(GetOpenSSL)
226+
get_openssl("${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}")
227+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/ssl")
228+
229+
224230
if (ENABLE_BZIP2 AND (ENABLE_LIBARCHIVE OR (ENABLE_ROCKSDB AND NOT WIN32)))
225-
include(BundledBZip2)
226-
use_bundled_bzip2(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
231+
include(GetBZip2)
232+
get_bzip2(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
227233
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/bzip2/dummy")
228234
endif()
229235

@@ -238,29 +244,25 @@ if(NOT WIN32)
238244
use_bundled_osspuuid(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
239245
endif()
240246

241-
# OpenSSL
242-
include(BundledOpenSSL)
243-
use_openssl("${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}")
244-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/ssl")
245-
246247
# libsodium
247248
include(BundledLibSodium)
248249
use_bundled_libsodium("${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}")
249250

250251
list(APPEND MINIFI_CPP_COMPILE_DEFINITIONS SODIUM_STATIC=1)
251252

252253
# zlib
253-
include(BundledZLIB)
254-
use_bundled_zlib(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
254+
include(GetZLIB)
255+
get_zlib(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
255256
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/zlib/dummy")
256257

257258
# cURL
258-
include(BundledLibcURL)
259-
use_bundled_curl(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
259+
include(GetLibCURL)
260+
get_curl(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
260261
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/curl/dummy")
261262

262263
# spdlog
263-
include(Spdlog)
264+
include(GetSpdlog)
265+
get_spdlog()
264266

265267
# yaml-cpp
266268
include(BundledYamlCpp)
@@ -340,13 +342,14 @@ include(Extensions)
340342
add_subdirectory(libminifi)
341343

342344
if (ENABLE_ALL OR ENABLE_AZURE)
343-
include(BundledLibXml2)
344-
use_bundled_libxml2(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
345+
include(GetLibXml2)
346+
get_libxml2(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
345347
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/libxml2/dummy")
346348
endif()
347349

348350
if (ENABLE_ALL OR ENABLE_PROMETHEUS OR ENABLE_CIVET)
349-
include(CivetWeb)
351+
include(GetCivetWeb)
352+
get_civetweb()
350353
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/civetweb/dummy")
351354
endif()
352355

CONAN.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
-->
15+
16+
# Apache NiFi - MiNiFi - C++ Conan Build Guide
17+
18+
We will walk through the steps to build MiNiFi using conan version 2 that comes with CMake integration. We will also go through the process of creating a MiNiFi conan package for easier integration into other C++ projects. We will start with a discussion on building MiNiFi using the standalone CMake approach and the conan approach. After we have built MiNiFi and created a MiNiFi conan package, we will conclude by elaborating on some of the benefits that can come with integrating a MiNiFi conan package into new or existing C++ infrastructure with respect to real-time robotic systems.
19+
20+
Conan build support is experimental, and not yet suitable for general use.
21+
22+
## Table of Contents
23+
24+
- [Apache NiFi - MiNiFi - C++ Conan Build Guide](#apache-nifi---minifi---c---conan-build-guide)
25+
- [Table of Contents](#table-of-contents)
26+
- [Description](#description)
27+
- [Build MiNiFi C++ with Conan](#build-minifi-c---with-conan)
28+
- [Create MiNiFi C++ Conan Package](#create-minifi-c---conan-package)
29+
- [Conclusion](#conclusion)
30+
- [Appendix](#appendix)
31+
32+
## Description
33+
34+
Apache NiFi MiNiFi C++ is normally built using standalone CMake. Similarly, we can also create a MiNiFi C++ package using make package. However, each time we build MiNiFi from
35+
source, it uses CMake to install the third party external libraries that are enabled by downloading the source code and then building each library until it is available to use toward building MiNiFi. If a change is made toward MiNiFi's CMake code in regards to one or more of the external libraries, then potentially the long process of installing one or more of the externl library(ies) happens again before the MiNiFi source code is built. Another way we can build MiNiFi and create MiNiFi packages without running into having to rebuild its external libraries is using conan. Conan provides some great features toward managing to install prebuilt conan packages, which for our case is the external libraries that are needed to then build MiNiFi. We will walk through the steps to build the MiNiFi project and create a MiNiFi conan package.
36+
37+
## Build MiNiFi C++ with Conan
38+
39+
To build MiNiFi using conan, first we install conan version 2, then we create a **default** conan profile that will later be ignored for our custom conan profile, create a MINIFI_HOME environment variable, then we install prebuilt conan packages representing the MiNiFi external libraries and finally we compile MiNiFi.
40+
41+
~~~bash
42+
sudo pip install --force-reinstall -v "conan==2.0.17"
43+
44+
# create a "default" conan profile, so conan has it on record in ~/.conan2/, before using your own custom profile.
45+
conan profile detect
46+
47+
# conanfile.py is in root dir of MiNiFi C++ project
48+
cd $HOME/nifi-minifi-cpp
49+
50+
# create MINIFI_HOME env variable for binary executable minifi
51+
export MINIFI_HOME=$(pwd)
52+
53+
# install conan packages for MiNiFi C++ using conanfile.py invoking Conan
54+
# since we created default profile earlier, we can override it with our own minifi profile
55+
conan install . --build=missing --output-folder=build_conan -pr=etc/conan/profiles/release-linux
56+
57+
# build MiNiFi C++ using conanfile.py invoking Conan & CMake
58+
conan build . --output-folder=build_conan -pr=etc/conan/profiles/release-linux
59+
~~~
60+
61+
- **NOTE**: After building MiNiFi, we must have the MINIFI_HOME environment variable created in order to successfully run the minifi binary executable.
62+
63+
- **NOTE**: When we install the prebuilt conan package representing the MiNiFi third party libraries, we add the `--build=missing` in case some of the prebuilt missing conan packages are not found from conancenter, jfrog, or one of our conan repositories, then conan will build the conan packages from source. We can upload new prebuilt conan packages by **[conan upload](https://docs.conan.io/2/reference/commands/upload.html)**.
64+
65+
- **NOTE**: When we tell conan to build MiNiFi, conan first installs prebuilt conan packages and then it compiles MiNiFi from source, so we have the MiNiFi library and its binary executable available.
66+
67+
### Run MiNiFi CTESTs from Build Folder
68+
69+
~~~bash
70+
pushd build_conan/
71+
ctest
72+
popd # build_conan/
73+
~~~
74+
75+
### Run MiNiFi Executable
76+
77+
~~~bash
78+
# verify we can run minifi binary executable
79+
./build_conan/bin/minifi
80+
~~~
81+
82+
## Create MiNiFi C++ Conan Package
83+
84+
To create a MiNiFi package, we will follow the similar steps we took to build MiNiFi. Then right after we install the prebuilt conan packages representing MiNiFi's external libraries, we create that MiNiFi conan package.
85+
86+
~~~bash
87+
# make sure to install conan2 for your environment
88+
sudo pip install --force-reinstall -v "conan==2.0.17"
89+
90+
# create a "default" conan profile, so conan has it on record, before using your own custom profile. Gets created in ~/.conan2/
91+
conan profile detect
92+
93+
# conanfile.py is in root dir of MiNiFi C++ project
94+
cd $HOME/nifi-minifi-cpp
95+
96+
# create MINIFI_HOME env variable for binary executable minifi
97+
export MINIFI_HOME=$(pwd)
98+
99+
# install conan packages for MiNiFi C++ using conanfile.py invoking Conan
100+
# since we created default profile earlier, we can override it with our own minifi profile
101+
# make sure path is correct
102+
conan install . --build=missing --output-folder=build_conan -pr=etc/conan/profiles/release-linux
103+
104+
# create MiNiFi C++ conan package using conanfile.py invoking Conan & CMake
105+
conan create . --user=minifi --channel=develop -pr=etc/conan/profiles/release-linux
106+
~~~
107+
108+
- **NOTE**: When we tell conan to create the MiNiFi conan package, conan first installs prebuilt conan packages, then it compiles MiNiFi from source inside `~/.conan2/p/b/minif<UUID>/b`, and then it copies over MiNiFi's libraries and its binary executables into the conan package folder `~/.conan2/p/b/minif<UUID>/p`. Once we have the MiNiFi conan package, we can integrate it into other C++ infrastructure using CMake.
109+
110+
### Run MiNiFi CTESTs from Its Conan Package
111+
112+
~~~bash
113+
# Example of minif<UUID> conan package folder name: minifbd17f6a02da35
114+
pushd ~/.conan2/p/b/minif<UUID>/b
115+
ctest
116+
popd # build_conan/
117+
~~~
118+
119+
## Conclusion
120+
121+
To have a more consistent quick build process for MiNiFi, we can use conan version 2. When we use conan with MiNiFi's build process, we can install prebuilt conan packages that can represent MiNiFi's external libraries and then build MiNiFi quickly. We also have a bit more control over when we want to make updates to MiNiFi's external libraries that impact their build and then re-build them as prebuilt conan packages. So these external library conan packages can be used toward building MiNiFi again without having to rebuild those external libraries while rebuilding MiNiFi. Therefore, we can focus mainly on configuring the way we want MiNiFi to build without having to worry about MiNiFi's external libraries needing to be rebuilt again. Similarly, if we create a MiNiFi conan package, it will install the prebuilt conan packages, build MiNiFi from source and then create the MiNiFi package.
122+
123+
There are multiple benefits of having MiNiFi prebuilt conan packages. We can upload these MiNiFi conan packages to a conan repository like jfrog for version management. We can easily integrate MiNiFi's edge data pipeline features into other C++ software infrastructure using conan's CMake support. We can still use MiNiFi for edge data collection from the IoT devices embedded on robotic systems. We can integrate MiNiFi into self-driving cars (sensor examples: cameras, lidar, radar, inertial measurement unit (IMU), electronic speed controller (ESC), steering servo, etc), into medical imaging robots (sensor examples: depth cameras, ultrasound, gamma detector, force/torque sensor, joint position sensor, etc) or some other real-time robotic system.
124+
125+
By leveraging MiNiFi as a conan package, we can leverage MiNiFi that comes with the best practices of building data pipelines from NiFi and bring them into existing C++ real-time robotics infrastructure. Some teams across companies typically have their own custom edge data pipelines that process data for the different events to eventually perform actions on that data. As an alternative to all these companies and their teams having their own custom edge data pipeline libraries, MiNiFi C++, which is like a headless NiFi, can provide a more consistent standard approach for team's to build edge pipelines. Through all stages of the edge data pipelines, MiNiFi can still provide telemetry to NiFi instances running in the cloud.
126+
127+
## Appendix
128+
129+
### Create Custom RocksDB Conan Package
130+
131+
~~~bash
132+
pushd nifi-minifi-cpp/thirdparty/rocksdb/all
133+
134+
conan create . --user=minifi --channel=develop --version=8.10.2 -pr=../../../etc/conan/profiles/release-linux
135+
136+
popd
137+
~~~

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ advanced features.
358358

359359
### Building
360360

361+
#### Build MiNiFi using Standalone CMake
362+
361363
- From your source checkout, create a directory to perform the build (e.g. build) and cd into that directory.
362364
```
363365
# ~/Development/code/apache/nifi-minifi-cpp on git:master
@@ -403,6 +405,8 @@ advanced features.
403405
[100%] Built target run-tests
404406
```
405407

408+
#### Create MiNiFi Package using Standalone CMake
409+
406410
- Create a binary assembly located in your build directory with suffix .tar.gz
407411
```
408412
~/Development/code/apache/nifi-minifi-cpp/build
@@ -427,6 +431,11 @@ advanced features.
427431
CPack: - package: ~/Development/code/apache/nifi-minifi-cpp/build/nifi-minifi-cpp-0.99.0-source.tar.gz generated.
428432
```
429433

434+
#### Build MiNiFi & Create MiNiFi Package using Conan v2
435+
436+
Building MiNiFi and creating MiNiFi package supporting a portion of the extensions has been tested with Conan version 2 using VS code as an alternative to standalone CMake. By building MiNiFi using prebuilt conan packages for the external libraries as an alternative to CMake building the sources of those external libraries, we maybe able to speed up MiNiFi builds. Additionally, by creating a MiNiFi package as a conan package, it should be easier to integrate MiNiFi library and its executables into other C++
437+
project infrastructure to build out data pipelines on the edge. For instance, once we create the MiNiFi conan package, we can upload it to jfrog, conancenter or some other supported conan cloud repository and then download the prebuilt MiNiFi conan package to our new C++ project by adding it to our conanfile. For more details on the conan commands to build MiNiFi and create a MiNiFi conan package, see [CONAN.md](CONAN.md).
438+
430439
### Building a docker image
431440

432441
#### Building your own custom image

cmake/BuildTests.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
include(Catch2)
18+
include(GetCatch2)
19+
get_catch2()
1920

2021
### test functions
2122
MACRO(GETSOURCEFILES result curdir)

cmake/BundledOpenSSL.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,5 @@ function(use_openssl SOURCE_DIR BINARY_DIR)
148148
set_property(TARGET OpenSSL::Crypto APPEND PROPERTY INTERFACE_LINK_LIBRARIES crypt32.lib )
149149
set_property(TARGET OpenSSL::SSL APPEND PROPERTY INTERFACE_LINK_LIBRARIES crypt32.lib)
150150
endif()
151+
151152
endfunction(use_openssl)

cmake/BundledRocksDB.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ function(use_bundled_rocksdb SOURCE_DIR BINARY_DIR)
2727
endif()
2828

2929
# Patch to fix build issue on ARM7 architecture: https://github.com/facebook/rocksdb/issues/8609#issuecomment-1009572506
30-
set(PATCH_FILE_1 "${SOURCE_DIR}/thirdparty/rocksdb/arm7.patch")
31-
set(PATCH_FILE_2 "${SOURCE_DIR}/thirdparty/rocksdb/dboptions_equality_operator.patch")
32-
set(PATCH_FILE_3 "${SOURCE_DIR}/thirdparty/rocksdb/cstdint.patch")
30+
set(PATCH_FILE_1 "${SOURCE_DIR}/thirdparty/rocksdb/all/patches/arm7.patch")
31+
set(PATCH_FILE_2 "${SOURCE_DIR}/thirdparty/rocksdb/all/patches/dboptions_equality_operator.patch")
32+
set(PATCH_FILE_3 "${SOURCE_DIR}/thirdparty/rocksdb/all/patches/cstdint.patch")
3333
set(PC ${Bash_EXECUTABLE} -c "set -x &&\
3434
(\"${Patch_EXECUTABLE}\" -p1 -R -s -f --dry-run -i \"${PATCH_FILE_1}\" || \"${Patch_EXECUTABLE}\" -p1 -N -i \"${PATCH_FILE_1}\") &&\
3535
(\"${Patch_EXECUTABLE}\" -p1 -R -s -f --dry-run -i \"${PATCH_FILE_2}\" || \"${Patch_EXECUTABLE}\" -p1 -N -i \"${PATCH_FILE_2}\") &&\

cmake/Bustache.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
# under the License.
1818
#
1919
include(FetchContent)
20-
include(fmt)
20+
include(GetFmt)
21+
get_fmt()
22+
2123
set(BUSTACHE_USE_FMT ON CACHE STRING "" FORCE)
2224
FetchContent_Declare(Bustache
2325
GIT_REPOSITORY https://github.com/jamboree/bustache.git

cmake/GetBZip2.cmake

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
function(get_bzip2 SOURCE_DIR BINARY_DIR)
19+
if(MINIFI_BZIP2_SOURCE STREQUAL "CONAN")
20+
message("Using Conan to install bzip2")
21+
find_package(BZip2 REQUIRED)
22+
elseif(MINIFI_BZIP2_SOURCE STREQUAL "BUILD")
23+
message("Using CMake to build bzip2 from source")
24+
include(BundledBZip2)
25+
use_bundled_bzip2(${SOURCE_DIR} ${BINARY_DIR})
26+
endif()
27+
endfunction(get_bzip2)

cmake/GetCatch2.cmake

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
function(get_catch2)
19+
if(MINIFI_CATCH2_SOURCE STREQUAL "CONAN")
20+
message("Using Conan to install Catch2")
21+
find_package(Catch2 REQUIRED)
22+
add_library(Catch2WithMain ALIAS Catch2::Catch2WithMain)
23+
elseif(MINIFI_CATCH2_SOURCE STREQUAL "BUILD")
24+
message("Using CMake to build Catch2 from source")
25+
include(Catch2)
26+
endif()
27+
endfunction(get_catch2)

cmake/GetCivetWeb.cmake

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
function(get_civetweb)
19+
if(MINIFI_CIVETWEB_SOURCE STREQUAL "CONAN")
20+
message("Using Conan to install CivetWeb")
21+
find_package(civetweb REQUIRED)
22+
elseif(MINIFI_CIVETWEB_SOURCE STREQUAL "BUILD")
23+
message("Using CMake to build CivetWeb from source")
24+
include(CivetWeb)
25+
endif()
26+
endfunction(get_civetweb)

0 commit comments

Comments
 (0)