Skip to content

Commit 057f10d

Browse files
committed
Implement Windows build
1 parent d83f361 commit 057f10d

40 files changed

+987
-727
lines changed

Include/Python.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include <assert.h> // assert()
3636
#include <wchar.h> // wchar_t
3737

38+
#define FFI_STATIC_BUILD
39+
3840
#include "pyport.h"
3941
#include "pymacro.h"
4042
#include "pymath.h"

Include/pathcch.private.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <Shlwapi.h>
2+
#include "windows.h"
3+
4+
#define DLLAPI __stdcall
5+
6+
#define PATHCCH_NONE 0x00
7+
#define PATHCCH_ALLOW_LONG_PATHS 0x01
8+
#define PATHCCH_FORCE_ENABLE_LONG_NAME_PROCESS 0x02
9+
#define PATHCCH_FORCE_DISABLE_LONG_NAME_PROCESS 0x04
10+
#define PATHCCH_DO_NOT_NORMALIZE_SEGMENTS 0x08
11+
#define PATHCCH_ENSURE_IS_EXTENDED_LENGTH_PATH 0x10
12+
#define PATHCCH_ENSURE_TRAILING_SLASH 0x20
13+
14+
#define PATHCCH_MAX_CCH 0x8000
15+
16+
#define STRSAFE_E_INSUFFICIENT_BUFFER ((HRESULT)0x8007007AL)
17+
18+
HRESULT DLLAPI PathAllocCanonicalize(const WCHAR *path_in, DWORD flags, WCHAR **path_out);
19+
HRESULT DLLAPI PathAllocCombine(const WCHAR *path1, const WCHAR *path2, DWORD flags, WCHAR **out);
20+
HRESULT DLLAPI PathCchAddBackslash(WCHAR *path, SIZE_T size);
21+
HRESULT DLLAPI PathCchAddBackslashEx(WCHAR *path, SIZE_T size, WCHAR **endptr, SIZE_T *remaining);
22+
HRESULT DLLAPI PathCchAddExtension(WCHAR *path, SIZE_T size, const WCHAR *extension);
23+
HRESULT DLLAPI PathCchAppend(WCHAR *path1, SIZE_T size, const WCHAR *path2);
24+
HRESULT DLLAPI PathCchAppendEx(WCHAR *path1, SIZE_T size, const WCHAR *path2, DWORD flags);
25+
HRESULT DLLAPI PathCchCanonicalize(WCHAR *out, SIZE_T size, const WCHAR *in);
26+
HRESULT DLLAPI PathCchCanonicalizeEx(WCHAR *out, SIZE_T size, const WCHAR *in, DWORD flags);
27+
HRESULT DLLAPI PathCchCombine(WCHAR *out, SIZE_T size, const WCHAR *path1, const WCHAR *path2);
28+
HRESULT DLLAPI PathCchCombineEx(WCHAR *out, SIZE_T size, const WCHAR *path1, const WCHAR *path2, DWORD flags);
29+
HRESULT DLLAPI PathCchFindExtension(const WCHAR *path, SIZE_T size, const WCHAR **extension);
30+
BOOL DLLAPI PathCchIsRoot(const WCHAR *path);
31+
HRESULT DLLAPI PathCchRemoveBackslash(WCHAR *path, SIZE_T path_size);
32+
HRESULT DLLAPI PathCchRemoveBackslashEx(WCHAR *path, SIZE_T path_size, WCHAR **path_end, SIZE_T *free_size);
33+
HRESULT DLLAPI PathCchRemoveExtension(WCHAR *path, SIZE_T size);
34+
HRESULT DLLAPI PathCchRemoveFileSpec(WCHAR *path, SIZE_T size);
35+
HRESULT DLLAPI PathCchRenameExtension(WCHAR *path, SIZE_T size, const WCHAR *extension);
36+
HRESULT DLLAPI PathCchSkipRoot(const WCHAR *path, const WCHAR **root_end);
37+
HRESULT DLLAPI PathCchStripPrefix(WCHAR *path, SIZE_T size);
38+
HRESULT DLLAPI PathCchStripToRoot(WCHAR *path, SIZE_T size);
39+
BOOL DLLAPI PathIsUNCEx(const WCHAR *path, const WCHAR **server);

