gradle-plugin: Use cinterop to compile stubs
The gradle plugin performed interop processing in two steps: 1. generate stubs using cinterop tool 2. compile the stubs generated using konanc. This led to code duplication since the cinterop tool also can do the same things. This patch removes two tasks used different tools and replaces them with one task which uses citerop tool for both stub generation and compilation
This commit is contained in:
+20
-50
@@ -33,8 +33,8 @@ project property (e.g. in `gradle.properties`). Note: the plugin ignores the `ko
|
||||
In this case the compiler will not be downloaded by the plugin.
|
||||
|
||||
To use the plugin you need to define artifacts you want to build in the `konanArtifacts` block. Here you can specify
|
||||
source files and compilation parameters (e.g. a target platform) for each artifact (see [**Plugin DSL**](#plugin-dsl) section below for
|
||||
details). The plugin uses `src/main/kotlin/` as a default directory for sources.
|
||||
source files and compilation parameters (e.g. a target platform) for each artifact (see [**Plugin DSL**](#plugin-dsl)
|
||||
section below for details). The plugin uses `src/main/kotlin/` as a default directory for sources.
|
||||
|
||||
konanArtifacts {
|
||||
foo {
|
||||
@@ -65,28 +65,11 @@ Each element (interop) in this block corresponds to some native library describe
|
||||
[`INTEROP.md`](INTEROP.md) to read more about def-files). The default path to the def-file of an interop is
|
||||
`src/main/c_interop/<interop-name>.def`.
|
||||
|
||||
Each interop is processed by the plugin in two steps:
|
||||
Each library is processed by the `cinterop` tool (see [`INTEROP.md`](INTEROP.md) for details). You can specify
|
||||
additional parameters for this tool in the interop block (e.g. a custom def-file is specified in the example above).
|
||||
See [**Plugin DSL**](#plugin-dsl) section below for available parameters.
|
||||
|
||||
1. **Stub generation.** In this step the plugin uses `cinterop` tool to generate Kotlin and bitcode (*.bc) stubs for the
|
||||
library. You can specify additional parameters for this tool in the interop block (e.g. a custom def-file is specified
|
||||
in the example above). See [**Plugin DSL**](#plugin-dsl) section below for available parameters and
|
||||
[`INTEROP.md`](INTEROP.md) for `cinterop` tool description.
|
||||
2. **Stub compilation.** In this step the plugin uses Kotlin/Native compiler to compile the stubs generated by the step (1)
|
||||
into a klib which can be linked with a Kotlin/Native application.
|
||||
Usually there is no need to specify additional compilation options for this stage. But if for some reason you need to do
|
||||
it, you can use `compileStubsConfig` property of an interop. This property provides an access to a `KonanCompileConfig`
|
||||
object containing the same methods as an artifact in the `konanArtifacts` block. E.g. this sample enables time measurement
|
||||
for compilation of stubs:
|
||||
|
||||
```
|
||||
konanInterop {
|
||||
stdio {
|
||||
compileStubsConfig.measureTime true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
To build some artifact with an interop add `useInterop` command in the artifact section:
|
||||
To build an artifact using an interop add `useInterop` command in the artifact section:
|
||||
|
||||
konanArtifacts {
|
||||
CsvParser {
|
||||
@@ -167,40 +150,32 @@ You may get this task using the `compilationTask` property of an artifact or by
|
||||
|`enableOptimization`|`boolean` |Is the optimization enabled |
|
||||
|`enableAssertions `|`boolean` |Is the assertion support enabled |
|
||||
|`measureTime `|`boolean` |Does the compiler print phase time |
|
||||
|
||||
* __gen*InteropName*InteropStubs__. The plugin creates such a task for each an interop defined in a `konanInterop` block.
|
||||
You may get this task using `generateStubsTask` property of an interop object or by its name:
|
||||
|
||||
* __process*InteropName*Interop__. The plugin creates such a task for each an interop defined in a `konanInterop` block.
|
||||
You may get this task using `interopProcessingTask` property of an interop object or by its name:
|
||||
|
||||
```
|
||||
// The task name is "genFooInteropStubs"
|
||||
konanInterop['foo'].generateStubsTask
|
||||
// The task name is "processFooInterop"
|
||||
konanInterop['foo']. interopProcessingTask
|
||||
```
|
||||
|
||||
Such a task generates stubs for the library defined by the interop and has the following properties accessible
|
||||
from a build script
|
||||
Such a task processes the library defined by the interop and creates a *.klib for it. The task has the following
|
||||
properties accessible from a build script:
|
||||
|
||||
|Property |Type |Description |
|
||||
|-------------- |----------------------------|--------------------------------------------------------|
|
||||
|`stubsDir `|`File` |An output directory for the Kotlin stubs generated |
|
||||
|`libsDir `|`File` |An output directory for the compiled stubs |
|
||||
|`outputDir `|`File` |An output directory for the *.klib built |
|
||||
|`kLib `|`File` |The *.klib built |
|
||||
|`defFile `|`File` |Def-file used by the interop |
|
||||
|`compilerOpts `|`List<String>` |Additional options passed to clang |
|
||||
|`linkerOpts `|`List<String>` |Additional options passed to a linker |
|
||||
|`headers `|`Collection<FileCollection>`|Additional headers used for stub generation |
|
||||
|`linkFiles `|`Collection<FileCollection>`|Additional files linked with the stubs |
|
||||
|`measureTime `|`boolean` |Does the compiler print phase time for stubs compilation|
|
||||
|
||||
* __compile*InteropName*InteropStubs__. The plugin creates such a task for each interop defined in a `konanInterop` block.
|
||||
You may get this task using `compileStubsTask` property of an interop object or by its name:
|
||||
|
||||
```
|
||||
// The task name is "compileStdioInteropStubs"
|
||||
konanInterop['stdio'].compileStubsTask
|
||||
|
||||
```
|
||||
|
||||
This task uses the Kotlin/Native compiler to compile the Kotlin stubs generated by the previous task. The task has the
|
||||
same properties as __compileKonan*ArtifactName*__.
|
||||
_Note_: In versions before 0.4 two tasks for each an interop were used: __gen*InteropName*InteropStubs__ and
|
||||
__compile*InteropName*InteropStubs__. Now actions of both of them are performed by the
|
||||
__process*InteropName*Interop__ task described above.
|
||||
|
||||
* __compileKonan__. This task is dependent on all compilation tasks and allows one to build all the artifacts supported
|
||||
by the current host. The task has no properties to use by a build script.
|
||||
@@ -238,11 +213,9 @@ For this project the task graph will be the following:
|
||||
build
|
||||
compileKonan
|
||||
compileKonanFooArtifact
|
||||
compileFooInteropStubs
|
||||
genFooInteropStubs
|
||||
processFooInterop
|
||||
compileKonanBarArtifact
|
||||
compileBarInteropStubs
|
||||
genBarInteropStubs
|
||||
processBarInterop
|
||||
clean
|
||||
|
||||
## Plugin DSL
|
||||
@@ -314,9 +287,6 @@ For this project the task graph will be the following:
|
||||
link <files which will be linked with native stubs> // Additional files to link with native stubs.
|
||||
|
||||
dumpParameters true // Print all parameters during the build.
|
||||
|
||||
// Print time of stub compilation phases (equivalent of the `--time` command line option).
|
||||
measureTime true
|
||||
|
||||
// Add the `anotherTask` to the stub generation task dependencies.
|
||||
dependsOn anotherTask
|
||||
|
||||
Reference in New Issue
Block a user