Improve interop user experience and docs (#342)

This commit is contained in:
Nikolay Igotti
2017-03-15 17:25:10 +03:00
committed by GitHub
parent e67d9d4065
commit f3794aa206
7 changed files with 105 additions and 17 deletions
@@ -28,7 +28,7 @@ public class K2NativeCompilerArguments extends CommonCompilerArguments {
@Argument(value = "nolink", description = "Don't link, just produce a bitcode file")
public boolean nolink;
@Argument(value = "linkerArg", description = "Add argument to linker")
@Argument(value = "linkerArgs", description = "Pass arguments to linker", delimiter = " ")
@ValueDescription("<arg>")
public String[] linkerArguments;
@@ -175,11 +175,26 @@ internal class LinkStage(val context: Context) {
return objectFile
}
fun asLinkerArgs(args: List<String>): List<String> {
val result = mutableListOf<String>()
for (arg in args) {
// If user passes compiler arguments to us - transform them to linker ones.
if (arg.startsWith("-Wl,")) {
result.addAll(arg.substring(4).split(','))
} else {
result.add(arg)
}
}
return result
}
fun link(objectFiles: List<ObjectFile>): ExecutableFile {
val executable = config.get(KonanConfigKeys.EXECUTABLE_FILE)!!
val linkCommand = platform.linkCommand(objectFiles, executable, optimize) +
config.getNotNull(KonanConfigKeys.LINKER_ARGS)
asLinkerArgs(config.getNotNull(KonanConfigKeys.LINKER_ARGS))
println(linkCommand.joinToString("|||"))
runTool(*linkCommand.toTypedArray())