Skip to content

Commit bd763a4

Browse files
committed
wip 3.14
1 parent e7cdfce commit bd763a4

File tree

10 files changed

+1151
-49
lines changed

10 files changed

+1151
-49
lines changed

emsdk-cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ else:
229229

230230
if arg.lower() in ("-fpic", "-latomic"):
231231
continue
232-
232+
# cpython use at least: -msse -msse2 -msse3 -msse4.1 -msse4.2 for HACL
233233
if arg.lower() in ("-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-msse4.2", "-msse4", "-mavx", "-mfpu=neon"):
234234
continue
235235

scripts/cpython-build-emsdk.sh

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,15 @@ ac_cv_func_dlopen=yes
171171
ac_cv_lib_ffi_ffi_call=yes
172172
py_cv_module__ctypes=yes
173173
py_cv_module__ctypes_test=yes
174-
ax_cv_c_float_words_bigendian=no
175174
ac_cv_func_sem_clockwait=no
176175
177176
ac_cv_file__dev_ptmx=no
178177
ac_cv_file__dev_ptc=no
179-
END
178+
ac_cv_func_memfd_create=no
180179
180+
ax_cv_c_float_words_bigendian=no
181+
# ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2=no
182+
END
181183

182184

183185
#_ctypes _ctypes/_ctypes.c _ctypes/callbacks.c _ctypes/callproc.c _ctypes/stgdict.c _ctypes/cfield.c -ldl -lffi -DHAVE_FFI_PREP_CIF_VAR -DHAVE_FFI_PREP_CLOSURE_LOC -DHAVE_FFI_CLOSURE_ALLOC
@@ -222,11 +224,14 @@ END
222224

223225
if [ ${PYMINOR} -ge 14 ]
224226
then
225-
226227
cp Tools/wasm/config.host-wasm32-emscripten Tools/wasm/config.site-wasm32-emscripten
227228

228229
sed -i 's|wasm32-unknown-emscripten|wasm32-bi-emscripten|g' Makefile.pre.in
229230
EXTRA_PYOPTS="$EXTRA_PYOPTS --disable-ipv6"
231+
# no PY_CALL_TRAMPOLINE
232+
sed -i 's|,__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET||g' configure
233+
sed -i 's|,__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET||g' configure.ac
234+
230235
else
231236
EXTRA_PYOPTS="$EXTRA_PYOPTS --with-emscripten-target=browser"
232237
fi
@@ -258,7 +263,7 @@ END
258263
sed -i 's|-lpthread|-lcrypto|g' Makefile
259264

260265

261-
echo "=========== cpython build ================" 1>&2
266+
echo "=========== cpython${PYMAJOR}.${PYMINOR} build ================" 1>&2
262267
if emmake make -j$(nproc) WASM_ASSETS_DIR=$(realpath ${PYTHONPYCACHEPREFIX}/empty)@/
263268
then
264269
echo -n
@@ -274,22 +279,36 @@ END
274279
fi
275280
#emmake make -j1 Modules/_ctypes/_ctypes.o
276281

277-
echo "=========== cpython install ================" 1>&2
278-
if emmake make WASM_ASSETS_DIR=$(realpath ${PYTHONPYCACHEPREFIX}/empty)@/ install
282+
echo "================ cpython${PYMAJOR}.${PYMINOR} install ================" 1>&2
283+
if [ ${PYMINOR} -ge 14 ]
284+
then
285+
if emmake make WASM_ASSETS_DIR=$(realpath ${PYTHONPYCACHEPREFIX}/empty)@/ build-details.json install
286+
then
287+
pushd Modules/_hacl
288+
$SDKROOT/emsdk/upstream/emscripten/emar rcs ${SDKROOT}/prebuilt/emsdk/lib_hacl${PYBUILD}.a *.o
289+
popd
290+
touch $PREFIX/python${PYMAJOR}.${PYMINOR}
291+
fi
292+
else
293+
if emmake make WASM_ASSETS_DIR=$(realpath ${PYTHONPYCACHEPREFIX}/empty)@/ install
294+
then
295+
touch $PREFIX/python${PYMAJOR}.${PYMINOR}
296+
fi
297+
fi
298+
299+
300+
if [ -f $PREFIX/python${PYMAJOR}.${PYMINOR} ]
279301
then
280-
echo "ok"
281-
#cp -rf ${PREFIX}/usr/lib/python${PYMAJOR}.${PYMINOR}/* ${ROOT}/devices/$(arch)/usr/lib/python${PYMAJOR}.${PYMINOR}/
282-
#rm -rf ${PREFIX}/lib/python${PYMAJOR}.${PYMINOR}
283-
#ln -sf ${ROOT}/devices/$(arch)/usr/lib/python${PYMAJOR}.${PYMINOR} ${PREFIX}/lib/python${PYMAJOR}.${PYMINOR}
302+
echo "cpython${PYMAJOR}.${PYMINOR} install success"
284303
else
285304
echo "
286305
287-
**** cpython wasm install failed ***
306+
**** cpython${PYMAJOR}.${PYMINOR}-wasm install failed ***
288307
289-
emmake make WASM_ASSETS_DIR=$(realpath ${PYTHONPYCACHEPREFIX}/empty)@/ install
308+
emmake make WASM_ASSETS_DIR=$(realpath ${PYTHONPYCACHEPREFIX}/empty)@/ build-details.json install
290309
291310
" 1>&2
292-
exit 263
311+
exit 308
293312

