Skip to content

Commit e963f99

Browse files
authored
Merge pull request #1037 from Nagico2/feat/win-arm-build
Add support for windows arm64
2 parents e29db12 + 6b1c886 commit e963f99

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

Diff for: .github/workflows/wheel.yml

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ jobs:
4545
cmake --build ${{github.workspace}}/build_win32 --config Release --target install --parallel 8
4646
cmake -A x64 -B ${{github.workspace}}/build_amd64 -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/root_amd64
4747
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
49+
cmake --build ${{github.workspace}}/build_arm64 --config Release --target install --parallel 8
4850
4951
- name: Build for Mac
5052
if: runner.os == 'macOS'
@@ -66,6 +68,7 @@ jobs:
6668
env:
6769
CIBW_ARCHS_LINUX: auto aarch64
6870
CIBW_ARCHS_MACOS: x86_64 universal2 arm64
71+
CIBW_ARCHS_WINDOWS: auto ARM64
6972
CIBW_SKIP: "pp* *-musllinux_*"
7073
CIBW_BUILD_VERBOSITY: 1
7174

Diff for: python/README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Python wrapper for SentencePiece. This API will offer the encoding, decoding and training of Sentencepiece.
44

55
## Build and Install SentencePiece
6-
For Linux (x64/i686), macOS, and Windows(win32/x64) environment, you can simply use pip command to install SentencePiece python module.
6+
For Linux (x64/i686), macOS, and Windows(win32/x64/arm64) environment, you can simply use pip command to install SentencePiece python module.
77

88
```
99
% pip install sentencepiece
@@ -27,6 +27,20 @@ If you don’t have write permission to the global site-packages directory or do
2727
% python setup.py install --user
2828
```
2929

30+
For Windows users who want to build from source, you can build and install the Python wrapper using Visual Studio. First, you need to install the `pwsh.exe` (Powershell 7). Use `winget install --id Microsoft.Powershell --source winget` to install directly. Then open the `Developer PowerShell for VS 2022`, and execute the following commands.
31+
```
32+
git clone https://github.com/google/sentencepiece.git
33+
cd sentencepiece
34+
mkdir build
35+
cd build
36+
cmake .. -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=".\root"
37+
cmake --build . --config Release --target install
38+
cd ../python
39+
pip install wheel
40+
python setup.py bdist_wheel
41+
Get-ChildItem .\dist\sentencepiece*.whl | ForEach-Object { pip install $_.FullName }
42+
```
43+
3044
## Usage
3145

3246
See [this google colab page](https://github.com/google/sentencepiece/blob/master/python/sentencepiece_python_module_example.ipynb) to run sentencepiece interactively.

Diff for: python/setup.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import string
2020
import subprocess
2121
import sys
22+
import platform
2223
from setuptools import Extension, setup
2324
from setuptools.command.build_ext import build_ext as _build_ext
2425
from setuptools.command.build_py import build_py as _build_py
@@ -103,11 +104,21 @@ def build_extension(self, ext):
103104
_build_ext.build_extension(self, ext)
104105

105106

106-
if os.name == 'nt':
107-
# Must pre-install sentencepice into build directory.
107+
def get_win_arch():
108108
arch = 'win32'
109109
if sys.maxsize > 2**32:
110110
arch = 'amd64'
111+
if 'arm' in platform.machine().lower():
112+
arch = 'arm64'
113+
if os.getenv('PYTHON_ARCH', '') == 'ARM64':
114+
# Special check for arm64 under ciwheelbuild, see https://github.com/pypa/cibuildwheel/issues/1942
115+
arch = 'arm64'
116+
return arch
117+
118+
119+
if os.name == 'nt':
120+
# Must pre-install sentencepice into build directory.
121+
arch = get_win_arch()
111122
if os.path.exists('..\\build\\root_{}\\lib'.format(arch)):
112123
cflags = ['/std:c++17', '/I..\\build\\root_{}\\include'.format(arch)]
113124
libs = [
@@ -125,6 +136,8 @@ def build_extension(self, ext):
125136
cmake_arch = 'Win32'
126137
if arch == 'amd64':
127138
cmake_arch = 'x64'
139+
elif arch == "arm64":
140+
cmake_arch = "ARM64"
128141
subprocess.check_call([
129142
'cmake',
130143
'sentencepiece',

0 commit comments

Comments
 (0)