Skip to content

Commit c0bf8ce

Browse files
zhjwpkuwgtmac
andauthored
Add iceberg_avro interface (#34)
Add iceberg_avro interface, this closes #17 --------- Signed-off-by: Junwang Zhao <[email protected]> Co-authored-by: Gang Wu <[email protected]>
1 parent 7e08c33 commit c0bf8ce

File tree

15 files changed

+390
-19
lines changed

15 files changed

+390
-19
lines changed

.github/workflows/test.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,25 @@ jobs:
7272
shell: bash
7373
run: ci/scripts/build_example.sh $(pwd)/example
7474
windows:
75-
name: AMD64 Windows 2019
76-
runs-on: windows-2019
75+
name: AMD64 Windows 2022
76+
runs-on: windows-2022
7777
timeout-minutes: 30
7878
steps:
7979
- name: Checkout iceberg-cpp
8080
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
8181
with:
8282
fetch-depth: 0
83+
- name: Install ZLIB
84+
shell: cmd
85+
run: |
86+
vcpkg install zlib:x64-windows
8387
- name: Build Iceberg
8488
shell: cmd
8589
run: |
86-
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
87-
bash -c "ci/scripts/build_iceberg.sh $(pwd)
90+
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
91+
bash -c "ci/scripts/build_iceberg.sh $(pwd)"
8892
- name: Build Example
8993
shell: cmd
9094
run: |
91-
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
92-
bash -c "ci/scripts/build_example.sh $(pwd)/example
95+
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
96+
bash -c "ci/scripts/build_example.sh $(pwd)/example"

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ option(ICEBERG_BUILD_STATIC "Build static library" ON)
3737
option(ICEBERG_BUILD_SHARED "Build shared library" OFF)
3838
option(ICEBERG_BUILD_TESTS "Build tests" ON)
3939
option(ICEBERG_ARROW "Build Arrow" ON)
40+
option(ICEBERG_AVRO "Build Avro" ON)
4041

4142
include(GNUInstallDirs)
4243
include(FetchContent)

ci/scripts/build_example.sh

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,27 @@ build_dir=${1}/build
2525
mkdir ${build_dir}
2626
pushd ${build_dir}
2727

28-
cmake \
29-
-DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX:-${ICEBERG_HOME}} \
30-
${source_dir}
31-
cmake --build .
28+
is_windows() {
29+
[[ "${OSTYPE}" == "msys" || "${OSTYPE}" == "win32" ]]
30+
}
31+
32+
CMAKE_ARGS=(
33+
"-DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX:-${ICEBERG_HOME}}"
34+
)
35+
36+
if is_windows; then
37+
CMAKE_ARGS+=("-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake")
38+
CMAKE_ARGS+=("-DCMAKE_BUILD_TYPE=Release")
39+
else
40+
CMAKE_ARGS+=("-DCMAKE_BUILD_TYPE=Debug")
41+
fi
42+
43+
cmake "${CMAKE_ARGS[@]}" ${source_dir}
44+
if is_windows; then
45+
cmake --build . --config Release
46+
else
47+
cmake --build .
48+
fi
3249

3350
popd
3451

ci/scripts/build_iceberg.sh

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,31 @@ build_dir=${1}/build
2525
mkdir ${build_dir}
2626
pushd ${build_dir}
2727

28-
cmake \
29-
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX:-${ICEBERG_HOME}} \
30-
-DICEBERG_BUILD_STATIC=ON \
31-
-DICEBERG_BUILD_SHARED=ON \
32-
${source_dir}
33-
cmake --build . --target install
34-
ctest --output-on-failure -C Debug
28+
is_windows() {
29+
[[ "${OSTYPE}" == "msys" || "${OSTYPE}" == "win32" ]]
30+
}
31+
32+
CMAKE_ARGS=(
33+
"-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX:-${ICEBERG_HOME}}"
34+
"-DICEBERG_BUILD_STATIC=ON"
35+
"-DICEBERG_BUILD_SHARED=ON"
36+
)
37+
38+
if is_windows; then
39+
CMAKE_ARGS+=("-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake")
40+
CMAKE_ARGS+=("-DCMAKE_BUILD_TYPE=Release")
41+
else
42+
CMAKE_ARGS+=("-DCMAKE_BUILD_TYPE=Debug")
43+
fi
44+
45+
cmake "${CMAKE_ARGS[@]}" ${source_dir}
46+
if is_windows; then
47+
cmake --build . --config Release --target install
48+
ctest --output-on-failure -C Release
49+
else
50+
cmake --build . --target install
51+
ctest --output-on-failure
52+
fi
3553

