Skip to content

Commit 923bf15

Browse files
committed
Adopt change from apache/avro#3299
1 parent 9358d17 commit 923bf15

File tree

8 files changed

+66
-39
lines changed

8 files changed

+66
-39
lines changed

cmake_modules/IcebergThirdpartyToolchain.cmake

Lines changed: 29 additions & 25 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,34 @@ 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+
install(TARGETS avrocpp_s
175+
EXPORT iceberg_targets
176+
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
177+
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
178+
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
173179

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}")
187-
endif()
180+
# TODO: add vendored ZLIB and Snappy support
181+
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES ZLIB Snappy)
182+
else()
183+
set(AVRO_VENDORED FALSE)
184+
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES Avro)
188185
endif()
186+
187+
set(ICEBERG_SYSTEM_DEPENDENCIES
188+
${ICEBERG_SYSTEM_DEPENDENCIES}
189+
PARENT_SCOPE)
190+
set(AVRO_VENDORED
191+
${AVRO_VENDORED}
192+
PARENT_SCOPE)
189193
endfunction()
190194

191195
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(ARROW_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

src/iceberg/demo_table.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "iceberg/demo_table.h"
2121

22+
#include "iceberg/avro.h" // include to export symbols
2223
#include "iceberg/puffin.h"
2324

2425
namespace iceberg {

test/core/avro_unittest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ TEST(AVROTest, TestDemoAvro) {
3535
}\n\
3636
";
3737

38-
auto avro = iceberg::DemoAvro();
38+
auto avro = iceberg::avro::DemoAvro();
3939
EXPECT_EQ(avro.print(), expected);
4040
}

0 commit comments

Comments
 (0)