Skip to content

Commit 096e5b0

Browse files
authored
Merge pull request #1237 from google/abseil-switch
Abseil switch
2 parents 1b604de + 5225e85 commit 096e5b0

43 files changed

Lines changed: 70 additions & 1638 deletions

Some content is hidden

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

.github/workflows/cmake.yml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,13 @@ jobs:
2020
matrix:
2121
os: [ ubuntu-latest, macos-latest ]
2222
arch: [ x64, arm64 ]
23-
absl_provider: [ module, internal ]
2423
include:
2524
- os: windows-latest
2625
arch: Win32
27-
absl_provider: internal
2826
- os: windows-latest
2927
arch: x64
30-
absl_provider: internal
3128
- os: windows-11-arm
3229
arch: ARM64
33-
absl_provider: internal
34-
- os: windows-latest
35-
arch: Win32
36-
absl_provider: module
37-
- os: windows-latest
38-
arch: x64
39-
absl_provider: module
40-
- os: windows-11-arm
41-
arch: ARM64
42-
absl_provider: module
4330

4431
runs-on: ${{ matrix.os }}
4532

@@ -51,11 +38,10 @@ jobs:
5138

5239
- name: Config for Windows
5340
if: runner.os == 'Windows'
54-
run: cmake -A ${{ matrix.arch }} -B build -DSPM_BUILD_TEST=ON -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=build/root -DSPM_ABSL_PROVIDER=${{ matrix.absl_provider }}
55-
41+
run: cmake -A ${{ matrix.arch }} -B build -DSPM_BUILD_TEST=ON -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=build/root
5642
- name: Config for Linux/MacOSX
5743
if: runner.os != 'Windows'
58-
run: cmake -B build -DSPM_BUILD_TEST=ON -DCMAKE_INSTALL_PREFIX=build/root -DSPM_ABSL_PROVIDER=${{ matrix.absl_provider }}
44+
run: cmake -B build -DSPM_BUILD_TEST=ON -DCMAKE_INSTALL_PREFIX=build/root
5945
env:
6046
CMAKE_OSX_ARCHITECTURES: arm64;x86_64
6147

