Mercurial > hgrepos > Python > libs > ConfigMix
comparison windows-dev/Configure.py @ 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 | 1b02659ece9c |
comparison
equal
deleted
inserted
replaced
| 573:59ab0b151269 | 574:0c9169de6e3a |
|---|---|
| 64 link_with_python = None, | 64 link_with_python = None, |
| 65 python_limited_api = None, | 65 python_limited_api = None, |
| 66 ) | 66 ) |
| 67 | 67 |
| 68 gbv = BuildVars() | 68 gbv = BuildVars() |
| 69 gbv.intdir = "_builddir-test" | 69 gbv.intdir = "build/_builddir-test/tmp" |
| 70 gbv.srcdir = "src" | 70 gbv.srcdir = "." |
| 71 gbv.builddir = "$intdir" | 71 gbv.builddir = "$intdir" |
| 72 gbv.pxx3dir = "pxx3" | 72 gbv.outdir = "$intdir/out" |
| 73 | 73 |
| 74 opts, args = getopt.getopt( | 74 opts, args = getopt.getopt( |
| 75 sys.argv[1:], | 75 sys.argv[1:], |
| 76 "B:H:t:I:L:", | 76 "B:H:t:I:L:", |
| 77 ["build=", | 77 ["build=", |
| 79 "tool=", | 79 "tool=", |
| 80 "include=", | 80 "include=", |
| 81 "libpath=", | 81 "libpath=", |
| 82 "sys-include=", | 82 "sys-include=", |
| 83 "sys-libpath=", | 83 "sys-libpath=", |
| 84 "CXX=", | 84 "CC=", |
| 85 "LINK=", | 85 "LINK=", |
| 86 "intdir=", # intermediate files | 86 "intdir=", # intermediate files |
| 87 "builddir=", # Ninja builddir | 87 "builddir=", # Ninja builddir |
| 88 "outdir=", # The built objects | |
| 88 "link-with-python=", # link with libpython | 89 "link-with-python=", # link with libpython |
| 89 "python-limited-api=", # Use Py_LIMITED_API | 90 "python-limited-api=", # Use Py_LIMITED_API |
| 90 ]) | 91 ]) |
| 91 for opt, val in opts: | 92 for opt, val in opts: |
| 92 if opt in ("-t", "--tool"): | 93 if opt in ("-t", "--tool"): |
| 164 options.user_libpath.append(val) | 165 options.user_libpath.append(val) |
| 165 elif opt == "--sys-include": | 166 elif opt == "--sys-include": |
| 166 options.sys_includes.append(val) | 167 options.sys_includes.append(val) |
| 167 elif opt == "--sys-libpath": | 168 elif opt == "--sys-libpath": |
| 168 options.sys_libpath.append(val) | 169 options.sys_libpath.append(val) |
| 169 elif opt == "--CXX": | 170 elif opt == "--CC": |
| 170 gbv.cxx = val | 171 gbv.cc = val |
| 171 elif opt == "--LINK": | 172 elif opt == "--LINK": |
| 172 gbv.link = val | 173 gbv.link = val |
| 173 elif opt == "--intdir": | 174 elif opt == "--intdir": |
| 174 gbv.intdir = val | 175 gbv.intdir = val |
| 175 elif opt == "--builddir": | 176 elif opt == "--builddir": |
| 176 gbv.builddir = val | 177 gbv.builddir = val |
| 178 elif opt == "--outdir": | |
| 179 gbv.outdir = val | |
| 177 elif opt == "--link-with-python": | 180 elif opt == "--link-with-python": |
| 178 options.link_with_python = val | 181 options.link_with_python = val |
| 179 elif opt == "--python-limited-api": | 182 elif opt == "--python-limited-api": |
| 180 if val.lower().startswith("0x"): | 183 if val.lower().startswith("0x"): |
| 181 options.python_limited_api = val | 184 options.python_limited_api = val |
| 182 else: | 185 else: |
| 183 options.python_limited_api = "0x03040000" | 186 # Here we are Python 3.7+ when using the limited API |
| 187 options.python_limited_api = "0x03070000" | |
| 184 else: | 188 else: |
| 185 raise getopt.GetoptError("Unhandled option `{}'".format(opt), opt) | 189 raise getopt.GetoptError("Unhandled option `{}'".format(opt), opt) |
| 186 | 190 |
| 187 if tool is None: | 191 if tool is None: |
| 188 print("ERROR: no tool given", file=sys.stderr) | 192 print("ERROR: no tool given", file=sys.stderr) |
| 198 import posixpath as pathmod | 202 import posixpath as pathmod |
| 199 build.pathmod = pathmod | 203 build.pathmod = pathmod |
| 200 | 204 |
| 201 if tool.msvc: | 205 if tool.msvc: |
| 202 if tool.clang: | 206 if tool.clang: |
| 203 if not getattr(gbv, "cxx", None): | 207 if not getattr(gbv, "cc", None): |
| 204 gbv.cxx = "clang-cl" | 208 gbv.cc = "clang-cl" |
| 205 if not getattr(gbv, "link", None): | 209 if not getattr(gbv, "link", None): |
| 206 gbv.link = "lld-link" | 210 gbv.link = "lld-link" |
| 207 else: | 211 else: |
| 208 gbv.cxx = "cl" | 212 gbv.cc = "cl" |
| 209 gbv.link = "link" | 213 gbv.link = "link" |
| 210 elif tool.clang: | 214 elif tool.clang: |
| 211 gbv.cxx = "clang++" | 215 gbv.cc = "clang" |
| 212 gbv.link = "clang++" # link C++ through the compiler | 216 gbv.link = "clang" # link C through the compiler |
| 213 elif tool.local: | 217 elif tool.local: |
| 214 gbv.cxx = "c++" | 218 gbv.cc = "cc" |
| 215 gbv.link = "c++" # link through the compiler | 219 gbv.link = "cc" # link through the compiler |
| 216 else: | 220 else: |
| 217 raise RuntimeError("tool condition is not handled") | 221 raise RuntimeError("tool condition is not handled") |
| 218 | 222 |
| 219 ext1_sources = [ | 223 speedups_sources = [ |
| 220 "$srcdir/ext1/testext1.cpp", | 224 "$srcdir/configmix/_speedups.c", |
| 221 "$pxx3dir/shared/thread.cpp", | |
| 222 ] | 225 ] |
| 223 | 226 |
| 224 ext2_sources = [ | |
| 225 "$srcdir/ext2/testext2.cpp", | |
| 226 "$srcdir/ext2/hashes.cpp", | |
| 227 "$pxx3dir/shared/thread.cpp", | |
| 228 "$pxx3dir/shared/module.cpp", | |
| 229 "$pxx3dir/shared/xcept.cpp", | |
| 230 "$pxx3dir/shared/cfunctions.cpp", | |
| 231 "$pxx3dir/shared/misc.cpp", | |
| 232 "$pxx3dir/shared/exttype.cpp", | |
| 233 "$pxx3dir/shared/allocator.cpp", | |
| 234 ] | |
| 235 | |
| 236 ccflags = [] | 227 ccflags = [] |
| 237 cxxflags = [] | |
| 238 ccwarnings = [] | 228 ccwarnings = [] |
| 239 ldflags = [] | 229 ldflags = [] |
| 240 | 230 |
| 241 defines = [ | 231 defines = [ |
| 242 "PY_SSIZE_T_CLEAN", | 232 # "PY_SSIZE_T_CLEAN", # in the source |
| 243 "HAVE_THREADS", | 233 "HAVE_THREADS", |
| 244 ] | 234 ] |
| 245 if options.python_limited_api: | 235 if options.python_limited_api: |
| 246 defines.append("Py_LIMITED_API={}".format(options.python_limited_api)) | 236 defines.append("Py_LIMITED_API={}".format(options.python_limited_api)) |
| 247 | 237 |
| 249 | 239 |
| 250 includes = [] | 240 includes = [] |
| 251 includes.extend(options.sys_includes) | 241 includes.extend(options.sys_includes) |
| 252 includes.extend(options.user_includes) | 242 includes.extend(options.user_includes) |
| 253 | 243 |
| 254 includes.append("$pxx3dir/include") | |
| 255 | 244 |
| 256 libpath = [] | 245 libpath = [] |
| 257 libpath.extend(options.sys_libpath) | 246 libpath.extend(options.sys_libpath) |
| 258 libpath.extend(options.user_libpath) | 247 libpath.extend(options.user_libpath) |
| 259 | 248 |
| 275 # for a user dll | 264 # for a user dll |
| 276 defines.append("_USRDLL") | 265 defines.append("_USRDLL") |
| 277 defines.append("_WINDLL") | 266 defines.append("_WINDLL") |
| 278 | 267 |
| 279 defines.append("WIN32_LEAN_AND_MEAN") | 268 defines.append("WIN32_LEAN_AND_MEAN") |
| 280 defines.append("_WIN32_WINNT=0x0501") # WinXP | 269 # WinXP: no extravagant Windows features |
| 270 defines.append("_WIN32_WINNT=0x0501") | |
| 281 | 271 |
| 282 if tool.msvc: | 272 if tool.msvc: |
| 283 # XXX TBD warnings | 273 # XXX TBD warnings |
| 284 | 274 |
| 285 defines.append("_CRT_SECURE_NO_WARNINGS") | 275 defines.append("_CRT_SECURE_NO_WARNINGS") |
| 287 ccflags.append("/Zi") | 277 ccflags.append("/Zi") |
| 288 ccflags.append("/MD") # link to dll runtime | 278 ccflags.append("/MD") # link to dll runtime |
| 289 ccflags.append("/EHsc") | 279 ccflags.append("/EHsc") |
| 290 ccflags.append("/Gy") # enable function level linking | 280 ccflags.append("/Gy") # enable function level linking |
| 291 | 281 |
| 292 cxxflags.append("/TP") | |
| 293 #cxxflags.append("/std:c++latest") | |
| 294 | |
| 295 # XXX TBD machine | 282 # XXX TBD machine |
| 296 ccflags.append("-m64") | 283 if tool.clang: |
| 284 ccflags.append("--target=x86_64-pc-windows-msvc") | |
| 285 else: | |
| 286 ccflags.append("-m64") | |
| 287 | |
| 288 if tool.clang: # or tool.gcc | |
| 289 ccflags.append("-fno-strict-aliasing") | |
| 297 | 290 |
| 298 ldflags.append("/dll") | 291 ldflags.append("/dll") |
| 299 ldflags.append("/debug") # PDB output | 292 ldflags.append("/debug") # PDB output |
| 300 # 32-bit: -> 5.01 64-bit: 5.02 | 293 # 32-bit: -> 5.01 64-bit: 5.02 |
| 301 ldflags.append("/subsystem:windows,5.02") | 294 ldflags.append("/subsystem:windows,5.02") |
| 321 ccflags.append("-pthread") | 314 ccflags.append("-pthread") |
| 322 | 315 |
| 323 if tool.clang: # || tool.gcc | 316 if tool.clang: # || tool.gcc |
| 324 ccflags.append("-ffunction-sections") | 317 ccflags.append("-ffunction-sections") |
| 325 ccflags.append("-fdata-sections") | 318 ccflags.append("-fdata-sections") |
| 319 ccflags.append("-fno-strict-aliasing") | |
| 326 | 320 |
| 327 if tool.clang: | 321 if tool.clang: |
| 328 ccflags.append("-faddrsig") # use with --icf=all/safe when linking | 322 ccflags.append("-faddrsig") # use with --icf=all/safe when linking |
| 329 | 323 |
| 330 ldflags.append("-shared") | 324 ldflags.append("-shared") |
| 338 ldflags.append("-Wl,--gc-sections") | 332 ldflags.append("-Wl,--gc-sections") |
| 339 | 333 |
| 340 if tool.clang: | 334 if tool.clang: |
| 341 ldflags.append("-Wl,--icf=safe") | 335 ldflags.append("-Wl,--icf=safe") |
| 342 | 336 |
| 337 if options.python_limited_api: | |
| 338 host.pydext = ".abi3" + host.pydext | |
| 339 | |
| 340 defines.append("NDEBUG") | |
| 341 | |
| 343 gbv.cppdefines = [tool.define_format.format(d) for d in defines] | 342 gbv.cppdefines = [tool.define_format.format(d) for d in defines] |
| 344 gbv.includes = [tool.include_format.format(pathmod.normpath(i)) | 343 gbv.includes = [tool.include_format.format(pathmod.normpath(i)) |
| 345 for i in includes] | 344 for i in includes] |
| 346 gbv.ccflags = ccflags | 345 gbv.ccflags = ccflags |
| 347 gbv.cxxflags = cxxflags | |
| 348 gbv.ccwarnings = ccwarnings | 346 gbv.ccwarnings = ccwarnings |
| 349 gbv.ldflags = ldflags | 347 gbv.ldflags = ldflags |
| 350 gbv.ldlibpath = [tool.libpath_format.format(pathmod.normpath(l)) | 348 gbv.ldlibpath = [tool.libpath_format.format(pathmod.normpath(l)) |
| 351 for l in libpath] | 349 for l in libpath] |
| 352 gbv.ldlibs = [tool.lib_format.format(l) for l in libs] | 350 gbv.ldlibs = [tool.lib_format.format(l) for l in libs] |
| 365 n.variable(k, v) | 363 n.variable(k, v) |
| 366 n.newline() | 364 n.newline() |
| 367 if tool.msvc: | 365 if tool.msvc: |
| 368 # Note: this includes clang-cl | 366 # Note: this includes clang-cl |
| 369 n.rule("compile-pyextension-unit", | 367 n.rule("compile-pyextension-unit", |
| 370 "$cxx /nologo /showIncludes /c $cppdefines $ccwarnings $includes $ccflags $cxxflags /Fd$intdir/$intsubdir/ /Fo$out $in", | 368 "$cc /nologo /showIncludes /c $cppdefines $ccwarnings $includes $ccflags /Fd$intdir/$intsubdir/ /Fo$out $in", |
| 371 deps=tool.dependencies) | 369 deps=tool.dependencies) |
| 372 else: | 370 else: |
| 373 n.rule("compile-pyextension-unit", | 371 n.rule("compile-pyextension-unit", |
| 374 "$cxx -MD -MF $intdir/_deps -MT $out $cppdefines $ccwarnings $includes $ccflags $cxxflags -c -o $out $in", | 372 "$cc -MD -MF $intdir/_deps -MT $out $cppdefines $ccwarnings $includes $ccflags -c -o $out $in", |
| 375 deps=tool.dependencies, | 373 deps=tool.dependencies, |
| 376 depfile="$intdir/_deps") | 374 depfile="$intdir/_deps") |
| 377 n.newline() | 375 n.newline() |
| 378 if tool.msvc: | 376 if tool.msvc: |
| 379 # XXX TBD: in "release" builds use /pdbaltpath:$out.pdb | 377 # XXX TBD: in "release" builds use /pdbaltpath:$out.pdb |
| 380 n.rule("link-pyextension", "$link /nologo $ldflags $ldlibpath /implib:$intdir/$out.lib /pdb:$intdir/$out.pdb /out:$out $in $ldlibs") | 378 n.rule("link-pyextension", "$link /nologo $ldflags $ldlibpath /implib:$out.lib /pdb:$out.pdb /out:$out $in $ldlibs") |
| 381 else: | 379 else: |
| 382 n.rule("link-pyextension", "$link $cppdefines $ccwarnings $ccflags $cxxflags $ldflags -o $out $in $ldlibpath $ldlibs") | 380 n.rule("link-pyextension", "$link $cppdefines $ccwarnings $ccflags $ldflags -o $out $in $ldlibpath $ldlibs") |
| 383 n.newline() | 381 n.newline() |
| 384 | 382 |
| 385 n.comment("testext1") | 383 n.comment("_speedups") |
| 386 for f in ext1_sources: | 384 for f in speedups_sources: |
| 387 n.build(pathmod.normpath("$intdir/$intsubdir/"+make_obj_name(f, host.objext)), | 385 n.build(pathmod.normpath("$intdir/$intsubdir/"+make_obj_name(f, host.objext)), |
| 388 "compile-pyextension-unit", | 386 "compile-pyextension-unit", |
| 389 inputs=pathmod.normpath(f), | 387 inputs=pathmod.normpath(f), |
| 390 variables={"intsubdir": "ext1"}) | 388 variables={"intsubdir": "speedups"}) |
| 391 n.newline() | 389 n.newline() |
| 392 linkinputs = [pathmod.normpath("$intdir/ext1/"+make_obj_name(f, host.objext)) | 390 linkinputs = [pathmod.normpath("$intdir/$intsubdir/"+make_obj_name(f, host.objext)) |
| 393 for f in ext1_sources] | 391 for f in speedups_sources] |
| 392 linkoutput = "$outdir/_speedups" + host.pydext | |
| 394 if tool.msvc: | 393 if tool.msvc: |
| 395 implicit_outputs = [ | 394 implicit_outputs = [ |
| 396 pathmod.normpath("$intdir/testext1"+host.pydext+".lib"), | 395 pathmod.normpath(linkoutput + ".pdb"), |
| 397 pathmod.normpath("$intdir/testext1"+host.pydext+".pdb")] | 396 pathmod.normpath(linkoutput + ".lib")] |
| 398 if not tool.clang: | 397 if not tool.clang: |
| 399 implicit_outputs.append(pathmod.normpath("$intdir/testext1"+host.pydext+".exp")) | 398 implicit_outputs.append(pathmod.normpath(linkoutput + ".exp")) |
| 400 else: | 399 else: |
| 401 implicit_outputs = None | 400 implicit_outputs = None |
| 402 n.build("testext1"+host.pydext, | 401 n.build(linkoutput, |
| 403 "link-pyextension", | 402 "link-pyextension", |
| 404 inputs=linkinputs, | 403 inputs=linkinputs, |
| 405 implicit_outputs=implicit_outputs) | 404 implicit_outputs=implicit_outputs, |
| 406 n.newline() | 405 variables={"intsubdir": "speedups"}) |
| 407 | 406 n.newline() |
| 408 n.comment("testext2") | |
| 409 for f in ext2_sources: | |
| 410 n.build(pathmod.normpath("$intdir/$intsubdir/"+make_obj_name(f, host.objext)), | |
| 411 "compile-pyextension-unit", | |
| 412 inputs=pathmod.normpath(f), | |
| 413 variables={"intsubdir": "ext2"}) | |
| 414 n.newline() | |
| 415 linkinputs = [pathmod.normpath("$intdir/ext2/"+make_obj_name(f, host.objext)) | |
| 416 for f in ext2_sources] | |
| 417 if tool.msvc: | |
| 418 implicit_outputs = [ | |
| 419 pathmod.normpath("$intdir/testext2"+host.pydext+".lib"), | |
| 420 pathmod.normpath("$intdir/testext2"+host.pydext+".pdb")] | |
| 421 if not tool.clang: | |
| 422 implicit_outputs.append(pathmod.normpath("$intdir/testext2"+host.pydext+".exp")) | |
| 423 else: | |
| 424 implicit_outputs = None | |
| 425 n.build("testext2"+host.pydext, | |
| 426 "link-pyextension", | |
| 427 inputs=linkinputs, | |
| 428 implicit_outputs=implicit_outputs) |
