Skip to content

Commit

Permalink
Not building when llvm is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
leventeBajczi committed Jul 24, 2023
1 parent 93ccad0 commit a4c9aab
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions subprojects/frontends/llvm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ plugins {
id("cpp-library")
}

val enabled = Os.isFamily(Os.FAMILY_UNIX) &&
try {
runCommandForOutput("llvm-config")
true
} catch (e: IOException) {
println("LLVM not installed, not building native library.")
false
}

fun runCommandForOutput(vararg args: String): Array<String> {
val process = ProcessBuilder(*args).start()
val outputStream = ByteArrayOutputStream()
Expand All @@ -37,7 +46,7 @@ fun runCommandForOutput(vararg args: String): Array<String> {
}

fun llvmConfigFlags(vararg args: String): Array<String> {
if (!Os.isFamily(Os.FAMILY_UNIX)) return arrayOf()
if (!enabled) return arrayOf()
return try {
runCommandForOutput("llvm-config", *args)
} catch (e: IOException) {
Expand All @@ -47,7 +56,7 @@ fun llvmConfigFlags(vararg args: String): Array<String> {
}

fun jniConfigFlags(): Array<String> {
if (!Os.isFamily(Os.FAMILY_UNIX)) return arrayOf()
if (!enabled) return arrayOf()
val jdkHomeArr = runCommandForOutput("bash", "-c", "dirname \$(cd \$(dirname \$(readlink \$(which javac))); pwd -P)")
check(jdkHomeArr.size == 1)
val jdkHome = File(jdkHomeArr[0])
Expand All @@ -68,7 +77,7 @@ library {
*jniConfigFlags(),
*llvmConfigFlags("--cxxflags")))
onlyIf {
Os.isFamily(Os.FAMILY_UNIX)
this@Build_gradle.enabled
}
}

Expand All @@ -78,7 +87,7 @@ library {
*llvmConfigFlags("--cxxflags", "--ldflags", "--libs", "core", "bitreader"),
"-ldl"))
onlyIf {
Os.isFamily(Os.FAMILY_UNIX)
this@Build_gradle.enabled
}
}
}

0 comments on commit a4c9aab

Please sign in to comment.