Skip to content

Commit 274cb7f

Browse files
Migrate third_party/ to git submodules.
This replaces third_party/absl/ and third_party/protobuf-lite/ with submodules checked out at specific versions for abseil-cpp, googletest, benchmark, and protobuf libraries. This change allows removing local code copies of absl and googltest functionality.
1 parent 2734490 commit 274cb7f

File tree

180 files changed

+1396
-42855
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+1396
-42855
lines changed

.github/workflows/cifuzz.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
dry-run: false
2424
language: c++
2525
- name: Upload Crash
26-
uses: actions/upload-artifact@v3
26+
uses: actions/upload-artifact@v4
2727
if: failure() && steps.build.outcome == 'success'
2828
with:
2929
name: artifacts

.github/workflows/cmake.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727

2828
steps:
2929
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
30+
with:
31+
submodules: 'recursive'
3032
- uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1
3133
with:
3234
python-version: '3.x'
@@ -40,11 +42,11 @@ jobs:
4042
} else {
4143
$msbuildPlatform = "Win32"
4244
}
43-
cmake -A $msbuildPlatform -B ${{github.workspace}}/build -DSPM_BUILD_TEST=ON -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/root
45+
cmake -A $msbuildPlatform -B ${{github.workspace}}/build -DSPM_BUILD_TEST=ON -DBUILD_SHARED_LIBS=OFF -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/root
4446
4547
- name: Config for Unix
4648
if: runner.os != 'Windows'
47-
run: cmake -B ${{github.workspace}}/build -DSPM_BUILD_TEST=ON -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/root
49+
run: cmake -B ${{github.workspace}}/build -DSPM_BUILD_TEST=ON -DBUILD_SHARED_LIBS=OFF -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/root
4850
env:
4951
CMAKE_OSX_ARCHITECTURES: arm64;x86_64
5052

@@ -54,6 +56,8 @@ jobs:
5456
- name: Test
5557
working-directory: ${{github.workspace}}/build
5658
run: ctest -C Release --output-on-failure
59+
env:
60+
TEST_SRCDIR: ${{github.workspace}}/data
5761

