Skip to content

Commit fbc804d

Browse files
authored
Merge pull request #3 from wgtmac/add_avro
Add iceberg_avro library
2 parents 9358d17 + 79cbf7b commit fbc804d

File tree

12 files changed

+117
-90
lines changed

12 files changed

+117
-90
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
shell: cmd
8989
run: |
9090
call "C:\Program Files (x86)\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
91-
bash -c "ci/scripts/build_iceberg_windows.sh $(pwd)
91+
bash -c "ci/scripts/build_iceberg.sh $(pwd)
9292
- name: Build Example
9393
shell: cmd
9494
run: |

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

ci/scripts/build_iceberg_windows.sh

Lines changed: 0 additions & 40 deletions
This file was deleted.

cmake_modules/IcebergThirdpartyToolchain.cmake

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,11 @@ function(resolve_avro_dependency)
147147

148148
fetchcontent_declare(Avro
149149
${FC_DECLARE_COMMON_OPTIONS}
150-
GIT_REPOSITORY https://github.com/apache/avro.git
151-
GIT_TAG 1144cb7322bab4cd1c8bf330a9c504a0d4252b56
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
152155
SOURCE_SUBDIR
153156
lang/c++
154157
FIND_PACKAGE_ARGS
@@ -159,33 +162,39 @@ function(resolve_avro_dependency)
159162
fetchcontent_makeavailable(Avro)
160163

161164
if(avro_SOURCE_DIR)
162-
if(NOT TARGET Avro::avro_static)
163-
add_library(Avro::avro_static INTERFACE IMPORTED)
164-
target_link_libraries(Avro::avro_static INTERFACE avrocpp_s)
165-
set_target_properties(avrocpp_s PROPERTIES OUTPUT_NAME "iceberg_vendored_avro")
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++)
166170
endif()
167171

168-
if(NOT TARGET Avro::avro_shared)
169-
add_library(Avro::avro_shared INTERFACE IMPORTED)
170-
target_link_libraries(Avro::avro_shared INTERFACE avrocpp)
171-
set_target_properties(avrocpp PROPERTIES OUTPUT_NAME "iceberg_vendored_avro")
172-
endif()
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}")
173180

174-
if(ICEBERG_BUILD_STATIC)
175-
install(TARGETS avrocpp_s
176-
EXPORT fmt-targets
177-
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
178-
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
179-
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
180-
endif()
181-
if(ICEBERG_BUILD_SHARED)
182-
install(TARGETS avrocpp
183-
EXPORT fmt-targets
184-
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
185-
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
186-
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
181+
# TODO: add vendored ZLIB and Snappy support
182+
find_package(Snappy CONFIG)
183+
if(Snappy_FOUND)
184+
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES Snappy)
187185
endif()
186+
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES ZLIB)
187+
else()
188+
set(AVRO_VENDORED FALSE)
189+
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES Avro)
188190
endif()
191+
192+
set(ICEBERG_SYSTEM_DEPENDENCIES
193+
${ICEBERG_SYSTEM_DEPENDENCIES}
194+
PARENT_SCOPE)
195+
set(AVRO_VENDORED
196+
${AVRO_VENDORED}
197+
PARENT_SCOPE)
189198
endfunction()
190199

191200
if(ICEBERG_AVRO)

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/avro/CMakeLists.txt

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,39 @@ set(ICEBERG_AVRO_SHARED_BUILD_INTERFACE_LIBS)
2828
set(ICEBERG_AVRO_STATIC_INSTALL_INTERFACE_LIBS)
2929
set(ICEBERG_AVRO_SHARED_INSTALL_INTERFACE_LIBS)
3030

31-
list(APPEND ICEBERG_AVRO_STATIC_BUILD_INTERFACE_LIBS
31+
list(APPEND
32+
ICEBERG_AVRO_STATIC_BUILD_INTERFACE_LIBS
3233
"$<IF:$<TARGET_EXISTS:iceberg_static>,iceberg_static,iceberg_shared>"
33-
Avro::avro_static)
34-
list(APPEND ICEBERG_AVRO_SHARED_BUILD_INTERFACE_LIBS
34+
"$<IF:$<TARGET_EXISTS:Avro::avrocpp_static>,Avro::avrocpp_static,Avro::avrocpp_shared>"
35+
)
36+
list(APPEND
37+
ICEBERG_AVRO_SHARED_BUILD_INTERFACE_LIBS
3538
"$<IF:$<TARGET_EXISTS:iceberg_shared>,iceberg_shared,iceberg_static>"
36-
Avro::avro_shared)
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+
3756
list(APPEND
3857
ICEBERG_AVRO_STATIC_INSTALL_INTERFACE_LIBS
3958
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_static>,Iceberg::iceberg_static,Iceberg::iceberg_shared>"
40-
Iceberg::avro_static)
59+
)
4160
list(APPEND
4261
ICEBERG_AVRO_SHARED_INSTALL_INTERFACE_LIBS
4362
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_shared>,Iceberg::iceberg_shared,Iceberg::iceberg_static>"
44-
Iceberg::avro_shared)
63+
)
4564

4665
add_iceberg_lib(iceberg_avro
4766
SOURCES

src/iceberg/avro/demo_avro.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "avro/ValidSchema.hh"
2626
#include "iceberg/demo_table.h"
2727

28-
namespace iceberg {
28+
namespace iceberg::avro {
2929

3030
std::string DemoAvro::print() const {
3131
std::string input =
@@ -42,11 +42,11 @@ std::string DemoAvro::print() const {
4242
}\n\
4343
";
4444

45-
avro::ValidSchema schema = avro::compileJsonSchemaFromString(input);
45+
::avro::ValidSchema schema = ::avro::compileJsonSchemaFromString(input);
4646
std::ostringstream actual;
4747
schema.toJson(actual);
4848

4949
return actual.str();
5050
}
5151

52-
} // namespace iceberg
52+
} // namespace iceberg::avro

src/iceberg/avro/demo_avro.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "iceberg/avro.h"
2525
#include "iceberg/avro/iceberg_avro_export.h"
2626

27-
namespace iceberg {
27+
namespace iceberg::avro {
2828

2929
class ICEBERG_AVRO_EXPORT DemoAvro : public Avro {
3030
public:
@@ -33,4 +33,4 @@ class ICEBERG_AVRO_EXPORT DemoAvro : public Avro {
3333
std::string print() const override;
3434
};
3535

36-
} // namespace iceberg
36+
} // namespace iceberg::avro

0 commit comments

Comments
 (0)