294313
fi
295314

@@ -353,7 +372,7 @@ MODSYSCONFIG="${SDKROOT}/prebuilt/emsdk/${PYBUILD}/_sysconfigdata__emscripten_de
353372
cp $PREFIX/lib/python${PYBUILD}/_sysconfigdata__emscripten_wasm32-emscripten.py \
354373
${MODSYSCONFIG}
355374

356-
sed -i 's|-Os|-O0|g' ${MODSYSCONFIG}
375+
sed -i 's|-Os|-O2|g' ${MODSYSCONFIG}
357376
sed -i 's|-g0|-g3|g' ${MODSYSCONFIG}
358377

359378
# this one is required for `python3-wasm -mbuild` venv

scripts/cpython-fetch.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,80 @@ then
5959

6060
pushd cpython${PYBUILD}
6161

62+
63+
patch -p1 <<END
64+
65+
--- Python-3.14.0rc1/Python/emscripten_syscalls.c
66+
+++ Python-3.14.0rc1-mvpbi/Python/emscripten_syscalls.c
67+
@@ -139,7 +139,7 @@
68+
"Unexpected __wasi_iovec_t layout");
69+
_Static_assert(sizeof(__wasi_iovec_t) == IOVEC_T_SIZE,
70+
"Unexpected __wasi_iovec_t layout");
71+
-
72+
+#ifdef __wasm_reference_types__
73+
// If the stream has a readAsync handler, read to buffer defined in iovs, write
74+
// number of bytes read to *nread, and return a promise that resolves to the
75+
// errno. Otherwise, return null.
76+
@@ -285,7 +285,7 @@
77+
}
78+
return __block_for_int(p);
79+
}
80+
-
81+
+#endif // __wasm_reference_types__
82+
#include <sys/ioctl.h>
83+
84+
int syscall_ioctl_orig(int fd, int request, void* varargs)
85+
END
86+
87+
patch -p1 <<END
88+
--- Python-3.14.0rc1/Modules/_hacl/include/krml/lowstar_endianness.h
89+
+++ Python-3.14.0rc1-mvpbi/Modules/_hacl/include/krml/lowstar_endianness.h
90+
@@ -12,7 +12,7 @@
91+
/******************************************************************************/
92+
93+
/* ... for Linux */
94+
-#if defined(__linux__) || defined(__CYGWIN__) || defined (__USE_SYSTEM_ENDIAN_H__) || defined(__GLIBC__)
95+
+#if defined(__linux__) || defined(__CYGWIN__) || defined (__USE_SYSTEM_ENDIAN_H__) || defined(__GLIBC__) || defined(__EMSCRIPTEN__)
96+
# include <endian.h>
97+
98+
/* ... for OSX */
99+
END
100+
patch -p1 <<END
101+
--- Python-3.14.0rc1/Modules/_hacl/libintvector.h
102+
+++ Python-3.14.0rc1-mvpbi/Modules/_hacl/libintvector.h
103+
@@ -21,13 +21,28 @@
104+
105+
#define Lib_IntVector_Intrinsics_bit_mask64(x) -((x) & 1)
106+
107+
-#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)
108+
+#if defined(__wasm__) && !defined(__wasm_simd128__)
109+
+ #define SIMDE_ENABLE_NATIVE_ALIASES
110+
+ #define SIMDE_NO_NATIVE
111+
+// typedef void* Lib_IntVector_Intrinsics_vec128;
112+
+ #define WASM_SIMD
113+
+#endif
114+
+
115+
+#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86) || defined(WASM_SIMD)
116+
117+
#if defined(HACL_CAN_COMPILE_VEC128)
118+
119+
+#if !defined(WASM_SIMD)
120+
#include <emmintrin.h>
121+
#include <tmmintrin.h>
122+
#include <smmintrin.h>
123+
+#else
124+
+ #warning "Modules/_hacl: using SIMDE emulation for wasm"
125+
+// #include <simde/wasm/simd128.h>
126+
+ #include <simde/x86/sse4.1.h>
127+
+ #include <simde/x86/sse4.2.h>
128+
+#endif
129+
+
130+
131+
typedef __m128i Lib_IntVector_Intrinsics_vec128;
132+
133+
END
134+
135+
62136
patch -p1 <<END
63137
--- Python-3.13.0rc3/Objects/moduleobject.c 2024-10-01 04:03:08.000000000 +0200
64138
+++ Python-3.13.0rc3.wasm/Objects/moduleobject.c 2024-10-02 13:16:33.030387509 +0200
@@ -75,6 +149,14 @@ then
75149
return 0;
76150
END
77151

152+
153+
154+
155+
156+
157+
158+
159+
78160
popd
79161

80162
fi

