CKlib is a gradle plugin that will build and package C/C++/Objective-C code for Kotlin/Native.

Related tags

Plugin cklib
Overview

C Klib

CKlib is a gradle plugin that will build and package C/C++/Objective-C code for Kotlin/Native.

The Problem

When you want to access C-etc code from Kotlin/Native, you point the cinterop process at it. That will create Kotlin code to enable calling the native code. That's only one part of the process, though. You also need to build and link binaries to implement the native calls. Configuring native builds can be complex because of the number of options that need to be correctly configured, as well as the need to package and link the complied binaries.

The Solution

This problem is already kind of solved by Kotlin/Native itself. The platform is based largely on C and C++. There's a Gradle plugin and set of tasks embedded within Kotlin/Native and the broader Kotlin platform that configures and builds native C-etc code. That plugin is not published in an accessible way, unfortunately. CKlib extracts that Clang Gradle plugin to be used externally.

For packaging, the problem is already solved there as well. You can just insert the compiled binary into your klib. CKlib is configured to do that for you.

Status

This plugin hasn't been designed for all use cases. We needed to compile and embed C code with no real external dependencies. You may want to build and embed C-etc code for other use cases we haven't considered, and this plugin will almost certainly need to be modified for your particular situation. Please start conversations and/or submit PRs if you add anything significant.

Usage

Add the plugin to your buildscript path:

<- Replace with current version } } ">
buildscript {
  repositories {
    mavenCentral() // <- need this
    google()
    gradlePluginPortal()
  }
  dependencies {
    classpath("co.touchlab:cklib-gradle-plugin:1.5.31.3") // <- Replace with current version
  }
}

Apply the plugin. You will also need to have the Kotlin Multiplatform plugin applied. CKlib depends on it.

plugins {
  kotlin("multiplatform")
  id("co.touchlab.cklib")
}

To create compilations, add the cklib block and then point at C-etc source.

cklib {
  create("somecode") {
    language = C
    compilerArgs.addAll(
      listOf(
        "-Wno-unused-function"
      )
    )
  }
}

By default, the C-etc code is built and packaged in compatible Kotlin/Native klibs. You can specify source folders and you will likely need to add some compiler args. Anything more custom will probably require tweaking the plugin itself, as it was really designed for a very particular use case.

Versioning

The underlying code comes from the Kotlin repo, and references local dependencies that are tightly coupled with Kotlin versions. As such, we have a 4 number version system. The first 3 are the Kotlin version, and the last is our point version.

So, for Kotlin 1.5.31, we have CKlib 1.5.31.3, which is the 3rd point release.

We're Hiring!

Touchlab is looking for a Mobile Developer, with Android/Kotlin experience, who is eager to dive into Kotlin Multiplatform Mobile (KMM) development. Come join the remote-first team putting KMM in production. More info here.

Primary Maintainer

Kevin Galligan

Image of Kevin

Ping me on twitter @kpgalligan if you don't get a timely reply! -Kevin

License

Copyright 2021 Touchlab, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
GPP is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and then promoting your App Bundle or APK to publishing app listings and other metadata.
GPP is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and then promoting your App Bundle or APK to publishing app listings and other metadata.

Gradle Play Publisher Gradle Play Publisher is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and

Kotlin Native's Clang Compiler Plugin

Kotlin Native's Clang Compiler Plugin This plugin makes possible to use konon clang compiler. Support targets: Target Name Host compatibility linux_x6

 Gradle plugin which downloads and manages your Android SDK.
Gradle plugin which downloads and manages your Android SDK.

DEPRECATED This plugin is deprecated and is no longer being developed. Tools and dependencies are automatically downloaded using version 2.2.0 of the

A gradle plugin to optimize built jars through individual file optimizations and increased compression

Machete Machete is a gradle plugin that attempts to optimize the size of output JARs through both individual file optimizations and overall compressio

A Gradle plugin to support the Groovy language for building Android apps

Groovy language support for Android Deprecated: This plugin has been deprecated in favor of Kotlin which has the full support of JetBrains and Google.

Add a different ribbon to each of your Android app variants using this gradle plugin. Of course, configure it as you will

Easylauncher gradle plugin for Android Modify the launcher icon of each of your app-variants using simple gradle rules. Add ribbons of any color, over

A Gradle Plugin that removes unused resources in Android projects.
A Gradle Plugin that removes unused resources in Android projects.

#Lint Cleaner Plugin Removes unused resources reported by Android lint including strings, colors and dimensions. Depracated As of Android Studio 2.0+

Gradle plugin for Google Protocol Buffers

Gradle Protobuf Plugin Author: Andrew Kroh Download: See maven central License: Apache License, Version 2.0 Requirements: Java 1.5+ Google Protocol Bu

