Skip to content

Commit 9240163

Browse files
authored
grpc: Update llvm-19 Konan dependency path after Kotlin compiler upgrade (#522)
1 parent 8531f0e commit 9240163

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

cinterop-c/README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ It uses the Bazel build system and contains two libraries: protowire and kgrpc.
33

44
### Protowire
55

6-
Is a thin layer over the CodedStream implementation of the C++ protobuf library.
7-
To build (e.g. ios_arm64) run
6+
Is a thin layer over the CodedStream implementation of the C++ protobuf library.
7+
To build (e.g. ios_arm64) run
8+
89
```bash
910
bazel build :protowire_fat --config=ios_arm64 --config=release
1011
```
@@ -15,9 +16,10 @@ We are using the gRPC-core library, which already exports its API with a C ABI.
1516
Therefore, the KgRPC library is almost empty primarily used for convenient functions
1617
or API that is not exposed by the C API.
1718

18-
Because the gRPC takes a while to build when compiling for multiple targets, we store
19+
Because the gRPC takes a while to build when compiling for multiple targets, we store
1920
it as a prebuilt static (fat) in `prebuilt-deps/grpc_fat`.
2021
The binary can be updated by running
22+
2123
```bash
2224
./gradlew :grpc:grpc-core:buildDependencyCLibGrpc_fat_iosArm64
2325
```
@@ -27,6 +29,32 @@ The binary can be updated by running
2729
To produce K/N compatible static libraries, we use the Konan toolchain for compilation.
2830
The Bazel toolchain is specified in `toolchain/` and requires the user to specify the
2931
`KONAN_HOME` variable like
32+
3033
```bash
3134
bazel build //:protowire --config=linux_arm64 --define=KONAN_HOME=$HOME/.konan/kotlin-native-prebuilt-macos-aarch64-2.2.10
32-
```
35+
```
36+
37+
#### Upgrading the Kotlin Compiler Version
38+
39+
When we upgrade the project's Kotlin compiler version, compilation for Linux will fail.
40+
Bazel will throw an error like
41+
42+
```
43+
[1,351 / 1,353] Compiling src/kgrpc.cpp; 1s darwin-sandbox
44+
ERROR: /Users/jozott/development/jetbrains/kotlinx-rpc/cinterop-c/BUILD.bazel:11:11: Compiling src/kgrpc.cpp failed: absolute path inclusion(s) found in rule '//:kgrpc_lib':
45+
the source file 'src/kgrpc.cpp' includes the following non-builtin files with absolute paths (if these are builtin files, make sure these paths are in your toolchain):
46+
/Users/jozott/development/jetbrains/kotlinx-rpc/cinterop-c/BUILD.bazel:11:11: Compiling src/kgrpc.cpp failed: absolute path inclusion(s) found in rule '//:kgrpc_lib':
47+
48+
/Users/jozott/.konan/dependencies/llvm-19-aarch64-macos-essentials-79/bin/clang ... -c src/kgrpc.cpp -o bazel-out/linux_arm64-opt/bin/_objs/kgrpc_lib/kgrpc.o
49+
'/Users/jozott/.konan/dependencies/llvm-19-aarch64-macos-essentials-79/lib/clang/19/include/stdbool.h'
50+
'/Users/jozott/.konan/dependencies/llvm-19-aarch64-macos-essentials-79/lib/clang/19/include/stdint.h'
51+
...
52+
```
53+
54+
To fix this, we need to adjust the clang built-in include paths defined in the `toolchain/cc_toolchain_config.bzl` file.
55+
In the case above, the path at `cxx_builtin_include_directories` must be replaced by
56+
`deps + "llvm-19-aarch64-macos-essentials-79/lib/clang/19/include"`.
57+
This must be done for aarch64 and x86_64 separately.
58+
The current LLVM toolchain bundle paths can be found in
59+
[kotlin/kotlin-native/gradle.properties](https://github.com/JetBrains/kotlin/blob/master/kotlin-native/gradle.properties)
60+
of the Kotlin repository.

cinterop-c/toolchain/cc_toolchain_config.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,14 @@ def _impl(ctx):
193193
tool_paths = tool_paths,
194194
features = features,
195195
cxx_builtin_include_directories = [
196+
# Built-in include directories from the toolchain.
197+
# Only one will be available on the host (x64 or arm64).
198+
# These paths must be updated after each upgrade of the project's Kotlin compiler version.
199+
# After upgrading the Kotlin compiler, the C compiler will throw an error that certain includes are not
200+
# are not part of the built-in include paths. In this case, replace the below path with the printed one.
201+
# See the cinterop-c/README.md for more details.
196202
deps + "/llvm-19-aarch64-macos-essentials-75/lib/clang/19/include",
203+
deps + "/llvm-19-x86_64-macos-essentials-103/lib/clang/19/include",
197204
] + includes,
198205
)
199206

0 commit comments

Comments
 (0)