How to use default system clang\llvm for kotlin-native?

Hello.
I’m trying to compile hello-world.kt with kotlin-native compiler. But it start to fetch its dependencies.
Could I use default system clang\llvm for it? My system (debian linux) has clang-6.0/llvm-6.0 installed.
Thank you.

konanc -o hello-native hello-native.kt
Downloading native dependencies (LLVM, sysroot etc). This is a one-time action performed only on the first run of the compiler.
Downloading dependency: https://download.jetbrains.com/kotlin/native/clang-llvm-5.0.0-linux-x86-64.tar.gz

konanc -version
info: kotlinc-native 1.2.50-dev-515 (JRE 1.8.0_172-b11)
Kotlin/Native: 0.7

You really should read documentation first:

If you already downloaded the compiler manually you may specify the path to its root directory using konan.home project property (e.g. in gradle.properties).
konan.home=/home/user/kotlin-native-0.5
In this case the compiler will not be downloaded by the plugin.

You don’t understand my question.

Let’s start again:

  1. My system already has clang6.0/llvm6.0.

apt list --installed | grep llvm
libllvm6.0/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] libllvm6.0-dbgsym/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] llvm-6.0/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] llvm-6.0-dbgsym/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] llvm-6.0-dev/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] llvm-6.0-dev-dbgsym/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] llvm-6.0-doc/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 all [installed] llvm-6.0-examples/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 all [installed] llvm-6.0-runtime/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] llvm-6.0-runtime-dbgsym/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] llvm-6.0-tools/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] llvm-6.0-tools-dbgsym/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed]

apt list --installed | grep clang
clang-6.0/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] clang-6.0-dbgsym/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] clang-6.0-doc/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 all [installed] clang-6.0-examples/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] clang-format-6.0/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] clang-format-6.0-dbgsym/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] clang-tidy-6.0/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] clang-tidy-6.0-dbgsym/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] clang-tools-6.0/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] clang-tools-6.0-dbgsym/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] libclang-6.0-dev/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] libclang-common-6.0-dev/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] libclang-common-6.0-dev-dbgsym/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] libclang1-6.0/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] libclang1-6.0-dbgsym/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed] python-clang-6.0/unknown,now 1:6.0.1~svn333623-1~exp1~20180604223356.84 amd64 [installed]

  1. My system has downloaded and installed kotlin-native compiler.
    /opt/kotlin-native-linux-0.7

  2. My system has environment variables for kotlin-native compiler.
    env | grep KOTLIN
    KOTLIN_HOME=/opt/kotlin-native-linux-0.7
    env | grep PATH
    PATH=...:/opt/kotlin-native-linux-0.7/bin:...

  3. When I try to do konanc -o hello-native hello-native.kt
    kotlin-native compiler begin to download clang-llvm-5.0.0-linux-x86-64.tar.gz and extract it to the home directory ~/.konan/dependencies/clang-llvm-5.0.0-linux-x86-64.
    Why? Could It use my system default clang6.0/llvm6.0?

I do understand. The problem is that we are talking about kotlin native compiler, not LLVM. It is based on llvm, but I am not sure that it can use just any user provided instance of llvm compiler, at least it is probably not supported. If you really want to use your own llvm, then you should download your own instance of kotlin compiler and then replaces LLVM references inside by those of your own llvm. Then you can follow the documentation and use custom kotlin native distribution you created instead of downloading something new.

1 Like

@superriva did you found a way to replace the default LLVM? I would like to use GitHub - espressif/llvm-project: Fork of LLVM with Xtensa specific patches. To be upstreamed. . There seems no documentation how to create a custom kotlin-native distribution or add a target platform.

I am interested in this as well.

The end goal is to develop EPS32 code in Kotlin/Native and compile it go LLVM bitcode and use espressif/llvm to compile it to esp32 target.