-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat: binary options #4974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
danil-pavlov
wants to merge
6
commits into
master
Choose a base branch
from
native-binary-options
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: binary options #4974
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
43e5285
feat: binary options
danil-pavlov 88c32e1
update: xml table
danil-pavlov ee0c924
update: review suggestions
danil-pavlov d58178c
fix: review suggestions
danil-pavlov 2f85e06
fix: review suggestions
danil-pavlov 35fc315
chore: broken anchor
danil-pavlov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,328 @@ | ||
[//]: # (title: Kotlin/Native binary options) | ||
|
||
This page lists helpful Kotlin/Native binary options that you can use to configure Kotlin/Native [final binaries](https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-build-native-binaries.html) | ||
and the ways to set them up in your project. | ||
|
||
## How to enable | ||
|
||
You can enable binary options in the `gradle.properties` file, your build file, or pass them as compiler arguments. | ||
|
||
### In Gradle properties | ||
|
||
You can set binary options in your project's `gradle.properties` file using `kotlin.native.binary`, for example: | ||
|
||
```none | ||
kotlin.native.binary.gc=cms | ||
kotlin.native.binary.latin1Strings=true | ||
``` | ||
|
||
### In your build file | ||
|
||
You can set binary options for your project in your `build.gradle.kts` file: | ||
|
||
* For specific binaries using the `binaryOption` attribute, for example: | ||
|
||
```kotlin | ||
kotlin { | ||
iosArm64 { | ||
binaries { | ||
framework { | ||
binaryOption("smallBinary", "true") | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
* As `-Xbinary=$option=$value` compiler options in the `freeCompilerArgs` attribute, for example: | ||
|
||
```kotlin | ||
kotlin { | ||
iosArm64 { | ||
compilations.configureEach { | ||
compilerOptions.configure { | ||
freeCompilerArgs.add("-Xbinary=smallBinary=true") | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### In the command-line compiler | ||
|
||
You can pass binary options as `-Xbinary=$option=$value` directly in the command line when executing | ||
the [Kotlin/Native compiler](native-get-started.md#using-the-command-line-compiler), | ||
for example: | ||
|
||
```bash | ||
kotlinc-native main.kt -Xbinary=enableSafepointSignposts=true | ||
``` | ||
|
||
## Binary options | ||
|
||
> This table is not an exhaustive list of all the existing options, only the most notable ones. | ||
> | ||
{style="note"} | ||
|
||
<table column-width="fixed"> | ||
<tr> | ||
<td width="240">Option</td> | ||
<td width="170">Values</td> | ||
<td>Description</td> | ||
<td width="110">Status</td> | ||
</tr> | ||
<tr> | ||
<td><a href="whatsnew-eap.md" anchor="smaller-binary-size-for-ios-targets"><code>smallBinary</code></a></td> | ||
<td> | ||
<list> | ||
<li><code>true</code></li> | ||
<li><code>false</code> (default)</li> | ||
</list> | ||
</td> | ||
<td>Decreases the binary size for iOS targets.</td> | ||
<td>Experimental since 2.2.20</td> | ||
</tr> | ||
<tr> | ||
<td><a href="whatsnew-eap.md" anchor="support-for-stack-canaries-in-binaries"><code>stackProtector</code></a></td> | ||
<td> | ||
<list> | ||
<li><code>yes</code></li> | ||
<li><code>strong</code></li> | ||
<li><code>all</code></li> | ||
<li><code>no</code> (default)</li> | ||
</list> | ||
</td> | ||
<td>Enables stack canaries: use <code>yes</code> for vulnerable functions, <code>all</code> for all functions, and <code>strong</code> to utilize stronger heuristic.</td> | ||
<td>Available since 2.2.20</td> | ||
</tr> | ||
<tr> | ||
<td><a href="native-memory-manager.md" anchor="disable-allocator-paging"><code>pagedAllocator</code></a></td> | ||
<td> | ||
<list> | ||
<li><code>true</code> (default)</li> | ||
<li><code>false</code></li> | ||
</list> | ||
</td> | ||
<td>Controls paging of allocations (buffering). When <code>false</code>, the memory allocator reserves memory on a per-object basis.</td> | ||
<td>Experimental since 2.2.0</td> | ||
</tr> | ||
<tr> | ||
<td><a href="native-memory-manager.md" anchor="enable-support-for-latin-1-strings"><code>latin1Strings</code></a></td> | ||
<td> | ||
<list> | ||
<li><code>true</code></li> | ||
<li><code>false</code> (default)</li> | ||
</list> | ||
</td> | ||
<td>Controls support for Latin-1-encoded strings to reduce application binary size and adjust memory consumption.</td> | ||
<td>Experimental since 2.2.0</td> | ||
</tr> | ||
<tr> | ||
<td><a href="native-memory-manager.md" anchor="track-memory-consumption-on-apple-platforms"><code>mmapTag</code></a></td> | ||
<td><code>UInt</code></td> | ||
<td>Controls memory tagging, necessary for memory consumption tracking on Apple platforms. Values <code>240</code>-<code>255</code> are available (default is <code>246</code>); <code>0</code> disables tagging</td> | ||
<td>Available since 2.2.0</td> | ||
</tr> | ||
<tr> | ||
<td><code>disableMmap</code></td> | ||
<td> | ||
<list> | ||
<li><code>true</code></li> | ||
<li><code>false</code> (default)</li> | ||
</list> | ||
</td> | ||
<td>Controls the default allocator. When <code>true</code>, uses the <code>malloc</code> memory allocator instead of <code>mmap</code>.</td> | ||
<td>Available since 2.2.0</td> | ||
</tr> | ||
<tr> | ||
<td><code>gc</code></td> | ||
<td> | ||
<list> | ||
<li><code>pmcs</code> (default)</li> | ||
<li><code>stwms</code></li> | ||
<li><a href="native-memory-manager.md" anchor="optimize-gc-performance"><code>cms</code></a></li> | ||
<li><a href="native-memory-manager.md" anchor="disable-garbage-collection"><code>noop</code></a></li> | ||
</list> | ||
</td> | ||
<td>Controls garbage collection behavior: | ||
<list> | ||
<li><code>pmcs</code> uses parallel mark concurrent sweep</li> | ||
<li><code>stwms</code> uses simple stop-the-world mark and sweep</li> | ||
<li><code>cms</code> enables concurrent marking that helps decrease GC pause time</li> | ||
<li><code>noop</code> disables garbage collection</li> | ||
</list> | ||
</td> | ||
<td><code>cms</code> is Experimental since 2.0.20</td> | ||
</tr> | ||
<tr> | ||
<td><a href="native-memory-manager.md" anchor="garbage-collector"><code>gcMarkSingleThreaded</code></a></td> | ||
<td> | ||
<list> | ||
<li><code>true</code></li> | ||
<li><code>false</code> (default)</li> | ||
</list> | ||
</td> | ||
<td>Disables parallelization of the mark phase in garbage collection. May increase GC pause time on large heaps.</td> | ||
<td>Available since 1.7.20</td> | ||
</tr> | ||
<tr> | ||
<td><a href="native-memory-manager.md" anchor="monitor-gc-performance"><code>enableSafepointSignposts</code></a></td> | ||
<td> | ||
<list> | ||
<li><code>true</code></li> | ||
<li><code>false</code> (default)</li> | ||
</list> | ||
</td> | ||
<td>Enables tracking GC-related pauses in the project for debugging in Xcode Instruments.</td> | ||
<td>Available since 2.0.20</td> | ||
</tr> | ||
<tr> | ||
<td><code>preCodegenInlineThreshold</code></td> | ||
<td><code>UInt</code></td> | ||
<td> | ||
<p>Configures inlining optimization pass in the Kotlin IR compiler, which comes before the actual code generation phase (disabled by default).</p> | ||
<p>The recommended number of tokens (code units parsed by the compiler) is 40.</p> | ||
</td> | ||
<td>Experimental since 2.1.20</td> | ||
</tr> | ||
<tr> | ||
<td><a href="native-arc-integration.md" anchor="deinitializers"><code>objcDisposeOnMain</code></a></td> | ||
<td> | ||
<list> | ||
<li><code>true</code> (default)</li> | ||
<li><code>false</code></li> | ||
</list> | ||
</td> | ||
<td>Controls deinitialization of Swift/Objective-C objects. When <code>false</code>, deinitialization happens on a special GC thread instead of the main one.</td> | ||
<td>Available since 1.9.0</td> | ||
</tr> | ||
<tr> | ||
<td><a href="native-arc-integration.md" anchor="support-for-background-state-and-app-extensions"><code>appStateTracking</code></a></td> | ||
<td> | ||
<list> | ||
<li><code>enabled</code></li> | ||
<li><code>disabled</code> (default)</li> | ||
</list> | ||
</td> | ||
<td> | ||
<p>Controls timer-based invocation of the garbage collector when the application runs in the background.</p> | ||
<p>When <code>enabled</code>, GC is called only when memory consumption becomes too high.</p> | ||
</td> | ||
<td>Experimental since 1.7.20</td> | ||
</tr> | ||
<tr> | ||
<td><code>bundleId</code></td> | ||
<td> | ||
<list> | ||
<li><code>String</code></li> | ||
</list> | ||
</td> | ||
<td>Sets bundle ID (<code>CFBundleIdentifier</code>) in the <code>Info.plst</code> file.</td> | ||
<td>Available since 1.7.20</td> | ||
</tr> | ||
<tr> | ||
<td><code>bundleShortVersionString</code></td> | ||
<td> | ||
<list> | ||
<li><code>String</code></li> | ||
</list> | ||
</td> | ||
<td>Sets short bundle version (<code>CFBundleShortVersionString</code>) in the <code>Info.plst</code> file.</td> | ||
<td>Available since 1.7.20</td> | ||
</tr> | ||
<tr> | ||
<td><code>bundleVersion</code></td> | ||
<td> | ||
<list> | ||
<li><code>String</code></li> | ||
</list> | ||
</td> | ||
<td>Sets bundle version (<code>CFBundleVersion</code>) in the <code>Info.plst</code> file.</td> | ||
<td>Available since 1.7.20</td> | ||
</tr> | ||
<tr> | ||
<td><code>sourceInfoType</code></td> | ||
<td> | ||
<list> | ||
<li><code>libbacktrace</code></li> | ||
<li><code>coresymbolication</code> (Apple targets)</li> | ||
<li><code>noop</code> (default)</li> | ||
</list> | ||
</td> | ||
<td> | ||
<p>Adds file locations and line numbers to exception stack traces.</p> | ||
<p><code>coresymbolication</code> is only available for Apple targets and enabled by default for macOS and Apple simulators in debug mode.</p> | ||
</td> | ||
<td>Experimental since 1.6.20</td> | ||
</tr> | ||
<!-- <tr> | ||
<td><code>objcExportReportNameCollisions</code></td> | ||
<td> | ||
<list> | ||
<li><code>true</code></li> | ||
<li><code>false</code> (default)</li> | ||
</list> | ||
</td> | ||
<td>When <code>enabled</code>, reports warnings in case name collisions occur during Objective-C export.</td> | ||
<td></td> | ||
</tr> | ||
<tr> | ||
<td><code>objcExportErrorOnNameCollisions</code></td> | ||
<td> | ||
<list> | ||
<li><code>true</code></li> | ||
<li><code>false</code> (default)</li> | ||
</list> | ||
</td> | ||
<td>When <code>true</code>, issues errors in case name collisions occur during Objective-C export.</td> | ||
<td></td> | ||
</tr> | ||
<tr> | ||
<td><code>debugCompilationDir</code></td> | ||
<td><code>String</code></td> | ||
<td>Specifies the directory path to use for debug information in the compiled binary.</td> | ||
<td></td> | ||
</tr> | ||
<tr> | ||
<td><code>fixedBlockPageSize</code></td> | ||
<td><code>UInt</code></td> | ||
<td>Controls the page size for fixed memory blocks in the memory allocator. Affects memory allocation performance and fragmentation.</td> | ||
<td></td> | ||
</tr> | ||
<tr> | ||
<td><code>gcMutatorsCooperate</code></td> | ||
<td> | ||
<list> | ||
<li><code>true</code></li> | ||
<li><code>false</code> (default)</li> | ||
</list> | ||
</td> | ||
<td>Controls cooperation between mutator threads and the garbage collector.</td> | ||
<td></td> | ||
</tr> | ||
<tr> | ||
<td><code>auxGCThreads</code></td> | ||
<td><code>UInt</code></td> | ||
<td>Specifies the number of auxiliary threads to use for garbage collection.</td> | ||
<td></td> | ||
</tr> | ||
<tr> | ||
<td><code>sanitizer</code></td> | ||
<td> | ||
<list> | ||
<li><code>address</code></li> | ||
<li><code>thread</code></li> | ||
</list> | ||
</td> | ||
<td>Enables runtime sanitizers for detecting various issues like memory errors, data races, and undefined behavior.</td> | ||
<td>Experimental</td> | ||
</tr> --> | ||
</table> | ||
|
||
> For more information on stability levels, see the [documentation](components-stability.md#stability-levels-explained). | ||
> | ||
{style="tip"} | ||
|
||
## What's next | ||
|
||
Learn how to [build final native binaries](https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-build-native-binaries.html). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This flag works for any target, but only in release mode at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, we missed this during WN 2.2.20-Beta publication, fixed in WN as well. thank you!