Skip to content

Commit 3f9f9d1

Browse files
committed
ci: add wheel builds
1 parent 8346966 commit 3f9f9d1

File tree

6 files changed

+203
-6
lines changed

6 files changed

+203
-6
lines changed

.github/workflows/build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
- uses: xmake-io/github-action-setup-xmake@v1
1616
with:
17-
xmake-version: branch@master
17+
xmake-version: latest
1818

1919
- uses: actions/setup-python@v5
2020
with:

.github/workflows/wheel.yaml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Wheel
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- "*"
9+
workflow_dispatch:
10+
11+
permissions: read-all
12+
13+
jobs:
14+
build_wheels:
15+
name: Build Wheel (${{ matrix.python-tag }}-${{ matrix.platform }})
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
os: [windows-latest]
21+
python-tag: ["cp39", "cp310", "cp311", "cp312", "cp313"]
22+
include:
23+
- os: windows-latest
24+
platform: win_amd64
25+
26+
steps:
27+
- name: Checkout Code
28+
uses: actions/checkout@v4
29+
with:
30+
submodules: "recursive"
31+
fetch-depth: 0
32+
33+
- uses: xmake-io/github-action-setup-xmake@v1
34+
with:
35+
xmake-version: latest
36+
37+
- uses: actions/cache@v4
38+
with:
39+
path: |
40+
~/AppData/Local/.xmake
41+
key: xmake-${{ hashFiles('xmake.lua') }}
42+
restore-keys: |
43+
xmake-
44+
45+
- run: |
46+
xmake repo -u
47+
48+
- name: Build wheels
49+
uses: pypa/[email protected]
50+
env:
51+
CIBW_BUILD_FRONTEND: build
52+
CIBW_BUILD: ${{ matrix.python-tag }}-${{ matrix.platform }}
53+
CIBW_BUILD_VERBOSITY: 1
54+
55+
- uses: actions/upload-artifact@v4
56+
with:
57+
name: endstone-wheels-${{ matrix.python-tag }}-${{ matrix.platform }}
58+
path: ./wheelhouse/*.whl

pyproject.toml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[build-system]
2+
requires = ["setuptools>=64.0.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "endstone"
7+
authors = [
8+
{ name = "Vincent Wu", email = "[email protected]" }
9+
]
10+
description = "Endstone offers a plugin API for Bedrock Dedicated Servers, supporting both Python and C++."
11+
readme = "README.md"
12+
requires-python = ">=3.9"
13+
keywords = ["plugin", "python", "minecraft", "bedrock"]
14+
license = { file = "LICENSE" }
15+
classifiers = [
16+
"Programming Language :: Python",
17+
"Programming Language :: Python :: 3",
18+
"Programming Language :: Python :: 3.9",
19+
"Programming Language :: Python :: 3.10",
20+
"Programming Language :: Python :: 3.11",
21+
"Programming Language :: Python :: 3.12",
22+
"Programming Language :: Python :: 3.13",
23+
"License :: OSI Approved :: Apache Software License",
24+
"Operating System :: Microsoft :: Windows",
25+
]
26+
dependencies = [
27+
"click",
28+
"endstone-bstats",
29+
"importlib-metadata",
30+
"importlib-resources",
31+
"numpy",
32+
"packaging",
33+
"pkginfo",
34+
"psutil",
35+
"pyyaml",
36+
"requests",
37+
"rich",
38+
"tomlkit",
39+
"typing-extensions",
40+
]
41+
dynamic = ["version"]
42+
43+
[project.optional-dependencies]
44+
test = ["pytest"]
45+
46+
[project.urls]
47+
Changelog = "https://endstone.readthedocs.io/en/latest/changelog"
48+
Discussions = "https://github.com/orgs/EndstoneMC/discussions"
49+
Documentation = "https://endstone.readthedocs.io"
50+
Homepage = "https://github.com/EndstoneMC/endstone"
51+
Issues = "https://github.com/EndstoneMC/endstone/issues"
52+
53+
[project.scripts]
54+
endstone = "endstone._internal.bootstrap:cli"
55+
56+
[tool.ruff]
57+
extend-exclude = ["endstone_python.pyi"]
58+
line-length = 120
59+
lint.extend-select = ["I"]

setup.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import re
2+
import os
3+
import sys
4+
import shutil
5+
import platform
6+
import subprocess
7+
from setuptools import setup, find_packages
8+
from setuptools.command.bdist_wheel import bdist_wheel
9+
from glob import glob
10+
11+
12+
data_path = "bin/EndstoneRuntime"
13+
native_path = data_path + "/Native"
14+
library_path = data_path + "/Lib"
15+
16+
17+
class TagProvider(bdist_wheel):
18+
def get_tag(self):
19+
python_version = f"cp{sys.version_info[0]}{sys.version_info[1]}"
20+
21+
if platform.system() != "Windows":
22+
raise Exception("unsupported system")
23+
if platform.architecture() != ("64bit", "WindowsPE"):
24+
raise Exception("unsupported architecture")
25+
return (python_version, python_version, "win_amd64")
26+
27+
28+
def build_native():
29+
python_version = f"{sys.version_info[0]}.{sys.version_info[1]}.x"
30+
env = os.environ.copy()
31+
env["PYTHON_VERSION"] = python_version
32+
proj_dir = os.path.dirname(__file__)
33+
subprocess.run(
34+
["xmake", "f", "-p", "windows", "-a", "x64", "-m", "release", "-y"],
35+
env=env,
36+
cwd=proj_dir,
37+
check=True,
38+
)
39+
subprocess.run(
40+
["xmake", "-v", "-y"],
41+
env=env,
42+
cwd=proj_dir,
43+
check=True,
44+
)
45+
46+
os.makedirs(native_path, exist_ok=True)
47+
ext = [".dll", ".pdb", ".json"]
48+
for e in ext:
49+
for f in glob(f"bin/EndstoneRuntime/*{e}"):
50+
shutil.copy(f, native_path)
51+
52+
53+
if not os.path.exists(data_path):
54+
build_native()
55+
56+
setup(
57+
name="levistone",
58+
packages=find_packages(library_path) + ["."],
59+
package_dir={"": library_path, ".": native_path},
60+
package_data={"": ["*"]},
61+
setup_requires=["setuptools_scm"],
62+
use_scm_version={
63+
"root": "endstone",
64+
"relative_to": __file__,
65+
"version_scheme": "guess-next-dev",
66+
"local_scheme": "no-local-version",
67+
},
68+
cmdclass={"bdist_wheel": TagProvider},
69+
)

src/levistone/runtime/endstone_runtime.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ bool EndstoneRuntime::load()
6868
// https://docs.python.org/3/c-api/init_config.html#init-isolated-conf
6969
PyConfig config;
7070
PyConfig_InitIsolatedConfig(&config);
71-
PyConfig_SetString(&config, &config.pythonpath_env, (getSelf().getModDir() / "Lib").c_str());
71+
PyConfig_SetString(&config, &config.pythonpath_env, (getSelf().getModDir()).c_str());
7272
config.isolated = 0;
7373
config.use_environment = 1;
7474
config.install_signal_handlers = 0;

xmake.lua

+15-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,17 @@ add_requires("toml++ v3.4.0")
1212
add_requires("levilamina 42b75be796e8481394a8dd380c2500f76287919f")
1313
add_requires("levibuildscript")
1414

15-
add_requires("python 3.12.8")
15+
python_version = "3.12.x"
16+
if os.getenv("PYTHON_VERSION") then
17+
python_version = os.getenv("PYTHON_VERSION")
18+
end
19+
local get_python_libname = function (version)
20+
local major, minor = version:match("(%d+)%.(%d+)")
21+
return "python" .. major .. minor
22+
end
23+
local python_libname = get_python_libname(python_version)
24+
add_requires("python " .. python_version)
1625
add_requires("pybind11 2.13.6")
17-
local python_libname = "python312"
1826

1927
-- Define common packages to avoid repetition
2028
local common_packages = {
@@ -66,7 +74,7 @@ target("endstone")
6674
end)
6775

6876
target("endstone_python")
69-
add_rules("python.library")
77+
add_rules("python.library", {soabi = true})
7078
add_files("src/levistone/memory_operators.cpp")
7179
add_files("endstone/src/endstone/python/**.cpp")
7280
add_deps("endstone")
@@ -126,7 +134,10 @@ target("endstone_core")
126134
target("endstone_runtime")
127135
set_kind("shared")
128136
on_load(function (target)
129-
target:add("rules", "@levibuildscript/modpacker", {modName = "EndstoneRuntime", modVersion = get_version(os)})
137+
target:add("rules", "@levibuildscript/modpacker", {
138+
modName = "EndstoneRuntime",
139+
modVersion = get_version(os)
140+
})
130141
end)
131142
add_files("src/levistone/memory_operators.cpp")
132143
add_files("endstone/src/endstone/runtime/windows.cpp")

0 commit comments

Comments
 (0)