Skip to content

Abseil migration#1270

Merged
taku910 merged 2 commits into
masterfrom
abseil_migration
Jun 12, 2026
Merged

Abseil migration#1270
taku910 merged 2 commits into
masterfrom
abseil_migration

Conversation

@taku910

@taku910 taku910 commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR migrates SentencePiece's internal custom status wrapper (sentencepiece::util::Status and StatusCode) to standard absl::Status and absl::StatusCode from the Abseil library.
This cleanup reduces custom code maintenance, aligns the project with modern C++ standards, and makes it easier to integrate SentencePiece into projects that already use Abseil.

Key Changes

  • Removed Custom Status Wrapper: Deleted src/error.cc and removed it from the build. Deleted the custom Status and StatusCode definitions from sentencepiece::util in src/sentencepiece_processor.h.
  • Global Code Migration: Replaced all usages of util::Status -> absl::Status, util::StatusCode -> absl::StatusCode, and util::OkStatus() -> absl::OkStatus() across all C++ source and test files.
  • CMake Updates:
    • Added absl::status to SPM_LIBS in src/CMakeLists.txt.
    • Updated target_link_libraries for shared libraries (sentencepiece and sentencepiece_train) to use PUBLIC linking, exposing the Abseil dependency to consumers.
  • Header Installation Translation:
    • Added a CMake helper script cmake/modify_headers.cmake to automatically replace internal "third_party/absl/..." includes with standard <absl/...> includes when installing public headers (sentencepiece_processor.h and sentencepiece_trainer.h).
    • This ensures the repository source files can use internal paths while installed headers remain clean and compatible with system-installed Abseil.
  • Test and Benchmark Updates:
    • Redefined EXPECT_OK and EXPECT_NOT_OK in src/testharness.h to use absl::Status::ok().
    • Fixed nodiscard warnings in sentencepiece_trainer_test.cc.
    • Updated sentencepiece_processor_benchmarks_test.cc to work with the migrated status types.
  • Style Guide Compliance (IWYU):
    • Formatted all modified files to ensure includes are sorted alphabetically.

Testing Done

  • Configured CMake with SPM_BUILD_TEST=ON and SPM_ENABLE_BENCHMARK=ON.
  • Successfully built the project and benchmark binaries.
  • Ran all unit tests via ctest and confirmed 100% pass rate.
  • Performed a trial installation (cmake --install) and verified that the installed headers in include/ correctly contain <absl/status/status.h> instead of "third_party/absl/status/status.h".

@taku910

taku910 commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

Python wrapper error is expected. we need to aligned with the project #1266

- Replaced sentencepiece::util::Status/StatusCode with absl::Status/StatusCode globally in src/.
- Removed custom Status implementation in src/error.cc (deleted).
- Included absl/status/status.h in public headers sentencepiece_processor.h and sentencepiece_trainer.h (using third_party/absl/ path in source tree).
- Updated src/CMakeLists.txt to link absl::status publicly for shared libraries.
- Added cmake/modify_headers.cmake to transform public headers during installation to use <absl/...> includes.
- Updated utility macros (DECLARE_ERROR, RET_CHECK, StatusBuilder) and test harness (EXPECT_OK) to work with absl::Status.
- Fixed nodiscard warnings in sentencepiece_trainer_test.cc.
- Added explicit includes (e.g., <absl/status/status.h>, <absl/strings/string_view.h>) to all files using these types directly to comply with IWYU.
- Formatted all modified C++ files using clang-format -style=Google, sorting includes.
- Updated SWIG wrapper python/src/sentencepiece/sentencepiece.i and helper header python/src/sentencepiece/sentencepiece_swig.h to use absl::Status/StatusCode.
- Updated python/setup.py to include Abseil headers directory and repo root in compiler include paths.
- Updated python/src/sentencepiece/sentencepiece_wrap.cxx to match the absl::Status migration.
@taku910 taku910 force-pushed the abseil_migration branch from cf5aefc to 39279bf Compare June 11, 2026 05:35
- Updated .github/workflows/wheel.yml to copy C++ source files into python/sentencepiece directory before running cibuildwheel.
- This ensures cibuildwheel uses the local modified C++ sources rather than cloning the upstream master branch, preventing compilation errors due to API mismatches during migration.
@taku910 taku910 force-pushed the abseil_migration branch from 4f626dc to 34cc226 Compare June 11, 2026 18:07
@taku910 taku910 merged commit 0032e05 into master Jun 12, 2026
31 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant