1

For example, I know that there is CoreCrypto for kotlin native. How to modify kotlin gradle script so the following code compiles:

import kotlinx.cinterop.*
import platform.CoreCrypto.CC_SHA256   // compile error, obviously, as there's no depenedncy
import platform.CoreCrypto.CC_SHA256_DIGEST_LENGTH

fun main() {
  // ...
}

My gradle script:

plugins {
    kotlin("multiplatform") version "1.6.10"
}

group = "com.jaga"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

kotlin {
    val hostOs = System.getProperty("os.name")
    val isMingwX64 = hostOs.startsWith("Windows")
    val nativeTarget = when {
        hostOs == "Mac OS X" -> macosX64("native")
        hostOs == "Linux" -> linuxX64("native")
        isMingwX64 -> mingwX64("native")
        else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
    }

    nativeTarget.apply {
        binaries {
            executable {
                entryPoint = "main"
            }
        }
    }
    sourceSets {
        val nativeMain by getting
        val nativeTest by getting
    }
}

I've been searching for a solution literally for hours now.

Docs: https://kotlinlang.org/docs/native-platform-libs.html

There are examples here: https://github.com/JetBrains/kotlin/tree/master/kotlin-native/samples

But they are not self-contained and handle dependencies in some complicated generic way which I cannot reproduce in a single gradle script.

EDIT: Actually, even those samples fail to build so they aren't useful as a reference...

Lutosław
  • 606
  • 7
  • 24
  • Hello! Could you please file an issue at kotl.in/issue? This code should be resolved correctly when using Mac host machines. I'm emphasising the host OS requirement as these symbols are being created based on the available system headers, so they cannot be delivered on Linux or Windows hosts. – Artyom Degtyarev Jan 31 '22 at 19:41

1 Answers1

0

I understand the frustration; it took me hours to get curl working with a custom build. I agree that the official documentation isn't helpful and is outdated, so use a reference project like Ktor instead.

Gabriel Pizarro
  • 400
  • 4
  • 15
  • Fix for: `Exception in thread "main" java.lang.Error: /tmp/15475645700324096303.c:1:10: fatal error: 'curl.h' file not found`: https://stackoverflow.com/questions/11471690/curl-h-no-such-file-or-directory/11471743 – Lutosław Jan 10 '22 at 15:25