Skip to content

Commit

Permalink
Add demo project for conan build
Browse files Browse the repository at this point in the history
  • Loading branch information
kenneth-jia committed Jul 26, 2022
1 parent 07b0478 commit 338dc9a
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 5 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/kafka_api_demo_conan_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: '[Kafka API] Demo: Conan Build'

on:
pull_request:
push:
branches:
- main

env:
DEMO_PROJ_DIR: demo_projects_for_build/conan_build

jobs:
kafka-api-demo-conan-build:
strategy:
matrix:
os:
- ubuntu-22.04
- macos-12
- windows-latest

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

- name: Prepare
run: |
pip3 install conan
- name: Build (non-windows)
if: ${{!contains(matrix.os, 'windows')}}
run: |
cd ${DEMO_PROJ_DIR}
mkdir -p build
cd build
conan install .. --build=missing
cmake .. -G "Unix Makefiles"
cmake --build .
bin/kafka_sync_producer
bin/kafka_async_producer_copy_payload
bin/kafka_async_producer_not_copy_payload
bin/kafka_auto_commit_consumer
bin/kafka_manual_commit_consumer
- name: Build (windows)
if: contains(matrix.os, 'windows')
run: |
cd $Env:DEMO_PROJ_DIR
mkdir -p build
cd build
conan install .. --build=missing
cmake ..
cmake --build .
bin/kafka_sync_producer.exe
bin/kafka_async_producer_copy_payload.exe
bin/kafka_async_producer_not_copy_payload.exe
bin/kafka_auto_commit_consumer.exe
bin/kafka_manual_commit_consumer.exe
28 changes: 28 additions & 0 deletions demo_projects_for_build/conan_build/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION "3.8")
project("kafka-examples")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

# Target: kafka_sync_producer
add_executable("kafka_sync_producer" "../../examples/kafka_sync_producer.cc")
target_link_libraries("kafka_sync_producer" ${CONAN_LIBS})

# Target: kafka_async_producer_copy_payload
add_executable("kafka_async_producer_copy_payload" "../../examples/kafka_async_producer_copy_payload.cc")
target_link_libraries("kafka_async_producer_copy_payload" ${CONAN_LIBS})

# Target: kafka_async_producer_not_copy_payload
add_executable("kafka_async_producer_not_copy_payload" "../../examples/kafka_async_producer_not_copy_payload.cc")
target_link_libraries("kafka_async_producer_not_copy_payload" ${CONAN_LIBS})

# Target: kafka_auto_commit_consumer
add_executable("kafka_auto_commit_consumer" "../../examples/kafka_auto_commit_consumer.cc")
target_link_libraries("kafka_auto_commit_consumer" ${CONAN_LIBS})

# Target: kafka_manual_commit_consumer
add_executable("kafka_manual_commit_consumer" "../../examples/kafka_manual_commit_consumer.cc")
target_link_libraries("kafka_manual_commit_consumer" ${CONAN_LIBS})
5 changes: 5 additions & 0 deletions demo_projects_for_build/conan_build/conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[requires]
modern-cpp-kafka/2022.06.15

[generators]
cmake
2 changes: 1 addition & 1 deletion examples/kafka_async_producer_copy_payload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int main(int argc, char **argv)

if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " <brokers> <topic>\n";
exit(1); // NOLINT
exit(argc == 1 ? 0 : 1); // NOLINT
}

std::string brokers = argv[1];
Expand Down
2 changes: 1 addition & 1 deletion examples/kafka_async_producer_not_copy_payload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int main(int argc, char **argv)

if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " <brokers> <topic>\n";
exit(1); // NOLINT
exit(argc == 1 ? 0 : 1); // NOLINT
}

std::string brokers = argv[1];
Expand Down
2 changes: 1 addition & 1 deletion examples/kafka_auto_commit_consumer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main(int argc, char **argv)
{
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " <brokers> <topic>\n";
exit(1); // NOLINT
exit(argc == 1 ? 0 : 1); // NOLINT
}

std::string brokers = argv[1];
Expand Down
2 changes: 1 addition & 1 deletion examples/kafka_manual_commit_consumer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main(int argc, char **argv)
{
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " <brokers> <topic>\n";
exit(1); // NOLINT
exit(argc == 1 ? 0 : 1); // NOLINT
}

std::string brokers = argv[1];
Expand Down
2 changes: 1 addition & 1 deletion examples/kafka_sync_producer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main(int argc, char **argv)

if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " <brokers> <topic>\n";
exit(1); // NOLINT
exit(argc == 1 ? 0 : 1); // NOLINT
}

std::string brokers = argv[1];
Expand Down

0 comments on commit 338dc9a

Please sign in to comment.