Skip to content

Commit a5b2854

Browse files
committed
grpc-native: Working linux arm64 and x64
1 parent 4c36ab4 commit a5b2854

22 files changed

+355
-146
lines changed

cinterop-c/.bazelrc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
build --experimental_cc_static_library --experimental_platform_in_output_dir
2-
build --action_env=KONAN_HOME
3-
build --host_action_env=KONAN_HOME
4-
build --cxxopt=-std=c++17
5-
build --host_cxxopt=-std=c++17
62

73
build:release --compilation_mode=opt --strip=always
84

@@ -11,6 +7,6 @@ build:macos_x64 --platforms=@build_bazel_apple_support//platforms:macos_x86_64 -
117
build:ios_arm64 --platforms=@build_bazel_apple_support//platforms:ios_arm64 --apple_platform_type=ios
128
build:ios_simulator_arm64 --platforms=@build_bazel_apple_support//platforms:ios_sim_arm64 --apple_platform_type=ios
139
build:ios_x64 --platforms=@build_bazel_apple_support//platforms:ios_x86_64 --apple_platform_type=ios
14-
build:linux_arm64 --platforms=@toolchains_llvm//platforms:linux-aarch64
1510

16-
build:linux_x64 --platforms=@toolchains_llvm//platforms:linux-x86_64
11+
build:linux_arm64 --platforms=//platforms:linux_arm64
12+
build:linux_x64 --platforms=//platforms:linux_x86_64

cinterop-c/MODULE.bazel

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ bazel_dep(
2929

3030
# Linux toolchain setup (cross-compile)
3131

32-
#TODO: Remove
33-
bazel_dep(name = "toolchains_llvm", version = "1.4.0")
34-
3532
register_toolchains(
3633
"//toolchain:toolchain_linux_x64_konan",
37-
# "//toolchain:exec_macos_konan",
34+
"//toolchain:toolchain_linux_arm64_konan",
3835
)

cinterop-c/MODULE.bazel.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cinterop-c/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,12 @@ The binary can be updated by running
2121
```bash
2222
./gradlew :grpc:grpc-core:buildDependencyCLibGrpc_fat_iosArm64
2323
```
24+
25+
### Compiling for Linux
26+
27+
To produce K/N compatible static libraries, we use the Konan toolchain for compilation.
28+
The Bazel toolchain is specified in `toolchain/` and requires the user to specify the
29+
`KONAN_HOME` variable like
30+
```bash
31+
bazel build //:protowire --config=linux_arm64 --define=KONAN_HOME=$HOME/.konan/kotlin-native-prebuilt-macos-aarch64-2.2.10
32+
```

cinterop-c/build_target.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,28 @@ trap 'echo "ERROR: Build failed at ${BASH_SOURCE}:${LINENO}" >&2' ERR
99
# Builds a static library for a specific platform (os/arch).
1010
#
1111
# Usage:
12-
# ./build_target.sh //path:libtarget dest konan_target
12+
# ./build_target.sh //path:libtarget dest konan_target konan_home
1313
# Example:
14-
# ./build_target.sh :protowire_static out/libprotowire_static.ios_arm64.a ios_arm64
14+
# ./build_target.sh :protowire_static out/libprotowire_static.ios_arm64.a ios_arm64 \
15+
# $HOME/.konan/kotlin-native-prebuilt-macos-aarch64-2.2.10
1516
#
1617
# The example will produce ./out/libprotowire_static.ios_arm64.a
1718

1819
LABEL="${1:?need bazel target label}"
1920
DST="${2:?need output destination}"
20-
KONANT_TARGET="${3:?need the konan_target name}"
21+
KONAN_TARGET="${3:?need the konan_target name}"
22+
KONAN_HOME="${4:?need the konan_home path}"
2123

2224
CONFIG=release
2325

24-
mkdir -p $(dirname "$DST")
26+
mkdir -p "$(dirname "$DST")"
2527

2628
echo "==> Building $LABEL to $DST" >&2
27-
bazel build "$LABEL" --config="$KONANT_TARGET" --config="$CONFIG" >/dev/null
29+
KONAN_DEP="--define=KONAN_DEPS=/Users/johannes.zottele/.konan//dependencies"
30+
bazel build "$LABEL" --config="$KONAN_TARGET" --config="$CONFIG" $KONAN_DEP "--define=KONAN_HOME=$KONAN_HOME" >/dev/null
2831

2932
# Ask Bazel what file(s) this target produced under this platform
30-
out="$(bazel cquery "$LABEL" --config="$KONANT_TARGET" --config="$CONFIG" --output=files | head -n1)"
33+
out="$(bazel cquery "$LABEL" --config="$KONAN_TARGET" --config="$CONFIG" $KONAN_DEP "--define=KONAN_HOME=$KONAN_HOME" --output=files | head -n1)"
3134
[[ -n "$out" ]] || { echo "No output for $LABEL ($SHORT)"; exit 1; }
3235

3336
cp -f "$out" "$DST"

cinterop-c/include/kgrpc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include <stdbool.h>
1111
#include <grpc/grpc.h>
12-
#include <version>
1312

1413
#ifdef __cplusplus
1514
extern "C" {

cinterop-c/platforms/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
platform(
2+
name = "linux_x86_64",
3+
constraint_values = [
4+
"@platforms//os:linux",
5+
"@platforms//cpu:x86_64",
6+
],
7+
)
8+
9+
platform(
10+
name = "linux_arm64",
11+
constraint_values = [
12+
"@platforms//os:linux",
13+
"@platforms//cpu:aarch64",
14+
],
15+
)
159 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fcd6d34d6ea4adbf935d0fcbacef91666427bb5f6386fb0eb37b21a460ecbba5
1+
5eab3ed3bebb20944f053cacf34c755173832ab65e1c7f199a5d70fb3f1e7d55
-2.01 MB
Binary file not shown.

0 commit comments

Comments
 (0)