Skip to content

Commit 854f3b7

Browse files
authored
Merge pull request #1049 from DaddyWesker/release-win-clean
Now release works on windows
2 parents 17f9e7f + 0a70f19 commit 854f3b7

File tree

6 files changed

+129
-11
lines changed

6 files changed

+129
-11
lines changed

.github/workflows/release.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
os: ["ubuntu-22.04", "macos-13", "macos-14", "ubuntu-24.04-arm"]
24-
max-parallel: 4
23+
os: ["ubuntu-22.04", "windows-latest", "macos-13", "macos-14", "ubuntu-24.04-arm"]
24+
max-parallel: 5
2525

2626
steps:
2727
- name: Checkout source code
@@ -32,15 +32,25 @@ jobs:
3232
with:
3333
python-version: "3.10"
3434

35-
- run: |
35+
- name: "Fill variables"
36+
shell: bash
37+
run: |
3638
echo "REF_NAME=${{github.ref_name}}" | tee -a $GITHUB_ENV
3739
echo "EVENT_NAME=${{github.event_name}}" | tee -a $GITHUB_ENV
3840
echo "PRERELEASE=${{github.event.release.prerelease}}" | tee -a $GITHUB_ENV
3941
echo "TAG_NAME=${{github.event.release.tag_name}}" | tee -a $GITHUB_ENV
4042
echo "COMMIT_HEAD=${{github.ref_name != '' && github.ref_name || env.GITHUB_SHA}}" | tee -a $GITHUB_ENV
4143
4244
- name: Build wheels on ${{ matrix.os }}
43-
if: ${{ !startsWith(matrix.os, 'macos') }}
45+
if: ${{ startsWith(matrix.os, 'windows') }}
46+
uses: pypa/cibuildwheel@v2.19.2
47+
env:
48+
CIBW_BEFORE_ALL: ".\\python\\install-hyperonc.bat -u https://github.com/${{github.repository}}.git -r ${{env.COMMIT_HEAD}}"
49+
with:
50+
package-dir: ./python
51+
52+
- name: Build wheels on ${{ matrix.os }}
53+
if: ${{ startsWith(matrix.os, 'ubuntu') }}
4454
uses: pypa/cibuildwheel@v2.19.2
4555
env:
4656
CIBW_BEFORE_ALL: sh -c "./python/install-hyperonc.sh -u https://github.com/${{github.repository}}.git -r ${{env.COMMIT_HEAD}}"
@@ -152,4 +162,4 @@ jobs:
152162
BUILDKIT_CONTEXT_KEEP_GIT_DIR=1
153163
tags: |
154164
trueagi/hyperon:${{github.event.release.tag_name}}
155-
trueagi/hyperon:latest
165+
trueagi/hyperon:latest

c/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ option(GIT "Adds git features to hyperon library; requires OpenSSL and Zlib" ON)
66

77
enable_testing()
88
option(BUILD_SHARED_LIBS "Build shared library" ON)
9-
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
9+
get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
10+
list(APPEND CTEST_ARGS --output-on-failure)
11+
if(IS_MULTI_CONFIG)
12+
list(APPEND CTEST_ARGS -C $<CONFIG>)
13+
endif()
14+
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} ${CTEST_ARGS})
1015

1116
# HYPERONC_TARGET_DIR is used as a target dir for cargo. Cargo automatically adds
1217
# `debug/release` suffix to the value of --target-dir argument so we need to
@@ -154,4 +159,4 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hyperonc-config.cmake"
154159

