Skip to content

Commit 557b8fa

Browse files
committed
Support multiple target hosts
1 parent 91a958f commit 557b8fa

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ org.gradle.jvmargs=-Xmx2g
1515

1616
GROUP=co.touchlab
1717
KOTLIN_VERSION=1.6.0
18-
CKLIB_VERSION=0.2.2
18+
CKLIB_VERSION=0.2.4
1919

2020
POM_NAME=CKlib
2121
POM_DESCRIPTION=C/C++ Bitcode Into Klib

plugin/src/main/kotlin/co/touchlab/cklib/gradle/CKlibGradleExtension.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ open class CKlibGradleExtension @Inject constructor(val project: Project) {
3939
}
4040

4141
var llvmHome: String
42-
get() = _llvmHome ?: "${System.getProperty("user.home")}/.cklib/clang-llvm-apple-8.0.0-darwin-macos"
42+
get() = _llvmHome ?: "$defaultCklibDir/${llvmName}"
4343
set(value) {
4444
_llvmHome = value
4545
}
4646
}
4747

48+
internal val defaultCklibDir:String
49+
get() = "${System.getProperty("user.home")}/.cklib"
50+
4851
internal val Project.platformManager: PlatformManager
4952
get() {
5053
val cklibExtension = extensions.getByType(CompileToBitcodeExtension::class.java)
@@ -77,13 +80,18 @@ internal val osName: String
7780
internal val llvmName: String
7881
get() {
7982
return when (osName) {
80-
"osx" -> llvm_macos_x64
83+
"osx" -> if (hostArch == "aarch64") {
84+
llvm_macos_arm64
85+
} else {
86+
llvm_macos_x64
87+
}
8188
"linux" -> llvm_linux_x64
8289
"windows" -> llvm_mingw_x64
8390
else -> throw TargetSupportException("Unknown operating system: $osName")
8491
}
8592
}
8693

94+
//https://download.jetbrains.com/kotlin/native/clang-llvm-8.0.0-linux-x86-64.tar.gz
8795
internal val llvm_linux_x64 = "clang-llvm-8.0.0-linux-x86-64"
8896
internal val llvm_mingw_x64 = "msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1"
8997
internal val llvm_macos_x64 = "clang-llvm-apple-8.0.0-darwin-macos"

plugin/src/main/kotlin/co/touchlab/cklib/gradle/CompileToBitcodePlugin.kt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010

1111
package co.touchlab.cklib.gradle
1212

13+
import org.gradle.api.GradleException
1314
import org.gradle.api.Plugin
1415
import org.gradle.api.Project
1516
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
16-
import org.rauschig.jarchivelib.ArchiveFormat
17-
import org.rauschig.jarchivelib.ArchiverFactory
1817
import java.io.BufferedInputStream
1918
import java.io.File
2019
import java.io.FileOutputStream
@@ -23,6 +22,9 @@ import java.util.*
2322

2423
class CompileToBitcodePlugin : Plugin<Project> {
2524
override fun apply(target: Project) = with(target) {
25+
if (osName == "windows") {
26+
throw GradleException("Windows is currently not compatible with cklib")
27+
}
2628
extensions.create(EXTENSION_NAME, CompileToBitcodeExtension::class.java, target)
2729
downloadIfNeeded(target)
2830

@@ -45,31 +47,31 @@ class CompileToBitcodePlugin : Plugin<Project> {
4547
//This is pretty hacky, but the process changed in 1.6.0. We'll probably just split off and do our own thing
4648
//going forward, but need to be able to build for the next few weeks.
4749
private fun downloadIfNeeded(target: Project) {
48-
val cklibDir = File("${System.getProperty("user.home")}/.cklib")
49-
val localFile = File(cklibDir, "clang-llvm-apple-8.0.0-darwin-macos")
50+
val cklibDir = File(defaultCklibDir)
51+
val localFile = File(cklibDir, llvmName)
5052
val clangExists = localFile.exists()
5153
if(!clangExists){
5254
target.logger.info("cklib downloading dependencies (may take a while...)")
5355
cklibDir.mkdirs()
5456
val tempFileName = UUID.randomUUID().toString()
55-
val extractDir = File(cklibDir, tempFileName)
56-
val tempDl = File(cklibDir, "${tempFileName}.zip")
57+
val tempFileNameWithExtension = "${tempFileName}.tar.gz"
58+
val tempDl = File(cklibDir, tempFileNameWithExtension)
5759

5860
try {
5961
val fos = FileOutputStream(tempDl)
60-
val inp = BufferedInputStream(URL("https://touchlab-deps-public.s3.us-east-2.amazonaws.com/clang-llvm-apple-8.0.0-darwin-macos.zip").openStream())
62+
63+
val inp = BufferedInputStream(URL("https://download.jetbrains.com/kotlin/native/${llvmName}.tar.gz").openStream())
6164
inp.copyTo(fos)
6265
fos.close()
6366
inp.close()
6467

65-
val archiver = ArchiverFactory.createArchiver(ArchiveFormat.ZIP)
66-
67-
archiver.extract(tempDl, extractDir)
68-
val extractChild = File(extractDir, "clang-llvm-apple-8.0.0-darwin-macos")
69-
extractChild.renameTo(localFile)
68+
target.exec {
69+
it.workingDir = cklibDir.absoluteFile
70+
it.executable = "tar"
71+
it.args = listOf("-xf", tempFileNameWithExtension)
72+
}
7073
} finally {
7174
tempDl.delete()
72-
extractDir.delete()
7375
}
7476
}
7577
}

0 commit comments

Comments
 (0)