Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cinterop-c/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# we build the cc_static library bundled with all dependencies
build --experimental_cc_static_library
build --experimental_cc_static_library --experimental_platform_in_output_dir

build:release --compilation_mode=opt --strip=always
2 changes: 2 additions & 0 deletions cinterop-c/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
/.aswb/
/.clwb/
.idea/

out/
2 changes: 1 addition & 1 deletion cinterop-c/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cc_library(
includes = ["include"],
visibility = ["//visibility:public"],
deps = [
"@com_github_grpc_grpc//:grpc"
"@com_github_grpc_grpc//:grpc",
],
)

Expand Down
5 changes: 4 additions & 1 deletion cinterop-c/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ bazel_dep(
version = "0.1.1",
)

# required to build for apple targets (like iOS)
bazel_dep(name = "apple_support", version = "1.22.1", repo_name = "build_bazel_apple_support")

# Protobuf
bazel_dep(
name = "protobuf",
Expand All @@ -19,6 +22,6 @@ bazel_dep(
# gRPC library
bazel_dep(
name = "grpc",
version = "1.73.1",
version = "1.74.1",
repo_name = "com_github_grpc_grpc",
)
34 changes: 23 additions & 11 deletions cinterop-c/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions cinterop-c/build_all_targets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
#
# Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
#

set -Eeuo pipefail
trap 'echo "ERROR: Build failed at ${BASH_SOURCE}:${LINENO}" >&2' ERR

# Builds a static library for all platforms (os/arch).
#
# Usage:
# ./build_all.sh //path:libtarget out_dir
# Example:
# ./build_all.sh :protowire_static out


LABEL="${1:?need bazel label}"
OUTDIR="${2:?need output dir}"
mkdir -p "$OUTDIR"

# Compilation Config
CONFIG=release

# Platform labels
MACOS=@build_bazel_apple_support//platforms:macos_arm64
IOS_DEV=@build_bazel_apple_support//platforms:ios_arm64
IOS_SIM=@build_bazel_apple_support//platforms:ios_sim_arm64
WATCHOS_ARM64_32_DEV=@build_bazel_apple_support//platforms:watchos_arm64_32
WATCHOS_ARM64_SIM=@build_bazel_apple_support//platforms:watchos_arm64

build_one() {
local plat="$1" short="$2" os="$3"
echo "==> Building $LABEL for $short" >&2
bazel build "$LABEL" --platforms="$plat" --apple_platform_type="$os" --config="$CONFIG" --announce_rc >/dev/null

# Ask Bazel what file(s) this target produced under this platform
local out
out="$(bazel cquery "$LABEL" --platforms="$plat" --apple_platform_type="$os" --config="$CONFIG" --output=files | head -n1)"
[[ -n "$out" ]] || { echo "No output for $LABEL ($short)"; exit 1; }

local dst="$OUTDIR/$(basename "$out" .a).${short}.a"
cp -f "$out" "$dst"
}

build_one "$MACOS" macos_arm64 macos
build_one "$IOS_DEV" ios_arm64 ios
build_one "$IOS_SIM" ios_sim_arm64 ios
# TODO: Uncomment when activating WatchOS
#build_one "$WATCHOS_ARM64_32_DEV" watchos_arm64_32 watchos
#build_one "$WATCHOS_ARM64_SIM" watchos_sim_arm64 watchos

echo "Done. Artifacts in $OUTDIR"
7 changes: 3 additions & 4 deletions gradle-conventions/src/main/kotlin/util/cinterop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.DefaultCInteropSettings
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.tasks.CInteropProcess
import java.io.File
import kotlin.io.resolve

// works with the cinterop-c Bazel project
fun KotlinMultiplatformExtension.configureCLibCInterop(
Expand Down Expand Up @@ -46,9 +45,9 @@ fun KotlinMultiplatformExtension.configureCLibCInterop(
val buildCinteropCLib = project.tasks.register<Exec>("buildCinteropCLib") {
group = "build"
workingDir = cinteropCLib
commandLine("bash", "-c", "bazel build $bazelTask --config=release")
inputs.files(project.fileTree(cinteropCLib) { exclude("bazel-*/**") })
outputs.dir(cinteropCLib.resolve("bazel-bin"))
commandLine("bash", "-c", "${cinteropCLib}/build_all_targets.sh $bazelTask out")
inputs.files(project.fileTree(cinteropCLib) { exclude("bazel-*/**", "out/**") })
outputs.dir(cinteropCLib.resolve("out"))

dependsOn(checkBazel)
}
Expand Down
4 changes: 1 addition & 3 deletions grpc/grpc-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ kotlin {
cinteropCLib.resolve("include"),
cinteropCLib.resolve("bazel-cinterop-c/external/grpc+/include"),
)
extraOpts(
"-libraryPath", "${cinteropCLib.resolve("bazel-out/darwin_arm64-opt/bin")}",
)
extraOpts("-libraryPath", "${cinteropCLib.resolve("out")}")
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions grpc/grpc-core/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
kotlinx.rpc.exclude.wasmWasi=true
kotlinx.rpc.exclude.js=true
kotlinx.rpc.exclude.wasmJs=true
kotlinx.rpc.exclude.iosArm64=true
kotlinx.rpc.exclude.iosX64=true
kotlinx.rpc.exclude.iosSimulatorArm64=true
kotlinx.rpc.exclude.linuxArm64=true
kotlinx.rpc.exclude.linuxX64=true
kotlinx.rpc.exclude.macosX64=true
Expand All @@ -15,7 +13,8 @@ kotlinx.rpc.exclude.tvosArm64=true
kotlinx.rpc.exclude.tvosSimulatorArm64=true
kotlinx.rpc.exclude.tvosX64=true
kotlinx.rpc.exclude.watchosArm32=true
kotlinx.rpc.exclude.watchosArm64=true
kotlinx.rpc.exclude.watchosDeviceArm64=true
kotlinx.rpc.exclude.watchosSimulatorArm64=true
kotlinx.rpc.exclude.watchosX64=true
# TODO: Remove once we ant to activate WatchOS (these two targets are already prepared for activation)
kotlinx.rpc.exclude.watchosArm64=true
kotlinx.rpc.exclude.watchosSimulatorArm64=true
8 changes: 7 additions & 1 deletion grpc/grpc-core/src/nativeInterop/cinterop/libkgrpc.def
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ headerFilter= kgrpc.h grpc/slice.h grpc/byte_buffer.h grpc/grpc.h \
noStringConversion = grpc_slice_from_copied_buffer my_grpc_slice_from_copied_buffer
strictEnums = grpc_status_code grpc_connectivity_state grpc_call_error

staticLibraries = libkgrpc_static.a

staticLibraries.macos_arm64 = libkgrpc_static.macos_arm64.a
staticLibraries.ios_arm64 = libkgrpc_static.ios_arm64.a
staticLibraries.ios_simulator_arm64 = libkgrpc_static.ios_sim_arm64.a
# TODO: Uncomment when activating WatchOS
# staticLibraries.watchos_arm64 = libkgrpc_static.watchos_arm64_32.a
# staticLibraries.watchos_simulator_arm64 = libkgrpc_static.watchos_sim_arm64.a
4 changes: 1 addition & 3 deletions protobuf/protobuf-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ kotlin {
includeDirs(
cinteropCLib.resolve("include")
)
extraOpts(
"-libraryPath", "${cinteropCLib.resolve("bazel-out/darwin_arm64-opt/bin")}",
)
extraOpts("-libraryPath", "${cinteropCLib.resolve("out")}")
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions protobuf/protobuf-core/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
kotlinx.rpc.exclude.wasmWasi=true
kotlinx.rpc.exclude.js=true
kotlinx.rpc.exclude.wasmJs=true
kotlinx.rpc.exclude.iosArm64=true
kotlinx.rpc.exclude.iosX64=true
kotlinx.rpc.exclude.iosSimulatorArm64=true
kotlinx.rpc.exclude.linuxArm64=true
kotlinx.rpc.exclude.linuxX64=true
kotlinx.rpc.exclude.macosX64=true
Expand All @@ -15,7 +13,8 @@ kotlinx.rpc.exclude.tvosArm64=true
kotlinx.rpc.exclude.tvosSimulatorArm64=true
kotlinx.rpc.exclude.tvosX64=true
kotlinx.rpc.exclude.watchosArm32=true
kotlinx.rpc.exclude.watchosArm64=true
kotlinx.rpc.exclude.watchosDeviceArm64=true
kotlinx.rpc.exclude.watchosSimulatorArm64=true
kotlinx.rpc.exclude.watchosX64=true
# TODO: Remove once we ant to activate WatchOS (these two targets are already prepared for activation)
kotlinx.rpc.exclude.watchosArm64=true
kotlinx.rpc.exclude.watchosSimulatorArm64=true
Loading
Loading