comparison setup.py @ 42457:f4a65077e949

rust-cpython: management of shared libray suffix Before this changeset, the shared library objects suffixes were both (rustc output and Python input) hardcoded to '.so', which is wrong for Python3 and non Linux targets.
author Georges Racinet <georges.racinet@octobus.net>
date Fri, 14 Jun 2019 10:57:07 +0100
parents 94167e701e12
children 8ee0fdf3b087
comparison
equal deleted inserted replaced
42456:87a34c767384 42457:f4a65077e949
30 '!=3.6.0', 30 '!=3.6.0',
31 '!=3.6.1', 31 '!=3.6.1',
32 ]) 32 ])
33 33
34 import sys, platform 34 import sys, platform
35 import sysconfig
35 if sys.version_info[0] >= 3: 36 if sys.version_info[0] >= 3:
36 printf = eval('print') 37 printf = eval('print')
37 libdir_escape = 'unicode_escape' 38 libdir_escape = 'unicode_escape'
38 def sysstr(s): 39 def sysstr(s):
39 return s.decode('latin-1') 40 return s.decode('latin-1')
101 Python 3 support. 102 Python 3 support.
102 """.format(py='.'.join('%d' % x for x in sys.version_info[0:2])) 103 """.format(py='.'.join('%d' % x for x in sys.version_info[0:2]))
103 104
104 printf(error, file=sys.stderr) 105 printf(error, file=sys.stderr)
105 sys.exit(1) 106 sys.exit(1)
107
108 if sys.version_info[0] >= 3:
109 DYLIB_SUFFIX = sysconfig.get_config_vars()['EXT_SUFFIX']
110 else:
111 # deprecated in Python 3
112 DYLIB_SUFFIX = sysconfig.get_config_vars()['SO']
106 113
107 # Solaris Python packaging brain damage 114 # Solaris Python packaging brain damage
108 try: 115 try:
109 import hashlib 116 import hashlib
110 sha = hashlib.sha1() 117 sha = hashlib.sha1()
1158 for dirpath, subdir, fnames in os.walk(os.path.join(srcdir, 'src')): 1165 for dirpath, subdir, fnames in os.walk(os.path.join(srcdir, 'src')):
1159 self.depends.extend(os.path.join(dirpath, fname) 1166 self.depends.extend(os.path.join(dirpath, fname)
1160 for fname in fnames 1167 for fname in fnames
1161 if os.path.splitext(fname)[1] == '.rs') 1168 if os.path.splitext(fname)[1] == '.rs')
1162 1169
1170 @staticmethod
1171 def rustdylibsuffix():
1172 """Return the suffix for shared libraries produced by rustc.
1173
1174 See also: https://doc.rust-lang.org/reference/linkage.html
1175 """
1176 if sys.platform == 'darwin':
1177 return '.dylib'
1178 elif os.name == 'nt':
1179 return '.dll'
1180 else:
1181 return '.so'
1182
1163 def rustbuild(self): 1183 def rustbuild(self):
1164 env = os.environ.copy() 1184 env = os.environ.copy()
1165 if 'HGTEST_RESTOREENV' in env: 1185 if 'HGTEST_RESTOREENV' in env:
1166 # Mercurial tests change HOME to a temporary directory, 1186 # Mercurial tests change HOME to a temporary directory,
1167 # but, if installed with rustup, the Rust toolchain needs 1187 # but, if installed with rustup, the Rust toolchain needs
1225 1245
1226 def build(self, target_dir): 1246 def build(self, target_dir):
1227 self.rustbuild() 1247 self.rustbuild()
1228 target = [target_dir] 1248 target = [target_dir]
1229 target.extend(self.name.split('.')) 1249 target.extend(self.name.split('.'))
1230 ext = '.so' # TODO Unix only 1250 target[-1] += DYLIB_SUFFIX
1231 target[-1] += ext 1251 shutil.copy2(os.path.join(self.rusttargetdir,
1232 shutil.copy2(os.path.join(self.rusttargetdir, self.dylibname + ext), 1252 self.dylibname + self.rustdylibsuffix()),
1233 os.path.join(*target)) 1253 os.path.join(*target))
1234 1254
1235 1255
1236 extmodules = [ 1256 extmodules = [
1237 Extension('mercurial.cext.base85', ['mercurial/cext/base85.c'], 1257 Extension('mercurial.cext.base85', ['mercurial/cext/base85.c'],