Skip to content

Commit bdb644e

Browse files
committed
add clean_rust command
1 parent 2bf0e6b commit bdb644e

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

CHANGES.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
CHANGES
22
=======
33

4-
0.4 (2017-03-xx)
4+
0.4 (2017-03-10)
55
----------------
66

77
- Fixed bdist_egg and bdist_wheel support
88

9+
- setuptool's clean command cleans rust project as well
10+
911
- Use absolute path to cargo manifest
1012

1113
- Enable debug builds for inplace builds, otherwise build release

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
],
3434
entry_points="""
3535
[distutils.commands]
36+
clean_rust=setuptools_rust:clean_rust
3637
build_ext=setuptools_rust:build_ext
3738
build_rust=setuptools_rust:build_rust
3839
"""

setuptools_rust/__init__.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from . import patch # noqa
1515
from .build_ext import build_ext
1616

17-
__all__ = ('RustExtension', 'build_ext', 'build_rust')
17+
__all__ = ('RustExtension', 'clean_rust', 'build_ext', 'build_rust')
1818

1919
patch.monkey_patch_dist(build_ext)
2020

@@ -232,3 +232,34 @@ def run(self):
232232
version, ext.rust_version))
233233

234234
self.build_extension(ext)
235+
236+
237+
class clean_rust(Command):
238+
""" Clean rust extensions. """
239+
240+
description = "clean rust extensions (compile/link to build directory)"
241+
242+
def initialize_options(self):
243+
self.extensions = ()
244+
self.inplace = False
245+
246+
def finalize_options(self):
247+
self.extensions = [ext for ext in self.distribution.rust_extensions
248+
if isinstance(ext, RustExtension)]
249+
250+
def run(self):
251+
if not self.extensions:
252+
return
253+
254+
for ext in self.extensions:
255+
# build cargo command
256+
args = (["cargo", "clean", "--manifest-path", ext.path])
257+
258+
if not ext.quiet:
259+
print(" ".join(args), file=sys.stderr)
260+
261+
# Execute cargo command
262+
try:
263+
subprocess.check_output(args)
264+
except:
265+
pass

setuptools_rust/patch.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from distutils.command.clean import clean
12
from distutils.command.install import install
23
from distutils.dist import Distribution as DistDistribution
34
from setuptools.dist import Distribution
@@ -50,3 +51,13 @@ def finalize_options(self):
5051
self.distribution.ext_modules = ext_modules
5152

5253
install.finalize_options = finalize_options
54+
55+
# clean rust project
56+
def run_clean(self):
57+
self.orig_run()
58+
59+
if not self.dry_run:
60+
self.run_command("clean_rust")
61+
62+
clean.orig_run = clean.run
63+
clean.run = run_clean

0 commit comments

Comments
 (0)