D6392: rust-cpython: build for py3, Windows and MacOSX

gracinet (Georges Racinet) phabricator at mercurial-scm.org
Thu May 16 16:10:24 EDT 2019


gracinet updated this revision to Diff 15156.
gracinet edited the summary of this revision.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6392?vs=15155&id=15156

REVISION DETAIL
  https://phab.mercurial-scm.org/D6392

AFFECTED FILES
  rust/hg-cpython/src/lib.rs
  setup.py

CHANGE DETAILS

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -32,6 +32,7 @@
     ])
 
 import sys, platform
+import sysconfig
 if sys.version_info[0] >= 3:
     printf = eval('print')
     libdir_escape = 'unicode_escape'
@@ -104,6 +105,12 @@
         printf(error, file=sys.stderr)
         sys.exit(1)
 
+if sys.version_info[0] >= 3:
+    DYLIB_SUFFIX = sysconfig.get_config_vars()['EXT_SUFFIX']
+else:
+    # deprecated in Python 3
+    DYLIB_SUFFIX = sysconfig.get_config_vars()['SO']
+
 # Solaris Python packaging brain damage
 try:
     import hashlib
@@ -1147,6 +1154,19 @@
                                 for fname in fnames
                                 if os.path.splitext(fname)[1] == '.rs')
 
+    @staticmethod
+    def rust_dylib_suffix():
+        """Return the suffix for shared libraries produced by rustc.
+
+        See also: https://doc.rust-lang.org/reference/linkage.html
+        """
+        if sys.platform == 'darwin':
+            return '.dylib'
+        elif os.name == 'nt':
+            return '.dll'
+        else:
+            return '.so'
+
     def rustbuild(self):
         if hgrustext is None:
             return
@@ -1168,6 +1188,9 @@
         if sys.version_info[0] == 3 and self.py3_features is not None:
             cargocmd.extend(('--features', self.py3_features,
                              '--no-default-features'))
+        if sys.platform == 'darwin':
+            env['RUSTFLAGS'] = ("-C link-arg=-undefined "
+                                "-C link-arg=dynamic_lookup")
         try:
             subprocess.check_call(cargocmd, env=env, cwd=self.rustsrcdir)
         except OSError as exc:
@@ -1212,9 +1235,9 @@
         self.rustbuild()
         target = [target_dir]
         target.extend(self.name.split('.'))
-        ext = '.so'  # TODO Unix only
-        target[-1] += ext
-        shutil.copy2(os.path.join(self.rusttargetdir, self.dylibname + ext),
+        target[-1] += DYLIB_SUFFIX
+        shutil.copy2(os.path.join(self.rusttargetdir,
+                                  self.dylibname + self.rust_dylib_suffix()),
                      os.path.join(*target))
 
 
diff --git a/rust/hg-cpython/src/lib.rs b/rust/hg-cpython/src/lib.rs
--- a/rust/hg-cpython/src/lib.rs
+++ b/rust/hg-cpython/src/lib.rs
@@ -23,7 +23,6 @@
 extern crate cpython;
 extern crate hg;
 extern crate libc;
-extern crate python27_sys;
 
 pub mod ancestors;
 mod cindex;



To: gracinet, #hg-reviewers
Cc: durin42, kevincox, mercurial-devel


More information about the Mercurial-devel mailing list