@@ -73,7 +59,7 @@ jobs:
7359
- name: Upload artifacts
7460
uses: actions/upload-artifact@v7
7561
with:
76-
name: artifacts-${{ matrix.os }}-${{ matrix.arch }}-absl_${{ matrix.absl_provider }}
62+
name: artifacts-${{ matrix.os }}-${{ matrix.arch }}
7763
path: ./build/*.7z
7864
overwrite: false
7965

.github/workflows/cross_build.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
arch: [ i686, arm, aarch64, riscv64, powerpc, powerpc64, powerpc64le, s390x, sparc64, m68k, sh4, alpha ]
24-
absl_provider: [ module, internal ]
2524

2625
steps:
2726
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -38,7 +37,7 @@ jobs:
3837
run: |
3938
mkdir -p build
4039
cd build
41-
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}} -DSPM_ABSL_PROVIDER=${{ matrix.absl_provider }}
40+
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}}
4241
make -j$(nproc)
4342
4443
- name: Test on QEMU

.github/workflows/wheel.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ jobs:
3838
- name: Build for Windows (Win32/x64)
3939
if: runner.os == 'Windows' && runner.arch != 'ARM64'
4040
run: |
41-
cmake -A Win32 -B build_win32 -DSPM_ENABLE_SHARED=OFF -DSPM_DISABLE_EMBEDDED_DATA=ON -DSPM_ABSL_PROVIDER=module -DCMAKE_INSTALL_PREFIX=build_win32/root
41+
cmake -A Win32 -B build_win32 -DSPM_ENABLE_SHARED=OFF -DSPM_DISABLE_EMBEDDED_DATA=ON -DCMAKE_INSTALL_PREFIX=build_win32/root
4242
cmake --build build_win32 --config Release --target install --parallel 8
43-
cmake -A x64 -B build_amd64 -DSPM_ENABLE_SHARED=OFF -DSPM_DISABLE_EMBEDDED_DATA=ON -DSPM_ABSL_PROVIDER=module -DCMAKE_INSTALL_PREFIX=build_amd64/root
43+
cmake -A x64 -B build_amd64 -DSPM_ENABLE_SHARED=OFF -DSPM_DISABLE_EMBEDDED_DATA=ON -DCMAKE_INSTALL_PREFIX=build_amd64/root
4444
cmake --build build_amd64 --config Release --target install --parallel 8
4545
4646
- name: Build for Windows (ARM64)
4747
if: runner.os == 'Windows' && runner.arch == 'ARM64'
4848
run: |
49-
cmake -A arm64 -B build_arm64 -DSPM_ENABLE_SHARED=OFF -DSPM_DISABLE_EMBEDDED_DATA=ON -DSPM_ABSL_PROVIDER=module -DCMAKE_INSTALL_PREFIX=build_arm64/root
49+
cmake -A arm64 -B build_arm64 -DSPM_ENABLE_SHARED=OFF -DSPM_DISABLE_EMBEDDED_DATA=ON -DCMAKE_INSTALL_PREFIX=build_arm64/root
5050
cmake --build build_arm64 --config Release --target install --parallel 8
5151
5252
- name: Build for Mac
5353
if: runner.os == 'macOS'
5454
run: |
55-
cmake -B build -DSPM_ENABLE_SHARED=OFF -DSPM_DISABLE_EMBEDDED_DATA=ON -DSPM_ABSL_PROVIDER=module -DCMAKE_INSTALL_PREFIX=build/root
55+
cmake -B build -DSPM_ENABLE_SHARED=OFF -DSPM_DISABLE_EMBEDDED_DATA=ON -DCMAKE_INSTALL_PREFIX=build/root
5656
cmake --build build --config Release --target install --parallel 8
5757
env:
5858
MACOSX_DEPLOYMENT_TARGET: 10.13

CMakeLists.txt

Lines changed: 15 additions & 16 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.10 FATAL_ERROR)
15+
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
1616
file(STRINGS "VERSION.txt" SPM_VERSION)
1717
message(STATUS "VERSION: ${SPM_VERSION}")
1818

@@ -36,8 +36,8 @@ option(SPM_NLCODEC_BPE
3636

3737
set(SPM_PROTOBUF_PROVIDER "internal" CACHE STRING "Provider of protobuf library")
3838
set_property(CACHE SPM_PROTOBUF_PROVIDER PROPERTY STRINGS "internal" "package")
39-
set(SPM_ABSL_PROVIDER "internal" CACHE STRING "Provider of absl library")
40-
set_property(CACHE SPM_ABSL_PROVIDER PROPERTY STRINGS "internal" "module" "package")
39+
set(SPM_ABSL_PROVIDER "module" CACHE STRING "Provider of absl library")
40+
set_property(CACHE SPM_ABSL_PROVIDER PROPERTY STRINGS "module" "package")
4141

4242
if(NOT CMAKE_BUILD_TYPE)
4343
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
@@ -51,7 +51,7 @@ endif()
5151

5252
# Includes processor name to avoid conflicts.
5353
set(CPACK_PACKAGE_FILE_NAME
54-
"sentencepiece-${SPM_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}-absl_${SPM_ABSL_PROVIDER}")
54+
"sentencepiece-${SPM_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
5555

5656
if (SPM_CROSS_SYSTEM_PROCESSOR)
5757
set(CMAKE_SYSTEM_PROCESSOR ${SPM_CROSS_SYSTEM_PROCESSOR})
@@ -184,29 +184,28 @@ if (SPM_DISABLE_EMBEDDED_DATA)
184184
install(FILES ${EMBEDDED_DATA_FILES} DESTINATION ${INSTALL_DATADIR})
185185
endif()
186186

187-
if (SPM_ABSL_PROVIDER STREQUAL "internal")
188-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl)
189-
elseif (SPM_ABSL_PROVIDER STREQUAL "module")
187+
if (SPM_ABSL_PROVIDER STREQUAL "module")
190188
include(FetchContent)
191189
FetchContent_Populate(abseil-cpp
192190
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
193191
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/abseil-cpp
194192
GIT_PROGRESS TRUE
195193
GIT_TAG 20260107.1)
196194
add_subdirectory(third_party/abseil-cpp)
197-
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl.org)
198-
file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl.org)
199-
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
200-
${CMAKE_CURRENT_SOURCE_DIR}/third_party/abseil-cpp/absl
201-
${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl)
195+
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl)
196+
file(CREATE_LINK
197+
${CMAKE_CURRENT_SOURCE_DIR}/third_party/abseil-cpp/absl
198+
${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl
199+
SYMBOLIC)
202200
endif()
203201
elseif (SPM_ABSL_PROVIDER STREQUAL "package")
204202
find_package(absl REQUIRED)
205203
get_target_property(ABSL_INCLUDE_DIRS absl::base INTERFACE_INCLUDE_DIRECTORIES)
206-
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl.org)
207-
file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl.org)
208-
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
209-
${ABSL_INCLUDE_DIRS}/absl ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl)
204+
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl)
205+
file(CREATE_LINK
206+
${ABSL_INCLUDE_DIRS}/absl
207+
${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl
208+
SYMBOLIC)
210209
endif()
211210
include_directories(${ABSL_INCLUDE_DIRS})
212211
endif()

python/build_bundled.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ cmake ${SRC_DIR} -B ${BUILD_DIR} \
2222
-DSPM_ENABLE_SHARED=OFF \
2323
-DSPM_DISABLE_EMBEDDED_DATA=ON \
2424
-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \
25-
-DSPM_ABSL_PROVIDER=module \
2625
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
2726
-DCMAKE_CXX_FLAGS="-fPIC -fvisibility=default -ffunction-sections -fdata-sections"
2827
cmake --build ${BUILD_DIR} --config Release --target install --parallel $(nproc)

python/setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ def build_extension(self, ext):
160160
'-B',
161161
'build',
162162
'-DSPM_ENABLE_SHARED=OFF',
163-
'-DSPM_ABSL_PROVIDER=module',
164-
'-DCMAKE_SHARED_LINKER_FLAGS="/OPT:REF /OPT:ICF /LTCG"',
163+
# '-DCMAKE_SHARED_LINKER_FLAGS="/OPT:REF /OPT:ICF /LTCG"',
165164
'-DCMAKE_INSTALL_PREFIX=build\\root',
166165
])
167166
subprocess.check_call([

src/CMakeLists.txt

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

15-
if (SPM_ABSL_PROVIDER STREQUAL "module" OR SPM_ABSL_PROVIDER STREQUAL "package")
16-
set(ABSL_FLAGS_SRCS "")
17-
set(ABSL_STRINGS_SRCS "")
18-
list(APPEND SPM_LIBS absl::strings)
19-
list(APPEND SPM_LIBS absl::flags)
20-
list(APPEND SPM_LIBS absl::flags_parse)
21-
list(APPEND SPM_LIBS absl::log)
22-
list(APPEND SPM_LIBS absl::check)
23-
add_compile_definitions(_USE_EXTERNAL_ABSL)
24-
elseif (SPM_ABSL_PROVIDER STREQUAL "internal")
25-
set(ABSL_FLAGS_SRCS
26-
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/absl/flags/flag.cc
27-
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/absl/log/log.cc)
28-
endif()
15+
list(APPEND SPM_LIBS absl::strings)
16+
list(APPEND SPM_LIBS absl::flags)
17+
list(APPEND SPM_LIBS absl::flags_parse)
18+
list(APPEND SPM_LIBS absl::log)
19+
list(APPEND SPM_LIBS absl::check)
2920

3021
if (SPM_PROTOBUF_PROVIDER STREQUAL "internal")
3122
set(SPM_PROTO_HDRS builtin_pb/sentencepiece.pb.h)
@@ -111,9 +102,7 @@ set(SPM_SRCS
111102
sentencepiece_processor.cc
112103
unigram_model.cc
113104
util.cc
114-
word_model.cc
115-
${ABSL_STRINGS_SRCS}
116-
${ABSL_FLAGS_SRCS})
105+
word_model.cc)
117106

118107
set(SPM_TRAIN_SRCS
119108
${SPM_PROTO_HDRS}
@@ -151,7 +140,6 @@ set(SPM_TEST_SRCS
151140
char_model_test.cc
152141
char_model_trainer_test.cc
153142
filesystem_test.cc
154-
init_test.cc
155143
model_factory_test.cc
156144
model_interface_test.cc
157145
normalizer_test.cc

src/common.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ static constexpr uint32_t kUnicodeError = 0xFFFD;
6363
CHECK(_status.ok()) << _status.ToString(); \
6464
} while (0)
6565

66-
#define QCHECK_OK CHECK_OK
66+
#define QCHECK_OK(expr) \
67+
do { \
68+
const auto _status = expr; \
69+
QCHECK(_status.ok()) << _status.ToString(); \
70+
} while (0)
6771

6872
#endif // COMMON_H_

src/compile_charsmap_main.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,12 @@ struct BinaryBlob {
127127
os << kHeader;
128128

129129
os << "#if defined(_WIN32) && !defined(__CYGWIN__)\n";
130-
os << "constexpr unsigned long long int kNormalizationRules_blob_uint64_t[] = "
130+
os << "constexpr unsigned long long int kNormalizationRules_blob_uint64_t[] "
131+
"= "
131132
"{\n";
132133
std::vector<size_t> offset;
133134
os << ToHexUInt64Array(data, &offset);
134-
CHECK_EQ(offset.size(), data.size());
135+
QCHECK_EQ(offset.size(), data.size());
135136
os << "};\n\n";
136137
os << "const BinaryBlob kNormalizationRules_blob[] = {\n";
137138
for (size_t i = 0; i < data.size(); ++i) {
@@ -179,14 +180,15 @@ int main(int argc, char **argv) {
179180
std::vector<std::pair<std::string, std::string>> data;
180181
for (const auto &[name, func] : kRuleList) {
181182
Builder::CharsMap normalized_map;
182-
CHECK_OK(func(&normalized_map));
183+
QCHECK_OK(func(&normalized_map));
183184

184185
// Write Header.
185186
std::string index;
186-
CHECK_OK(Builder::CompileCharsMap(normalized_map, &index));
187+
QCHECK_OK(Builder::CompileCharsMap(normalized_map, &index));
187188

188189
// Write TSV file.
189-
CHECK_OK(Builder::SaveCharsMap(absl::StrCat(name, ".tsv"), normalized_map));
190+
QCHECK_OK(
191+
Builder::SaveCharsMap(absl::StrCat(name, ".tsv"), normalized_map));
190192

191193
// Do not make NFKD map as it is optionally created.
192194
if (name == "nfkd" || name == "nfd" || name == "nfc" || name == "nfkd_cf" ||
@@ -201,7 +203,7 @@ int main(int argc, char **argv) {
201203
constexpr char kPrecompiledHeaderFileName[] = "normalization_rule.h";
202204
auto output =
203205
sentencepiece::filesystem::NewWritableFile(kPrecompiledHeaderFileName);
204-
CHECK_OK(output->status());
206+
QCHECK_OK(output->status());
205207
output->Write(sentencepiece::MakeHeader(data));
206208
}
207209

src/init_test.cc

Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
 (0)