3654
popd
3755

cmake_modules/IcebergThirdpartyToolchain.cmake

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,77 @@ endfunction()
126126
if(ICEBERG_ARROW)
127127
resolve_arrow_dependency()
128128
endif()
129+
130+
# ----------------------------------------------------------------------
131+
# Apache Avro
132+
133+
function(resolve_avro_dependency)
134+
prepare_fetchcontent()
135+
136+
set(AVRO_USE_BOOST
137+
OFF
138+
CACHE BOOL "" FORCE)
139+
140+
set(AVRO_BUILD_EXECUTABLES
141+
OFF
142+
CACHE BOOL "" FORCE)
143+
144+
set(AVRO_BUILD_TESTS
145+
OFF
146+
CACHE BOOL "" FORCE)
147+
148+
fetchcontent_declare(Avro
149+
${FC_DECLARE_COMMON_OPTIONS}
150+
# TODO: switch to upstream once the PR below is merged
151+
# https://github.com/apache/avro/pull/3299
152+
# Eventually, we should switch to Apache Avro 1.3.0.
153+
GIT_REPOSITORY https://github.com/wgtmac/avro.git
154+
GIT_TAG 0aa7adf87a9af6d472a3e9d5966c5e7f1d6baa7d
155+
SOURCE_SUBDIR
156+
lang/c++
157+
FIND_PACKAGE_ARGS
158+
NAMES
159+
Avro
160+
CONFIG)
161+
162+
fetchcontent_makeavailable(Avro)
163+
164+
if(avro_SOURCE_DIR)
165+
if(NOT TARGET Avro::avrocpp_static)
166+
add_library(Avro::avrocpp_static INTERFACE IMPORTED)
167+
target_link_libraries(Avro::avrocpp_static INTERFACE avrocpp_s)
168+
target_include_directories(Avro::avrocpp_static
169+
INTERFACE ${avro_BINARY_DIR} ${avro_SOURCE_DIR}/lang/c++)
170+
endif()
171+
172+
set(AVRO_VENDORED TRUE)
173+
set_target_properties(avrocpp_s PROPERTIES OUTPUT_NAME "iceberg_vendored_avrocpp")
174+
set_target_properties(avrocpp_s PROPERTIES POSITION_INDEPENDENT_CODE ON)
175+
install(TARGETS avrocpp_s
176+
EXPORT iceberg_targets
177+
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
178+
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
179+
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
180+
181+
# TODO: add vendored ZLIB and Snappy support
182+
find_package(Snappy CONFIG)
183+
if(Snappy_FOUND)
184+
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES Snappy)
185+
endif()
186+
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES ZLIB)
187+
else()
188+
set(AVRO_VENDORED FALSE)
189+
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES Avro)
190+
endif()
191+
192+
set(ICEBERG_SYSTEM_DEPENDENCIES
193+
${ICEBERG_SYSTEM_DEPENDENCIES}
194+
PARENT_SCOPE)
195+
set(AVRO_VENDORED
196+
${AVRO_VENDORED}
197+
PARENT_SCOPE)
198+
endfunction()
199+
200+
if(ICEBERG_AVRO)
201+
resolve_avro_dependency()
202+
endif()

example/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ find_package(Iceberg CONFIG REQUIRED)
2626

2727
add_executable(demo_example demo_example.cc)
2828

29-
target_link_libraries(demo_example PRIVATE Iceberg::iceberg_puffin_static
30-
Iceberg::iceberg_arrow_static)
29+
target_link_libraries(demo_example
30+
PRIVATE Iceberg::iceberg_puffin_static
31+
Iceberg::iceberg_arrow_static Iceberg::iceberg_avro_static)

example/demo_example.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
#include <iostream>
2121

2222
#include "iceberg/arrow/demo_arrow.h"
23+
#include "iceberg/avro/demo_avro.h"
2324
#include "iceberg/demo_table.h"
2425
#include "iceberg/puffin/demo_puffin.h"
2526

2627
int main() {
2728
std::cout << iceberg::DemoTable().print() << std::endl;
2829
std::cout << iceberg::puffin::DemoPuffin().print() << std::endl;
2930
std::cout << iceberg::arrow::DemoArrow().print() << std::endl;
31+
std::cout << iceberg::avro::DemoAvro().print() << std::endl;
3032
return 0;
3133
}

src/iceberg/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iceberg_export.h
2929
DESTINATION ${ICEBERG_INSTALL_INCLUDEDIR}/iceberg)
3030

3131
add_subdirectory(arrow)
32+
add_subdirectory(avro)
3233
add_subdirectory(puffin)
3334

