Skip to content

Commit e734201

Browse files
committed
fixed OSX extension compilation
1 parent 3d75a9b commit e734201

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

CHANGES.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ CHANGES
44
0.3 (2017-04-09)
55
----------------
66

7-
- Use distutils exceptions for errors.
7+
- Fixed OSX extension compilation
88

9-
- Add rust version check for extension.
9+
- Use distutils exceptions for errors
10+
11+
- Add rust version check for extension
1012

1113
- Cleanup example project
1214

example/extensions/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![crate_type = "dylib"]
2-
31
#[macro_use] extern crate cpython;
42

53
use cpython::{PyObject, PyResult, Python, PyTuple, PyDict};

setuptools_rust/__init__.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ def finalize_options(self):
9696
def _cpython_feature(self):
9797
version = sys.version_info
9898
if (2, 7) < version < (2, 8):
99-
return "cpython/python27-sys"
99+
return ("cpython/python27-sys", "cpython/extension-module-2-7")
100100
elif (3, 3) < version:
101-
return "cpython/python3-sys"
101+
return ("cpython/python3-sys", "cpython/extension-module")
102102
else:
103103
raise DistutilsPlatformError(
104104
"Unsupported python version: %s" % sys.version)
@@ -122,17 +122,28 @@ def build_extension(self, ext):
122122
"Can not file rust extension project file: %s" % ext.path)
123123

124124
features = set(ext.features)
125-
features.add(self._cpython_feature())
125+
features.update(self._cpython_feature())
126126

127-
# Execute cargo.
127+
# build cargo command
128+
args = (["cargo", "rustc", "--lib", "--manifest-path", ext.path,
129+
"--features", " ".join(features)]
130+
+ list(ext.args or []))
131+
if not ext.debug:
132+
args.append("--release")
133+
134+
args.extend(["--", '--crate-type', 'cdylib'])
135+
136+
# OSX requires special linker argument
137+
if sys.platform == "darwin":
138+
args.extend(["-C", "link-arg=-undefined",
139+
"-C", "link-arg=dynamic_lookup"])
140+
141+
if not ext.quiet:
142+
print(" ".join(args), file=sys.stderr)
143+
144+
# Execute cargo
128145
try:
129-
args = (["cargo", "build", "--manifest-path", ext.path,
130-
"--features", " ".join(features)] + list(ext.args or []))
131-
if not ext.debug:
132-
args.append("--release")
133-
if not ext.quiet:
134-
print(" ".join(args), file=sys.stderr)
135-
output = subprocess.check_output(args, env=env)
146+
output = subprocess.check_output(args, env=env)
136147
except subprocess.CalledProcessError as e:
137148
raise CompileError(
138149
"cargo failed with code: %d\n%s" % (e.returncode, e.output))
@@ -142,6 +153,8 @@ def build_extension(self, ext):
142153
"requires rust to be installed and cargo to be on the PATH")
143154

144155
if not ext.quiet:
156+
if isinstance(output, bytes):
157+
output = output.decode('latin-1')
145158
print(output, file=sys.stderr)
146159

147160
# Find the shared library that cargo hopefully produced and copy

setuptools_rust/patch.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ def has_rust_extensions(self):
3030

3131

3232
def monkey_run_command(self, cmd):
33-
print(cmd)
3433
orig_run_command(self, cmd)
3534

36-
print(cmd)
3735
if cmd == 'build_ext':
3836
self.reinitialize_command('build_rust', inplace=1)
3937
orig_run_command(self, 'build_rust')

0 commit comments

Comments
 (0)