Commit Graph

165 Commits

Author SHA1 Message Date
Teng Zhang bf86afc867 KT-57870: Suppress InvalidPathException for paths with invalid characters when loading Konan library
^KT-57870 Fixed
2023-10-30 07:03:55 +00:00
Dmitrii Krasnov 10a6d8fd2c [Gradle IT] Added configuration for running IT with k/n from master
[Gradle] Updated kotlin-build-gradle-plugin to 0.0.40

#KT-45978 Ready for Review


Merge-request: KT-MR-12509
Merged-by: Dmitrii Krasnov <Dmitrii.Krasnov@jetbrains.com>
2023-10-24 08:38:51 +00:00
Alexander Shabalin 4922223bec [K/N] Refactor :kotlin-native:dependencies
Move K/N dependencies handling logic into gradle plugins:

`NativeDependenciesDownloader` is instantiated in
`:kotlin-native:dependencies` and provides a single configuration that
contains all directories with the dependencies. The configuration has
a variant for each target.

`NativeDependencies` is instantiated by projects that require native
dependencies (i.e. previously used to depend on
`:kotlin-native:dependencies:update`). This plugin creates a configuration
that by default depends on `:kotlin-native:dependencies`. Its extension
provides `llvmDependency`, `libffiDependency`, `hostPlatformDependency`,
`targetDependency()` to depend on the parts needed for the project and
provides accessors `llvmPath`, `libffiPath`, `hostPlatform` that are
safe to use during configuration time, but which do not automatically
resolve those dependencies.

`llvmDir`, `*LibffiDir` properties on `:kotlin-native` are removed
completely, as their use is replaced by `NativeDependencies`. As a
consequence, `evaluationDependsOn(":kotlin-native:dependencies")` is
also gone.

All direct dependencies on `:kotlin-native:dependencies:update` are
replaced with dependencies on specific parts via `NativeDependencies`
2023-10-18 10:53:12 +00:00
Dmitriy Novozhilov 704e2ef5c5 Suppress K2 specific warnings in the codebase
^KT-62472
2023-10-18 07:59:27 +00:00
Dave MacLachlan c820e82db3 Native: remove linker warning when building libllvmstubs
Building with macOS gave the linker warning
`ld: warning: ignoring duplicate libraries: '/Users/foo/.konan/dependencies/apple-llvm-20200714-macos-aarch64-1/lib/libclangEdit.a'`

Remove duplication from the build script to get rid of the warning.

Co-authored-by: Dave MacLachlan <dmaclach@gmail.com>
2023-10-09 16:49:16 +00:00
Timofey Solonin 8dc9307f9e Add iconv void * overloads for backwards compatibility
Since Xcode 15 the iconv APIs operate on an opaque type __tag_iconv_t* instead of
void*. This causes a runtime exception in older Ktor versions which
depended on iconv.

^KT-62286
2023-10-04 08:04:37 +02:00
Konstantin Tskhovrebov 4ad5be35f4 KT-56369: [cinterop] Throw an error for an unexpected module imports
Module imports require explicit '-fmodules' compiler flag.
If the indexer meets a module import but there is no the flag
then it throws an error.
2023-09-19 15:23:52 +00:00
Alexander Shabalin 3ec4f2e0ee [K/N] Remove jsinterop because K/N wasm32 target is removed ^KT-59008
See https://kotl.in/native-targets-tiers for details
2023-08-30 12:17:52 +00:00
Leonid Startsev 8b821e1feb Deprecate KmProperty.hasGetter(hasSetter) in favor of KmProperty.getter(setter)
as a follow-up of flag deprecation.

#KT-59440
2023-08-14 12:36:34 +00:00
Abduqodiri Qurbonzoda 0f33d71de3 Migrate Vector128 from kotlin.native to kotlinx.cinterop #KT-58402
Make kotlin.native.Vector128 a typealias for kotlinx.cinterop.Vector128
Choose source compatibility over binary compatibility.
2023-07-31 19:38:05 +00:00
Svyatoslav Scherbina dcb34e0ec0 Native: mention cinterop libraries in the ExperimentalForeignApi KDoc
Now (mostly after 3f3f6eb) cinterop adds ExperimentalForeignApi to all
Kotlin declarations it generates from C and Objective-C libraries,
except for the platform libraries.
This commit changes the KDoc for ExperimentalForeignApi to reflect that
change.

