|
2 | 2 |
|
3 | 3 | CKlib is a gradle plugin that will build and package C/C++/Objective-C code for Kotlin/Native. |
4 | 4 |
|
5 | | -## The Problem |
| 5 | +# Note |
6 | 6 |
|
7 | | -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 |
8 | | -calling the native code. That's only one part of the process, though. You *also* need to build and link binaries to implement |
9 | | -the native calls. Configuring native builds can be complex because of the number of options that need to be correctly configured, |
10 | | -as well as the need to package and link the complied binaries. |
| 7 | +The main Kotlin project has changed how locally embedded C-like code is included in libraries, so we'll probably remove |
| 8 | +this project from public access soon until we land on a complete answer to handling this (our current solution is kind |
| 9 | +of a copy/paste of the main Kotlin solution). |
11 | 10 |
|
12 | | -## The Solution |
13 | | - |
14 | | -This problem is already kind of solved by Kotlin/Native itself. The platform is based largely on C and C++. There's a [Gradle |
15 | | -plugin](https://github.com/JetBrains/kotlin/blob/7b73917217de6dc66330593887c44e67a4efb7d3/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcodePlugin.kt) |
16 | | -and set of tasks embedded within Kotlin/Native and the broader Kotlin platform that configures and builds native C-etc code. |
17 | | -That plugin is not published in an accessible way, unfortunately. CKlib extracts that Clang Gradle plugin to be used externally. |
18 | | - |
19 | | -For packaging, the problem is already solved there as well. You can just insert the compiled binary into your klib. CKlib |
20 | | -is configured to do that for you. |
21 | | - |
22 | | -## Status |
23 | | - |
24 | | -This plugin hasn't been designed for all use cases. We needed to compile and embed C code with no real external dependencies. |
25 | | -You may want to build and embed C-etc code for other use cases we haven't considered, and this plugin will almost certainly |
26 | | -need to be modified for your particular situation. Please start conversations and/or submit PRs if you add anything significant. |
27 | | - |
28 | | -## Usage |
29 | | - |
30 | | -Add the plugin to your buildscript path: |
31 | | - |
32 | | -```kotlin |
33 | | -buildscript { |
34 | | - repositories { |
35 | | - mavenCentral() // <- need this |
36 | | - google() |
37 | | - gradlePluginPortal() |
38 | | - } |
39 | | - dependencies { |
40 | | - classpath("co.touchlab:cklib-gradle-plugin:1.5.31.3") // <- Replace with current version |
41 | | - } |
42 | | -} |
43 | | -``` |
44 | | - |
45 | | -Apply the plugin. You will also need to have the Kotlin Multiplatform plugin applied. CKlib depends on it. |
46 | | - |
47 | | -```kotlin |
48 | | -plugins { |
49 | | - kotlin("multiplatform") |
50 | | - id("co.touchlab.cklib") |
51 | | -} |
52 | | -``` |
53 | | - |
54 | | -To create compilations, add the `cklib` block, set the Kotlin version, and then point at C-etc source. |
55 | | - |
56 | | -```kotlin |
57 | | -cklib { |
58 | | - config.kotlinVersion = "1.6.0" |
59 | | - create("somecode") { |
60 | | - language = C |
61 | | - compilerArgs.addAll( |
62 | | - listOf( |
63 | | - "-Wno-unused-function" |
64 | | - ) |
65 | | - ) |
66 | | - } |
67 | | -} |
68 | | -``` |
69 | | - |
70 | | -By default, the C-etc code is built and packaged in compatible Kotlin/Native klibs. You can specify source folders and |
71 | | -you will likely need to add some compiler args. Anything more custom will probably require tweaking the plugin itself, as |
72 | | -it was really designed for a very particular use case. |
73 | | - |
74 | | -## We're Hiring! |
75 | | - |
76 | | -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](https://go.touchlab.co/careers-gh). |
77 | | - |
78 | | -## Primary Maintainer |
79 | | - |
80 | | -[Kevin Galligan](https://github.com/kpgalligan/) |
81 | | - |
82 | | - |
83 | | - |
84 | | -*Ping me on twitter [@kpgalligan](https://twitter.com/kpgalligan/) if you don't get a timely reply!* -Kevin |
| 11 | +You can use this, but we won't be supporting it publicly as it's kind of brittle to set up and debug. Just FYI. |
85 | 12 |
|
86 | 13 | License |
87 | 14 | ======= |
|
0 commit comments