Skip to content

Commit eed6848

Browse files
committed
Integrate OpenSSL prebuilt static lib via NativeBuilds
This way the underlying OpenSSL version can be controlled/updated as a separate Gradle dependency and the updates are delivered more quickly from vcpkg via an automatically scheduled build & publication process.
1 parent b6b6904 commit eed6848

File tree

6 files changed

+13
-82
lines changed

6 files changed

+13
-82
lines changed

cryptography-providers/cryptokit/swift/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:6.2
1+
// swift-tools-version:6.1
22
import PackageDescription
33

44
// dwc = dev.whyoleg.cryptography

cryptography-providers/openssl3/api/build.gradle.kts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33
*/
44

55
import ckbuild.*
6-
import ckbuild.openssl.*
7-
import org.jetbrains.kotlin.gradle.*
8-
import org.jetbrains.kotlin.gradle.plugin.mpp.*
9-
import org.jetbrains.kotlin.gradle.tasks.*
6+
import com.ensody.nativebuilds.*
107

118
plugins {
129
id("ckbuild.multiplatform-library")
13-
id("ckbuild.use-openssl")
10+
alias(libs.plugins.nativebuilds)
1411
}
1512

1613
description = "cryptography-kotlin OpenSSL3 provider (API)"
1714

18-
@OptIn(ExperimentalKotlinGradlePluginApi::class)
1915
kotlin {
2016
nativeTargets()
2117

@@ -33,13 +29,7 @@ kotlin {
3329
implementation(projects.cryptographyProviderBase)
3430
}
3531

36-
targets.withType<KotlinNativeTarget>().configureEach {
37-
cinterop("declarations", "common")
38-
}
39-
}
40-
41-
tasks.withType<CInteropProcess>().configureEach {
42-
uses(openssl.v3_0) {
43-
settings.includeDirs(includeDirectory(konanTarget))
32+
cinterops(libs.nativebuilds.openssl.headers) {
33+
definitionFile.set(file("src/commonMain/cinterop/declarations.def"))
4434
}
4535
}

cryptography-providers/openssl3/prebuilt/build.gradle.kts

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,15 @@
33
*/
44

55
import ckbuild.*
6-
import ckbuild.openssl.*
7-
import org.jetbrains.kotlin.gradle.*
8-
import org.jetbrains.kotlin.gradle.plugin.*
9-
import org.jetbrains.kotlin.gradle.plugin.mpp.*
10-
import org.jetbrains.kotlin.gradle.targets.native.tasks.*
11-
import org.jetbrains.kotlin.gradle.tasks.*
126

137
plugins {
148
id("ckbuild.multiplatform-library")
159
id("ckbuild.multiplatform-provider-tests")
16-
id("ckbuild.use-openssl")
10+
alias(libs.plugins.nativebuilds)
1711
}
1812

1913
description = "cryptography-kotlin OpenSSL3 provider (prebuilt)"
2014

21-
@OptIn(ExperimentalKotlinGradlePluginApi::class)
2215
kotlin {
2316
nativeTargets()
2417

@@ -31,61 +24,12 @@ kotlin {
3124
sourceSets {
3225
commonMain.dependencies {
3326
api(projects.cryptographyProviderOpenssl3Api)
27+
api(libs.nativebuilds.openssl.libcrypto)
3428
}
3529
commonTest.dependencies {
3630
api(projects.cryptographyProviderOpenssl3Test)
3731
}
3832
}
39-
40-
targets.withType<KotlinNativeTarget>().configureEach {
41-
cinterop("linking", "common")
42-
}
43-
44-
// for mingw we link `zlib` statically, as on final-users Windows PCs, `zlib` is not installed by default,
45-
// while linking works fine (because K/N provides `zlib` inside it), running executable will fail.
46-
//
47-
// on other platforms `zlib` is pre-installed, so there are no such issues
48-
//
49-
// to properly test this on CI (where `zlib` is available),
50-
// we need to remove from PATH all paths that contain `zlib1.dll`.
51-
// we don't remove those paths from PATH automatically to not iterate over all files in PATH at configuration time.
52-
// instead, we do check if the new (adapted) PATH doesn't contain `zlib1.dll` at task execution time
53-
mingwX64 {
54-
testRuns.configureEach {
55-
@Suppress("UNCHECKED_CAST")
56-
(this as ExecutionTaskHolder<KotlinNativeTest>).executionTask.configure {
57-
// those values found experimentally on CI machines...
58-
val knownPathsWithZlibDll = setOf(
59-
"C:\\Program Files\\Git\\mingw64\\bin",
60-
"C:\\Program Files\\Microsoft Service Fabric\\bin\\Fabric\\Fabric.Code",
61-
"C:\\Strawberry\\c\\bin"
62-
)
63-
val currentPath = providers.environmentVariable("PATH").get()
64-
val paths = currentPath
65-
.split(";")
66-
.filter(String::isNotBlank)
67-
.filter { it !in knownPathsWithZlibDll }
68-
val newPath = paths.joinToString(";")
69-
70-
environment("PATH", newPath)
71-
doFirst {
72-
val folders = paths.mapNotNull { folder ->
73-
val hasZlib = File(folder).listFiles()?.any { it.name == "zlib1.dll" } == true
74-
if (hasZlib) folder else null
75-
}
76-
if (folders.isNotEmpty()) {
77-
error("Found `zlib1.dll` in paths: ${folders.joinToString("\n", "\n")}")
78-
}
79-
}
80-
}
81-
}
82-
}
83-
}
84-
85-
tasks.withType<CInteropProcess>().configureEach {
86-
uses(openssl.v3_5) {
87-
settings.extraOpts("-libraryPath", libDirectory(konanTarget).get().asFile.absolutePath)
88-
}
8933
}
9034

9135
providerTests {

cryptography-providers/openssl3/prebuilt/src/commonMain/cinterop/linking.def

Lines changed: 0 additions & 9 deletions
This file was deleted.
-98.5 KB
Binary file not shown.

gradle/libs.versions.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ maven-publish = "0.34.0"
2222
# other
2323
bouncycastle = "1.81"
2424
logback = "1.5.18"
25+
nativebuilds = "0.4.0"
26+
openssl = "3.6.0"
2527

2628
[libraries]
2729
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
@@ -43,6 +45,9 @@ kotlinx-benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-
4345

4446
bouncycastle = { module = "org.bouncycastle:bcprov-jdk18on", version.ref = "bouncycastle" }
4547

48+
nativebuilds-openssl-libcrypto = { module = "com.ensody.nativebuilds:openssl-libcrypto", version.ref = "openssl" }
49+
nativebuilds-openssl-headers = { module = "com.ensody.nativebuilds:openssl", version.ref = "openssl" }
50+
4651
androidx-test = { module = "androidx.test:runner", version.ref = "androidx-test" }
4752

4853
ktor-serialization-cbor = { module = "io.ktor:ktor-serialization-kotlinx-cbor", version.ref = "ktor" }
@@ -65,3 +70,4 @@ kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref
6570
kotlin-plugin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
6671
kotlin-dokka = { id = "org.jetbrains.dokka", version.ref = "kotlin-dokka" }
6772
android-kotlin-multiplatform-library = { id = "com.android.kotlin.multiplatform.library", version.ref = "android" }
73+
nativebuilds = { id = "com.ensody.nativebuilds", version.ref = "nativebuilds" }

0 commit comments

Comments
 (0)