change gtest into submodule & add workflows

Former-commit-id: 845051b313
This commit is contained in:
Minchul Lee 2021-07-25 16:21:37 +09:00
commit 94a6026bcf
10 changed files with 256 additions and 26 deletions

58
.github/workflows/macos.yml vendored Normal file
View file

@ -0,0 +1,58 @@
name: macOS
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-macos:
strategy:
matrix:
include:
# macOS 10.15 + Xcode 11.7
- name: "macOS 10.15 + Xcode 11.7"
os: macos-10.15
compiler: xcode
version: "11.7"
# macOS 10.15 + Xcode 12.2
- name: "macOS 10.15 + Xcode 12.2"
os: macos-10.15
compiler: xcode
version: "12.2"
# macOS 10.15 + gcc-9
- name: "macOS 10.15 + gcc-9"
os: macos-10.15
compiler: gcc
version: "9"
# macOS 10.15 + gcc-10
- name: "macOS 10.15 + gcc-10"
os: macos-10.15
compiler: gcc
version: "10"
runs-on: ${{ matrix.os }}
name: ${{ matrix.name }}
steps:
- uses: actions/checkout@v1
with:
submodules: true
- name: Configure Compiler
run: |
if [ "${{ matrix.compiler }}" = "gcc" ]; then
echo "CC=gcc-${{ matrix.version }}" >> $GITHUB_ENV
echo "CXX=g++-${{ matrix.version }}" >> $GITHUB_ENV
else
ls -ls /Applications/
sudo xcode-select -switch /Applications/Xcode_${{ matrix.version }}.app
echo "CC=clang" >> $GITHUB_ENV
echo "CXX=clang++" >> $GITHUB_ENV
fi
- name: Configure Build
run: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release ..
- name: Build
run: cd build && make
- name: Run Unit Test
run: ./build/test/kiwi-test

58
.github/workflows/ubuntu.yml vendored Normal file
View file

@ -0,0 +1,58 @@
name: Ubuntu
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-ubuntu:
strategy:
matrix:
include:
# Ubuntu 18.04 + gcc-9
- name: "Ubuntu 18.04 + gcc-9"
os: ubuntu-18.04
compiler: gcc
version: "9"
# Ubuntu 20.04 + gcc-10
- name: "Ubuntu 20.04 + gcc-10"
os: ubuntu-20.04
compiler: gcc
version: "10"
# Ubuntu 18.04 + clang-9
- name: "Ubuntu 18.04 + clang-9"
os: ubuntu-18.04
compiler: clang
version: "9"
# Ubuntu 20.04 + clang-10
- name: "Ubuntu 20.04 + clang-10"
os: ubuntu-20.04
compiler: clang
version: "10"
runs-on: ${{ matrix.os }}
name: ${{ matrix.name }}
steps:
- uses: actions/checkout@v1
with:
submodules: true
- name: Install packages
run: sudo apt-get install -yq python3-setuptools
- name: Configure Compiler
run: |
if [ "${{ matrix.compiler }}" = "gcc" ]; then
echo "CC=gcc-${{ matrix.version }}" >> $GITHUB_ENV
echo "CXX=g++-${{ matrix.version }}" >> $GITHUB_ENV
else
echo "CC=clang-${{ matrix.version }}" >> $GITHUB_ENV
echo "CXX=clang++-${{ matrix.version }}" >> $GITHUB_ENV
fi
- name: Configure Build
run: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release ..
- name: Build
run: cd build && make
- name: Run Unit Test
run: ./build/test/kiwi-test

30
.github/workflows/windows.yml vendored Normal file
View file

@ -0,0 +1,30 @@
name: Windows
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-windows:
strategy:
matrix:
os: [windows-2016, windows-2019]
arch: [x86, x64]
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} ${{ matrix.arch }}
steps:
- uses: actions/checkout@v1
with:
submodules: true
- name: Configure Build
run: mkdir build && cd build && cmake -DCMAKE_GENERATOR_PLATFORM=${{ matrix.arch }} -DCMAKE_BUILD_TYPE=Release ..
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
- name: Build
run: cd build && MSBuild.exe Kiwi.sln /p:Configuration=Release
- name: Run Unit Test
run: ./build/test/kiwi-test.exe

4
.gitmodules vendored
View file

@ -8,3 +8,7 @@
path = third_party/cpp-btree
url = https://github.com/bab2min/cpp-btree
branch = improve-mscv-compatibility
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://github.com/google/googletest
branch = v1.8.x

View file

