changeset 574:0c9169de6e3a

Cross-building for Windows 64-bit
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 08 Jan 2022 21:46:04 +0100
parents 59ab0b151269
children 9ce13f753c04
files windows-dev/Configure.py windows-dev/pc03/cross.sh
diffstat 2 files changed, 53 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/windows-dev/Configure.py	Sat Jan 08 18:35:58 2022 +0100
+++ b/windows-dev/Configure.py	Sat Jan 08 21:46:04 2022 +0100
@@ -66,10 +66,10 @@
 )
 
 gbv = BuildVars()
-gbv.intdir = "_builddir-test"
-gbv.srcdir = "src"
+gbv.intdir = "build/_builddir-test/tmp"
+gbv.srcdir = "."
 gbv.builddir = "$intdir"
-gbv.pxx3dir = "pxx3"
+gbv.outdir = "$intdir/out"
 
 opts, args = getopt.getopt(
     sys.argv[1:],
@@ -81,10 +81,11 @@
      "libpath=",
      "sys-include=",
      "sys-libpath=",
-     "CXX=",
+     "CC=",
      "LINK=",
      "intdir=",              # intermediate files
      "builddir=",            # Ninja builddir
+     "outdir=",              # The built objects
      "link-with-python=",    # link with libpython
      "python-limited-api=",  # Use Py_LIMITED_API
      ])
@@ -166,21 +167,24 @@
         options.sys_includes.append(val)
     elif opt == "--sys-libpath":
         options.sys_libpath.append(val)
-    elif opt == "--CXX":
-        gbv.cxx = val
+    elif opt == "--CC":
+        gbv.cc = val
     elif opt == "--LINK":
         gbv.link = val
     elif opt == "--intdir":
         gbv.intdir = val
     elif opt == "--builddir":
         gbv.builddir = val
+    elif opt == "--outdir":
+        gbv.outdir = val
     elif opt == "--link-with-python":
         options.link_with_python = val
     elif opt == "--python-limited-api":
         if val.lower().startswith("0x"):
             options.python_limited_api = val
         else:
-            options.python_limited_api = "0x03040000"
+            # Here we are Python 3.7+ when using the limited API
+            options.python_limited_api = "0x03070000"
     else:
         raise getopt.GetoptError("Unhandled option `{}'".format(opt), opt)
 
@@ -200,46 +204,32 @@
 
 if tool.msvc:
     if tool.clang:
-        if not getattr(gbv, "cxx", None):
-            gbv.cxx = "clang-cl"
+        if not getattr(gbv, "cc", None):
+            gbv.cc = "clang-cl"
         if not getattr(gbv, "link", None):
             gbv.link = "lld-link"
     else:
-        gbv.cxx = "cl"
+        gbv.cc = "cl"
         gbv.link = "link"
 elif tool.clang:
-    gbv.cxx = "clang++"
-    gbv.link = "clang++"   # link C++ through the compiler
+    gbv.cc = "clang"
+    gbv.link = "clang"   # link C through the compiler
 elif tool.local:
-    gbv.cxx = "c++"
-    gbv.link = "c++"       # link through the compiler
+    gbv.cc = "cc"
+    gbv.link = "cc"       # link through the compiler
 else:
     raise RuntimeError("tool condition is not handled")
 
