Changed link stage from using "clang++" to "clang -lc++abi".

This commit is contained in:
Alexander Gorshenev
2016-12-06 15:23:31 +03:00
committed by alexander-gorshenev
parent 44d07ef829
commit f79b0bdf6a
2 changed files with 38 additions and 26 deletions
+36 -25
View File
@@ -104,41 +104,44 @@ abstract class KonanTest extends DefaultTask {
return project.isLinux() return project.isLinux()
} }
// TODO: stop copy-pasting protected List<String> linkCppAbi() {
protected String linkDl() { if (linux()) {
return ["-Wl,-Bstatic", "-lc++abi", "-Wl,-Bdynamic"]
} else {
// Life is hard. MacOS linker is harder.
// This is how we force the linker to link statically.
return ["${project.llvmDir}/lib/libc++abi.a"]
}
}
protected List<String> linkPlatform() {
if (linux()) { if (linux()) {
return "-ldl" return ["-ldl", "-lpthread", "-lm", "-rdynamic"]
} }
else { else {
return "" return []
} }
} }
protected String linkM() { protected List<String> libLink() {
if (linux()) { def libs = []
return "-lm" libs.addAll(linkPlatform())
} libs.addAll(linkCppAbi())
else { return libs
return ""
}
} }
protected String rdynamic() {
if (linux()) {
return "-rdynamic"
}
else {
return ""
}
}
} }
class UnitKonanTest extends KonanTest { class UnitKonanTest extends KonanTest {
void compileTest(File sourceS, File runtimeS, File stdlibKtBc, File exe) { void compileTest(File sourceS, File runtimeS, File stdlibKtBc, File exe) {
def testC = sourceS.absolutePath.replace(".kt.S", "-test.c") def testC = sourceS.absolutePath.replace(".kt.S", "-test.c")
project.execClang { project.execClang {
commandLine "clang++", runtimeS.absolutePath, stdlibKtBc.absolutePath, sourceS.absolutePath, executable "clang"
"-o", exe.absolutePath, linkDl(), linkM(), rdynamic(), '-xc', testC, mainC def argList = []
argList.addAll([ runtimeS.absolutePath, stdlibKtBc.absolutePath, sourceS.absolutePath,
"-o", exe.absolutePath, testC, mainC ])
argList.addAll(libLink())
args argList
} }
} }
} }
@@ -146,8 +149,12 @@ class UnitKonanTest extends KonanTest {
class RunKonanTest extends KonanTest { class RunKonanTest extends KonanTest {
void compileTest(File sourceS, File runtimeS, File libraryPath, File exe) { void compileTest(File sourceS, File runtimeS, File libraryPath, File exe) {
project.execClang { project.execClang {
commandLine "clang++", launcherBc.absolutePath, startKtBc.absolutePath, runtimeS.absolutePath, stdlibKtBc.absolutePath, sourceS.absolutePath, executable "clang"
"-o", exe.absolutePath, linkDl(), linkM(), rdynamic(), '-xc' def argList = []
argList.addAll([ launcherBc.absolutePath, startKtBc.absolutePath,
runtimeS.absolutePath, stdlibKtBc.absolutePath, sourceS.absolutePath, "-o", exe.absolutePath ])
argList.addAll(libLink())
args argList
} }
} }
} }
@@ -202,8 +209,12 @@ class LinkKonanTest extends KonanTest {
void compileTest(File sourceS, File runtimeS, File stdlibKtBc, File exe) { void compileTest(File sourceS, File runtimeS, File stdlibKtBc, File exe) {
def testC = sourceS.absolutePath.replace(".kt.S", "-test.c") def testC = sourceS.absolutePath.replace(".kt.S", "-test.c")
project.execClang { project.execClang {
commandLine "clang++", runtimeS.absolutePath, stdlibKtBc.absolutePath, sourceS.absolutePath, executable "clang"
"-o", exe.absolutePath, linkDl(), rdynamic(), '-xc', testC, mainC def argList = []
argList.addAll([ runtimeS.absolutePath, stdlibKtBc.absolutePath,
sourceS.absolutePath, "-o", exe.absolutePath, testC, mainC ])
argList.addAll(libLink())
args argList
} }
} }
+2 -1
View File
@@ -29,7 +29,8 @@ allprojects {
binDir = "$gccToolchainDir/$gnuTriplet/bin" binDir = "$gccToolchainDir/$gnuTriplet/bin"
ext.clangArgs.addAll([ ext.clangArgs.addAll([
"--sysroot=$gccToolchainDir/$gnuTriplet/sysroot", "--sysroot=$gccToolchainDir/$gnuTriplet/sysroot",
"--gcc-toolchain=$gccToolchainDir" "--gcc-toolchain=$gccToolchainDir",
"-L$llvmDir/lib"
]) ])
} else { } else {
binDir = "$sysrootDir/usr/bin" binDir = "$sysrootDir/usr/bin"