@ -45,18 +45,35 @@ include_directories( include/ )
include_directories( third_party/tclap/include )
include_directories( third_party/cpp-btree )
link_libraries ( pthread )
if(MSVC)
set ( CMAKE_C_FLAGS_DEBUG "-DDEBUG -DC_FLAGS -Zi -Od ${ADDITIONAL_FLAGS}" )
set ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" )
set ( CMAKE_EXE_LINKER_FLAGS_DEBUG "-DDEBUG -DLINKER_FLAGS" )
set ( CMAKE_EXE_LINKER_FLAGS "-static -Wl,--gc-sections" )
set ( CMAKE_C_FLAGS_RELEASE "-DNDEBUG -DRELEASE -DC_FLAGS -O2 -Oi -Gy -DKIWI_USE_BTREE ${ADDITIONAL_FLAGS}" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" )
set ( CMAKE_EXE_LINKER_FLAGS_RELEASE "-DRELEASE -DLINKER_FLAGS" )
set ( CMAKE_C_FLAGS_DEBUG "-DDEBUG -DC_FLAGS -g3 -O0 ${ADDITIONAL_FLAGS}" )
set ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" )
set ( CMAKE_EXE_LINKER_FLAGS_DEBUG "-DDEBUG -DLINKER_FLAGS" )
set ( CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -Zi")
set ( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
set ( CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELEASE}" )
else()
link_libraries ( pthread )
set ( CMAKE_EXE_LINKER_FLAGS "-static -Wl,--gc-sections" )
set ( CMAKE_C_FLAGS_RELEASE "-DRELEASE -DC_FLAGS -O3 -DKIWI_USE_BTREE ${ADDITIONAL_FLAGS}" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" )
set ( CMAKE_EXE_LINKER_FLAGS_RELEASE "-DRELEASE -DLINKER_FLAGS" )
set ( CMAKE_C_FLAGS_DEBUG "-DDEBUG -DC_FLAGS -g3 -O0 ${ADDITIONAL_FLAGS}" )
set ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" )
set ( CMAKE_EXE_LINKER_FLAGS_DEBUG "-DDEBUG -DLINKER_FLAGS" )
set ( CMAKE_C_FLAGS_RELEASE "-DNDEBUG -DRELEASE -DC_FLAGS -O3 -DKIWI_USE_BTREE ${ADDITIONAL_FLAGS}" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" )
set ( CMAKE_EXE_LINKER_FLAGS_RELEASE "-DRELEASE -DLINKER_FLAGS" )
set ( CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g3")
set ( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
set ( CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELEASE}" )
endif()
add_library( "${CMAKE_PROJECT_NAME}_static" STATIC
${CORE_SRCS}
@ -85,6 +102,21 @@ target_link_libraries( "${CMAKE_PROJECT_NAME}-evaluator"
"${CMAKE_PROJECT_NAME}_static"
)
if(MSVC)
target_compile_options("${CMAKE_PROJECT_NAME}_static" PUBLIC
-MT
)
add_library( "${CMAKE_PROJECT_NAME}_rtd" SHARED
${CORE_SRCS}
src/capi/kiwi_c.cpp
)
target_compile_options("${CMAKE_PROJECT_NAME}_rtd" PUBLIC
-MD
)
endif()
#if(KIWI_USE_MIMALLOC)
# target_link_libraries( "${CMAKE_PROJECT_NAME}_static"
# mimalloc-static
@ -106,11 +138,5 @@ set_target_properties("${CMAKE_PROJECT_NAME}" PROPERTIES
include/kiwi/capi.h
)
include(ExternalProject)
ExternalProject_Add(gtest
URL https://github.com/google/googletest/archive/release-1.8.1.zip
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gtest
INSTALL_COMMAND ""
)
ExternalProject_Get_Property(gtest source_dir binary_dir)
add_subdirectory(test)
add_subdirectory( third_party/googletest )
add_subdirectory( test )

50
CMakeSettings.json Normal file
View file

@ -0,0 +1,50 @@
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
},
{
"name": "x86-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x86" ]
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": []
},
{
"name": "x86-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x86" ],
"variables": []
}
]
}

View file

@ -353,7 +353,7 @@ namespace kiwi
node.num_nexts = node_sizes[i];
node.next_offset = next_offset;
next_offset += node_sizes[i];
key_ranges.emplace_back(std::array<size_t, 3>{ non_leaf_idx, node.next_offset, node.next_offset + node.num_nexts });
key_ranges.emplace_back(std::array<size_t, 3>{ non_leaf_idx, (size_t)node.next_offset, (size_t)(node.next_offset + node.num_nexts) });
non_leaf_idx++;
}
else

View file

@ -126,7 +126,7 @@ WordDetector::WordDetector(const std::string& modelPath, size_t _numThreads)
{
{
ifstream ifs{ modelPath + "/extract.mdl", ios_base::binary };
if (ifs.fail()) throw Exception{ "Failed to open model file '" + modelPath + "extract.mdl'." };
if (ifs.fail()) throw Exception{ "Failed to open model file '" + modelPath + "/extract.mdl'." };
serializer::readMany(ifs, posScore, nounTailScore);
}
}

View file

@ -13,10 +13,13 @@ test_cpp.cpp
# If used often, could be made a macro.
add_dependencies(kiwi-test gtest)
include_directories(${source_dir}/googletest/include)
target_link_libraries(kiwi-test ${binary_dir}/googlemock/gtest/libgtest_main.a)
target_link_libraries(kiwi-test ${binary_dir}/googlemock/gtest/libgtest.a)
target_link_libraries(kiwi-test -Wl,--whole-archive -lpthread -Wl,--no-whole-archive)
include_directories(third_party/googletest/include)
target_link_libraries(kiwi-test gtest_main gtest)
if(MSVC)
else()
target_link_libraries(kiwi-test -Wl,--whole-archive -lpthread -Wl,--no-whole-archive)
endif()
target_link_libraries(kiwi-test "${CMAKE_PROJECT_NAME}_static")
##################################

1
third_party/googletest vendored Submodule

@ -0,0 +1 @@
Subproject commit dea0216d0c6bc5e63cf5f6c8651cd268668032ec