^KT-58362
2023-07-25 17:18:00 +00:00
Svyatoslav Scherbina 3f3f6eb5a8 Native: add ExperimentalForeignApi to generated cinterop declarations
cinterop tool should add ExperimentalForeignApi to all generated
declarations by default. This commit implements adding the annotation.
Nested declarations don't get the annotation, because they inherit the
opt-in requirement from the enclosing classes implicitly.

The annotation is not added to platform libraries, as intended. See
previous commits.

^KT-58362
2023-07-21 11:54:14 +00:00
Svyatoslav Scherbina 93ef98cbec Native: make .annotations mutable for some Stub IR nodes
cinterop tool should add ExperimentalForeignApi to all generated
declarations by default. To make this possible to implement in a
non-intrusive manner, this commit enables adding annotations to some of
the existing Stub IR nodes.
After that, one can add annotations to all generated declarations with
a simple post pass.

^KT-58362
2023-07-21 11:54:14 +00:00
Svyatoslav Scherbina d118844b17 Native: represent ExperimentalForeignApi in cinterop's Stub IR
cinterop tool should add ExperimentalForeignApi to all generated
declarations by default. This commit supports this annotation in
cinterop intermediate representation -- Stub IR.

^KT-58362
2023-07-21 11:54:14 +00:00
Svyatoslav Scherbina cabb25d3e0 Native: add -Xdisable-experimental-annotation flag to cinterop
It disables adding `ExperimentalForeignApi` opt-in to declarations
generated by cinterop.
Main use case is platform libraries, which are not supposed to have this
annotation. Applying the flag to user cinterop libraries is discouraged
and effectively means opting in.

^KT-58362
2023-07-21 11:54:14 +00:00
Svyatoslav Scherbina 1053d18871 Native: add support for annotations on typealiases in cinterop
^KT-58362
2023-07-21 11:54:14 +00:00
Yahor Berdnikau 5b5dae9249 [repo] Move buildSrc into repo/gradle-build-conventions/buildsrc-compat project
Include new project as build logic included build. Such change will
allow us to start migration into build convention plugins by splitting
buildSrc logic into subprojects.
2023-07-13 08:24:49 +00:00
Sebastian Sellmair 3f0130ecf1 [Gradle] Change 'UnsafeNumber' RequiresOptIn.level to 'ERROR'
^KT-59859 Verification Pending
^KT-55757 Verification Pending
2023-07-12 20:17:03 +00:00
Dmitrii Krasnov f2816a5531 Added property for overriding konan distribution location
#KT-50463 Fixed

Merge-request: KT-MR-10310
Merged-by: Dmitrii Krasnov <Dmitrii.Krasnov@jetbrains.com>
2023-07-12 12:36:51 +00:00
Sergey Bogolepov d433d1eb3f KT-58862: Remove cinterop -mode option
metadata cinterop libraries perform pretty well for years,
so we can drop this flag.
2023-06-30 14:16:01 +00:00
Leonid Startsev b15da7c63a Deprecate old kotlinx-metadata flags API:
Flag, Flag constants, Flags typealias, flagsOf() function, and
Flag accessors in nodes (such as KmClass.flags, KmClass.jvmFlags, KmProperty.setterFlags, etc)

#KT-59440
2023-06-27 15:12:46 +00:00
Leonid Startsev 1a1cbcb321 Rework flags in kotlinx.metadata:
Introduce extensions for KmNodes to work with various modifiers instead of old Flags.SOMETHING.invoke(flags).
Provide Visibility, Modality, and Kind enums.
Introduce KmPropertyAccessorAttributes to replace KmProperty.getterFlags and KmProperty.setterFlags.
Deprecate nodes constructors which take flags but not flags itself (yet).
Adapt KotlinP to changes.

