@@ -96,9 +96,9 @@ def finalize_options(self):
96
96
def _cpython_feature (self ):
97
97
version = sys .version_info
98
98
if (2 , 7 ) < version < (2 , 8 ):
99
- return "cpython/python27-sys"
99
+ return ( "cpython/python27-sys" , "cpython/extension-module-2-7" )
100
100
elif (3 , 3 ) < version :
101
- return "cpython/python3-sys"
101
+ return ( "cpython/python3-sys" , "cpython/extension-module" )
102
102
else :
103
103
raise DistutilsPlatformError (
104
104
"Unsupported python version: %s" % sys .version )
@@ -122,17 +122,28 @@ def build_extension(self, ext):
122
122
"Can not file rust extension project file: %s" % ext .path )
123
123
124
124
features = set (ext .features )
125
- features .add (self ._cpython_feature ())
125
+ features .update (self ._cpython_feature ())
126
126
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
128
145
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 )
136
147
except subprocess .CalledProcessError as e :
137
148
raise CompileError (
138
149
"cargo failed with code: %d\n %s" % (e .returncode , e .output ))
@@ -142,6 +153,8 @@ def build_extension(self, ext):
142
153
"requires rust to be installed and cargo to be on the PATH" )
143
154
144
155
if not ext .quiet :
156
+ if isinstance (output , bytes ):
157
+ output = output .decode ('latin-1' )
145
158
print (output , file = sys .stderr )
146
159
147
160
# Find the shared library that cargo hopefully produced and copy
0 commit comments