Include/staticinit.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ extern "C" {
2828
extern PyObject* PyInit__overlapped(void);
2929
extern PyObject* PyInit__elementtree(void);
3030
extern PyObject* PyInit__uuid(void);
31-
extern PyObject* PyInit__msi(void);
3231
extern PyObject* PyInit__sqlite3(void);
3332
extern PyObject* PyInit__tkinter(void);
3433
extern PyObject* PyInit__zoneinfo(void);
@@ -57,7 +56,6 @@ static inline void Py_InitStaticModules() {
5756
PyImport_AppendInittab("_overlapped", PyInit__overlapped);
5857
PyImport_AppendInittab("_elementtree", PyInit__elementtree);
5958
PyImport_AppendInittab("_uuid", PyInit__uuid);
60-
PyImport_AppendInittab("_msi", PyInit__msi);
6159
PyImport_AppendInittab("_sqlite3", PyInit__sqlite3);
6260
PyImport_AppendInittab("_tkinter", PyInit__tkinter);
6361
PyImport_AppendInittab("_zoneinfo", PyInit__zoneinfo);

Lib/distutils/_msvccompiler.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,16 @@ def initialize(self, plat_name=None):
262262

263263
self.ldflags_exe = [*ldflags, '/MANIFEST:EMBED,ID=1']
264264
self.ldflags_exe_debug = [*ldflags_debug, '/MANIFEST:EMBED,ID=1']
265-
self.ldflags_shared = [*ldflags, '/DLL', '/MANIFEST:EMBED,ID=2', '/MANIFESTUAC:NO']
266-
self.ldflags_shared_debug = [*ldflags_debug, '/DLL', '/MANIFEST:EMBED,ID=2', '/MANIFESTUAC:NO']
267265
self.ldflags_static = [*ldflags]
268266
self.ldflags_static_debug = [*ldflags_debug]
269267

270268
self._ldflags = {
271269
(CCompiler.EXECUTABLE, None): self.ldflags_exe,
272270
(CCompiler.EXECUTABLE, False): self.ldflags_exe,
273271
(CCompiler.EXECUTABLE, True): self.ldflags_exe_debug,
274-
(CCompiler.SHARED_OBJECT, None): self.ldflags_shared,
275-
(CCompiler.SHARED_OBJECT, False): self.ldflags_shared,
276-
(CCompiler.SHARED_OBJECT, True): self.ldflags_shared_debug,
272+
(CCompiler.SHARED_OBJECT, None): self.ldflags_static,
273+
(CCompiler.SHARED_OBJECT, False): self.ldflags_static,
274+
(CCompiler.SHARED_OBJECT, True): self.ldflags_static_debug,
277275
(CCompiler.SHARED_LIBRARY, None): self.ldflags_static,
278276
(CCompiler.SHARED_LIBRARY, False): self.ldflags_static,
279277
(CCompiler.SHARED_LIBRARY, True): self.ldflags_static_debug,

Lib/ensurepip/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from importlib import resources
99

1010

11-
__all__ = ["version", "bootstrap"]
11+
__all__ = ["version", "bootstrap", "_SETUPTOOLS_VERSION", "_get_packages"]
1212
_PACKAGE_NAMES = ('setuptools', 'pip', 'wheel')
13-
_SETUPTOOLS_VERSION = "70.0.0.post20240616"
13+
_SETUPTOOLS_VERSION = "75.2.0.post20241019"
1414
_PIP_VERSION = "23.3.2"
1515
_WHEEL_VERSION = "0.42.0"
1616
_PROJECTS = [
Binary file not shown.
Binary file not shown.

Lib/pip.py

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def _getPythonVersion():
3939

4040
python_version = _getPythonVersion()
4141

42+
4243
# Portability, lending an import code to module function from Nuitka.
4344
def importFileAsModule(modulename, filename):
4445
"""Import Python module given as a file name.
@@ -146,10 +147,10 @@ def install_build_tool(name):
146147
install_build_tool(tool)
147148

148149
if os.path.isfile(
149-
os.path.join(__np__.getToolsInstallDir(), name, "version.txt")
150+
os.path.join(__np__.getToolsInstallDir(), name, "version.txt")
150151
):
151152
with open(
152-
os.path.join(__np__.getToolsInstallDir(), name, "version.txt"), "r"
153+
os.path.join(__np__.getToolsInstallDir(), name, "version.txt"), "r"
153154
) as f:
154155
version = f.read()
155156
if version == package_index["version"]:
@@ -187,7 +188,7 @@ def install_build_tool(name):
187188
os.environ.update(initenviron)
188189

189190
with open(
190-
os.path.join(__np__.getToolsInstallDir(), name, "version.txt"), "w"
191+
os.path.join(__np__.getToolsInstallDir(), name, "version.txt"), "w"
191192
) as f:
192193
f.write(package_index["version"])
193194

@@ -204,10 +205,10 @@ def install_dependency(name):
204205
install_dependency(dep)
205206

206207
if os.path.isfile(
207-
os.path.join(__np__.getDependencyInstallDir(), name, "version.txt")
208+
os.path.join(__np__.getDependencyInstallDir(), name, "version.txt")
208209
):
209210
with open(
210-
os.path.join(__np__.getDependencyInstallDir(), name, "version.txt"), "r"
211+
os.path.join(__np__.getDependencyInstallDir(), name, "version.txt"), "r"
211212
) as f:
212213
version = f.read()
213214
if version == package_index["version"]:
@@ -245,22 +246,38 @@ def install_dependency(name):
245246
os.environ.update(initenviron)
246247

247248
with open(
248-
os.path.join(__np__.getDependencyInstallDir(), name, "version.txt"), "w"
249+
os.path.join(__np__.getDependencyInstallDir(), name, "version.txt"), "w"
249250
) as f:
250251
f.write(package_index["version"])
251252

252253

254+
import pip._internal.pyproject
255+
256+
load_pyproject_toml_orig = pip._internal.pyproject.load_pyproject_toml
257+
def our_load_pyproject_toml(use_pep517, pyproject_toml, setup_py, req_name):
258+
has_pyproject = os.path.isfile(pyproject_toml)
259+
has_setup = os.path.isfile(setup_py)
260+
261+
if not has_pyproject and not has_setup:
262+
return pip._internal.pyproject.BuildSystemDetails(
263+
["setuptools>=40.8.0", "wheel"], "setuptools.build_meta:__legacy__", [], [])
264+
265+
return load_pyproject_toml_orig(use_pep517, pyproject_toml, setup_py, req_name)
266+
267+
253268
from pip._internal.req.req_install import InstallRequirement
254269
from typing import Iterable, List, Optional, Tuple
255270
import pip._internal.wheel_builder
271+
256272
_orig_build_one_inside_env = pip._internal.wheel_builder._build_one_inside_env
257273

274+
258275
def _build_one_inside_env(
259-
req: InstallRequirement,
260-
output_dir: str,
261-
build_options: List[str],
262-
global_options: List[str],
263-
editable: bool,
276+
req: InstallRequirement,
277+
output_dir: str,
278+
build_options: List[str],
279+
global_options: List[str],
280+
editable: bool,
264281
) -> Optional[str]:
265282
fallback = False
266283
if req.name == "setuptools":
@@ -370,6 +387,20 @@ def build_stub(
370387

371388
class PackageFinder(_PackageFinder):
372389
def find_all_candidates(self, project_name):
390+
import pip._internal.pyproject
391+
pip._internal.pyproject.load_pyproject_toml = our_load_pyproject_toml
392+
pip._internal.req.req_install.load_pyproject_toml = our_load_pyproject_toml
393+
394+
if project_name == "setuptools":
395+
import ensurepip
396+
import pathlib
397+
398+
our_uri = pathlib.Path(os.path.join(os.path.dirname(ensurepip.__file__), '_bundled',
399+
ensurepip._get_packages()["setuptools"].wheel_name)).as_uri()
400+
return [InstallationCandidate(
401+
project_name, ensurepip._SETUPTOOLS_VERSION, Link(our_uri)
402+
)]
403+
373404
base_candidates = _PackageFinder.find_all_candidates(self, project_name)
374405

375406
try:
@@ -393,30 +424,35 @@ def find_all_candidates(self, project_name):
393424

394425
my_path = os.path.abspath(__file__)
395426

427+
396428
def get_runnable_pip() -> str:
397429
return my_path
398430

431+
399432
import pip._internal.build_env
400-
pip._internal.build_env.get_runnable_pip = get_runnable_pip
401433

434+
pip._internal.build_env.get_runnable_pip = get_runnable_pip
402435

403436
import pip._internal.req.req_install
437+
404438
orig_install = pip._internal.req.req_install.InstallRequirement.install
405439

440+
406441
def install(
407442
self,
408-
global_options = None,
409-
root = None,
410-
home = None,
411-
prefix = None,
412-
warn_script_location = True,
413-
use_user_site = False,
414-
pycompile = True,
415-
):
443+
global_options=None,
444+
root=None,
445+
home=None,
446+
prefix=None,
447+
warn_script_location=True,
448+
use_user_site=False,
449+
pycompile=True,
450+
):
416451
orig_install(self, global_options, root, home, prefix, warn_script_location, use_user_site, pycompile)
417452

418453
rebuildpython.run_rebuild()
419454

455+
420456
pip._internal.req.req_install.InstallRequirement.install = install
421457

422458

Lib/rebuildpython.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def run_rebuild():
221221
"Cabinet",
222222
"winmm",
223223
"Netapi32",
224+
"Bcrypt"
224225
]
225226
if "32" in platform.architecture()[0]:
226227
link_libs += ["msvcrt"]

Lib/sysconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ def get_config_vars(*args):
654654
_CONFIG_VARS['platbase'] = _EXEC_PREFIX
655655
_CONFIG_VARS['projectbase'] = _PROJECT_BASE
656656
_CONFIG_VARS['platlibdir'] = sys.platlibdir
657-
_CONFIG_VARS['SOABI'] = 'cpnuitka3.9'
657+
_CONFIG_VARS['SOABI'] = 'cpnuitka3.11'
658658
try:
659659
_CONFIG_VARS['abiflags'] = sys.abiflags
660660
except AttributeError:

Modules/_tkinter.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Copyright (C) 1994 Steen Lumholt.
4444
Tcl are empty. */
4545
#define TCL_THREADS
4646

47+
#define STATIC_BUILD
48+
4749
#ifdef TK_FRAMEWORK
4850
#include <Tcl/tcl.h>
4951
#include <Tk/tk.h>
@@ -52,6 +54,8 @@ Copyright (C) 1994 Steen Lumholt.
5254
#include <tk.h>
5355
#endif
5456

57+
#undef STATIC_BUILD
58+
5559
#include "tkinter.h"
5660

5761
#if TK_HEX_VERSION < 0x0805020c

Modules/getpath.c

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
#ifdef MS_WINDOWS
1313
# include <windows.h> // GetFullPathNameW(), MAX_PATH
14-
# include <pathcch.h>
14+
// # include <pathcch.h>
15+
# include "pathcch.private.h"
1516
#endif
1617

1718
#ifdef __APPLE__
@@ -758,47 +759,6 @@ progname_to_dict(PyObject *dict, const char *key)
758759
}
759760

760761

761-
/* Add the runtime library's path to the dict */
762-
static int
763-
library_to_dict(PyObject *dict, const char *key)
764-
{
765-
#ifdef MS_WINDOWS
766-
extern HMODULE PyWin_DLLhModule;
767-
if (PyWin_DLLhModule) {
768-
return winmodule_to_dict(dict, key, PyWin_DLLhModule);
769-
}
770-
#elif defined(WITH_NEXT_FRAMEWORK)
771-
static char modPath[MAXPATHLEN + 1];
772-
static int modPathInitialized = -1;
773-
if (modPathInitialized < 0) {
774-
modPathInitialized = 0;
775-
776-
/* On Mac OS X we have a special case if we're running from a framework.
777-
This is because the python home should be set relative to the library,
778-
which is in the framework, not relative to the executable, which may
779-
be outside of the framework. Except when we're in the build
780-
directory... */
781-
NSSymbol symbol = NSLookupAndBindSymbol("_Py_Initialize");
782-
if (symbol != NULL) {
783-
NSModule pythonModule = NSModuleForSymbol(symbol);
784-
if (pythonModule != NULL) {
785-
/* Use dylib functions to find out where the framework was loaded from */
786-
const char *path = NSLibraryNameForModule(pythonModule);
787-
if (path) {
788-
strncpy(modPath, path, MAXPATHLEN);
789-
modPathInitialized = 1;
790-
}
791-
}
792-
}
793-
}
794-
if (modPathInitialized > 0) {
795-
return decode_to_dict(dict, key, modPath);
796-
}
797-
#endif
798-
return PyDict_SetItemString(dict, key, Py_None) == 0;
799-
}
800-
801-
802762
PyObject *
803763
_Py_Get_Getpath_CodeObject(void)
804764
{
@@ -909,7 +869,7 @@ _PyConfig_InitPathConfig(PyConfig *config, int compute_path_config)
909869
!env_to_dict(dict, "ENV_PYTHONEXECUTABLE", 0) ||
910870
!env_to_dict(dict, "ENV___PYVENV_LAUNCHER__", 1) ||
911871
!progname_to_dict(dict, "real_executable") ||
912-
!library_to_dict(dict, "library") ||
872+
!wchar_to_dict(dict, "library", NULL) ||
913873
!wchar_to_dict(dict, "executable_dir", NULL) ||
914874
!wchar_to_dict(dict, "py_setpath", _PyPathConfig_GetGlobalModuleSearchPath()) ||
915875
!funcs_to_dict(dict, config->pathconfig_warnings) ||

Modules/posixmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
// whereas pycore_condvar.h defines the WIN32_LEAN_AND_MEAN macro.
1616
#ifdef MS_WINDOWS
1717
# include <windows.h>
18-
# include <pathcch.h>
18+
//# include <pathcch.h>
19+
# include "pathcch.private.h"
1920
# include <lmcons.h> // UNLEN
2021
# include "osdefs.h" // SEP
2122
# define HAVE_SYMLINK

PC/config_minimal.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
#include "Python.h"
77

8-
/* Define extern variables omitted from minimal builds */
9-
void *PyWin_DLLhModule = NULL;
10-
118

129
extern PyObject* PyInit_faulthandler(void);
1310
extern PyObject* PyInit__tracemalloc(void);

0 commit comments

Comments
 (0)