|
11 | 11 |
|
12 | 12 |
|
13 | 13 | import os |
| 14 | +import subprocess |
14 | 15 | import shlex |
15 | 16 | from cffi import FFI |
16 | 17 |
|
|
807 | 808 | compiler_args = [] |
808 | 809 | libraries = [] |
809 | 810 |
|
| 811 | + |
| 812 | +def check_linker_need_libatomic(): |
| 813 | + """ |
| 814 | + Test if linker on system needs libatomic. |
| 815 | + This has been copied from https://github.com/grpc/grpc/blob/master/setup.py#L205 |
| 816 | + """ |
| 817 | + code_test = (b'#include <atomic>\n' + |
| 818 | + b'int main() { return std::atomic<int64_t>{}; }') |
| 819 | + cxx = shlex.split(os.environ.get('CXX', 'c++')) |
| 820 | + cpp_test = subprocess.Popen(cxx + ['-x', 'c++', '-std=c++14', '-'], |
| 821 | + stdin=subprocess.PIPE, |
| 822 | + stdout=subprocess.PIPE, |
| 823 | + stderr=subprocess.PIPE) |
| 824 | + cpp_test.communicate(input=code_test) |
| 825 | + if cpp_test.returncode == 0: |
| 826 | + return False |
| 827 | + # Double-check to see if -latomic actually can solve the problem. |
| 828 | + # https://github.com/grpc/grpc/issues/22491 |
| 829 | + cpp_test = subprocess.Popen(cxx + |
| 830 | + ['-x', 'c++', '-std=c++14', '-', '-latomic'], |
| 831 | + stdin=subprocess.PIPE, |
| 832 | + stdout=subprocess.PIPE, |
| 833 | + stderr=subprocess.PIPE) |
| 834 | + cpp_test.communicate(input=code_test) |
| 835 | + return cpp_test.returncode == 0 |
| 836 | + |
| 837 | + |
810 | 838 | if os.name == "posix": |
811 | 839 | compiler_args = ["-g1", "-O3", "-ffast-math"] |
812 | | - libraries = ["m", "pthread", "dl", "atomic"] |
813 | | - |
| 840 | + libraries = ["m", "pthread", "dl"] |
| 841 | + if check_linker_need_libatomic(): |
| 842 | + libraries.append("atomic") |
814 | 843 | if "PYMINIAUDIO_EXTRA_CFLAGS" in os.environ: |
815 | 844 | compiler_args += shlex.split(os.environ.get("PYMINIAUDIO_EXTRA_CFLAGS", "")) |
816 | 845 |
|
|
844 | 873 |
|
845 | 874 |
|
846 | 875 | if __name__ == "__main__": |
| 876 | + print("NEED LIBATOMIC?", check_linker_need_libatomic()) |
847 | 877 | ffibuilder.compile(verbose=True) |
0 commit comments