[KT-54284][Native] Produce deterministic klibs from cinterop. (#4979)
Pass in temp-file C sources to clang via stdin instead of by name. This prevents absolute paths of temp files from being encoded in bitcode.
This commit is contained in:
+10
-5
@@ -105,9 +105,12 @@ private fun List<String>?.isTrue(): Boolean {
|
||||
return this?.last() == "true"
|
||||
}
|
||||
|
||||
private fun runCmd(command: Array<String>, verbose: Boolean = false) {
|
||||
if (verbose) println("COMMAND: " + command.joinToString(" "))
|
||||
Command(*command).getOutputLines(true).let { lines ->
|
||||
private fun runCmd(command: Array<String>, verbose: Boolean = false, redirectInputFile: File? = null) {
|
||||
if (verbose) {
|
||||
val redirect = if (redirectInputFile == null) "" else " < ${redirectInputFile.path}"
|
||||
println("COMMAND: " + command.joinToString(" ") + redirect)
|
||||
}
|
||||
Command(command.toList(), redirectInputFile = redirectInputFile).getOutputLines(true).let { lines ->
|
||||
if (verbose) lines.forEach(::println)
|
||||
}
|
||||
}
|
||||
@@ -384,9 +387,11 @@ private fun processCLib(flavor: KotlinPlatform, cinteropArguments: CInteropArgum
|
||||
}
|
||||
KotlinPlatform.NATIVE -> {
|
||||
val outLib = File(nativeLibsDir, "$libName.bc")
|
||||
// Note that the output bitcode contains the source file path, which can lead to non-deterministc builds (see KT-54284).
|
||||
// The source file is passed in via stdin to ensure the output library is deterministic.
|
||||
val compilerCmd = arrayOf(compiler, *compilerArgs,
|
||||
"-emit-llvm", "-c", outCFile.absolutePath, "-o", outLib.absolutePath)
|
||||
runCmd(compilerCmd, verbose)
|
||||
"-emit-llvm", "-x", library.language.clangLanguageName, "-c", "-", "-o", outLib.absolutePath)
|
||||
runCmd(compilerCmd, verbose, redirectInputFile = File(outCFile.absolutePath))
|
||||
outLib.absolutePath
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user