Comments
  • Clang in .cklib fails due to missing libtinfo.so.5

    Clang in .cklib fails due to missing libtinfo.so.5

    We had a pull request build fail due to this crash:

    /home/runner/.cklib/clang-llvm-8.0.0-linux-x86-64/bin/clang: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
    
    > Task :zipline:linuxX64Quickjs FAILED
    

    It looks like an issue with Kotlin/Native libraries built before this fix?

    I was able to workaround the issue by installing libtinfo5.

          - name: Install libtinfo5
            if: matrix.os == 'ubuntu-latest'
            run: sudo apt-get install -y libtinfo5
    
    opened by swankjesse 0
  • Crash with Kotlin 1.7.20-Beta

    Crash with Kotlin 1.7.20-Beta

    Building watchosArm64() with Kermit test builds fails with:

    error: unknown target triple 'unknown-apple-watchos5.0.0', please use -triple or -arch
    

    The argument is:

    -target arm64_32-apple-watchos5.0
    
    opened by kpgalligan 0
  • Crash when Konan classes aren’t downloaded yet

    Crash when Konan classes aren’t downloaded yet

    I’m seeing this in CI for Zipline, and can reproduce locally by deleting my local Konan directory.

    $ rm -rf ~/.konan/kotlin-native-prebuilt-*
    $ ./gradlew build --stacktrace
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Build file '/Users/jwilson/Projects/zipline/zipline/build.gradle.kts' line: 155
    
    * What went wrong:
    org.jetbrains.kotlin.konan.target.PlatformManager
    
    * Try:
    Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    
    * Exception is:
    java.lang.ClassNotFoundException: org.jetbrains.kotlin.konan.target.PlatformManager
            at co.touchlab.cklib.gradle.reflection.PlatformManager.<init>(PlatformManager.kt:28)
            at co.touchlab.cklib.gradle.CKlibGradleExtensionKt.getPlatformManager(CKlibGradleExtension.kt:28)
            at co.touchlab.cklib.gradle.CompileToBitcodeExtension.create(CompileToBitcodeExtension.kt:33)
            at co.touchlab.cklib.gradle.CompileToBitcodeExtension.create$default(CompileToBitcodeExtension.kt:24)
            at Build_gradle$2.execute(build.gradle.kts:155)
            at Build_gradle$2.execute(build.gradle.kts:6)
    
    opened by swankjesse 7
Releases(0.2.4)
Owner
Touchlab
Kotlin Multiplatform Mobile Development
Touchlab
Gradle Replace In Place (GRIP): a gradle plugin to update your documentation or any file with a simple gradle task

GRIP (Gradle Replace In-Place) A gradle tool to update some values in your (documentation) files by running a task. (inspired by Knit) Directives Inse

Grégory Lureau 2 Oct 18, 2022
gradle-android-scala-plugin adds scala language support to official gradle android plugin

gradle-android-scala-plugin gradle-android-scala-plugin adds scala language support to official gradle android plugin. See also sample projects at htt

saturday06 345 Dec 10, 2022
Helper to upload Gradle Android Artifacts, Gradle Java Artifacts and Gradle Kotlin Artifacts to Maven repositories (JCenter, Maven Central, Corporate staging/snapshot servers and local Maven repositories).

GradleMavenPush Helper to upload Gradle Android Artifacts, Gradle Java Artifacts and Gradle Kotlin Artifacts to Maven repositories (JCenter, Maven Cen

 Vorlonsoft LLC 21 Oct 3, 2022
A Gradle plugin to report the number of method references in your APK on every build.

Dexcount Gradle Plugin A Gradle plugin to report the number of method references in your APK, AAR, or java module. This helps you keep tabs on the gro

Keepsafe 3k Dec 29, 2022
바코드 네트워크에서 제작 및 사용하는 Gradle build plugin 모음입니다. GradlePluginPortal 에 publish 되어 있습니다.

BarcodeGradlePlugins GradlePluginPortal 에 publish 되어 있는 바코드 네트워크의 빌드 플러그인들은 barcodeTasks 스코프 안에서 공통된 인자를 사용하여 실행될 수 있습니다. barcodeTasks { // 바코드 네트워크

Barcode Network 5 Nov 28, 2022
BuildPlots-Plugin - PaperMC-Plugin for build contests written in Kotlin.

BuildPlotsPlugin PaperMC-Plugin for build contests. This is my first time using Kotlin and the first plugin I've written after a long time. It is stil

Lukas Heinzl 0 Jan 1, 2022
Move on provides a complete package from shifting to ride, households to warehouses, packers and movers.

Move On Move on provides a complete package from shifting to ride, households to warehouses, packers and movers. Available on Playstore Packers and Mo

Mausam Singh 5 Feb 1, 2022
A full-featured package manager and viewer for Android

App Manager Docs · Releases · Telegram Channel Features General features Fully reproducible, copylefted libre software (GPLv3+) Material design (but n

Muntashir Al-Islam 2.3k Dec 29, 2022
Audio notifications for your Gradle build status

Let me serenade you ?? View Releases and Changelogs ?? Currently only functional on Mac OSX ?? Serenador is a Gradle plugin that utilizes text-to-spee

Thanos Psaridis 7 Jun 27, 2022
This plugin helps tp build GraphQL applications in Java using the DGS framework

dgs-intellij-plugin This plugin helps tp build GraphQL applications in Java using the DGS framework. The DGS Framework is open sourced by Netflix and

Netflix, Inc. 16 Nov 3, 2022