##// END OF EJS Templates
rust: new rust options in setup.py...
Georges Racinet -
r42646:302acc78 default draft
parent child Browse files
Show More
@@ -446,10 +446,12 class hgbuildmo(build):
446 446
447 447 class hgdist(Distribution):
448 448 pure = False
449 rust = hgrustext is not None
449 450 cffi = ispypy
450 451
451 452 global_options = Distribution.global_options + [
452 453 ('pure', None, "use pure (slow) Python code instead of C extensions"),
454 ('rust', None, "use Rust extensions additionally to C extensions"),
453 455 ]
454 456
455 457 def has_ext_modules(self):
@@ -460,18 +462,25 class hgdist(Distribution):
460 462 # This is ugly as a one-liner. So use a variable.
461 463 buildextnegops = dict(getattr(build_ext, 'negative_options', {}))
462 464 buildextnegops['no-zstd'] = 'zstd'
465 buildextnegops['no-rust'] = 'rust'
463 466
464 467 class hgbuildext(build_ext):
465 468 user_options = build_ext.user_options + [
466 469 ('zstd', None, 'compile zstd bindings [default]'),
467 470 ('no-zstd', None, 'do not compile zstd bindings'),
471 ('rust', None,
472 'compile Rust extensions if they are in use '
473 '(requires Cargo) [default]'),
474 ('no-rust', None, 'do not compile Rust extensions'),
468 475 ]
469 476
470 boolean_options = build_ext.boolean_options + ['zstd']
477 boolean_options = build_ext.boolean_options + ['zstd', 'rust']
471 478 negative_opt = buildextnegops
472 479
473 480 def initialize_options(self):
474 481 self.zstd = True
482 self.rust = True
483
475 484 return build_ext.initialize_options(self)
476 485
477 486 def build_extensions(self):
@@ -484,13 +493,18 class hgbuildext(build_ext):
484 493 self.extensions = [e for e in self.extensions
485 494 if e.name != 'mercurial.zstd']
486 495
496 # Build Rust standalon extensions if it'll be used
497 # and its build is not explictely disabled (for external build
498 # as Linux distributions would do)
499 if self.distribution.rust and self.rust and hgrustext != 'direct-ffi':
487 500 for rustext in ruststandalones:
488 501 rustext.build('' if self.inplace else self.build_lib)
489 502
490 503 return build_ext.build_extensions(self)
491 504
492 505 def build_extension(self, ext):
493 if isinstance(ext, RustExtension):
506 if (self.distribution.rust and self.rust
507 and isinstance(ext, RustExtension)):
494 508 ext.rustbuild()
495 509 try:
496 510 build_ext.build_extension(self, ext)
@@ -553,20 +567,14 class hgbuildpy(build_py):
553 567 basepath = os.path.join(self.build_lib, 'mercurial')
554 568 self.mkpath(basepath)
555 569
570 rust = self.distribution.rust
556 571 if self.distribution.pure:
557 572 modulepolicy = 'py'
558 573 elif self.build_lib == '.':
559 # in-place build should run without rebuilding C
560 # and Rust extensions
561 if hgrustext == 'cpython':
562 modulepolicy = 'rust+c-allow'
574 # in-place build should run without rebuilding and Rust extensions
575 modulepolicy = 'rust+c-allow' if rust else 'allow'
563 576 else:
564 modulepolicy = 'allow'
565 else:
566 if hgrustext == 'cpython':
567 modulepolicy = 'rust+c'
568 else:
569 modulepolicy = 'c'
577 modulepolicy = 'rust+c' if rust else 'c'
570 578
571 579 content = b''.join([
572 580 b'# this file is autogenerated by setup.py\n',
@@ -1138,8 +1146,6 class RustExtension(Extension):
1138 1146 def __init__(self, mpath, sources, rustlibname, subcrate,
1139 1147 py3_features=None, **kw):
1140 1148 Extension.__init__(self, mpath, sources, **kw)
1141 if hgrustext is None:
1142 return
1143 1149 srcdir = self.rustsrcdir = os.path.join('rust', subcrate)
1144 1150 self.py3_features = py3_features
1145 1151
@@ -1155,8 +1161,6 class RustExtension(Extension):
1155 1161 if os.path.splitext(fname)[1] == '.rs')
1156 1162
1157 1163 def rustbuild(self):
1158 if hgrustext is None:
1159 return
1160 1164 env = os.environ.copy()
1161 1165 if 'HGTEST_RESTOREENV' in env:
1162 1166 # Mercurial tests change HOME to a temporary directory,
@@ -1208,6 +1212,10 class RustEnhancedExtension(RustExtensio
1208 1212 self.libraries.append(rustlibname)
1209 1213 self.library_dirs.append(self.rusttargetdir)
1210 1214
1215 def rustbuild(self):
1216 if hgrustext == 'direct-ffi':
1217 RustExtension.rustbuild(self)
1218
1211 1219 class RustStandaloneExtension(RustExtension):
1212 1220
1213 1221 def __init__(self, pydottedname, rustcrate, dylibname, **kw):
@@ -1262,14 +1270,10 extmodules = [
1262 1270 ]),
1263 1271 Extension('hgext.fsmonitor.pywatchman.bser',
1264 1272 ['hgext/fsmonitor/pywatchman/bser.c']),
1273 RustStandaloneExtension('mercurial.rustext', 'hg-cpython', 'librusthg',
1274 py3_features='python3'),
1265 1275 ]
1266 1276
1267 if hgrustext == 'cpython':
1268 extmodules.append(
1269 RustStandaloneExtension('mercurial.rustext', 'hg-cpython', 'librusthg',
1270 py3_features='python3')
1271 )
1272
1273 1277
1274 1278 sys.path.insert(0, 'contrib/python-zstandard')
1275 1279 import setup_zstd
General Comments 0
You need to be logged in to leave comments. Login now