-ext1_sources = [
-    "$srcdir/ext1/testext1.cpp",
-    "$pxx3dir/shared/thread.cpp",
-]
-
-ext2_sources = [
-    "$srcdir/ext2/testext2.cpp",
-    "$srcdir/ext2/hashes.cpp",    
-    "$pxx3dir/shared/thread.cpp",
-    "$pxx3dir/shared/module.cpp",
-    "$pxx3dir/shared/xcept.cpp",
-    "$pxx3dir/shared/cfunctions.cpp",
-    "$pxx3dir/shared/misc.cpp",
-    "$pxx3dir/shared/exttype.cpp",    
-    "$pxx3dir/shared/allocator.cpp",    
+speedups_sources = [
+    "$srcdir/configmix/_speedups.c",
 ]
 
 ccflags = []
-cxxflags = []
 ccwarnings = []
 ldflags = []
 
 defines = [
-    "PY_SSIZE_T_CLEAN",
+#    "PY_SSIZE_T_CLEAN",   # in the source
     "HAVE_THREADS",
 ]
 if options.python_limited_api:
@@ -251,7 +241,6 @@
 includes.extend(options.sys_includes)
 includes.extend(options.user_includes)
 
-includes.append("$pxx3dir/include")
 
 libpath = []
 libpath.extend(options.sys_libpath)
@@ -277,7 +266,8 @@
     defines.append("_WINDLL")
 
     defines.append("WIN32_LEAN_AND_MEAN")
-    defines.append("_WIN32_WINNT=0x0501")    # WinXP
+    # WinXP: no extravagant Windows features
+    defines.append("_WIN32_WINNT=0x0501")
 
     if tool.msvc:
         # XXX TBD warnings
@@ -289,11 +279,14 @@
         ccflags.append("/EHsc")
         ccflags.append("/Gy")   # enable function level linking
 
-        cxxflags.append("/TP")
-        #cxxflags.append("/std:c++latest")
+        # XXX TBD machine
+        if tool.clang:
+            ccflags.append("--target=x86_64-pc-windows-msvc")
+        else:
+            ccflags.append("-m64")
 
-        # XXX TBD machine
-        ccflags.append("-m64")
+        if tool.clang:  # or tool.gcc
+            ccflags.append("-fno-strict-aliasing")
 
         ldflags.append("/dll")
         ldflags.append("/debug")    # PDB output
@@ -323,6 +316,7 @@
     if tool.clang:  # || tool.gcc
         ccflags.append("-ffunction-sections")
         ccflags.append("-fdata-sections")
+        ccflags.append("-fno-strict-aliasing")
 
     if tool.clang:
         ccflags.append("-faddrsig")    # use with --icf=all/safe when linking
@@ -340,11 +334,15 @@
     if tool.clang:
         ldflags.append("-Wl,--icf=safe")
 
+    if options.python_limited_api:
+        host.pydext = ".abi3" + host.pydext
+
+defines.append("NDEBUG")
+
 gbv.cppdefines = [tool.define_format.format(d) for d in defines]
 gbv.includes = [tool.include_format.format(pathmod.normpath(i))
                 for i in includes]
 gbv.ccflags = ccflags
-gbv.cxxflags = cxxflags
 gbv.ccwarnings = ccwarnings
 gbv.ldflags = ldflags
 gbv.ldlibpath = [tool.libpath_format.format(pathmod.normpath(l))
@@ -367,62 +365,42 @@
 if tool.msvc:
     # Note: this includes clang-cl
     n.rule("compile-pyextension-unit",
-           "$cxx /nologo /showIncludes /c $cppdefines $ccwarnings $includes $ccflags $cxxflags /Fd$intdir/$intsubdir/ /Fo$out $in",
+           "$cc /nologo /showIncludes /c $cppdefines $ccwarnings $includes $ccflags /Fd$intdir/$intsubdir/ /Fo$out $in",
            deps=tool.dependencies)
 else:
     n.rule("compile-pyextension-unit",
-           "$cxx -MD -MF $intdir/_deps -MT $out $cppdefines $ccwarnings $includes $ccflags $cxxflags -c -o $out $in",
+           "$cc -MD -MF $intdir/_deps -MT $out $cppdefines $ccwarnings $includes $ccflags -c -o $out $in",
            deps=tool.dependencies,
            depfile="$intdir/_deps")
 n.newline()
 if tool.msvc:
     # XXX TBD: in "release" builds use /pdbaltpath:$out.pdb
-    n.rule("link-pyextension", "$link /nologo $ldflags $ldlibpath /implib:$intdir/$out.lib /pdb:$intdir/$out.pdb /out:$out $in $ldlibs")
+    n.rule("link-pyextension", "$link /nologo $ldflags $ldlibpath /implib:$out.lib /pdb:$out.pdb /out:$out $in $ldlibs")
 else:
-    n.rule("link-pyextension", "$link $cppdefines $ccwarnings $ccflags $cxxflags $ldflags -o $out $in $ldlibpath $ldlibs")
+    n.rule("link-pyextension", "$link $cppdefines $ccwarnings $ccflags $ldflags -o $out $in $ldlibpath $ldlibs")
 n.newline()
 
-n.comment("testext1")
-for f in ext1_sources:
+n.comment("_speedups")
+for f in speedups_sources:
     n.build(pathmod.normpath("$intdir/$intsubdir/"+make_obj_name(f, host.objext)),
             "compile-pyextension-unit",
             inputs=pathmod.normpath(f),
-            variables={"intsubdir": "ext1"})
+            variables={"intsubdir": "speedups"})
 n.newline()
-linkinputs = [pathmod.normpath("$intdir/ext1/"+make_obj_name(f, host.objext))
-              for f in ext1_sources]
+linkinputs = [pathmod.normpath("$intdir/$intsubdir/"+make_obj_name(f, host.objext))
+              for f in speedups_sources]
+linkoutput = "$outdir/_speedups" + host.pydext
 if tool.msvc:
     implicit_outputs = [
-        pathmod.normpath("$intdir/testext1"+host.pydext+".lib"),
-        pathmod.normpath("$intdir/testext1"+host.pydext+".pdb")]
+        pathmod.normpath(linkoutput + ".pdb"),
+        pathmod.normpath(linkoutput + ".lib")]
     if not tool.clang:
-        implicit_outputs.append(pathmod.normpath("$intdir/testext1"+host.pydext+".exp"))
+        implicit_outputs.append(pathmod.normpath(linkoutput + ".exp"))
 else:
     implicit_outputs = None
-n.build("testext1"+host.pydext,
+n.build(linkoutput,
         "link-pyextension",
         inputs=linkinputs,
-        implicit_outputs=implicit_outputs)
-n.newline()
-
-n.comment("testext2")
-for f in ext2_sources:
-    n.build(pathmod.normpath("$intdir/$intsubdir/"+make_obj_name(f, host.objext)),
-            "compile-pyextension-unit",
-            inputs=pathmod.normpath(f),
-            variables={"intsubdir": "ext2"})
+        implicit_outputs=implicit_outputs,
+        variables={"intsubdir": "speedups"})
 n.newline()
-linkinputs = [pathmod.normpath("$intdir/ext2/"+make_obj_name(f, host.objext))
-              for f in ext2_sources]
-if tool.msvc:
-    implicit_outputs = [
-        pathmod.normpath("$intdir/testext2"+host.pydext+".lib"),
-        pathmod.normpath("$intdir/testext2"+host.pydext+".pdb")]
-    if not tool.clang:
-        implicit_outputs.append(pathmod.normpath("$intdir/testext2"+host.pydext+".exp"))
-else:
-    implicit_outputs = None
-n.build("testext2"+host.pydext,
-        "link-pyextension",
-        inputs=linkinputs,
-        implicit_outputs=implicit_outputs)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/windows-dev/pc03/cross.sh	Sat Jan 08 21:46:04 2022 +0100
@@ -0,0 +1,1 @@
+python3 windows-dev/Configure.py --build=posix --host=windows --tool=clang-cl --intdir=build/_builddir-win-amd64 --sys-include=/home/fag/work/windows-dev/WindowsKit-10/Include/10.0.18362.0/um --sys-include=/home/fag/work/windows-dev/WindowsKit-10/Include/10.0.18362.0/shared --sys-include=/home/fag/work/windows-dev/WindowsKit-10/Include/10.0.18362.0/ucrt --sys-include=/home/fag/work/windows-dev/VS2017-2019/VC/Tools/MSVC/14.29.30133/include --include=/home/fag/work/windows-dev/Python37-SDK-Win/amd64/include --CC=/usr/local/llvm11/bin/clang-cl --sys-libpath=/home/fag/work/windows-dev/WindowsKit-10/Lib/10.0.18362.0/um/x64 --sys-libpath=/home/fag/work/windows-dev/WindowsKit-10/Lib/10.0.18362.0/ucrt/x64 --sys-libpath=/home/fag/work/windows-dev/VS2017-2019/VC/Tools/MSVC/14.29.30133/lib/x64 --libpath=/home/fag/work/windows-dev/Python37-SDK-Win/amd64/libs/ --LINK=/usr/local/llvm11/bin/lld-link --python-limited-api=0x030A0000 > _build-win-amd64.ninja