From aec149623e271499439bf6f14fe6629818cd62d2 Mon Sep 17 00:00:00 2001 From: konstin Date: Fri, 1 Jun 2018 13:46:15 +0200 Subject: [PATCH 1/3] Use cargo metadata instead of overwriting CARGO_TARGET_DIR This hugely improves performance --- setuptools_rust/build.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/setuptools_rust/build.py b/setuptools_rust/build.py index 0a691c9b..b455fc71 100644 --- a/setuptools_rust/build.py +++ b/setuptools_rust/build.py @@ -1,5 +1,6 @@ from __future__ import print_function, absolute_import import glob +import json import os import shutil import sys @@ -8,6 +9,7 @@ from distutils.errors import ( CompileError, DistutilsExecError, DistutilsFileError, DistutilsPlatformError, DistutilsSetupError) +from subprocess import check_output from .extension import RustExtension from .utils import Binding, Strip, cpython_feature, get_rust_version @@ -59,20 +61,19 @@ def build_extension(self, ext): # executing python interpreter. bindir = os.path.dirname(sys.executable) - # Find where to put the temporary build files created by `cargo` - targetdir = os.environ.get('CARGO_TARGET_DIR') \ - or os.path.join(self.build_temp, self.distribution.get_name()) - env = os.environ.copy() env.update({ - 'CARGO_TARGET_DIR': targetdir, - # disables rust's pkg-config seeking for specified packages, # which causes pythonXX-sys to fall back to detecting the # interpreter from the path. "PATH": os.path.join(bindir, os.environ.get("PATH", "")), }) + # Find where to put the temporary build files created by `cargo` + metadata_command = ["cargo", "metadata", "--manifest-path", ext.path, "--format-version", "1"] + metadata = json.loads(check_output(metadata_command)) + target_dir = metadata["target_directory"] + if not os.path.exists(ext.path): raise DistutilsFileError( "Can not find rust extension project file: %s" % ext.path) @@ -149,7 +150,7 @@ def build_extension(self, ext): suffix = "release" # location of cargo compiled files - artifactsdir = os.path.join(targetdir, suffix) + artifactsdir = os.path.join(target_dir, suffix) dylib_paths = [] if executable: From 2ef1272de814e6d85c7c8008face0c780d90f4f8 Mon Sep 17 00:00:00 2001 From: konstin Date: Fri, 1 Jun 2018 14:54:19 +0200 Subject: [PATCH 2/3] Python 3.5 compatibility --- setuptools_rust/build.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setuptools_rust/build.py b/setuptools_rust/build.py index b455fc71..3b155b97 100644 --- a/setuptools_rust/build.py +++ b/setuptools_rust/build.py @@ -71,7 +71,8 @@ def build_extension(self, ext): # Find where to put the temporary build files created by `cargo` metadata_command = ["cargo", "metadata", "--manifest-path", ext.path, "--format-version", "1"] - metadata = json.loads(check_output(metadata_command)) + # The decoding is needed for python 3.5 compatibility + metadata = json.loads(check_output(metadata_command).decode()) target_dir = metadata["target_directory"] if not os.path.exists(ext.path): From 7d62bc9a028fc88301e2df279c59c80d02697d7b Mon Sep 17 00:00:00 2001 From: konstin Date: Fri, 1 Jun 2018 15:04:14 +0200 Subject: [PATCH 3/3] Python 2 compatibility --- setuptools_rust/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setuptools_rust/build.py b/setuptools_rust/build.py index 3b155b97..779b3c4f 100644 --- a/setuptools_rust/build.py +++ b/setuptools_rust/build.py @@ -72,7 +72,7 @@ def build_extension(self, ext): # Find where to put the temporary build files created by `cargo` metadata_command = ["cargo", "metadata", "--manifest-path", ext.path, "--format-version", "1"] # The decoding is needed for python 3.5 compatibility - metadata = json.loads(check_output(metadata_command).decode()) + metadata = json.loads(check_output(metadata_command).decode("utf-8")) target_dir = metadata["target_directory"] if not os.path.exists(ext.path):