rust: Make the hg-cpython crate default to Python 3
authorSimon Sapin <simon.sapin@octobus.net>
Fri, 08 Oct 2021 11:06:03 +0200
changeset 48182 01c3dd208c75
parent 48181 c95f6c2d1f4e
child 48183 eb8092f9304f
rust: Make the hg-cpython crate default to Python 3 This default is used when running `cargo` manually such as for `cargo test`. `setup.py` and `Makefile` both configure the Python major version explicitly. Differential Revision: https://phab.mercurial-scm.org/D11618
rust/hg-cpython/Cargo.toml
setup.py
--- a/rust/hg-cpython/Cargo.toml	Sun Oct 03 20:11:42 2021 -0400
+++ b/rust/hg-cpython/Cargo.toml	Fri Oct 08 11:06:03 2021 +0200
@@ -9,7 +9,7 @@
 crate-type = ["cdylib"]
 
 [features]
-default = ["python27"]
+default = ["python3"]
 
 # Features to build an extension module:
 python27 = ["cpython/python27-sys", "cpython/extension-module-2-7"]
--- a/setup.py	Sun Oct 03 20:11:42 2021 -0400
+++ b/setup.py	Fri Oct 08 11:06:03 2021 +0200
@@ -1398,12 +1398,9 @@
 
     rusttargetdir = os.path.join('rust', 'target', 'release')
 
-    def __init__(
-        self, mpath, sources, rustlibname, subcrate, py3_features=None, **kw
-    ):
+    def __init__(self, mpath, sources, rustlibname, subcrate, **kw):
         Extension.__init__(self, mpath, sources, **kw)
         srcdir = self.rustsrcdir = os.path.join('rust', subcrate)
-        self.py3_features = py3_features
 
         # adding Rust source and control files to depends so that the extension
         # gets rebuilt if they've changed
@@ -1451,9 +1448,11 @@
 
         feature_flags = []
 
-        if sys.version_info[0] == 3 and self.py3_features is not None:
-            feature_flags.append(self.py3_features)
-            cargocmd.append('--no-default-features')
+        cargocmd.append('--no-default-features')
+        if sys.version_info[0] == 2:
+            feature_flags.append('python27')
+        elif sys.version_info[0] == 3:
+            feature_flags.append('python3')
 
         rust_features = env.get("HG_RUST_FEATURES")
         if rust_features:
@@ -1575,7 +1574,9 @@
         extra_compile_args=common_cflags,
     ),
     RustStandaloneExtension(
-        'mercurial.rustext', 'hg-cpython', 'librusthg', py3_features='python3'
+        'mercurial.rustext',
+        'hg-cpython',
+        'librusthg',
     ),
 ]