3435
iceberg_install_cmake_package(Iceberg iceberg_targets)

src/iceberg/avro.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#pragma once
21+
22+
#include <string>
23+
24+
#include "iceberg/iceberg_export.h"
25+
26+
namespace iceberg {
27+
28+
class ICEBERG_EXPORT Avro {
29+
public:
30+
virtual ~Avro() = default;
31+
virtual std::string print() const = 0;
32+
};
33+
34+
} // namespace iceberg

src/iceberg/avro/CMakeLists.txt

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
if(NOT ICEBERG_AVRO)
19+
return()
20+
endif()
21+
22+
set(ICEBERG_AVRO_SOURCES demo_avro.cc)
23+
set(ICEBERG_AVRO_INCLUDES "${ICEBERG_INCLUDES}")
24+
25+
# Libraries to link with exported libiceberg_avro.{so,a}.
26+
set(ICEBERG_AVRO_STATIC_BUILD_INTERFACE_LIBS)
27+
set(ICEBERG_AVRO_SHARED_BUILD_INTERFACE_LIBS)
28+
set(ICEBERG_AVRO_STATIC_INSTALL_INTERFACE_LIBS)
29+
set(ICEBERG_AVRO_SHARED_INSTALL_INTERFACE_LIBS)
30+
31+
list(APPEND
32+
ICEBERG_AVRO_STATIC_BUILD_INTERFACE_LIBS
33+
"$<IF:$<TARGET_EXISTS:iceberg_static>,iceberg_static,iceberg_shared>"
34+
"$<IF:$<TARGET_EXISTS:Avro::avrocpp_static>,Avro::avrocpp_static,Avro::avrocpp_shared>"
35+
)
36+
list(APPEND
37+
ICEBERG_AVRO_SHARED_BUILD_INTERFACE_LIBS
38+
"$<IF:$<TARGET_EXISTS:iceberg_shared>,iceberg_shared,iceberg_static>"
39+
"$<IF:$<TARGET_EXISTS:Avro::avrocpp_shared>,Avro::avrocpp_shared,Avro::avrocpp_static>"
40+
)
41+
42+
if(AVRO_VENDORED)
43+
list(APPEND ICEBERG_AVRO_STATIC_INSTALL_INTERFACE_LIBS Iceberg::avrocpp_s)
44+
list(APPEND ICEBERG_AVRO_SHARED_INSTALL_INTERFACE_LIBS Iceberg::avrocpp_s)
45+
else()
46+
list(APPEND
47+
ICEBERG_AVRO_STATIC_INSTALL_INTERFACE_LIBS
48+
"$<IF:$<TARGET_EXISTS:Avro::avrocpp_static>,Avro::avrocpp_static,Avro::avrocpp_shared>"
49+
)
50+
list(APPEND
51+
ICEBERG_AVRO_SHARED_INSTALL_INTERFACE_LIBS
52+
"$<IF:$<TARGET_EXISTS:Avro::avrocpp_shared>,Avro::avrocpp_shared,Avro::avrocpp_static>"
53+
)
54+
endif()
55+
56+
list(APPEND
57+
ICEBERG_AVRO_STATIC_INSTALL_INTERFACE_LIBS
58+
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_static>,Iceberg::iceberg_static,Iceberg::iceberg_shared>"
59+
)
60+
list(APPEND
61+
ICEBERG_AVRO_SHARED_INSTALL_INTERFACE_LIBS
62+
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_shared>,Iceberg::iceberg_shared,Iceberg::iceberg_static>"
63+
)
64+
65+
add_iceberg_lib(iceberg_avro
66+
SOURCES
67+
${ICEBERG_AVRO_SOURCES}
68+
PRIVATE_INCLUDES
69+
${ICEBERG_AVRO_INCLUDES}
70+
SHARED_LINK_LIBS
71+
${ICEBERG_AVRO_SHARED_BUILD_INTERFACE_LIBS}
72+
STATIC_LINK_LIBS
73+
${ICEBERG_AVRO_STATIC_BUILD_INTERFACE_LIBS}
74+
STATIC_INSTALL_INTERFACE_LIBS
75+
${ICEBERG_AVRO_STATIC_INSTALL_INTERFACE_LIBS}
76+
SHARED_INSTALL_INTERFACE_LIBS
77+
${ICEBERG_AVRO_SHARED_INSTALL_INTERFACE_LIBS})
78+
79+
iceberg_install_all_headers(iceberg/avro)
80+
81+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iceberg_avro_export.h
82+
DESTINATION ${ICEBERG_INSTALL_INCLUDEDIR}/iceberg/avro)

0 commit comments

Comments
 (0)