155160
add_test(NAME rust_c_api
156161
COMMAND cargo test ${CARGO_ARGS_LIST} --target-dir ${HYPERONC_TARGET_DIR}
157-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
162+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ if(APPLE)
5151
endif()
5252
if(WIN32)
5353
target_link_libraries(hyperonpy PRIVATE wsock32 ws2_32 userenv ntdll bcrypt winhttp Rpcrt4)
54+
include_directories(${pybind11_INCLUDE_DIRS})
5455
endif()
5556
if(GIT)
5657
target_link_libraries(hyperonpy PRIVATE OpenSSL::SSL OpenSSL::Crypto ZLIB::ZLIB)

python/install-hyperonc.bat

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
@echo off
2+
set HYPERONC_URL=https://github.com/trueagi-io/hyperon-experimental.git
3+
set HYPERONC_REV=main
4+
5+
:loop
6+
IF NOT "%1"=="" (
7+
IF "%1"=="-u" (
8+
SET HYPERONC_URL=%2
9+
SHIFT
10+
)
11+
IF "%1"=="-r" (
12+
SET HYPERONC_REV=%2
13+
SHIFT
14+
)
15+
IF "%1"=="?" (
16+
echo Usage: %~nx0 [-u hyperonc_repo_url] [-r hyperonc_revision]
17+
echo -u hyperonc_repo_url Git repo URL to get hyperonc source code
18+
echo -r hyperonc_revision Revision of hyperonc to get from Git
19+
exit /b
20+
)
21+
IF "%1"=="-h" (
22+
echo Usage: %~nx0 [-u hyperonc_repo_url] [-r hyperonc_revision]
23+
echo -u hyperonc_repo_url Git repo URL to get hyperonc source code
24+
echo -r hyperonc_revision Revision of hyperonc to get from Git
25+
exit /b
26+
)
27+
SHIFT
28+
GOTO :loop
29+
)
30+
31+
echo hyperonc repository URL: %HYPERONC_URL%
32+
echo hyperonc revision: %HYPERONC_REV%
33+
34+
IF NOT "%RUNNER_TEMP%"=="" set TEMP_FOLDER=%RUNNER_TEMP%
35+
IF "%RUNNER_TEMP%"=="" set TEMP_FOLDER=%USERPROFILE%
36+
37+
set CARGO_HOME=%TEMP_FOLDER%\\.cargo
38+
set RUSTUP_HOME=%TEMP_FOLDER%\\.rustup
39+
curl --proto "=https" --tlsv1.2 -sSf https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe > %TEMP_FOLDER%/rustup-init.exe
40+
call %TEMP_FOLDER%/rustup-init.exe -y
41+
del %TEMP_FOLDER%\rustup-init.exe
42+
set PATH=%PATH%;%TEMP_FOLDER%\\.cargo\\bin
43+
cargo install cbindgen
44+
45+
python -m pip install cmake==3.24 conan==2.19.1 pip==23.1.2
46+
set PATH=%PATH%;%TEMP_FOLDER%\\.local\\bin
47+
conan profile detect --force
48+
49+
rem protobuf-compiler (v3) is required by Das
50+
set PROTOC_ZIP=protoc-31.1-win64.zip
51+
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v31.1/%PROTOC_ZIP%
52+
mkdir %TEMP_FOLDER%\.local
53+
tar -xf %PROTOC_ZIP% -C %TEMP_FOLDER%\.local
54+
del -f %PROTOC_ZIP%
55+
56+
mkdir %TEMP_FOLDER%\\hyperonc
57+
cd %TEMP_FOLDER%\\hyperonc
58+
git init
59+
git remote add origin %HYPERONC_URL%
60+
git fetch --depth=1 origin %HYPERONC_REV%
61+
git reset --hard FETCH_HEAD
62+
63+
mkdir %TEMP_FOLDER%\hyperonc\c\build
64+
cd %TEMP_FOLDER%\hyperonc\c\build
65+
66+
rem if this script works on github workflow, it is crucial for cmake to install in the defauls installation folder
67+
rem otherwise it will fail. On the local machine it could be crucial to set install folder manually since it tries
68+
rem to install into C:/ProgramFiles... which could be restricted and script will fail. Because of that cmake args
69+
rem will or will not contain CMAKE_INSTALL_PREFIX argument.
70+
71+
set CMAKE_ARGS=-DBUILD_SHARED_LIBS=ON -DCMAKE_CONFIGURATION_TYPES=Release -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=%TEMP_FOLDER%/hyperonc/conan_provider.cmake
72+
73+
IF "%RUNNER_TEMP%"=="" set CMAKE_ARGS=set CMAKE_ARGS=-DBUILD_SHARED_LIBS=ON -DCMAKE_CONFIGURATION_TYPES=Release -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=%TEMP_FOLDER%/hyperonc/conan_provider.cmake -DCMAKE_INSTALL_PREFIX=%TEMP_FOLDER%\\.local
74+
75+
echo hyperonc CMake arguments: %CMAKE_ARGS%
76+
cmake %CMAKE_ARGS% ..
77+
cmake --build . --config Release
78+
cmake --build . --target check --config Release
79+
cmake --build . --target install --config Release

python/pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ classifiers = [
1717
"Development Status :: 2 - Pre-Alpha",
1818
"Operating System :: POSIX :: Linux",
1919
"Operating System :: MacOS :: MacOS X",
20+
"Operating System :: Microsoft :: Windows"
2021
]
2122

2223
dynamic = [
@@ -44,3 +45,7 @@ before-all = "sh -c ./python/install-hyperonc.sh"
4445
skip = "*musllinux*"
4546
test-requires = ["pytest==7.3.2"]
4647
test-command = "pytest {project}/python/tests"
48+
49+
[tool.cibuildwheel.windows]
50+
before-all = ".\\python\\install-hyperonc.bat"
51+
archs = ["native"]

python/setup.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
import shutil
44
import subprocess
5+
import glob
56
from pathlib import Path
67

78
from setuptools import Extension, setup
@@ -60,7 +61,6 @@ def _build_with_cmake(self, ext: CMakeExtension) -> None:
6061
# CMake 3.12+ only.
6162
build_args += [f"-j{self.parallel}"]
6263

63-
6464
build_temp = Path(self.build_temp) / ext.name
6565
if not build_temp.exists():
6666
build_temp.mkdir(parents=True)
@@ -69,15 +69,33 @@ def _build_with_cmake(self, ext: CMakeExtension) -> None:
6969
["conan", "install", ext.sourcedir, "--output-folder=.",
7070
"--build=missing"], cwd=build_temp, check=True
7171
)
72+
73+
if os.name == 'nt':
74+
dcmake_toolchain_file_path = f"{build_temp}/build/generators/conan_toolchain.cmake"
75+
else:
76+
dcmake_toolchain_file_path = f"./build/{cfg}/generators/conan_toolchain.cmake"
7277
subprocess.run(
7378
["cmake", ext.sourcedir,
74-
f"-DCMAKE_TOOLCHAIN_FILE=./build/{cfg}/generators/conan_toolchain.cmake", *cmake_args],
79+
f"-DCMAKE_TOOLCHAIN_FILE={dcmake_toolchain_file_path}", *cmake_args],
7580
cwd=build_temp, check=True
7681
)
7782
subprocess.run(
7883
["cmake", "--build", ".", *build_args], cwd=build_temp, check=True
7984
)
80-
85+
if os.name == 'nt':
86+
import platform
87+
bin_dir = ".\\"
88+
current_python_version = sys.version.split(" ")[0].split(".")
89+
machine = platform.machine().lower()
90+
_platform = platform.python_implementation()
91+
if _platform == "CPython":
92+
_pyd = f"hyperonpy.cp{current_python_version[0]}{current_python_version[1]}*{machine}*.pyd"
93+
elif _platform == "PyPy":
94+
_pyd = f"hyperonpy.pypy{current_python_version[0]}{current_python_version[1]}*{machine}*.pyd"
95+
else:
96+
raise Exception("Unknown python implementation") # should be unreachable except new implementation appears in the future.
97+
pyd_file = glob.glob(os.path.join(bin_dir, _pyd))
98+
shutil.copyfile(pyd_file[0], ext_fullpath)
8199

82100
def get_version(rel_path):
83101
try:
@@ -97,4 +115,4 @@ def version_scheme(*args):
97115
use_scm_version={'root': '..',
98116
'version_scheme': version_scheme,
99117
'version_file': './hyperon/_version.py'},
100-
)
118+
)

0 commit comments

Comments
 (0)