Skip to content

Commit

Permalink
Merge pull request #35 from PyO3/target_dir
Browse files Browse the repository at this point in the history
Use cargo metadata instead of overwriting CARGO_TARGET_DIR
  • Loading branch information
konstin authored Jun 1, 2018
2 parents edf8c34 + 7d62bc9 commit 26a55fa
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions setuptools_rust/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import print_function, absolute_import
import glob
import json
import os
import shutil
import sys
Expand All @@ -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
Expand Down Expand Up @@ -59,20 +61,20 @@ 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"]
# The decoding is needed for python 3.5 compatibility
metadata = json.loads(check_output(metadata_command).decode("utf-8"))
target_dir = metadata["target_directory"]

if not os.path.exists(ext.path):
raise DistutilsFileError(
"Can not find rust extension project file: %s" % ext.path)
Expand Down Expand Up @@ -149,7 +151,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:
Expand Down

3 comments on commit 26a55fa

@konstin
Copy link
Member Author

@konstin konstin commented on 26a55fa Jun 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fafhrd91 @messense Could you publish v0.10.0 to pypi?

@fafhrd91
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is your pypi login?

@konstin
Copy link
Member Author

@konstin konstin commented on 26a55fa Jun 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's "konstin"

Please sign in to comment.