scripts/emsdk-fetch.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ then
5959
END
6060
fi
6161

62+
# this one for debug mode and changing -Wl,--global-base= with -sGLOBAL_BASE
63+
patch -p1 <<END
64+
--- emsdk/upstream/emscripten/tools/link.py 2025-06-23 08:45:26.554013381 +0200
65+
+++ emsdk.fix/upstream/emscripten/tools/link.py 2025-06-23 08:45:31.445921560 +0200
66+
@@ -1662,7 +1662,7 @@
67+
# use a smaller LEB encoding).
68+
# However, for debugability is better to have the stack come first
69+
# (because stack overflows will trap rather than corrupting data).
70+
- settings.STACK_FIRST = True
71+
+ settings.STACK_FIRST = False
72+
73+
if state.has_link_flag('--stack-first'):
74+
settings.STACK_FIRST = True
75+
END
76+
77+
6278
pushd upstream/emscripten
6379

6480
echo "FIXME: applying stdio* are not const"

sources.wasm/7000-zstd.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
. scripts/emsdk-fetch.sh
4+
5+
VERSION=1.5.7
6+
PKG=zstd
7+
8+
cd ${ROOT}/src
9+
10+
if [ -d $PKG ]
11+
then
12+
echo "using $PKG local copy"
13+
else
14+
wget -c https://github.com/facebook/zstd/releases/download/v${VERSION}/${PKG}-${VERSION}.tar.gz
15+
tar xfz ${PKG}-${VERSION}.tar.gz
16+
fi
17+
18+
if [ -f $PREFIX/lib/lib${PKG}.a ]
19+
then
20+
echo "
21+
already built in $PREFIX/lib/lib${PKG}.a
22+
"
23+
else
24+
mkdir -p $ROOT/build/${PKG}
25+
pushd $ROOT/build/${PKG}
26+
emcmake cmake ../../src/${PKG}-${VERSION}/build/cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_INSTALL_PREFIX=$PREFIX \
27+
&& emmake make install
28+
popd
29+
fi
30+
31+
32+

sources.wasm/8000-simde.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
PKG=simde
4+
5+
cd ${ROOT}/src
6+
7+
if [ -d $PKG ]
8+
then
9+
echo "using $PKG local copy"
10+
else
11+
git clone --no-tags --depth 1 --single-branch --branch master https://github.com/simd-everywhere/simde
12+
fi
13+
14+
if [ -d $PREFIX/include/${PKG} ]
15+
then
16+
echo "
17+
$PKG already built in $PREFIX/include/${PKG}
18+
"
19+
else
20+
cp -R ${ROOT}/src/${PKG}/${PKG} $PREFIX/include/
21+
fi
22+
23+
24+

support/__EMSCRIPTEN__.patches/3.14/asyncio/__init__.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,52 @@
55
import sys
66

77
# This relies on each of the submodules having an __all__ variable.
8+
from . import base_events
89
from .base_events import *
10+
11+
from . import coroutines
912
from .coroutines import *
13+
14+
from . import events
1015
from .events import *
16+
17+
from . import exceptions
1118
from .exceptions import *
19+
20+
from . import futures
1221
from .futures import *
22+
23+
from . import locks
1324
from .locks import *
25+
26+
from . import protocols
1427
from .protocols import *
28+
29+
from . import runners
1530
from .runners import *
31+
32+
from . import queues
1633
from .queues import *
34+
35+
from . import streams
1736
from .streams import *
37+
38+
from . import subprocess
1839
from .subprocess import *
40+
41+
from . import tasks
1942
from .tasks import *
43+
44+
from . import taskgroups
2045
from .taskgroups import *
46+
47+
from . import timeouts
2148
from .timeouts import *
49+
50+
from . import threads
2251
from .threads import *
52+
53+
from . import transports
2354
from .transports import *
2455

2556
__all__ = (base_events.__all__ +
@@ -47,3 +78,31 @@
4778
else:
4879
from .unix_events import * # pragma: no cover
4980
__all__ += unix_events.__all__
81+
82+
def __getattr__(name: str):
83+
import warnings
84+
85+
match name:
86+
case "AbstractEventLoopPolicy":
87+
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
88+
return events._AbstractEventLoopPolicy
89+
case "DefaultEventLoopPolicy":
90+
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
91+
if sys.platform in ['emscripten','wasi']:
92+
return wasm_events._DefaultEventLoopPolicy
93+
elif sys.platform == 'win32':
94+
return windows_events._DefaultEventLoopPolicy
95+
return unix_events._DefaultEventLoopPolicy
96+
case "WindowsSelectorEventLoopPolicy":
97+
if sys.platform == 'win32':
98+
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
99+
return windows_events._WindowsSelectorEventLoopPolicy
100+
# Else fall through to the AttributeError below.
101+
case "WindowsProactorEventLoopPolicy":
102+
if sys.platform == 'win32':
103+
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
104+
return windows_events._WindowsProactorEventLoopPolicy
105+
# Else fall through to the AttributeError below.
106+
107+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
108+

0 commit comments

Comments
 (0)