|
1 | 1 | from __future__ import print_function, absolute_import
|
2 | 2 | import glob
|
| 3 | +import json |
3 | 4 | import os
|
4 | 5 | import shutil
|
5 | 6 | import sys
|
|
8 | 9 | from distutils.errors import (
|
9 | 10 | CompileError, DistutilsExecError, DistutilsFileError,
|
10 | 11 | DistutilsPlatformError, DistutilsSetupError)
|
| 12 | +from subprocess import check_output |
11 | 13 |
|
12 | 14 | from .extension import RustExtension
|
13 | 15 | from .utils import Binding, Strip, cpython_feature, get_rust_version
|
@@ -59,20 +61,20 @@ def build_extension(self, ext):
|
59 | 61 | # executing python interpreter.
|
60 | 62 | bindir = os.path.dirname(sys.executable)
|
61 | 63 |
|
62 |
| - # Find where to put the temporary build files created by `cargo` |
63 |
| - targetdir = os.environ.get('CARGO_TARGET_DIR') \ |
64 |
| - or os.path.join(self.build_temp, self.distribution.get_name()) |
65 |
| - |
66 | 64 | env = os.environ.copy()
|
67 | 65 | env.update({
|
68 |
| - 'CARGO_TARGET_DIR': targetdir, |
69 |
| - |
70 | 66 | # disables rust's pkg-config seeking for specified packages,
|
71 | 67 | # which causes pythonXX-sys to fall back to detecting the
|
72 | 68 | # interpreter from the path.
|
73 | 69 | "PATH": os.path.join(bindir, os.environ.get("PATH", "")),
|
74 | 70 | })
|
75 | 71 |
|
| 72 | + # Find where to put the temporary build files created by `cargo` |
| 73 | + metadata_command = ["cargo", "metadata", "--manifest-path", ext.path, "--format-version", "1"] |
| 74 | + # The decoding is needed for python 3.5 compatibility |
| 75 | + metadata = json.loads(check_output(metadata_command).decode("utf-8")) |
| 76 | + target_dir = metadata["target_directory"] |
| 77 | + |
76 | 78 | if not os.path.exists(ext.path):
|
77 | 79 | raise DistutilsFileError(
|
78 | 80 | "Can not find rust extension project file: %s" % ext.path)
|
@@ -149,7 +151,7 @@ def build_extension(self, ext):
|
149 | 151 | suffix = "release"
|
150 | 152 |
|
151 | 153 | # location of cargo compiled files
|
152 |
| - artifactsdir = os.path.join(targetdir, suffix) |
| 154 | + artifactsdir = os.path.join(target_dir, suffix) |
153 | 155 | dylib_paths = []
|
154 | 156 |
|
155 | 157 | if executable:
|
|
0 commit comments