475 self.make_file([pofile], mobuildfile, spawn, (cmd,)) |
468 self.make_file([pofile], mobuildfile, spawn, (cmd,)) |
476 |
469 |
477 |
470 |
478 class hgdist(Distribution): |
471 class hgdist(Distribution): |
479 pure = False |
472 pure = False |
480 rust = hgrustext is not None |
473 rust = False |
|
474 no_rust = False |
481 cffi = ispypy |
475 cffi = ispypy |
482 |
476 |
483 global_options = Distribution.global_options + [ |
477 global_options = Distribution.global_options + [ |
484 ('pure', None, "use pure (slow) Python code instead of C extensions"), |
478 ('pure', None, "use pure (slow) Python code instead of C extensions"), |
485 ('rust', None, "use Rust extensions additionally to C extensions"), |
479 ('rust', None, "use Rust extensions additionally to C extensions"), |
|
480 ( |
|
481 'no-rust', |
|
482 None, |
|
483 "do not use Rust extensions additionally to C extensions", |
|
484 ), |
486 ] |
485 ] |
|
486 |
|
487 negative_opt = Distribution.negative_opt.copy() |
|
488 boolean_options = ['pure', 'rust', 'no-rust'] |
|
489 negative_opt['no-rust'] = 'rust' |
|
490 |
|
491 def _set_command_options(self, command_obj, option_dict=None): |
|
492 # Not all distutils versions in the wild have boolean_options. |
|
493 # This should be cleaned up when we're Python 3 only. |
|
494 command_obj.boolean_options = ( |
|
495 getattr(command_obj, 'boolean_options', []) + self.boolean_options |
|
496 ) |
|
497 return Distribution._set_command_options( |
|
498 self, command_obj, option_dict=option_dict |
|
499 ) |
|
500 |
|
501 def parse_command_line(self): |
|
502 ret = Distribution.parse_command_line(self) |
|
503 if not (self.rust or self.no_rust): |
|
504 hgrustext = os.environ.get('HGWITHRUSTEXT') |
|
505 # TODO record it for proper rebuild upon changes |
|
506 # (see mercurial/__modulepolicy__.py) |
|
507 if hgrustext != 'cpython' and hgrustext is not None: |
|
508 if hgrustext: |
|
509 msg = 'unkown HGWITHRUSTEXT value: %s' % hgrustext |
|
510 printf(msg, file=sys.stderr) |
|
511 hgrustext = None |
|
512 self.rust = hgrustext is not None |
|
513 self.no_rust = not self.rust |
|
514 return ret |
487 |
515 |
488 def has_ext_modules(self): |
516 def has_ext_modules(self): |
489 # self.ext_modules is emptied in hgbuildpy.finalize_options which is |
517 # self.ext_modules is emptied in hgbuildpy.finalize_options which is |
490 # too late for some cases |
518 # too late for some cases |
491 return not self.pure and Distribution.has_ext_modules(self) |
519 return not self.pure and Distribution.has_ext_modules(self) |
1382 "command: %r, environment: %r" |
1428 "command: %r, environment: %r" |
1383 % (self.rustsrcdir, cargocmd, env) |
1429 % (self.rustsrcdir, cargocmd, env) |
1384 ) |
1430 ) |
1385 |
1431 |
1386 |
1432 |
1387 class RustEnhancedExtension(RustExtension): |
|
1388 """A C Extension, conditionally enhanced with Rust code. |
|
1389 |
|
1390 If the HGWITHRUSTEXT environment variable is set to something else |
|
1391 than 'cpython', the Rust sources get compiled and linked within |
|
1392 the C target shared library object. |
|
1393 """ |
|
1394 |
|
1395 def __init__(self, mpath, sources, rustlibname, subcrate, **kw): |
|
1396 RustExtension.__init__( |
|
1397 self, mpath, sources, rustlibname, subcrate, **kw |
|
1398 ) |
|
1399 if hgrustext != 'direct-ffi': |
|
1400 return |
|
1401 self.extra_compile_args.append('-DWITH_RUST') |
|
1402 self.libraries.append(rustlibname) |
|
1403 self.library_dirs.append(self.rusttargetdir) |
|
1404 |
|
1405 def rustbuild(self): |
|
1406 if hgrustext == 'direct-ffi': |
|
1407 RustExtension.rustbuild(self) |
|
1408 |
|
1409 |
|
1410 class RustStandaloneExtension(RustExtension): |
1433 class RustStandaloneExtension(RustExtension): |
1411 def __init__(self, pydottedname, rustcrate, dylibname, **kw): |
1434 def __init__(self, pydottedname, rustcrate, dylibname, **kw): |
1412 RustExtension.__init__( |
1435 RustExtension.__init__( |
1413 self, pydottedname, [], dylibname, rustcrate, **kw |
1436 self, pydottedname, [], dylibname, rustcrate, **kw |
1414 ) |
1437 ) |
1430 extmodules = [ |
1453 extmodules = [ |
1431 Extension( |
1454 Extension( |
1432 'mercurial.cext.base85', |
1455 'mercurial.cext.base85', |
1433 ['mercurial/cext/base85.c'], |
1456 ['mercurial/cext/base85.c'], |
1434 include_dirs=common_include_dirs, |
1457 include_dirs=common_include_dirs, |
|
1458 extra_compile_args=common_cflags, |
1435 depends=common_depends, |
1459 depends=common_depends, |
1436 ), |
1460 ), |
1437 Extension( |
1461 Extension( |
1438 'mercurial.cext.bdiff', |
1462 'mercurial.cext.bdiff', |
1439 ['mercurial/bdiff.c', 'mercurial/cext/bdiff.c'] + xdiff_srcs, |
1463 ['mercurial/bdiff.c', 'mercurial/cext/bdiff.c'] + xdiff_srcs, |
1440 include_dirs=common_include_dirs, |
1464 include_dirs=common_include_dirs, |
|
1465 extra_compile_args=common_cflags, |
1441 depends=common_depends + ['mercurial/bdiff.h'] + xdiff_headers, |
1466 depends=common_depends + ['mercurial/bdiff.h'] + xdiff_headers, |
1442 ), |
1467 ), |
1443 Extension( |
1468 Extension( |
1444 'mercurial.cext.mpatch', |
1469 'mercurial.cext.mpatch', |
1445 ['mercurial/mpatch.c', 'mercurial/cext/mpatch.c'], |
1470 ['mercurial/mpatch.c', 'mercurial/cext/mpatch.c'], |
1446 include_dirs=common_include_dirs, |
1471 include_dirs=common_include_dirs, |
|
1472 extra_compile_args=common_cflags, |
1447 depends=common_depends, |
1473 depends=common_depends, |
1448 ), |
1474 ), |
1449 RustEnhancedExtension( |
1475 Extension( |
1450 'mercurial.cext.parsers', |
1476 'mercurial.cext.parsers', |
1451 [ |
1477 [ |
1452 'mercurial/cext/charencode.c', |
1478 'mercurial/cext/charencode.c', |
1453 'mercurial/cext/dirs.c', |
1479 'mercurial/cext/dirs.c', |
1454 'mercurial/cext/manifest.c', |
1480 'mercurial/cext/manifest.c', |
1455 'mercurial/cext/parsers.c', |
1481 'mercurial/cext/parsers.c', |
1456 'mercurial/cext/pathencode.c', |
1482 'mercurial/cext/pathencode.c', |
1457 'mercurial/cext/revlog.c', |
1483 'mercurial/cext/revlog.c', |
1458 ], |
1484 ], |
1459 'hgdirectffi', |
|
1460 'hg-direct-ffi', |
|
1461 include_dirs=common_include_dirs, |
1485 include_dirs=common_include_dirs, |
|
1486 extra_compile_args=common_cflags, |
1462 depends=common_depends |
1487 depends=common_depends |
1463 + [ |
1488 + ['mercurial/cext/charencode.h', 'mercurial/cext/revlog.h',], |
1464 'mercurial/cext/charencode.h', |
|
1465 'mercurial/cext/revlog.h', |
|
1466 'rust/hg-core/src/ancestors.rs', |
|
1467 'rust/hg-core/src/lib.rs', |
|
1468 ], |
|
1469 ), |
1489 ), |
1470 Extension( |
1490 Extension( |
1471 'mercurial.cext.osutil', |
1491 'mercurial.cext.osutil', |
1472 ['mercurial/cext/osutil.c'], |
1492 ['mercurial/cext/osutil.c'], |
1473 include_dirs=common_include_dirs, |
1493 include_dirs=common_include_dirs, |
1474 extra_compile_args=osutil_cflags, |
1494 extra_compile_args=common_cflags + osutil_cflags, |
1475 extra_link_args=osutil_ldflags, |
1495 extra_link_args=osutil_ldflags, |
1476 depends=common_depends, |
1496 depends=common_depends, |
1477 ), |
1497 ), |
1478 Extension( |
1498 Extension( |
1479 'mercurial.thirdparty.zope.interface._zope_interface_coptimizations', |
1499 'mercurial.thirdparty.zope.interface._zope_interface_coptimizations', |
1480 [ |
1500 [ |
1481 'mercurial/thirdparty/zope/interface/_zope_interface_coptimizations.c', |
1501 'mercurial/thirdparty/zope/interface/_zope_interface_coptimizations.c', |
1482 ], |
1502 ], |
|
1503 extra_compile_args=common_cflags, |
1483 ), |
1504 ), |
1484 Extension( |
1505 Extension( |
1485 'mercurial.thirdparty.sha1dc', |
1506 'mercurial.thirdparty.sha1dc', |
1486 [ |
1507 [ |
1487 'mercurial/thirdparty/sha1dc/cext.c', |
1508 'mercurial/thirdparty/sha1dc/cext.c', |
1488 'mercurial/thirdparty/sha1dc/lib/sha1.c', |
1509 'mercurial/thirdparty/sha1dc/lib/sha1.c', |
1489 'mercurial/thirdparty/sha1dc/lib/ubc_check.c', |
1510 'mercurial/thirdparty/sha1dc/lib/ubc_check.c', |
1490 ], |
1511 ], |
|
1512 extra_compile_args=common_cflags, |
1491 ), |
1513 ), |
1492 Extension( |
1514 Extension( |
1493 'hgext.fsmonitor.pywatchman.bser', ['hgext/fsmonitor/pywatchman/bser.c'] |
1515 'hgext.fsmonitor.pywatchman.bser', |
|
1516 ['hgext/fsmonitor/pywatchman/bser.c'], |
|
1517 extra_compile_args=common_cflags, |
1494 ), |
1518 ), |
1495 RustStandaloneExtension( |
1519 RustStandaloneExtension( |
1496 'mercurial.rustext', 'hg-cpython', 'librusthg', py3_features='python3' |
1520 'mercurial.rustext', 'hg-cpython', 'librusthg', py3_features='python3' |
1497 ), |
1521 ), |
1498 ] |
1522 ] |
1499 |
1523 |
1500 |
1524 |
1501 sys.path.insert(0, 'contrib/python-zstandard') |
1525 sys.path.insert(0, 'contrib/python-zstandard') |
1502 import setup_zstd |
1526 import setup_zstd |
1503 |
1527 |
1504 extmodules.append( |
1528 zstd = setup_zstd.get_c_extension( |
1505 setup_zstd.get_c_extension( |
1529 name='mercurial.zstd', root=os.path.abspath(os.path.dirname(__file__)) |
1506 name='mercurial.zstd', root=os.path.abspath(os.path.dirname(__file__)) |
|
1507 ) |
|
1508 ) |
1530 ) |
|
1531 zstd.extra_compile_args += common_cflags |
|
1532 extmodules.append(zstd) |
1509 |
1533 |
1510 try: |
1534 try: |
1511 from distutils import cygwinccompiler |
1535 from distutils import cygwinccompiler |
1512 |
1536 |
1513 # the -mno-cygwin option has been deprecated for years |
1537 # the -mno-cygwin option has been deprecated for years |