make spm build for static ort-web build (#293)

This commit is contained in:
Guenther Schmuelling 2022-09-16 12:42:15 -07:00 коммит произвёл GitHub
Родитель ae416f6aa6
Коммит 929283d4df
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 62 добавлений и 3 удалений

24
cmake/externals/sentencepieceproject.cmake поставляемый
Просмотреть файл

@ -8,14 +8,32 @@ FetchContent_GetProperties(spm)
if(NOT spm_POPULATED)
FetchContent_Populate(spm)
# need to patch sentencepiece to use protobuf provided by ort. This is ifdef onnxruntime_BUILD_WEBASSEMBLY
# for now but there is no real reason to not use it for all builds.
# 'git apply' should be in FetchContent_Declare() but that creates issues in sucessive builds so for now it is using execute_process().
if(onnxruntime_BUILD_WEBASSEMBLY)
set(SPM_PATCH "${PROJECT_SOURCE_DIR}/cmake/externals/sentencepieceproject.patch")
message("-- sentencepiece: patching with ${SPM_PATCH}")
execute_process(COMMAND git apply --ignore-space-change --ignore-whitespace ${SPM_PATCH} WORKING_DIRECTORY ${spm_SOURCE_DIR})
endif()
add_subdirectory(${spm_SOURCE_DIR} ${spm_BINARY_DIR} EXCLUDE_FROM_ALL)
set_target_properties(sentencepiece-static PROPERTIES
FOLDER externals/google/sentencepiece)
endif()
set(spm_INCLUDE_DIRS
${spm_SOURCE_DIR}/third_party/protobuf-lite
if (onnxruntime_BUILD_WEBASSEMBLY)
set(SPM_USE_BUILTIN_PROTOBUF OFF)
set(spm_INCLUDE_DIRS
${REPO_ROOT}/cmake/external/protobuf/src
${spm_SOURCE_DIR}/src/builtin_pb
${spm_SOURCE_DIR}/third_party
${spm_SOURCE_DIR}/src
)
)
else()
set(spm_INCLUDE_DIRS
${spm_SOURCE_DIR}/third_party/protobuf-lite
${spm_SOURCE_DIR}/src/builtin_pb
${spm_SOURCE_DIR}/third_party
${spm_SOURCE_DIR}/src
)
endif()

41
cmake/externals/sentencepieceproject.patch поставляемый Normal file
Просмотреть файл

@ -0,0 +1,41 @@
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 8b7fb76..3aa0f1f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -69,12 +69,23 @@ if (SPM_USE_BUILTIN_PROTOBUF)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite)
include_directories(builtin_pb)
else()
- find_package(Protobuf REQUIRED)
+ include_directories(${REPO_ROOT}/cmake/external/protobuf/src)
+ if(EXISTS "${ONNX_CUSTOM_PROTOC_EXECUTABLE}")
+ set(PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE})
+ else()
+ set(PROTOC_EXECUTABLE ${CMAKE_BINARY_DIR}/external/protobuf/cmake/protoc)
+ endif()
+ execute_process(COMMAND ${PROTOC_EXECUTABLE} --cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/builtin_pb --proto_path=${CMAKE_CURRENT_SOURCE_DIR} sentencepiece_model.proto)
+ execute_process(COMMAND ${PROTOC_EXECUTABLE} --cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/builtin_pb --proto_path=${CMAKE_CURRENT_SOURCE_DIR} sentencepiece.proto)
include_directories(${Protobuf_INCLUDE_DIRS})
- protobuf_generate_cpp(SPM_PROTO_SRCS SPM_PROTO_HDRS sentencepiece.proto)
- protobuf_generate_cpp(SPM_MODEL_PROTO_SRCS SPM_MODEL_PROTO_HDRS sentencepiece_model.proto)
set(PROTOBUF_LITE_SRCS "")
+ set(PROTOBUF_LITE_LIBRARY "")
include_directories(${PROTOBUF_INCLUDE_DIR})
+ include_directories(builtin_pb)
+ set(SPM_PROTO_HDRS builtin_pb/sentencepiece.pb.h)
+ set(SPM_PROTO_SRCS builtin_pb/sentencepiece.pb.cc)
+ set(SPM_MODEL_PROTO_HDRS builtin_pb/sentencepiece_model.pb.h)
+ set(SPM_MODEL_PROTO_SRCS builtin_pb/sentencepiece_model.pb.cc)
endif()
include_directories(${CMAKE_CURRENT_BINARY_DIR})
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt
index d00ecba..b355ccc 100644
--- a/third_party/CMakeLists.txt
+++ b/third_party/CMakeLists.txt
@@ -1,4 +1,4 @@
-include_directories(absl/strings darts_clone esaxx protobuf-lite)
+include_directories(absl/strings darts_clone esaxx)