Foundations(iOS Sourceset): Streamline libsodium bindings configuration.
This commit is contained in:
+35
-71
@@ -62,12 +62,30 @@ kotlin {
|
|||||||
// project can be found here:
|
// project can be found here:
|
||||||
// https://developer.android.com/kotlin/multiplatform/migrate
|
// https://developer.android.com/kotlin/multiplatform/migrate
|
||||||
val xcfName = "quartz-kmpKit"
|
val xcfName = "quartz-kmpKit"
|
||||||
|
val libsodiumPath = project.file("src/nativeInterop/libsodium").toString()
|
||||||
|
|
||||||
listOf(
|
listOf(
|
||||||
iosArm64(),
|
iosArm64(),
|
||||||
iosX64(),
|
iosX64(),
|
||||||
iosSimulatorArm64(),
|
iosSimulatorArm64(),
|
||||||
).forEach { target ->
|
).forEach { target ->
|
||||||
|
|
||||||
|
target.compilations.getByName("main") {
|
||||||
|
val headerFilesPath = "$libsodiumPath/include/sodium"
|
||||||
|
val Clibsodium by cinterops.creating {
|
||||||
|
definitionFile.set(project.file("Clibsodium.def"))
|
||||||
|
includeDirs("${libsodiumPath}/ios-simulators/lib")
|
||||||
|
//compilerOpts("-I${libsodiumPath}/ios-simulators/lib")
|
||||||
|
|
||||||
|
|
||||||
|
headers(
|
||||||
|
"$headerFilesPath/crypto_aead_xchacha20poly1305.h",
|
||||||
|
"$headerFilesPath/crypto_core_hchacha20.h",
|
||||||
|
"$headerFilesPath/crypto_stream_chacha20.h"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
target.swiftPackageConfig(cinteropName = "swiftbridge") {
|
target.swiftPackageConfig(cinteropName = "swiftbridge") {
|
||||||
minIos = "17"
|
minIos = "17"
|
||||||
minMacos = "14"
|
minMacos = "14"
|
||||||
@@ -84,75 +102,40 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val libsodiumPath = project.file("src/nativeInterop/libsodium").toString()
|
|
||||||
|
|
||||||
iosX64 {
|
iosX64 {
|
||||||
compilations.getByName("main") {
|
|
||||||
val headerFilesPath = "$libsodiumPath/include/sodium"
|
|
||||||
val Clibsodium by cinterops.creating {
|
|
||||||
definitionFile.set(project.file("Clibsodium.def"))
|
|
||||||
includeDirs("$libsodiumPath/include/sodium")
|
|
||||||
|
|
||||||
headers(
|
|
||||||
"$headerFilesPath/crypto_aead_xchacha20poly1305.h",
|
|
||||||
"$headerFilesPath/crypto_core_hchacha20.h",
|
|
||||||
"$headerFilesPath/crypto_stream_chacha20.h"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
binaries.all {
|
|
||||||
//linkerOpts("-L${libsodiumPath}/ios/lib", "-llibsodium")
|
|
||||||
}
|
|
||||||
binaries.framework {
|
binaries.framework {
|
||||||
baseName = xcfName
|
baseName = xcfName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iosArm64 {
|
iosArm64 {
|
||||||
compilations.getByName("main") {
|
|
||||||
val headerFilesPath = "$libsodiumPath/include/sodium"
|
|
||||||
val Clibsodium by cinterops.creating {
|
|
||||||
definitionFile.set(project.file("Clibsodium.def"))
|
|
||||||
includeDirs("$libsodiumPath/include/sodium")
|
|
||||||
|
|
||||||
headers(
|
|
||||||
"$headerFilesPath/crypto_aead_xchacha20poly1305.h",
|
|
||||||
"$headerFilesPath/crypto_core_hchacha20.h",
|
|
||||||
"$headerFilesPath/crypto_stream_chacha20.h"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
binaries.all {
|
|
||||||
//linkerOpts("-L${libsodiumPath}/ios/lib", "-llibsodium")
|
|
||||||
}
|
|
||||||
binaries.framework {
|
binaries.framework {
|
||||||
baseName = xcfName
|
baseName = xcfName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iosSimulatorArm64 {
|
iosSimulatorArm64 {
|
||||||
compilations.getByName("main") {
|
|
||||||
val headerFilesPath = "$libsodiumPath/include/sodium"
|
|
||||||
val Clibsodium by cinterops.creating {
|
|
||||||
definitionFile.set(project.file("Clibsodium.def"))
|
|
||||||
includeDirs("${libsodiumPath}/ios-simulators/lib")
|
|
||||||
//compilerOpts("-I${libsodiumPath}/ios-simulators/lib")
|
|
||||||
|
|
||||||
|
|
||||||
headers(
|
|
||||||
"$headerFilesPath/crypto_aead_xchacha20poly1305.h",
|
|
||||||
"$headerFilesPath/crypto_core_hchacha20.h",
|
|
||||||
"$headerFilesPath/crypto_stream_chacha20.h"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
binaries.all {
|
|
||||||
//linkerOpts("-L${libsodiumPath}/ios-simulators/lib", "-llibsodium-simulator")
|
|
||||||
}
|
|
||||||
binaries.framework {
|
binaries.framework {
|
||||||
baseName = xcfName
|
baseName = xcfName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// This generates the Libsodium definition file, necessary for creating native bindings(a Kotlin API) for libsodium(for iOS).
|
||||||
|
val libsodiumDefFileGeneration = tasks.register<Exec>("GenerateSodiumCinteropFile") {
|
||||||
|
val libsodiumPath = project.file("src/nativeInterop/libsodium").toString()
|
||||||
|
val definitionFile = project.file("src/nativeInterop/cinterop/Clibsodium.def")
|
||||||
|
definitionFile.writeText("package = Clibsodium")
|
||||||
|
definitionFile.appendText("\n" + "staticLibraries = libsodium.a libsodium-simulator.a")
|
||||||
|
definitionFile.appendText("\n" + "libraryPaths = ${libsodiumPath}/ios/lib ${libsodiumPath}/ios-simulators/lib")
|
||||||
|
|
||||||
|
doLast {
|
||||||
|
executionResult.get().assertNormalExitValue()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType<KotlinNativeCompile>().configureEach {
|
||||||
|
// doFirst { libsodiumDefFileGeneration.get() }
|
||||||
|
dependsOn(libsodiumDefFileGeneration)
|
||||||
|
}
|
||||||
|
|
||||||
// This makes sure that the resource file directory is visible for iOS tests.
|
// This makes sure that the resource file directory is visible for iOS tests.
|
||||||
val rootDir = "${rootProject.rootDir.path}/quartz/src/iosTest/resources"
|
val rootDir = "${rootProject.rootDir.path}/quartz/src/iosTest/resources"
|
||||||
@@ -375,22 +358,3 @@ mavenPublishing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<Exec>("GenerateSodiumCinteropFile") {
|
|
||||||
val libsodiumPath = project.file("src/nativeInterop/libsodium").toString()
|
|
||||||
val definitionFile = project.file("src/nativeInterop/cinterop/Clibsodium.def")
|
|
||||||
definitionFile.writeText("package = Clibsodium")
|
|
||||||
definitionFile.appendText("\n" + "staticLibraries = libsodium.a libsodium-simulator.a")
|
|
||||||
definitionFile.appendText("\n" + "libraryPaths = ${libsodiumPath}/ios/lib ${libsodiumPath}/ios-simulators/lib")
|
|
||||||
|
|
||||||
doLast {
|
|
||||||
executionResult.get().assertNormalExitValue()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType<KotlinNativeCompile>().configureEach {
|
|
||||||
val fileDefinition = project.file("src/nativeInterop/cinterop/Clibsodium.def")
|
|
||||||
if (!fileDefinition.exists()) {
|
|
||||||
dependsOn("GenerateSodiumCinteropFile")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user