Moved link args computation to the root build.gradle.
Pass the link args to konanc.
This commit is contained in:
committed by
alexander-gorshenev
parent
f79b0bdf6a
commit
b04c52664e
@@ -100,36 +100,9 @@ abstract class KonanTest extends DefaultTask {
|
|||||||
return "${project.llvmDir}/bin/${tool}"
|
return "${project.llvmDir}/bin/${tool}"
|
||||||
}
|
}
|
||||||
|
|
||||||
private linux() {
|
protected List<String> clangLinkArgs() {
|
||||||
return project.isLinux()
|
return project.clangLinkArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<String> linkCppAbi() {
|
|
||||||
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()) {
|
|
||||||
return ["-ldl", "-lpthread", "-lm", "-rdynamic"]
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<String> libLink() {
|
|
||||||
def libs = []
|
|
||||||
libs.addAll(linkPlatform())
|
|
||||||
libs.addAll(linkCppAbi())
|
|
||||||
return libs
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class UnitKonanTest extends KonanTest {
|
class UnitKonanTest extends KonanTest {
|
||||||
@@ -140,7 +113,7 @@ class UnitKonanTest extends KonanTest {
|
|||||||
def argList = []
|
def argList = []
|
||||||
argList.addAll([ runtimeS.absolutePath, stdlibKtBc.absolutePath, sourceS.absolutePath,
|
argList.addAll([ runtimeS.absolutePath, stdlibKtBc.absolutePath, sourceS.absolutePath,
|
||||||
"-o", exe.absolutePath, testC, mainC ])
|
"-o", exe.absolutePath, testC, mainC ])
|
||||||
argList.addAll(libLink())
|
argList.addAll(clangLinkArgs())
|
||||||
args argList
|
args argList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,7 +126,7 @@ class RunKonanTest extends KonanTest {
|
|||||||
def argList = []
|
def argList = []
|
||||||
argList.addAll([ launcherBc.absolutePath, startKtBc.absolutePath,
|
argList.addAll([ launcherBc.absolutePath, startKtBc.absolutePath,
|
||||||
runtimeS.absolutePath, stdlibKtBc.absolutePath, sourceS.absolutePath, "-o", exe.absolutePath ])
|
runtimeS.absolutePath, stdlibKtBc.absolutePath, sourceS.absolutePath, "-o", exe.absolutePath ])
|
||||||
argList.addAll(libLink())
|
argList.addAll(clangLinkArgs())
|
||||||
args argList
|
args argList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,7 +186,7 @@ class LinkKonanTest extends KonanTest {
|
|||||||
def argList = []
|
def argList = []
|
||||||
argList.addAll([ runtimeS.absolutePath, stdlibKtBc.absolutePath,
|
argList.addAll([ runtimeS.absolutePath, stdlibKtBc.absolutePath,
|
||||||
sourceS.absolutePath, "-o", exe.absolutePath, testC, mainC ])
|
sourceS.absolutePath, "-o", exe.absolutePath, testC, mainC ])
|
||||||
argList.addAll(libLink())
|
argList.addAll(clangLinkArgs())
|
||||||
args argList
|
args argList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+43
-1
@@ -22,6 +22,7 @@ allprojects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
convention.plugins.clangFlags = new ClangFlags(isLinux(), "$llvmDir")
|
||||||
ext.clangPath = ["$llvmDir/bin"]
|
ext.clangPath = ["$llvmDir/bin"]
|
||||||
ext.clangArgs = []
|
ext.clangArgs = []
|
||||||
final String binDir
|
final String binDir
|
||||||
@@ -41,6 +42,8 @@ allprojects {
|
|||||||
|
|
||||||
ext.jvmArgs = ["-ea"]
|
ext.jvmArgs = ["-ea"]
|
||||||
|
|
||||||
|
ext.clangLinkArgs = libLink()
|
||||||
|
|
||||||
convention.plugins.execClang = new org.jetbrains.kotlin.ExecClang(project)
|
convention.plugins.execClang = new org.jetbrains.kotlin.ExecClang(project)
|
||||||
|
|
||||||
plugins.withType(NativeComponentPlugin) {
|
plugins.withType(NativeComponentPlugin) {
|
||||||
@@ -63,6 +66,44 @@ allprojects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ClangFlags {
|
||||||
|
|
||||||
|
protected Boolean isLinux
|
||||||
|
protected String llvmDir
|
||||||
|
|
||||||
|
ClangFlags(linux, llvm) {
|
||||||
|
isLinux = linux
|
||||||
|
llvmDir = llvm
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> linkCppAbi() {
|
||||||
|
if (isLinux) {
|
||||||
|
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 ["${llvmDir}/lib/libc++abi.a"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> linkPlatform() {
|
||||||
|
if (isLinux) {
|
||||||
|
return ["-ldl", "-lpthread", "-lm", "-rdynamic"]
|
||||||
|
} else {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> libLink() {
|
||||||
|
def libs = []
|
||||||
|
libs.addAll(linkPlatform())
|
||||||
|
libs.addAll(linkCppAbi())
|
||||||
|
return libs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PlatformInfo {
|
class PlatformInfo {
|
||||||
private final String osName = System.properties['os.name']
|
private final String osName = System.properties['os.name']
|
||||||
private final String osArch = System.properties['os.arch']
|
private final String osArch = System.properties['os.arch']
|
||||||
@@ -118,7 +159,8 @@ task dist_compiler(type: Copy) {
|
|||||||
include('konanc')
|
include('konanc')
|
||||||
include('kotlinc-native')
|
include('kotlinc-native')
|
||||||
|
|
||||||
filter { line -> line.replaceAll("FILTER_CLANG_PLATFORM_ARGS", clangArgs.join(' ')) }
|
def allClangArgs = "${clangArgs.join(' ')} ${clangLinkArgs.join(' ')}"
|
||||||
|
filter { line -> line.replaceAll("FILTER_CLANG_PLATFORM_ARGS", allClangArgs) }
|
||||||
filter { line -> line.replaceAll("FILTER_CLANG_BIN_PATH", "${project.llvmDir}/bin") }
|
filter { line -> line.replaceAll("FILTER_CLANG_BIN_PATH", "${project.llvmDir}/bin") }
|
||||||
|
|
||||||
into('bin')
|
into('bin')
|
||||||
|
|||||||
+2
-2
@@ -131,7 +131,7 @@ START="${KONAN_HOME}/lib/start.kt.bc"
|
|||||||
CLANG_PLATFORM_ARGS="FILTER_CLANG_PLATFORM_ARGS"
|
CLANG_PLATFORM_ARGS="FILTER_CLANG_PLATFORM_ARGS"
|
||||||
CLANG_BIN_PATH="FILTER_CLANG_BIN_PATH"
|
CLANG_BIN_PATH="FILTER_CLANG_BIN_PATH"
|
||||||
|
|
||||||
CLANG="$CLANG_BIN_PATH/clang++"
|
CLANG="$CLANG_BIN_PATH/clang"
|
||||||
|
|
||||||
# TODO: Compilation without stdlib.kt.bc doesn't work because 'start' requires stdlib, for example.
|
# TODO: Compilation without stdlib.kt.bc doesn't work because 'start' requires stdlib, for example.
|
||||||
# Probably, we need a .klib compilation mode.
|
# Probably, we need a .klib compilation mode.
|
||||||
@@ -139,7 +139,7 @@ CLANG="$CLANG_BIN_PATH/clang++"
|
|||||||
[ "$OPTIMIZE" == "YES" ] && clang_args=("-flto -O3 ${clang_args[@]}")
|
[ "$OPTIMIZE" == "YES" ] && clang_args=("-flto -O3 ${clang_args[@]}")
|
||||||
clang_args=($STDLIB "${clang_args[@]}")
|
clang_args=($STDLIB "${clang_args[@]}")
|
||||||
clang_args=($LAUNCHER $START $RUNTIME "${clang_args[@]}")
|
clang_args=($LAUNCHER $START $RUNTIME "${clang_args[@]}")
|
||||||
clang_args=("${clang_args[@]} -xc $CLANG_PLATFORM_ARGS")
|
clang_args=("${clang_args[@]} $CLANG_PLATFORM_ARGS")
|
||||||
|
|
||||||
$CLANG $KTBC_NAME -o $OUTPUT_NAME ${clang_args[@]}
|
$CLANG $KTBC_NAME -o $OUTPUT_NAME ${clang_args[@]}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user