|
37 | 37 | import struct
|
38 | 38 | from subprocess import Popen, PIPE, STDOUT
|
39 | 39 | import sys
|
| 40 | +import platform |
40 | 41 |
|
41 | 42 | ARCH_64BIT = sys.maxsize > 2**32 # Works with Python 2.6 and greater
|
42 | 43 |
|
@@ -429,35 +430,33 @@ def _finalize_connector_c(self, connc_loc):
|
429 | 430 | copy_tree(os.path.join(connc_loc, 'lib'), self.connc_lib)
|
430 | 431 | copy_tree(os.path.join(connc_loc, 'include'), self.connc_include)
|
431 | 432 |
|
| 433 | + # Remove all but static libraries to force static linking |
432 | 434 | for lib_file in os.listdir(self.connc_lib):
|
433 | 435 | if os.name == 'posix' and not lib_file.endswith('.a'):
|
434 | 436 | os.unlink(os.path.join(self.connc_lib, lib_file))
|
435 | 437 |
|
436 | 438 | def fix_compiler(self):
|
437 | 439 | BuildExtDynamic.fix_compiler(self)
|
438 | 440 |
|
439 |
| - extra_compile_args = [] |
440 |
| - extra_link_args = [] |
| 441 | + include_dirs = [] |
| 442 | + library_dirs = [] |
| 443 | + libraries = [] |
441 | 444 |
|
442 | 445 | if os.name == 'posix':
|
443 |
| - extra_compile_args = [ |
444 |
| - '-I%s' % self.connc_include |
445 |
| - ] |
446 |
| - extra_link_args = [ |
447 |
| - #'-lstdc++', |
448 |
| - '-L%s' % self.connc_lib, |
449 |
| - '-lmysqlclient', |
450 |
| - ] |
451 |
| - |
452 |
| - if not extra_compile_args and not extra_link_args: |
453 |
| - return |
| 446 | + include_dirs.append(self.connc_include) |
| 447 | + library_dirs.append(self.connc_lib) |
| 448 | + libraries.append("mysqlclient") |
454 | 449 |
|
455 |
| - for ext in self.extensions: |
456 |
| - if extra_compile_args: |
457 |
| - ext.extra_compile_args.extend(extra_compile_args) |
458 |
| - if extra_link_args: |
459 |
| - ext.extra_link_args.extend(extra_link_args) |
| 450 | + # As we statically link and the "libmysqlclient.a" library |
| 451 | + # carry no information what it depends on, we need to |
| 452 | + # manually add library dependencies here. |
| 453 | + if platform.system() not in ["Darwin", "Windows"]: |
| 454 | + libraries.append("rt") |
460 | 455 |
|
| 456 | + for ext in self.extensions: |
| 457 | + ext.include_dirs.extend(include_dirs) |
| 458 | + ext.library_dirs.extend(library_dirs) |
| 459 | + ext.libraries.extend(libraries) |
461 | 460 |
|
462 | 461 |
|
463 | 462 | class InstallLib(install_lib):
|
|
0 commit comments