|
56 | 56 | f.write("#[cfg(" + ', '.join(cfg) + ")]\n")
|
57 | 57 |
|
58 | 58 | # LLVM libs
|
59 |
| - args = [llconfig, '--libs'] |
| 59 | + args = [llconfig, '--libs', '--system-libs'] |
60 | 60 | args.extend(components)
|
61 | 61 | proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
62 | 62 | out, err = proc.communicate()
|
|
65 | 65 | print("failed to run llconfig: args = `{}`".format(args))
|
66 | 66 | sys.exit(1)
|
67 | 67 |
|
68 |
| - for lib in out.strip().split(' '): |
69 |
| - lib = lib[2:] # chop of the leading '-l' |
70 |
| - f.write("#[link(name = \"" + lib + "\", kind = \"static\")]\n") |
| 68 | + for lib in out.strip().replace("\n", ' ').split(' '): |
| 69 | + lib = lib.strip()[2:] # chop of the leading '-l' |
| 70 | + f.write("#[link(name = \"" + lib + "\"") |
| 71 | + # LLVM libraries are all static libraries |
| 72 | + if 'LLVM' in lib: |
| 73 | + f.write(", kind = \"static\"") |
| 74 | + f.write(")]\n") |
71 | 75 |
|
72 | 76 | # LLVM ldflags
|
73 | 77 | args = [llconfig, '--ldflags']
|
|
82 | 86 | if lib[:2] == "-l":
|
83 | 87 | f.write("#[link(name = \"" + lib[2:] + "\")]\n")
|
84 | 88 |
|
85 |
| - #extra |
86 |
| - f.write("#[link(name = \"stdc++\")]\n") |
87 |
| - if os == 'win32': |
88 |
| - f.write("#[link(name = \"imagehlp\")]\n") |
| 89 | + # C++ runtime library |
| 90 | + args = [llconfig, '--cxxflags'] |
| 91 | + proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 92 | + out, err = proc.communicate() |
| 93 | + |
| 94 | + if err: |
| 95 | + print("failed to run llconfig: args = `{}`".format(args)) |
| 96 | + sys.exit(1) |
| 97 | + |
| 98 | + if 'stdlib=libc++' in out: |
| 99 | + f.write("#[link(name = \"c++\")]\n") |
| 100 | + else: |
| 101 | + f.write("#[link(name = \"stdc++\")]\n") |
| 102 | + |
| 103 | + # Attach everything to an extern block |
89 | 104 | f.write("extern {}\n")
|
0 commit comments