Commit Graph

59 Commits

Author SHA1 Message Date
Yahor Berdnikau 6b19b8b9d0 [Repo] Don't use kotlinOptions in repo build scripts
^KT-63419 In Progress
2024-02-22 14:48:10 +00:00
Alexander Shabalin 4468167a64 [K/N] Move kotlin-native/utilities/basic-utils to compiler/utils 2024-02-08 20:43:11 +00:00
Svyatoslav Scherbina 2e5a9b1416 [K/N] Make cinterop include unused Objective-C forward declarations
Previously, when an Objective-C library had an unused Objective-C
forward declaration (`@class` or `@protocol`), cinterop tool didn't
include it into the resulting klib at all.

This led to a subtle bug (KT-64105). One Obj-C library has unused
Obj-C forward declaration, and another one depends on the first and
uses this forward declaration, e.g. as a function result type.
When building the first cinterop klib, this forward declaration is not
added to `includedForwardDeclarations` in the klib manifest (the
compiler uses this property to decide whether to synthesize the
corresponding class).
When building the second cinterop klib, the forward declaration is not
added to its manifest either, because it is located in the dependency
(and therefore should've been included there).
As a result, the forward declaration is included nowhere, and any
attempt to use it in Kotlin fails, including calling the function from
the second lib.

This commit fixes this bug by including even unused Objective-C forward
declarations, which is consistent with any other kind of declarations
and seems more natural.

^KT-64105 Fixed
2024-01-25 14:06:10 +00:00
Svyatoslav Scherbina 2cdf8cd7b1 Native: support Objective-C instancetype in more cases in cinterop
Objective-C has a special type, "instancetype". Generally, it is a type
that matches the method receiver type. So, if `Foo.foo` method returns
`instancetype`, then `Foo.foo()` would be of type `Foo`, while
`Bar.foo()` would be of type `Bar` (where `Bar` is a subclass of `Foo`).

Surprisingly, `instancetype` can be used not only as a return type, but
also somewhere inside a return type. cinterop wasn't ready for this.

This commit expands implementation of `instancetype` in cinterop to
cover more cases.

^KT-59597 Fixed
2023-12-14 08:57:29 +00:00
Alexander.Likhachev a19bd2ed2e [Build] Migrate most of the build logic from Project.buildDir usage
It's going to be deprecated in Gradle 8.3

There's currently no way to pass a `org.gradle.api.provider.Provider` to the JavaExec.systemProperty or Test.systemProperty. There's a workaround using `org.gradle.process.CommandLineArgumentProvider`, but I intentionally don't rework these calls as Gradle is going to allow passing providers to configure system properties: https://github.com/gradle/gradle/issues/12247#issuecomment-1568427242
^KTI-1473 In Progress
2023-12-07 18:31:06 +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
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
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
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
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
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 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
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
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
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 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
Vladimir Sukharev b883dc5434 [KT-39120] Add "-fmodules" argument support to Cinterop
Merge-request: KT-MR-6921
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2022-11-30 08:46:40 +00:00
Martin Petrov 6c0b4bcfd4 [KT-54284][Native] Produce deterministic klibs from cinterop. (#4979)
Pass in temp-file C sources to clang via stdin instead of by name.
This prevents absolute paths of temp files from being encoded in bitcode.
2022-10-21 12:16:34 +02:00
Johan Bay bc13173ea9 [K/N] cinterop: Do not expand non-constant macros
Expanding macros such as __FILE__ or __TIME__ exposes
arbitrary generated filenames and timestamps from the compiler
pipeline which are not useful for interop and makes the klib
generation non-deterministic. This patch instead redefines
the macros to just map to their name in the properties
available from Kotlin.

Co-authored-by: Johan Bay <jobay@google.com>
2022-10-12 16:54:00 +00:00
Mikhail Glukhikh a22d7aea25 Native: don't set allWarningsAsErrors = true in K2 mode
Related to KT-54123
2022-09-29 15:32:01 +00:00
Alexander Udalov c410c5d3cd Do not reset freeCompilerArgs for some kotlin-native modules
Otherwise common compiler arguments which are set for all modules in the
project in `buildSrc/src/main/kotlin/common-configuration.gradle.kts`
are not applied. The most interesting of those are `-Xuse-k2` (if K2 is
enabled) and `-Xjvm-default=all`.
2022-09-27 11:04:31 +00:00
Rick Clephas 85d4e3071c Include mainFile header for modules def file 2022-07-15 19:14:11 +03:00
Yahor Berdnikau ec545f6273 Add Kotlin SourceDirectorySet as extension
KotlinSourceSet now should be accessed via Kotlin project extension.
Conventions are still available, but not used inside plugins.

^KT-47047 In Progress
2022-06-21 11:26:29 +00:00
Svyatoslav Scherbina fce5ad1358 Native: check return value of clang_saveTranslationUnit 2022-04-20 16:56:41 +00:00
Svyatoslav Scherbina d8b1992fde Native: fix cinterop for Swift-produced Objective-C categories
For some reason, libclang's indexer doesn't index categories with
__attribute__((external_source_symbol(language="Swift",...))),
so we have to additionally enumerate them explicitly.

^KT-49455 Fixed
2022-02-11 12:45:39 +00:00
Igor Chevdar 650d4c78e9 [K/N][interop] A small optimization 2022-01-14 10:29:08 +05:00
Igor Chevdar 993816a400 [K/N][runtime][interop] Refactoring to run cinterop in daemon 2022-01-14 10:29:05 +05:00
Igor Chevdar 353f82f9e6 Revert "[K/N][runtime][interop] Refactoring to run cinterop in daemon"
This reverts commit 47858126da.
2021-11-26 14:05:59 +05:00
Igor Chevdar 07adab561c Revert "[K/N][interop] A small optimization"
This reverts commit 2cbe946331.
2021-11-26 14:02:43 +05:00
Igor Chevdar 2cbe946331 [K/N][interop] A small optimization 2021-11-25 23:42:10 +05:00
Igor Chevdar 47858126da [K/N][runtime][interop] Refactoring to run cinterop in daemon 2021-11-25 23:42:09 +05:00
Sergey Bogolepov ed4fa2c391 [K/N] Fix for KT-48807
Make NS_FORMAT_ARGUMENT(A) a no-op in cinterop because our
Clang doesn't support it for NSAttributedString.
2021-09-27 09:38:02 +00:00
Sergey Bogolepov fd71520d6e Add test for KT-48807 2021-09-27 09:38:01 +00:00
Vyacheslav Gerasimov ab146bd6d4 Build: Fix deprecated Gradle configurations usages
for migration to Gradle 7+ #KTI-559
2021-09-26 18:28:44 +03:00
Svyatoslav Scherbina c9348b3512 Native: improve "could not build module" cinterop error message
Extract diagnostics from imported modules by instructing libclang to
serialize diagnostics to file. Then deserialize this file and use
first compilation errors in the error message.

^KT-35059 Fixed
2021-09-22 07:31:23 +00:00
Svyatoslav Scherbina 12f4cd5aa1 Native: add unit tests for modules support in Interop/Indexer 2021-09-22 07:31:22 +00:00
Svyatoslav Scherbina ae349846e1 Native: support writing unit tests for Interop/Indexer 2021-09-14 10:42:16 +00:00
Vladimir Ivanov 8ba164163c [K/N] cinterop: ignore CXIdxEntity_CXXClass in ObjC header
Unexpected behavior is caused by `@class` declaration in ObjC context.
This entity is not used in CPP context either.
2021-09-09 09:37:05 +00:00
Dmitriy Novozhilov ca9cbf7eb7 Fix warnings in K/Native code 2021-08-03 07:40:57 +00:00
Sergey Bogolepov 66ddd15798 [K/N] Support compiler compilation in MSVC environment
The right way is to add something like KonanTarget.MSVC_X64, but doing
so requires changes throughout whole compiler. It would be especially
painful in HostManager, where we would need to deprecate
KonanTarget.MINGW_X64 as host. Instead we "hack" ClangArgs to compile
for x86_64-pc-windows-msvc instead of x86_64-pc-windows-gnu in JNI case.

CI may contain custom MSVC and Windows Kit installation path, so we
should support it. Things might break when machine has several MSVC
installed (at custom and default path), but it sounds more like
incorrect environment setup problem than ours.
2021-08-03 05:42:05 +00:00
Sergey Bogolepov a78fcd6b64 [K/N] Separate ClangArgs for jni and native
Since LLVM for Windows is now native instead on MinGW, we have to
compile code in a different environment in case of JNI. This commits
just separates ClangArgs into two subclasses without actual behavior
changes.
2021-08-03 05:42:05 +00:00
Sergey Bogolepov 493fa1c1e3 [K/N] Update Clang stubs for 11.1.0
Removed hacks for CXType_ExtVector type because now it is included in
Clang C API.
2021-08-03 05:42:01 +00:00
Sergey Bogolepov 36386de9a2 [Native] Drop explicit -fPIC flag setup
We don't need to explicitly set -fPIC flag everywhere
because since d82109cc92
it is set by default for all ClangArgs users.
2021-06-11 12:18:14 +00:00
Vladimir Ivanov 5a0f113e6d [cinterop] Fix type annotation for struct containing anonymous union … (#4289) 2021-05-18 14:34:56 +03:00
Alexander Gorshenev 887032667d [Kotlin/Native][Interop] Skia interop plugin for cinterop 2021-04-29 21:43:26 +03:00
Vladimir Ivanov 5f582ad28a [Kotlin/Native][Interop] Provide pure c wrappers over cpp for skia interop 2021-04-29 21:43:25 +03:00
Sergey Bogolepov 645014092c Add a mention of KT-46231. 2021-04-21 15:14:33 +07:00