5862
- name: Package
5963
working-directory: ${{github.workspace}}/build
@@ -65,10 +69,14 @@ jobs:
6569
python -m pip install --require-hashes --no-dependencies -r ../.github/workflows/requirements/base.txt
6670
python setup.py build
6771
python setup.py bdist_wheel
72+
pip install dist/*.whl
73+
pushd test
6874
python -m pytest
75+
env:
76+
GITHUB_REF_NAME: "${{ github.ref_name }}"
6977

7078
- name: Upload artifcacts
71-
uses: actions/upload-artifact@v3
79+
uses: actions/upload-artifact@v4
7280
with:
7381
name: artifcacts
7482
path: ./build/*.7z

.github/workflows/cross_build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121

2222
steps:
2323
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
24+
with:
25+
submodules: 'recursive'
2426

2527
- name: Install cross tools
2628
run: |
@@ -34,7 +36,7 @@ jobs:
3436
run: |
3537
mkdir -p ${{github.workspace}}/build
3638
cd ${{github.workspace}}/build
37-
env CXX=/usr/bin/${{matrix.arch}}-linux-gnu-g++-10 CC=/usr/bin/${{matrix.arch}}-linux-gnu-gcc-10 cmake .. -DSPM_BUILD_TEST=ON -DSPM_ENABLE_SHARED=OFF -DCMAKE_FIND_ROOT_PATH=/usr/${{matrix.arch}}-linux-gnu -DSPM_CROSS_SYSTEM_PROCESSOR=${{matrix.arch}}
39+
env CXX=/usr/bin/${{matrix.arch}}-linux-gnu-g++-10 CC=/usr/bin/${{matrix.arch}}-linux-gnu-gcc-10 cmake .. -DSPM_BUILD_TEST=ON -DBUILD_SHARED_LIBS=OFF -DSPM_ENABLE_SHARED=OFF -DCMAKE_FIND_ROOT_PATH=/usr/${{matrix.arch}}-linux-gnu -DSPM_CROSS_SYSTEM_PROCESSOR=${{matrix.arch}}
3840
make -j$(nproc)
3941
4042
- name: Test on QEMU

.github/workflows/wheel.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ jobs:
2828

2929
steps:
3030
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
31+
with:
32+
submodules: 'recursive'
3133
- uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1
3234
with:
33-
python-version: "3.x"
35+
python-version: ">=3.8"
3436

3537
- name: Set up QEMU
3638
if: runner.os == 'Linux'
@@ -41,17 +43,17 @@ jobs:
4143
- name: Build for Windows
4244
if: runner.os == 'Windows'
4345
run: |
44-
cmake -A Win32 -B ${{github.workspace}}/build_win32 -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/root_win32
46+
cmake -A Win32 -B ${{github.workspace}}/build_win32 -DBUILD_SHARED_LIBS=OFF -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/root_win32
4547
cmake --build ${{github.workspace}}/build_win32 --config Release --target install --parallel 8
46-
cmake -A x64 -B ${{github.workspace}}/build_amd64 -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/root_amd64
48+
cmake -A x64 -B ${{github.workspace}}/build_amd64 -DBUILD_SHARED_LIBS=OFF -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/root_amd64
4749
cmake --build ${{github.workspace}}/build_amd64 --config Release --target install --parallel 8
48-
cmake -A arm64 -B ${{github.workspace}}/build_arm64 -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/root_arm64
50+
cmake -A arm64 -B ${{github.workspace}}/build_arm64 -DBUILD_SHARED_LIBS=OFF -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/root_arm64
4951
cmake --build ${{github.workspace}}/build_arm64 --config Release --target install --parallel 8
5052
5153
- name: Build for Mac
5254
if: runner.os == 'macOS'
5355
run: |
54-
cmake -B ${{github.workspace}}/build -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/root
56+
cmake -B ${{github.workspace}}/build -DSPM_ENABLE_SHARED=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/root
5557
cmake --build ${{github.workspace}}/build --config Release --target install --parallel 8
5658
env:
5759
CMAKE_OSX_ARCHITECTURES: arm64;x86_64
@@ -66,10 +68,11 @@ jobs:
6668
working-directory: ${{github.workspace}}/python
6769
run: python -m cibuildwheel --output-dir wheelhouse
6870
env:
71+
CIBW_ENVIRONMENT: "GITHUB_REF_NAME=${{ github.ref_name }}"
6972
CIBW_ARCHS_LINUX: auto aarch64
7073
CIBW_ARCHS_MACOS: x86_64 universal2 arm64
7174
CIBW_ARCHS_WINDOWS: auto ARM64
72-
CIBW_SKIP: "pp* *-musllinux_*"
75+
CIBW_SKIP: "pp* *-musllinux_* cp3{6,7}-*"
7376
CIBW_BUILD_VERBOSITY: 1
7477

7578
- name: Build sdist archive
@@ -91,7 +94,7 @@ jobs:
9194
run: cp -f dist/*.tar.gz wheelhouse/
9295

9396
- name: Upload artifact
94-
uses: actions/upload-artifact@v3
97+
uses: actions/upload-artifact@v4
9598
with:
9699
name: artifacts
97100
path: |

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ dist/
6363
*.swp
6464
*.swo
6565
*.pyc
66+
*.whl
6667

6768
m.model
6869
m.vocab
@@ -72,6 +73,8 @@ libsentencepiece.so*
7273
libsentencepiece_train.so*
7374
python/bundled
7475
_sentencepiece.*.so
75-
third_party/abseil-cpp
76+
77+
# Generated proto files.
78+
src/*.pb.*
7679

7780
python/sentencepiece

.gitmodules

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[submodule "third_party/googletest"]
2+
path = third_party/googletest
3+
url = https://github.com/google/googletest.git
4+
[submodule "third_party/protobuf"]
5+
path = third_party/protobuf
6+
url = https://github.com/protocolbuffers/protobuf.git
7+
[submodule "third_party/abseil-cpp"]
8+
path = third_party/abseil-cpp
9+
url = https://github.com/abseil/abseil-cpp.git
10+
[submodule "third_party/benchmark"]
11+
path = third_party/benchmark
12+
url = https://github.com/google/benchmark.git

CMakeLists.txt

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.!
1414

15-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
15+
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
1616
file(STRINGS "VERSION.txt" SPM_VERSION)
1717
message(STATUS "VERSION: ${SPM_VERSION}")
1818

@@ -36,7 +36,7 @@ option(SPM_CROSS_SYSTEM_PROCESSOR, "Override system processor" "")
3636
set(SPM_PROTOBUF_PROVIDER "internal" CACHE STRING "Provider of protobuf library")
3737
set_property(CACHE SPM_PROTOBUF_PROVIDER PROPERTY STRINGS "internal" "package")
3838
set(SPM_ABSL_PROVIDER "internal" CACHE STRING "Provider of absl library")
39-
set_property(CACHE SPM_ABSL_PROVIDER PROPERTY STRINGS "internal" "module" "package")
39+
set_property(CACHE SPM_ABSL_PROVIDER PROPERTY STRINGS "internal" "package")
4040

4141
if (SPM_CROSS_SYSTEM_PROCESSOR)
4242
set(CMAKE_SYSTEM_PROCESSOR ${SPM_CROSS_SYSTEM_PROCESSOR})
@@ -45,11 +45,14 @@ endif()
4545
# Disable shared build on windows
4646
if(WIN32)
4747
set(SPM_ENABLE_SHARED OFF)
48+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
4849
endif()
4950

5051
set(CMAKE_CXX_STANDARD 17)
5152
set(CMAKE_CXX_STANDARD_REQUIRED ON)
5253

54+
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
55+
5356
if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
5457
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 10.0) OR
5558
(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
@@ -154,21 +157,24 @@ if (SPM_BUILD_TEST)
154157
enable_testing()
155158
endif()
156159

160+
set(ABSL_PROPAGATE_CXX_STD ON)
157161
if (SPM_ABSL_PROVIDER STREQUAL "internal")
158-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl)
159-
elseif (SPM_ABSL_PROVIDER STREQUAL "module")
160162
include(FetchContent)
161-
FetchContent_Populate(abseil-cpp
162-
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
163-
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/abseil-cpp
164-
GIT_PROGRESS TRUE)
165-
add_subdirectory(third_party/abseil-cpp)
166-
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl.org)
167-
file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl.org)
168-
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
169-
${CMAKE_CURRENT_SOURCE_DIR}/third_party/abseil-cpp/absl
170-
${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl)
171-
endif()
163+
FetchContent_Declare(
164+
googletest
165+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/googletest)
166+
set(ABSL_ENABLE_INSTALL ON)
167+
set(ASBL_BUILD_TESTING OFF)
168+
FetchContent_Declare(
169+
absl
170+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/abseil-cpp)
171+
FetchContent_MakeAvailable(googletest absl)
172+
FetchContent_GetProperties(googletest SOURCE_DIR googletest_SOURCE_DIR)
173+
include_directories("${googletest_SOURCE_DIR}/googletest/include/")
174+
include_directories("${googletest_SOURCE_DIR}/googlemock/include")
175+
176+
FetchContent_GetProperties(absl SOURCE_DIR absl_SOURCE_DIR)
177+
include_directories(${absl_SOURCE_DIR})
172178
elseif (SPM_ABSL_PROVIDER STREQUAL "package")
173179
find_package(absl REQUIRED)
174180
get_target_property(ABSL_INCLUDE_DIRS absl::base INTERFACE_INCLUDE_DIRECTORIES)
@@ -180,6 +186,42 @@ elseif (SPM_ABSL_PROVIDER STREQUAL "package")
180186
include_directories(${ABSL_INCLUDE_DIRS})
181187
endif()
182188

189+
if ((${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") OR
190+
(${CMAKE_SYSTEM_PROCESSOR} MATCHES "mips") OR
191+
(${CMAKE_SYSTEM_PROCESSOR} MATCHES "m68k") OR
192+
(${CMAKE_SYSTEM_PROCESSOR} MATCHES "ppc") OR
193+
(${CMAKE_SYSTEM_PROCESSOR} MATCHES "powerpc") OR
194+
(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch") OR
195+
(${CMAKE_SYSTEM_PROCESSOR} MATCHES "sh4"))
196+
set(protobuf_LINK_LIBATOMIC ON)
197+
endif()
198+
199+
# Note: Protobuf must occuring after abseil-cpp due to dependency.
200+
if (SPM_PROTOBUF_PROVIDER STREQUAL "internal")
201+
set(protobuf_INSTALL ON)
202+
set(utf8_range_ENABLE_INSTALL ON)
203+
set(protobuf_BUILD_TESTS OFF)
204+
# https://github.com/protocolbuffers/protobuf/issues/14549
205+
if (${CMAKE_SYSTEM_PROCCESSOR} MATCHES "riscv|powerpc")
206+
set(protobuf_LINK_LIBATOMIC true)
207+
endif()
208+
FetchContent_Declare(
209+
Protobuf
210+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/
211+
)
212+
if (SPM_ENABLE_SHARED)
213+
set(protobuf_BUILD_SHARED_LIBS ON)
214+
set(Protobuf_USE_STATIC_LIBS OFF)
215+
else ()
216+
set(protobuf_BUILD_SHARED_LIBS OFF)
217+
set(Protobuf_USE_STATIC_LIBS ON)
218+
endif()
219+
FetchContent_MakeAvailable(Protobuf)
220+
FetchContent_GetProperties(Protobuf SOURCE_DIR Protobuf_SOURCE_DIR)
221+
include(${Protobuf_SOURCE_DIR}/cmake/protobuf-generate.cmake)
222+
include_directories("${Protobuf_SOURCE_DIR}/src")
223+
endif()
224+
183225
add_subdirectory(src)
184226
add_subdirectory(third_party)
185227

python/build_bundled.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

3-
VERSION="$1"
3+
set -x
4+
5+
REF_NAME="${1}"
46

57
mkdir -p build
68

@@ -10,13 +12,25 @@ INSTALL_DIR=./build/root
1012
if [ -f ./sentencepiece/src/CMakeLists.txt ]; then
1113
SRC_DIR=./sentencepiece
1214
elif [ -f ../src/CMakeLists.txt ]; then
13-
SRC_DIR=..
15+
SRC_DIR=..
1416
else
1517
# Try taged version. Othewise, use head.
16-
git clone https://github.com/google/sentencepiece.git -b v"${VERSION}" --depth 1 || \
18+
echo -e "\033[0;35mSource not found, cloning from github...\033[0m"
1719
git clone https://github.com/google/sentencepiece.git --depth 1
20+
pushd sentencepiece
21+
git checkout ${REF_NAME}
22+
if [[ $? > 0 ]]; then
23+
echo -e "\033[0;35mRef named ${REF_NAME} not found, trying it as a pull request...\033[0m"
24+
PR_NUM=${REF_NAME%/merge}
25+
git pull origin pull/${PR_NUM}/head:pr_${PR_NUM} && git checkout -q pr_${PR_NUM}
26+
fi
27+
git submodule init && git submodule update
28+
echo -e "\033[0;35mWorking from ref:\033[0m"
29+
git --no-pager log -n 1 --decorate=short --pretty=oneline
30+
popd
1831
SRC_DIR=./sentencepiece
1932
fi
33+
echo -e "\033[0;32mSource at ${SRC_DIR}\033[0m"
2034

21-
cmake ${SRC_DIR} -B ${BUILD_DIR} -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
35+
cmake ${SRC_DIR} -B ${BUILD_DIR} -DBUILD_SHARED_LIBS=OFF -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
2236
cmake --build ${BUILD_DIR} --config Release --target install --parallel $(nproc)

0 commit comments

Comments
 (0)