#KT-59440 Fixed
2023-06-27 15:12:46 +00:00
Dmitriy Dolovov 72525a22a6 [KLIB] Extract "ir_provider" manifest property name as a const val 2023-06-15 11:07:30 +00:00
Leonid Startsev 0cfe2b04f5 Move KmModuleFragment to an internal.common package
because it is klib-related and can be read only with KotlinCommonMetadata.
2023-06-08 17:53:31 +00:00
Svyatoslav Scherbina 1bf3d55bdf Native: add detachObjCObject internal function for Obj-C objects
For a Kotlin wrapper of an Objective-C object, this functions zeroes
and releases the strong reference from the Kotlin wrapper to the
Objective-C object.
Usually, such a release happens only when the Kotlin wrapper is GCed.
So using this function can help that happen sooner.

^KT-59134
2023-06-07 11:57:54 +00:00
cristiangarcia 46d113605b Adopt configuration-avoidance where possible
Before this change `./gradlew help` (with native enabled)
Created immediately: 1322
Created during configuration: 1541

after this change:
Created immediately: 596
Created during configuration: 1509

To know more about configuration avoidance: https://docs.gradle.org/current/userguide/task_configuration_avoidance.html
2023-06-06 14:27:42 +00:00
Dmitriy Dolovov 2b913d7c47 [Native] Don't produce broken @Deprecated annotations in c-interop
#KT-58651
2023-05-16 08:30:29 +00:00
Alexander Udalov 41cb2ce3d8 K/N: enable -Xlambdas=class for :kotlin-native:Interop:Indexer
`staticCFunction` is used a few times in this module, and it uses
kotlin-reflect to inspect the lambda parameter, which is only possible
for class-generated lambdas.

This is needed to enable indy lambdas in the project.
2023-05-12 14:01:30 +00:00
Vsevolod Tolstopyatov f4e8ae5191 Explicitly declare stability levels of declarations in kotlinx.cinterop package
* @ExperimentalForeignApi for all declarations that operate on
    unmanaged memory (i.e. pointers and references)
* @BetaInteropApi for the rest of the interoperability declarations,
    namely Swift/CInterop-specific interfaces and convenience-functions

### Implementation details

* Some typealiases are not marked explicitly because it crashes the compiler,
    yet their experimentality is properly propagated
* License header is adjusted where it previously had been existing
* Deprecated with ERROR interop declarations that are deprecated for more than
    two years are removed
* WASM target interop declarations are deprecated
* Deliberately make Boolean.toByte and Byte.toBoolean foreign-experimental to scare
    people away

^KT-57728 fixed

Merge-request: KT-MR-9788
Merged-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
2023-05-04 13:52:21 +00:00
Gleb Lukianets 242ca73d83 rrn/rd/KT-55578 User-provided hints for linker errors
[K/N] KT-55578 Show customized user suggestions on linkage errors

Merge-request: KT-MR-9636
Merged-by: Gleb Lukianets <Gleb.Lukianets@jetbrains.com>
2023-04-27 14:14:43 +00:00
Abduqodiri Qurbonzoda 95f1d0b6ae [K/N] Internalize getNativeNullPtr() functions
As a part of efforts to stabilize Native stdlib.
2023-04-08 21:50:32 +03:00
Abduqodiri Qurbonzoda 5cc6338fb9 [K/N] Deprecate Retain and RetainForTarget annotations
As a part of efforts to stabilize Native stdlib #KT-55765.
2023-04-07 17:03:36 +00:00
Mark Mann b6f669189b Use protocol name when creating objc protocol wrapper class 2023-03-31 09:50:25 +00:00
Gleb Lukianets fc96eb6d8d [KN] CInterop: __attribute__((objc_direct)) support
Merge-request: KT-MR-8828
Merged-by: Gleb Lukianets <Gleb.Lukianets@jetbrains.com>
2023-03-02 10:36:53 +00:00
Svyatoslav Scherbina 3904966e2c Native: fix error message for C union with nested struct with bitfields
tryRenderStructOrUnion can return null for a struct or union to indicate
that passing it by value to or from C is not supported (e.g. it has
bitfields).

It incorrectly handled the case when passing a nested struct or union by
value was unsupported -- instead of null, it returned incorrect struct
declaration.

As a result, when passing such a complex struct or union by value to or
from C, the backend generated C stubs with syntax errors, which resulted
into obscure compilation error ("unable to compile C bridge").

This commit fixes this case in tryRenderStructOrUnion function, and thus
makes the compilation error message more understandable.

