Hi, I'm trying to link a Rust static library targe...
# kotlin-native
c
Hi, I'm trying to link a Rust static library targeting MinGW to a Kotlin/Native library on macOS. Since Rust builds library with the `-exclude-symbols:___chkstk_ms`` option which seems to not be known by the
lld-link
automatically installed by Konan (the one in
~/.konan/dependencies/apple-llvm-20200714-macos-aarch64-essentials
, I get an error like the following:
Copy code
e: /Users/(user)/.konan/dependencies/apple-llvm-20200714-macos-aarch64-essentials/bin/clang++ invocation reported errors

The /Users/(user)/.konan/dependencies/apple-llvm-20200714-macos-aarch64-essentials/bin/clang++ command returned non-zero exit code: 1.
output:
lld-link: warning: ignoring unknown argument: -exclude-symbols:___chkstk_ms
lld-link: error: -exclude-symbols:___chkstk_ms is not allowed in .drectve
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

FAILURE: Build failed with an exception.
I want to use another version of
clang
, Is there a way to use
clang
specified by the user when linking?
a
I want to use K/N with Clang 16, which is installed on my machine. Is there any way to use a user-specified version of Clang when using K/N?
If I understand your question correctly, then the answer is no, K/N must use the version of clang/gcc/etc in the Konan dir
😢 1
c
I found this file https://github.com/JetBrains/kotlin/blob/master/kotlin-native/konan/konan.properties, maybe I can modify this file somehow...
image.png
After several experiments, I'll leave some comments here about the results 😄
a
Hey, I was pointed to this chat. I am able to use a different Linker. So if you issue is just with the linker than simply override the konan.properties
linker.macos_x64-linux_x64
or which ever you need property. With that a different Linker version will be used, but the clang compiler stays the same (11.1.0)
This worked at least for me, since I had to use ld.lld linker of LLVM 17.x.x Therefore I used the tools/llvm_builder/package.py script, pointed to a newer version of the apple repository and build the llvm backend. I pointed the konan.properties to the ld.lld of that build directory. Updating the entire LLVM Backend in the repository is a massive task, with a lot of fixes for deprecations. I assume thats why no one ever did this yet.
c
@Anton Saatze Wow, thanks for the comment! I built my own version of LLVM (17.0.6) following the docs in
kotlin-native
, but for some reason Gradle crashes while running the compiler. I'll try with that option. Thanks! 😄
Copy code
mingwX64().binaries.executable {
    compilerOptions {
        freeCompilerArgs.add("-Xoverride-konan-properties=linker.macos_arm64-mingw_x64=/opt/homebrew/opt/llvm/bin/ld.lld")
    }
}
Overriding the
linkter.<host>-<target>
option did work. @Anton Saatze Thanks for the comment again!
🎉 2