Contents

spencer0124/sentencepiecekit

A Swift package wrapper for Google's [SentencePiece](https://github.com/google/sentencepiece), allowing you to use SentencePiece tokenizer directly in your **iOS**, **macOS**, and **watchOS** projects.

πŸ“‚ Project Structure

To use the build script, your directory structure must look like this:

Projects/                  # Verification Root
β”œβ”€β”€ sentencepiece/         # Cloned Google SentencePiece repository
└── SentencePieceKit/      # This project
    β”œβ”€β”€ Scripts/
    β”‚   └── build_xcframework.sh
    └── Package.swift

Note: The script assumes sentencepiece and SentencePieceKit are sibling directories.

πŸ›  Prerequisites

Ensure you have the following tools installed on your Mac:

  • Xcode (with Command Line Tools)
  • CMake (brew install cmake)
  • wget (brew install wget) - Used to download the iOS toolchain

πŸš€ How to Build

  1. Clone Repositories:

```bash # Go to your working directory cd Projects

# 1. Clone Google's SentencePiece git clone https://github.com/google/sentencepiece.git

# 2. Clone SentencePieceKit (if you haven't already) git clone https://github.com/your-repo/SentencePieceKit.git ```

  1. Run the Build Script:

``bash cd SentencePieceKit/Scripts chmod +x build_xcframework.sh ./build_xcframework.sh ``

  1. Wait for Completion:

The script will: - Clean up previous builds. - Automatically download the necessary ios.toolchain.cmake. - Patch CMakeLists.txt for watchOS compatibility. - Compile for all platforms and architectures. - Generate sentencepiece.xcframework.

  1. Verify:

After the build finishes, you will see sentencepiece.xcframework in the root of SentencePieceKit. You can run the verification script to ensure all architectures are present: ``bash ./verify_kit.sh ``

πŸ“¦ Installation in Xcode

  1. Open your project in Xcode.
  2. Go to File > Add Package Dependencies...
  3. Add local SentencePieceKit package or drag sentencepiece.xcframework manually if you prefer direct linking.
  4. Add import SentencePieceKit in your Swift code.

πŸ“ License

Package Metadata

Repository: spencer0124/sentencepiecekit

Default branch: main

README: README.md