^KT-55030
2023-03-02 09:00:11 +00:00
Pavel Punegov 71eaa43d95 [K/N][build] Move Native plugin to build-tools
This is K/N only plugin that shouldn't be
in the buildSrc of the whole Kotlin project
2023-02-27 10:48:27 +00:00
Pavel Punegov 395e3e0f81 [K/N][build] Composite build with build.tools-conventions plugin
Adds convention plugin instead of sources inclusion
inside the buildSrc, effectively reducing the amount
of the code to be compiled in buildSrc.

Merge-request: KT-MR-8898
2023-02-27 10:48:26 +00:00
Sergey Bogolepov 7402ef24bb [K/N] Remove obsolete TempFiles constructor parameter 2023-02-09 08:20:33 +00:00
Vladimir Sukharev c86f3d1103 Transform native compiler source code to be compiled by K2 bootstrap.
Merge-request: KT-MR-8720
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-02-08 15:37:34 +00:00
Nikita Bobko 62b27b4613 Cleanup: drop KlibIrVersion
Review: https://jetbrains.team/p/kt/reviews/8401
In scope of: KT-55082

Because this version isn't used for anything. We have KotlinAbiVersion
to version the IR format.
2023-02-01 15:13:34 +01:00
Pavel Punegov c9aeadd31f [K/N] Remove old Compiler and Meta Version ^KT-55677 Fixed
* Replace it with KotlinCompilerVersion
* K/N version should be set now with `deployVersion`.
* Cleanup deprecated functions in older versions
 of the Gradle plugin
* Cleanup tests for older versions of compiler downloader

Merge-request: KT-MR-8436
Merged-by: Pavel Punegov <Pavel.Punegov@jetbrains.com>
2023-01-30 13:10:08 +00:00
Svyatoslav Scherbina 322a8a443b Native: add included forward declarations into cinterop klib manifest
This allows the compiler to limit imports from "magic" packages like
cnames.structs to forward declarations actually present in dependent
cinterop klibs.

The manifest already had `exportForwardDeclarations` field, but
- it didn't include Objective-C forward declarations (@class, @protocol)
- it has a slightly different meaning (the export list enables importing
  the listed declarations through the interop package of the library,
  while the include list shouldn't do that), so we better avoid mixing
  them.
2023-01-30 11:00:33 +00:00
Sergey Bogolepov d0778d78b5 [K/N] Fix KT-40426 2023-01-17 17:54:27 +00:00
Sergey Bogolepov c3a250e57a [K/N] Fix KT-55653 2023-01-16 13:26:09 +00:00
Sergey Bogolepov 72637f19dc [K/N][cinterop] Generate members of included categories as class members
This way inheritors of such class would be able to override category
members the same way they can in Objective-C. Also, API surface of
interop libraries should become a little more stable.
2023-01-16 13:26:07 +00:00
Sergey Bogolepov 898dd02d29 [K/N][cinterop] Indexer unit-tests of objcClassesIncludingCategories 2023-01-16 13:26:07 +00:00
Sergey Bogolepov eded880225 [K/N][cinterop] Add location to ObjCCategory
To avoid adding unnecessary included categories to index, we need
to track their location. Also, we can't just implement TypeDeclaration
interface because category is not a type. Thus, we extract `location`
property from TypeDeclaration to LocatableDeclaration and implement it
in ObjCCategory.
2023-01-16 13:26:06 +00:00
Sergey Bogolepov fe8e18cb33 [K/N][cinterop] Improve Imports interface
Extracting `isImported(headerId: HeaderId): Boolean` method allows
mocking this interface in tests
2023-01-16 13:26:06 +00:00
Sergey Bogolepov 2f0bdfc5e2 [K/N] Add objcClassesIncludingCategories cinterop property
It allows to list Objective-C classes that should include
corresponding categories from the same file.
The current implementation is super-simple and slow, but
it is OK since it is not intended to be a general-purpose
solution for now.
2023-01-16 13:26:05 +00:00
Vladimir Sukharev 45de88abae [K/N][KT-39120] Build platform libraries with -fmodules
Merge-request: KT-MR-8175
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-01-13 07:33:42 +00:00