Skip to content

Commit

Permalink
Add operating system detection for C-headers
Browse files Browse the repository at this point in the history
The code now dynamically detects the operating system and uses appropriate C-headers. A new function "inferPlatformSuffix" was introduced to select the correct C-headers zip file based on the operating system. Also, the directory path to C-headers has been adjusted.
  • Loading branch information
ygdrasil-io committed Feb 13, 2024
1 parent 3a45fec commit daea1c5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions klang/gradle-plugin/src/main/kotlin/io/ygdrasil/KlangPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import klang.helper.*
import klang.parser.json.parseAstJson
import klang.parser.libclang.parseFile
import klang.tools.generateAstFromDocker
import operatingSystem
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
Expand Down Expand Up @@ -84,7 +85,7 @@ class KlangPlugin : Plugin<Project> {
get() = workingDirectory.resolve("c-headers")

private val Project.cHeadersDirectory: File
get() = cHeadersExtractDirectory.resolve("c").resolve("include")
get() = cHeadersExtractDirectory.resolve("c")

override fun apply(project: Project) {
val extension = project.extensions.create("klang", KlangPluginExtension::class.java)
Expand Down Expand Up @@ -202,7 +203,7 @@ class KlangPlugin : Plugin<Project> {
task.onlyIf { cHeadersDirectory.doesNotExists() || cHeadersDirectory.isDirectoryEmpty() }
task.doFirst {
cHeadersExtractDirectory.deleteRecursively()
unzipFromClasspath("/c-headers.zip", cHeadersDirectory)
unzipFromClasspath("/c-${inferPlatformSuffix()}-headers.zip", cHeadersDirectory)
}
}

Expand Down Expand Up @@ -275,3 +276,9 @@ fun downloadFile(fileUrl: URL, targetFile: File): File? = try {
null
}


private fun inferPlatformSuffix() = when (operatingSystem) {
OperatingSystem.MAC -> "darwin"
OperatingSystem.LINUX -> "linux"
else -> error("Operating system $operatingSystem not supported")
}

0 comments on commit daea1c5

Please sign in to comment.