Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor flatbuffer parser into a lib (#3864)
* refactor: refactor flatbuffer parser into a lib * dont remove io and allreduce * move fb tests * fmt * increase LINK_INTERFACE_MULTIPLICITY of fb parser * dont use latest std on windows * remove multiplicity * build fix * change target name
- Loading branch information
1 parent
05a0e39
commit 4dc4503
Showing
19 changed files
with
219 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2014 Stefan.Eilemann@epfl.ch | ||
# Copyright 2014 Google Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Find the flatbuffers schema compiler | ||
# | ||
# Output Variables: | ||
# * FLATBUFFERS_FLATC_EXECUTABLE the flatc compiler executable | ||
# * FLATBUFFERS_FOUND | ||
# | ||
|
||
# File modified from original contents to remove FLATBUFFERS_GENERATE_C_HEADERS and inclusion of BuildFlatBuffers.cmake | ||
|
||
set(FLATBUFFERS_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
find_program(FLATBUFFERS_FLATC_EXECUTABLE NAMES flatc) | ||
find_path(FLATBUFFERS_INCLUDE_DIR NAMES flatbuffers/flatbuffers.h) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(Flatbuffers | ||
DEFAULT_MSG FLATBUFFERS_FLATC_EXECUTABLE FLATBUFFERS_INCLUDE_DIR) | ||
|
||
if(FLATBUFFERS_FOUND) | ||
set(FLATBUFFERS_INCLUDE_DIRS ${FLATBUFFERS_INCLUDE_DIR}) | ||
include_directories(${CMAKE_BINARY_DIR}) | ||
else() | ||
set(FLATBUFFERS_INCLUDE_DIR) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
include(CMakeParseArguments) | ||
|
||
function(add_flatbuffer_schema) | ||
cmake_parse_arguments(ADD_FB_SCHEMA_ARGS | ||
"" | ||
"TARGET;FLATC_EXE;OUTPUT_DIR;FLATC_EXTRA_SCHEMA_ARGS" | ||
"SCHEMAS" | ||
${ARGN} | ||
) | ||
|
||
if(NOT DEFINED ADD_FB_SCHEMA_ARGS_TARGET) | ||
message(FATAL_ERROR "Missing TARGET argument to build_flatbuffers") | ||
endif() | ||
|
||
if(NOT DEFINED ADD_FB_SCHEMA_ARGS_FLATC_EXE) | ||
message(FATAL_ERROR "Missing FLATC_EXE argument to build_flatbuffers") | ||
endif() | ||
|
||
if(NOT EXISTS ${ADD_FB_SCHEMA_ARGS_FLATC_EXE}) | ||
message(FATAL_ERROR "FLATC_EXE ${ADD_FB_SCHEMA_ARGS_FLATC_EXE} does not exist") | ||
endif() | ||
|
||
if(NOT DEFINED ADD_FB_SCHEMA_ARGS_OUTPUT_DIR) | ||
message(FATAL_ERROR "Missing OUTPUT_DIR argument to build_flatbuffers") | ||
endif() | ||
|
||
if(NOT DEFINED ADD_FB_SCHEMA_ARGS_SCHEMAS) | ||
message(FATAL_ERROR "Missing SCHEMAS argument to build_flatbuffers") | ||
endif() | ||
|
||
set(FLATC_SCHEMA_ARGS --gen-mutable) | ||
if(DEFINED ADD_FB_SCHEMA_ARGS_FLATC_EXTRA_SCHEMA_ARGS) | ||
set(FLATC_SCHEMA_ARGS ${ADD_FB_SCHEMA_ARGS_FLATC_EXTRA_SCHEMA_ARGS} ${FLATC_SCHEMA_ARGS}) | ||
endif() | ||
|
||
foreach(schema IN ITEMS ${ADD_FB_SCHEMA_ARGS_SCHEMAS}) | ||
get_filename_component(filename ${schema} NAME_WE) | ||
set(generated_file_name ${ADD_FB_SCHEMA_ARGS_OUTPUT_DIR}/${filename}_generated.h) | ||
add_custom_command( | ||
OUTPUT ${generated_file_name} | ||
COMMAND ${ADD_FB_SCHEMA_ARGS_FLATC_EXE} ${FLATC_SCHEMA_ARGS} -o ${ADD_FB_SCHEMA_ARGS_OUTPUT_DIR} -c ${schema} | ||
DEPENDS ${schema} | ||
) | ||
list(APPEND ALL_SCHEMAS ${generated_file_name}) | ||
endforeach() | ||
|
||
add_custom_target(${ADD_FB_SCHEMA_ARGS_TARGET} DEPENDS ${ALL_SCHEMAS}) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
add_executable(to_flatbuff txt_to_flat.cc vw_to_flat.cc vw_to_flat.h) | ||
target_link_libraries(to_flatbuff PUBLIC VowpalWabbit::vw explore FlatbuffersTarget) | ||
target_link_libraries(to_flatbuff PUBLIC vw explore vw_fb_parser) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Generate header file | ||
add_flatbuffer_schema( | ||
TARGET fbschemas | ||
SCHEMAS "${CMAKE_CURRENT_LIST_DIR}/schema/example.fbs" | ||
OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/include/vw/fb_parser/generated/" | ||
FLATC_EXE ${flatc_location} | ||
) | ||
add_library(fb_generate_headers INTERFACE) | ||
add_dependencies(fb_generate_headers fbschemas) | ||
target_include_directories(fb_generate_headers INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/include/) | ||
|
||
set(vw_fb_parser_sources | ||
include/vw/fb_parser/parse_example_flatbuffer.h | ||
src/parse_example_flatbuffer.cc | ||
src/parse_label.cc | ||
) | ||
|
||
vw_add_library( | ||
NAME "fb_parser" | ||
TYPE "STATIC_ONLY" | ||
SOURCES ${vw_fb_parser_sources} | ||
PUBLIC_DEPS VowpalWabbit::vw $<BUILD_INTERFACE:fb_generate_headers> | ||
) | ||
target_include_directories(vw_fb_parser PUBLIC ${FLATBUFFERS_INCLUDE_DIR}) | ||
|
||
# Install the generated header | ||
# if(VW_INSTALL) | ||
# install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ | ||
# DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | ||
# endif() | ||
|
||
vw_add_test_executable( | ||
FOR_LIB "fb_parser" | ||
SOURCES "tests/flatbuffer_parser_test.cc" | ||
EXTRA_DEPS VowpalWabbit::vw | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.