Skip to content

Commit 1a53639

Browse files
committed
add strip option
1 parent 442dcef commit 1a53639

File tree

6 files changed

+46
-6
lines changed

6 files changed

+46
-6
lines changed

CHANGES.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGES
22
=======
33

4+
0.7.1 (2017-08-18)
5+
------------------
6+
7+
- Allow to strip symbols from executable or dynamic library.
8+
9+
- Use PyO3 0.2 for example.
10+
411

512
0.7.0 (2017-08-11)
613
------------------

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup
22

3-
version = '0.7.0'
3+
version = '0.7.1'
44

55

66
setup(

setuptools_rust/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from .clean import clean_rust
88
from .test import test_rust
99
from .extension import RustExtension
10-
from .utils import Binding
10+
from .utils import Binding, Strip
1111

12-
__all__ = ('RustExtension', 'Binding',
12+
__all__ = ('RustExtension', 'Binding', 'Strip',
1313
'check_rust', 'clean_rust', 'build_ext', 'build_rust', 'test_rust')
1414

1515

setuptools_rust/build.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
DistutilsPlatformError, DistutilsSetupError)
1111

1212
from .extension import RustExtension
13-
from .utils import Binding, cpython_feature, get_rust_version
13+
from .utils import Binding, Strip, cpython_feature, get_rust_version
1414

1515

1616
class build_rust(Command):
@@ -194,6 +194,21 @@ def build_extension(self, ext):
194194
pass
195195
shutil.copyfile(dylib_path, ext_path)
196196

197+
if not debug_build:
198+
args = []
199+
if ext.strip == Strip.All:
200+
args.append('-x')
201+
elif ext.strip == Strip.Debug:
202+
args.append('-S')
203+
204+
if args:
205+
args.insert(0, 'strip')
206+
args.append(ext_path)
207+
try:
208+
output = subprocess.check_output(args, env=env)
209+
except subprocess.CalledProcessError as e:
210+
pass
211+
197212
if executable:
198213
mode = os.stat(ext_path).st_mode
199214
mode |= (mode & 0o444) >> 2 # copy R bits to X

setuptools_rust/extension.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import sys
44
from distutils.errors import DistutilsSetupError
5-
from .utils import Binding
5+
from .utils import Binding, Strip
66

77

88
import semantic_version
@@ -36,21 +36,27 @@ class RustExtension:
3636
Binding.RustCPython uses Rust CPython.
3737
Binding.NoBinding uses no binding.
3838
Binding.Exec build executable.
39+
strip : setuptools_rust.Binding
40+
Strip symbols from final file. Does nothing for debug build.
41+
* Strip.No - do not strip symbols
42+
* Strip.Debug - strip debug symbols
43+
* Strip.All - strip all symbols
3944
optional : bool
4045
if it is true, a build failure in the extension will not abort the
4146
build process, but instead simply not install the failing extension.
4247
"""
4348

4449
def __init__(self, name, path,
4550
args=None, features=None, rust_version=None,
46-
quiet=False, debug=None, binding=Binding.PyO3,
51+
quiet=False, debug=None, binding=Binding.PyO3, strip=Strip.No,
4752
optional=False):
4853
self.name = name
4954
self.args = args
5055
self.binding = binding
5156
self.rust_version = rust_version
5257
self.quiet = quiet
5358
self.debug = debug
59+
self.strip = strip
5460
self.optional = optional
5561

5662
if features is None:

setuptools_rust/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ class Binding:
2020
Exec = 3
2121

2222

23+
class Strip:
24+
"""
25+
Strip Options
26+
"""
27+
# do not strip symbols
28+
No = 0
29+
# strip debug symbols
30+
Debug = 1
31+
# strip all symbos
32+
All = 2
33+
34+
2335
def cpython_feature(ext=True, binding=Binding.PyO3):
2436
version = sys.version_info
2537

0 commit comments

Comments
 (0)