Skip to content

Commit 3dbf3bf

Browse files
authored
Implement ssss141414's fixes (#14)
* implement ssss141414's fixes
1 parent a4c2eff commit 3dbf3bf

38 files changed

Lines changed: 1847 additions & 2388 deletions

‎.github/workflows/release.yml‎

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,79 @@ jobs:
128128
name: dist-wheels-${{ matrix.os }}-${{ matrix.python }}-${{ matrix.cibw_arch }}
129129
path: wheelhouse/*.whl
130130

131+
build-windows-wheels:
132+
needs: validate-release-request
133+
runs-on: ${{ matrix.os }}
134+
strategy:
135+
fail-fast: false
136+
matrix:
137+
include:
138+
- os: windows-latest
139+
arch: AMD64
140+
build: "cp38-* cp39-* cp310-* cp311-* cp312-* cp313-* cp314-* cp314t-*"
141+
constraint: ""
142+
- os: windows-11-arm
143+
arch: ARM64
144+
build: "cp311-* cp312-* cp313-* cp314-* cp314t-*"
145+
constraint: PIP_CONSTRAINT=${{ github.workspace }}\constraints-windows-arm64.txt
146+
147+
env:
148+
PIP_DISABLE_PIP_VERSION_CHECK: 1
149+
150+
steps:
151+
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
152+
with:
153+
fetch-depth: 50
154+
submodules: true
155+
156+
- uses: pypa/cibuildwheel@7c619efba910c04005a835b110b057fc28fd6e93 # v3.2.0
157+
env:
158+
CIBW_BUILD_VERBOSITY: 1
159+
CIBW_BUILD: ${{ matrix.build }}
160+
CIBW_ARCHS: ${{ matrix.arch }}
161+
CIBW_ENVIRONMENT: ${{ matrix.constraint }}
162+
163+
- name: Verify Windows ARM64 wheels
164+
if: matrix.arch == 'ARM64'
165+
shell: pwsh
166+
run: |
167+
Add-Type -AssemblyName System.IO.Compression.FileSystem
168+
Get-ChildItem wheelhouse/*.whl | ForEach-Object {
169+
$archive = [System.IO.Compression.ZipFile]::OpenRead($_.FullName)
170+
try {
171+
$nativeEntry = $archive.Entries |
172+
Where-Object FullName -Like 'uvloop/*.pyd' |
173+
Select-Object -First 1
174+
if (-not $nativeEntry) {
175+
throw "Missing native extension in $($_.Name)"
176+
}
177+
178+
$reader = [System.IO.BinaryReader]::new($nativeEntry.Open())
179+
try {
180+
$bytes = $reader.ReadBytes([int]$nativeEntry.Length)
181+
} finally {
182+
$reader.Dispose()
183+
}
184+
$peOffset = [BitConverter]::ToInt32($bytes, 0x3c)
185+
$machine = [BitConverter]::ToUInt16($bytes, $peOffset + 4)
186+
if ($machine -ne 0xAA64) {
187+
throw ('Expected ARM64 PE machine 0xAA64 in {0}, found 0x{1:X4}' -f $_.Name, $machine)
188+
}
189+
} finally {
190+
$archive.Dispose()
191+
}
192+
}
193+
194+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
195+
with:
196+
name: dist-wheels-windows-${{ matrix.arch }}
197+
path: wheelhouse/*.whl
198+
131199
publish:
132-
needs: [build-sdist, build-wheels]
200+
needs:
201+
- build-sdist
202+
- build-wheels
203+
- build-windows-wheels
133204
runs-on: ubuntu-latest
134205

135206
steps:

‎.github/workflows/tests.yml‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,18 @@ jobs:
2424
- "3.13"
2525
- "3.14"
2626
- "3.14t"
27-
# TODO: (Vizonex) windows-11-arm
2827
os: [ubuntu-latest, macos-latest, windows-latest]
28+
include:
29+
- os: windows-11-arm
30+
python-version: "3.11.9"
31+
- os: windows-11-arm
32+
python-version: "3.12.10"
33+
- os: windows-11-arm
34+
python-version: "3.13.15"
35+
- os: windows-11-arm
36+
python-version: "3.14.7"
37+
- os: windows-11-arm
38+
python-version: "3.14t"
2939

3040
env:
3141
PIP_DISABLE_PIP_VERSION_CHECK: 1
@@ -58,6 +68,11 @@ jobs:
5868
run: |
5969
brew install gnu-sed libtool autoconf automake
6070
71+
- name: Install Windows ARM64 test prerequisite
72+
if: matrix.os == 'windows-11-arm' && steps.release.outputs.version == 0
73+
run: |
74+
pip install --only-binary cryptography --constraint constraints-windows-arm64.txt cryptography
75+
6176
- name: Install Python Deps
6277
if: steps.release.outputs.version == 0
6378
run: |

‎Makefile‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
PYTHON ?= python
55
ROOT = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
6+
DEBUG_BUILD = --debug
7+
ifeq ($(OS),Windows_NT)
8+
DEBUG_BUILD =
9+
endif
610

711

812
_default: compile
@@ -34,14 +38,12 @@ setup-build:
3438
compile: clean setup-build
3539

3640

37-
# NOTE: --debug will not work on windows since it asks for a non-existant _d.lib file.
38-
# TODO: Fix workflows for missing debug binaries in the future.
3941
debug: clean
40-
$(PYTHON) setup.py build_ext --inplace \
42+
$(PYTHON) setup.py build_ext --inplace $(DEBUG_BUILD) \
4143
--cython-always \
4244
--cython-annotate \
4345
--cython-directives="linetrace=True" \
44-
--define UVLOOP_DEBUG --define CYTHON_TRACE --define CYTHON_TRACE_NOGIL
46+
--define UVLOOP_DEBUG,CYTHON_TRACE,CYTHON_TRACE_NOGIL
4547

4648

4749
docs:

‎constraints-windows-arm64.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cryptography==46.0.3

‎setup.py‎

Lines changed: 32 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
if vi < (3, 8):
55
raise RuntimeError('uvloop requires Python 3.8 or greater')
66

7-
# TODO: Remove Completely because Winloop Author is mergeing his project to uvloop.
8-
# if sys.platform in ('win32', 'cygwin', 'cli'):
9-
# raise RuntimeError('uvloop does not support Windows at the moment')
10-
117
import os
128
import os.path
139
import pathlib
@@ -30,10 +26,6 @@
3026
LIBUV_DIR = str(_ROOT / 'vendor' / 'libuv')
3127
LIBUV_BUILD_DIR = str(_ROOT / 'build' / 'libuv-{}'.format(MACHINE))
3228

33-
# NOTE: Mingw was added by another contributor in the winloop project.
34-
MINGW = bool(os.environ.get("MINGW_PREFIX", ""))
35-
36-
3729
def _libuv_build_env():
3830
env = os.environ.copy()
3931

@@ -88,9 +80,7 @@ class uvloop_build_ext(build_ext):
8880

8981
def initialize_options(self):
9082
super().initialize_options()
91-
# Use mingw if prefix was given for it otherwise it
92-
# will always be false.
93-
self.use_system_libuv = MINGW
83+
self.use_system_libuv = False
9484
self.cython_always = False
9585
self.cython_annotate = None
9686
self.cython_directives = None
@@ -125,21 +115,17 @@ def finalize_options(self):
125115
import Cython
126116
except ImportError:
127117
raise RuntimeError(
128-
"please install {} to compile uvloop from source".format(
129-
CYTHON_DEPENDENCY
130-
)
131-
)
118+
'please install {} to compile uvloop from source'.format(
119+
CYTHON_DEPENDENCY))
132120

133121
cython_dep = Requirement(CYTHON_DEPENDENCY)
134122
if not cython_dep.specifier.contains(Cython.__version__):
135123
raise RuntimeError(
136-
"uvloop requires {}, got Cython=={}".format(
124+
'uvloop requires {}, got Cython=={}'.format(
137125
CYTHON_DEPENDENCY, Cython.__version__
138-
)
139-
)
126+
))
140127

141128
from Cython.Build import cythonize
142-
143129

144130
directives = {}
145131
if self.cython_directives:
@@ -201,7 +187,7 @@ def build_libuv(self):
201187
cwd=LIBUV_BUILD_DIR, env=env, check=True)
202188

203189
def build_extensions(self):
204-
if sys.platform == "win32" and not MINGW:
190+
if sys.platform == "win32":
205191
path = pathlib.Path("vendor", "libuv", "src")
206192
c_files = [p.as_posix() for p in path.iterdir() if p.suffix == ".c"]
207193
c_files += [
@@ -249,41 +235,26 @@ def build_extensions(self):
249235
raise RuntimeError(
250236
'unable to read the version from uvloop/_version.py')
251237

252-
if sys.platform == "win32":
253-
from Cython.Build import cythonize
254-
from Cython.Compiler.Main import default_options
255-
256-
default_options["compile_time_env"] = dict(DEFAULT_FREELIST_SIZE=250)
257-
ext = cythonize(
258-
[
259-
Extension(
260-
"uvloop.loop",
261-
sources=["uvloop/loop.pyx"],
262-
include_dirs=[]
263-
if MINGW
264-
else [
265-
"vendor/libuv/src",
266-
"vendor/libuv/src/win",
267-
"vendor/libuv/include",
268-
],
269-
# subset of libuv Windows libraries:
270-
extra_link_args=[
271-
(f"-l{lib}" if MINGW else f"{lib}.lib")
272-
for lib in (
273-
"Shell32",
274-
"Ws2_32",
275-
"Advapi32",
276-
"iphlpapi",
277-
"Userenv",
278-
"User32",
279-
"Dbghelp",
280-
"Ole32",
281-
)
282-
],
283-
define_macros=[("WIN32_LEAN_AND_MEAN", 1), ("_WIN32_WINNT", "0x0602")],
284-
),
285-
]
286-
)
238+
if sys.platform == 'win32':
239+
ext = [
240+
Extension(
241+
'uvloop.loop',
242+
sources=['uvloop/loop.pyx'],
243+
include_dirs=[
244+
'vendor/libuv/src',
245+
'vendor/libuv/src/win',
246+
'vendor/libuv/include',
247+
],
248+
libraries=[
249+
'Shell32', 'Ws2_32', 'Advapi32', 'iphlpapi',
250+
'Userenv', 'User32', 'Dbghelp', 'Ole32',
251+
],
252+
define_macros=[
253+
('WIN32_LEAN_AND_MEAN', 1),
254+
('_WIN32_WINNT', '0x0602'),
255+
],
256+
),
257+
]
287258
else:
288259
ext = [
289260
Extension(
@@ -297,14 +268,17 @@ def build_extensions(self):
297268

298269
setup_requires = []
299270

300-
if not (_ROOT / "uvloop" / "loop.c").exists() or "--cython-always" in sys.argv:
271+
if not (_ROOT / 'uvloop' / 'loop.c').exists() or '--cython-always' in sys.argv:
301272
# No Cython output, require Cython to build.
302273
setup_requires.append(CYTHON_DEPENDENCY)
303-
274+
304275

305276
setup(
306277
version=VERSION,
307-
cmdclass={"sdist": uvloop_sdist, "build_ext": uvloop_build_ext},
278+
cmdclass={
279+
'sdist': uvloop_sdist,
280+
'build_ext': uvloop_build_ext
281+
},
308282
ext_modules=ext,
309283
setup_requires=setup_requires,
310284
)

‎tests/__main__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def suite():
1010
return test_suite
1111

1212

13-
if __name__ == "__main__":
13+
if __name__ == '__main__':
1414
runner = unittest.runner.TextTestRunner()
1515
result = runner.run(suite())
1616
sys.exit(not result.wasSuccessful())

0 commit comments

Comments
 (0)