Mercurial > public > mercurial-scm > hg
comparison setup.py @ 40985:4277e20cfec4
rust-cpython: build and support for Python3
Defined Cargo features for Python3, making them overall simpler to
use, hooked them in build and made mercurial.rustext importable.
This is tested with Python 3.6.7.
Differential Revision: https://phab.mercurial-scm.org/D5446
author | Georges Racinet <gracinet@anybox.fr> |
---|---|
date | Mon, 17 Dec 2018 15:05:52 +0100 |
parents | f6987f654356 |
children | 98ce494e104d |
comparison
equal
deleted
inserted
replaced
40984:6a372f943e49 | 40985:4277e20cfec4 |
---|---|
920 """Base classes for concrete Rust Extension classes. | 920 """Base classes for concrete Rust Extension classes. |
921 """ | 921 """ |
922 | 922 |
923 rusttargetdir = os.path.join('rust', 'target', 'release') | 923 rusttargetdir = os.path.join('rust', 'target', 'release') |
924 | 924 |
925 def __init__(self, mpath, sources, rustlibname, subcrate, **kw): | 925 def __init__(self, mpath, sources, rustlibname, subcrate, |
926 py3_features=None, **kw): | |
926 Extension.__init__(self, mpath, sources, **kw) | 927 Extension.__init__(self, mpath, sources, **kw) |
927 if hgrustext is None: | 928 if hgrustext is None: |
928 return | 929 return |
929 srcdir = self.rustsrcdir = os.path.join('rust', subcrate) | 930 srcdir = self.rustsrcdir = os.path.join('rust', subcrate) |
931 self.py3_features = py3_features | |
930 | 932 |
931 # adding Rust source and control files to depends so that the extension | 933 # adding Rust source and control files to depends so that the extension |
932 # gets rebuilt if they've changed | 934 # gets rebuilt if they've changed |
933 self.depends.append(os.path.join(srcdir, 'Cargo.toml')) | 935 self.depends.append(os.path.join(srcdir, 'Cargo.toml')) |
934 cargo_lock = os.path.join(srcdir, 'Cargo.lock') | 936 cargo_lock = os.path.join(srcdir, 'Cargo.lock') |
955 # HOME is shadowed like this) | 957 # HOME is shadowed like this) |
956 import pwd | 958 import pwd |
957 env['HOME'] = pwd.getpwuid(os.getuid()).pw_dir | 959 env['HOME'] = pwd.getpwuid(os.getuid()).pw_dir |
958 | 960 |
959 cargocmd = ['cargo', 'build', '-vv', '--release'] | 961 cargocmd = ['cargo', 'build', '-vv', '--release'] |
962 if sys.version_info[0] == 3 and self.py3_features is not None: | |
963 cargocmd.extend(('--features', self.py3_features, | |
964 '--no-default-features')) | |
960 try: | 965 try: |
961 subprocess.check_call(cargocmd, env=env, cwd=self.rustsrcdir) | 966 subprocess.check_call(cargocmd, env=env, cwd=self.rustsrcdir) |
962 except OSError as exc: | 967 except OSError as exc: |
963 if exc.errno == errno.ENOENT: | 968 if exc.errno == errno.ENOENT: |
964 raise RustCompilationError("Cargo not found") | 969 raise RustCompilationError("Cargo not found") |
1045 ['hgext/fsmonitor/pywatchman/bser.c']), | 1050 ['hgext/fsmonitor/pywatchman/bser.c']), |
1046 ] | 1051 ] |
1047 | 1052 |
1048 if hgrustext == 'cpython': | 1053 if hgrustext == 'cpython': |
1049 extmodules.append( | 1054 extmodules.append( |
1050 RustStandaloneExtension('mercurial.rustext', 'hg-cpython', 'librusthg') | 1055 RustStandaloneExtension('mercurial.rustext', 'hg-cpython', 'librusthg', |
1056 py3_features='python3') | |
1051 ) | 1057 ) |
1052 | 1058 |
1053 | 1059 |
1054 sys.path.insert(0, 'contrib/python-zstandard') | 1060 sys.path.insert(0, 'contrib/python-zstandard') |
1055 import setup_zstd | 1061 import setup_zstd |