Skip to content

Commit

Permalink
Merge pull request #153 from asottile/static_when_needed
Browse files Browse the repository at this point in the history
Test for -static support before using it
  • Loading branch information
chriskuehl authored Dec 1, 2017
2 parents 2132d82 + 9542174 commit 5ae82b9
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from __future__ import print_function

import os.path
import subprocess
import tempfile
from distutils.command.build import build as orig_build
from distutils.core import Command

Expand Down Expand Up @@ -84,16 +88,26 @@ def run(self):

compiler = new_compiler(verbose=True)

print('supports -static... ', end='')
with tempfile.NamedTemporaryFile(mode='w', suffix='.c') as f:
f.write('int main(void){}\n')
f.flush()
cmd = compiler.linker_exe + [f.name, '-static', '-o', os.devnull]
with open(os.devnull, 'wb') as devnull:
if not subprocess.call(cmd, stderr=devnull):
print('yes')
link_args = ['-static']
else:
print('no')
link_args = []

for exe in self.distribution.c_executables:
objects = compiler.compile(
exe.sources,
output_dir=self.build_temp,
)
objects = compiler.compile(exe.sources, output_dir=self.build_temp)
compiler.link_executable(
objects,
exe.name,
output_dir=self.build_scripts,
extra_postargs=exe.extra_link_args,
extra_postargs=link_args,
)

def get_outputs(self):
Expand All @@ -110,13 +124,7 @@ def get_outputs(self):
author='Yelp',
url='https://github.com/Yelp/dumb-init/',
platforms='linux',
c_executables=[
Extension(
'dumb-init',
['dumb-init.c'],
extra_link_args=['-static'],
),
],
c_executables=[Extension('dumb-init', ['dumb-init.c'])],
cmdclass={
'bdist_wheel': bdist_wheel,
'build': build,
Expand Down

0 comments on commit 5ae82b9

Please sign in to comment.