Improve Gradle DSL in docs (#3481)

This commit is contained in:
Ilya Matveev
2019-10-25 16:05:35 +03:00
committed by GitHub
parent b8df05ed49
commit 61702a64c0
2 changed files with 84 additions and 26 deletions
+57 -22
View File
@@ -16,13 +16,19 @@ garbage.
### Q: How do I create a shared library?
A: Use the `-produce dynamic` compiler switch, or `binaries.sharedLib()` in Gradle, i.e.
```groovy
targets {
fromPreset(presets.iosArm64, 'mylib') {
<div class="sample" markdown="1" theme="idea" mode="kotlin" data-highlight-only>
```kotlin
kotlin {
iosArm64("mylib") {
binaries.sharedLib()
}
}
```
</div>
It will produce a platform-specific shared object (.so on Linux, .dylib on macOS, and .dll on Windows targets) and a
C language header, allowing the use of all public APIs available in your Kotlin/Native program from C/C++ code.
See `samples/python_extension` for an example of using such a shared object to provide a bridge between Python and
@@ -32,13 +38,19 @@ Kotlin/Native.
### Q: How do I create a static library or an object file?
A: Use the `-produce static` compiler switch, or `binaries.staticLib()` in Gradle, i.e.
```groovy
targets {
fromPreset(presets.iosArm64, 'mylib') {
<div class="sample" markdown="1" theme="idea" mode="kotlin" data-highlight-only>
```kotlin
kotlin {
iosArm64("mylib") {
binaries.staticLib()
}
}
```
</div>
It will produce a platform-specific static object (.a library format) and a C language header, allowing you to
use all the public APIs available in your Kotlin/Native program from C/C++ code.
@@ -54,26 +66,47 @@ or set it via the `JAVA_OPTS` environment variable.
A: Use the `-module-name` compiler option or matching Gradle DSL statement, i.e.
<div class="sample" markdown="1" theme="idea" mode="groovy">
<div class="multi-language-sample" data-lang="kotlin">
<div class="sample" markdown="1" theme="idea" mode="kotlin" data-highlight-only>
```groovy
targets {
fromPreset(presets.iosArm64, 'myapp') {
binaries.framework()
compilations.main.extraOpts '-module-name', 'TheName'
```kotlin
kotlin {
iosArm64("myapp") {
binaries.framework {
freeCompilerArgs += listOf("-module-name", "TheName")
}
}
}
```
</div>
</div>
<div class="multi-language-sample" data-lang="groovy">
<div class="sample" markdown="1" theme="idea" mode="groovy">
```groovy
kotlin {
iosArm64("myapp") {
binaries.framework {
freeCompilerArgs += ["-module-name", "TheName"]
}
}
}
```
</div>
</div>
### Q: How do I rename the iOS framework? (default name is _\<project name\>_.framework)
A: Use the `baseName` option. This will also set the module name.
```groovy
targets {
fromPreset(presets.iosArm64, 'myapp') {
<div class="sample" markdown="1" theme="idea" mode="kotlin" data-highlight-only>
```kotlin
kotlin {
iosArm64("myapp") {
binaries {
framework {
baseName = "TheName"
@@ -83,6 +116,8 @@ targets {
}
```
</div>
### Q: How do I enable bitcode for my Kotlin framework?
A: By default gradle plugin adds it on iOS target.
@@ -92,27 +127,27 @@ A: By default gradle plugin adds it on iOS target.
Or commandline arguments: `-Xembed-bitcode` (for release) and `-Xembed-bitcode-marker` (debug)
Setting this in a Gradle DSL:
<div class="sample" markdown="1" theme="idea" mode="groovy">
<div class="sample" markdown="1" theme="idea" mode="kotlin" data-highlight-only>
```groovy
targets {
fromPreset(presets.iosArm64, 'myapp') {
```kotlin
kotlin {
iosArm64("myapp") {
binaries {
framework {
// Use "marker" to embed the bitcode marker (for debug builds).
// Use "disable" to disable embedding.
embedBitcode "bitcode" // for release binaries.
embedBitcode("bitcode") // for release binaries.
}
}
}
}
```
</div>
These options have nearly the same effect as clang's `-fembed-bitcode`/`-fembed-bitcode-marker`
and swiftc's `-embed-bitcode`/`-embed-bitcode-marker`.
</div>
### Q: Why do I see `InvalidMutabilityException`?
A: It likely happens, because you are trying to mutate a frozen object. An object can transfer to the