diff --git a/cinterop-c/.bazelrc b/cinterop-c/.bazelrc index f8ad4585f..20da163f7 100644 --- a/cinterop-c/.bazelrc +++ b/cinterop-c/.bazelrc @@ -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 \ No newline at end of file diff --git a/cinterop-c/.gitignore b/cinterop-c/.gitignore index d5a638ef2..4b23e2e04 100644 --- a/cinterop-c/.gitignore +++ b/cinterop-c/.gitignore @@ -12,3 +12,5 @@ /.aswb/ /.clwb/ .idea/ + +out/ \ No newline at end of file diff --git a/cinterop-c/BUILD.bazel b/cinterop-c/BUILD.bazel index 4bb16b167..6383bade5 100644 --- a/cinterop-c/BUILD.bazel +++ b/cinterop-c/BUILD.bazel @@ -15,7 +15,7 @@ cc_library( includes = ["include"], visibility = ["//visibility:public"], deps = [ - "@com_github_grpc_grpc//:grpc" + "@com_github_grpc_grpc//:grpc", ], ) diff --git a/cinterop-c/MODULE.bazel b/cinterop-c/MODULE.bazel index a9d45ecc3..a749399ca 100644 --- a/cinterop-c/MODULE.bazel +++ b/cinterop-c/MODULE.bazel @@ -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", @@ -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", ) diff --git a/cinterop-c/MODULE.bazel.lock b/cinterop-c/MODULE.bazel.lock index 09e36896c..12f0973a3 100644 --- a/cinterop-c/MODULE.bazel.lock +++ b/cinterop-c/MODULE.bazel.lock @@ -15,12 +15,15 @@ "https://bcr.bazel.build/modules/abseil-cpp/20240722.0/MODULE.bazel": "88668a07647adbdc14cb3a7cd116fb23c9dda37a90a1681590b6c9d8339a5b84", "https://bcr.bazel.build/modules/abseil-cpp/20250127.0/MODULE.bazel": "d1086e248cda6576862b4b3fe9ad76a214e08c189af5b42557a6e1888812c5d5", "https://bcr.bazel.build/modules/abseil-cpp/20250127.1/MODULE.bazel": "c4a89e7ceb9bf1e25cf84a9f830ff6b817b72874088bf5141b314726e46a57c1", - "https://bcr.bazel.build/modules/abseil-cpp/20250127.1/source.json": "03c90ee57977264436d3231676dcddae116c4769a5d02b6fc16c2c9e019b583a", + "https://bcr.bazel.build/modules/abseil-cpp/20250512.0/MODULE.bazel": "c4d02dd22cd87458516655a45512060246ee2a4732f1fbe948a5bd9eb614e626", + "https://bcr.bazel.build/modules/abseil-cpp/20250512.1/MODULE.bazel": "d209fdb6f36ffaf61c509fcc81b19e81b411a999a934a032e10cd009a0226215", + "https://bcr.bazel.build/modules/abseil-cpp/20250512.1/source.json": "d725d73707d01bb46ab3ca59ba408b8e9bd336642ca77a2269d4bfb8bbfd413d", "https://bcr.bazel.build/modules/apple_support/1.11.1/MODULE.bazel": "1843d7cd8a58369a444fc6000e7304425fba600ff641592161d9f15b179fb896", "https://bcr.bazel.build/modules/apple_support/1.13.0/MODULE.bazel": "7c8cdea7e031b7f9f67f0b497adf6d2c6a2675e9304ca93a9af6ed84eef5a524", "https://bcr.bazel.build/modules/apple_support/1.15.1/MODULE.bazel": "a0556fefca0b1bb2de8567b8827518f94db6a6e7e7d632b4c48dc5f865bc7c85", "https://bcr.bazel.build/modules/apple_support/1.17.1/MODULE.bazel": "655c922ab1209978a94ef6ca7d9d43e940cd97d9c172fb55f94d91ac53f8610b", - "https://bcr.bazel.build/modules/apple_support/1.17.1/source.json": "6b2b8c74d14e8d485528a938e44bdb72a5ba17632b9e14ef6e68a5ee96c8347f", + "https://bcr.bazel.build/modules/apple_support/1.22.1/MODULE.bazel": "90bd1a660590f3ceffbdf524e37483094b29352d85317060b2327fff8f3f4458", + "https://bcr.bazel.build/modules/apple_support/1.22.1/source.json": "2bc34da8d0ebc4c4132c8b26db766ca1b86bbcf26dea94b94aa1cd73e2623aeb", "https://bcr.bazel.build/modules/aspect_bazel_lib/1.31.2/MODULE.bazel": "7bee702b4862612f29333590f4b658a5832d433d6f8e4395f090e8f4e85d442f", "https://bcr.bazel.build/modules/aspect_bazel_lib/1.38.0/MODULE.bazel": "6307fec451ba9962c1c969eb516ebfe1e46528f7fa92e1c9ac8646bef4cdaa3f", "https://bcr.bazel.build/modules/aspect_bazel_lib/1.40.3/MODULE.bazel": "668e6bcb4d957fc0e284316dba546b705c8d43c857f87119619ee83c4555b859", @@ -38,6 +41,7 @@ "https://bcr.bazel.build/modules/bazel_features/1.19.0/MODULE.bazel": "59adcdf28230d220f0067b1f435b8537dd033bfff8db21335ef9217919c7fb58", "https://bcr.bazel.build/modules/bazel_features/1.21.0/MODULE.bazel": "675642261665d8eea09989aa3b8afb5c37627f1be178382c320d1b46afba5e3b", "https://bcr.bazel.build/modules/bazel_features/1.23.0/MODULE.bazel": "fd1ac84bc4e97a5a0816b7fd7d4d4f6d837b0047cf4cbd81652d616af3a6591a", + "https://bcr.bazel.build/modules/bazel_features/1.27.0/MODULE.bazel": "621eeee06c4458a9121d1f104efb80f39d34deff4984e778359c60eaf1a8cb65", "https://bcr.bazel.build/modules/bazel_features/1.3.0/MODULE.bazel": "cdcafe83ec318cda34e02948e81d790aab8df7a929cec6f6969f13a489ccecd9", "https://bcr.bazel.build/modules/bazel_features/1.30.0/MODULE.bazel": "a14b62d05969a293b80257e72e597c2da7f717e1e69fa8b339703ed6731bec87", "https://bcr.bazel.build/modules/bazel_features/1.30.0/source.json": "b07e17f067fe4f69f90b03b36ef1e08fe0d1f3cac254c1241a1818773e3423bc", @@ -97,7 +101,8 @@ "https://bcr.bazel.build/modules/googletest/1.14.0/MODULE.bazel": "cfbcbf3e6eac06ef9d85900f64424708cc08687d1b527f0ef65aa7517af8118f", "https://bcr.bazel.build/modules/googletest/1.15.2/MODULE.bazel": "6de1edc1d26cafb0ea1a6ab3f4d4192d91a312fd2d360b63adaa213cd00b2108", "https://bcr.bazel.build/modules/googletest/1.16.0/MODULE.bazel": "a175623c69e94fca4ca7acbc12031e637b0c489318cd4805606981d4d7adb34a", - "https://bcr.bazel.build/modules/googletest/1.16.0/source.json": "dd011b202542efcd4c0e3df34b1558d41598c6f287846728315ded5f7984b77a", + "https://bcr.bazel.build/modules/googletest/1.17.0/MODULE.bazel": "dbec758171594a705933a29fcf69293d2468c49ec1f2ebca65c36f504d72df46", + "https://bcr.bazel.build/modules/googletest/1.17.0/source.json": "38e4454b25fc30f15439c0378e57909ab1fd0a443158aa35aec685da727cd713", "https://bcr.bazel.build/modules/grpc-java/1.62.2/MODULE.bazel": "99b8771e8c7cacb130170fed2a10c9e8fed26334a93e73b42d2953250885a158", "https://bcr.bazel.build/modules/grpc-java/1.66.0/MODULE.bazel": "86ff26209fac846adb89db11f3714b3dc0090fb2fb81575673cc74880cda4e7e", "https://bcr.bazel.build/modules/grpc-java/1.66.0/source.json": "f841b339ff8516c86c3a5272cd053194dd0cb2fdd63157123835e1157a28328d", @@ -109,8 +114,9 @@ "https://bcr.bazel.build/modules/grpc/1.63.1.bcr.1/MODULE.bazel": "d7b9fef03bd175e6825237b521b18a3c29f1ac15f8aa52c8a1a0f3bd8f33d54b", "https://bcr.bazel.build/modules/grpc/1.66.0.bcr.2/MODULE.bazel": "0fa2b0fd028ce354febf0fe90f1ed8fecfbfc33118cddd95ac0418cc283333a0", "https://bcr.bazel.build/modules/grpc/1.66.0.bcr.3/MODULE.bazel": "f6047e89faf488f5e3e65cb2594c6f5e86992abec7487163ff6b623526e543b0", - "https://bcr.bazel.build/modules/grpc/1.73.1/MODULE.bazel": "69737e1dab5c36fd12daf0a0f9d3adaaf983c8422052a58a3a652454435975b4", - "https://bcr.bazel.build/modules/grpc/1.73.1/source.json": "38ddb26495a5241da802af9b80c51bf0cbc13d06dce4a1e68e2f898d9d981ea0", + "https://bcr.bazel.build/modules/grpc/1.71.0/MODULE.bazel": "7fcab2c05530373f1a442c362b17740dd0c75b6a2a975eec8f5bf4c70a37928a", + "https://bcr.bazel.build/modules/grpc/1.74.1/MODULE.bazel": "09523be10ba2bfd999683671d0f8f22fb5b20ec77ad89b05ef58ff19a1b65c82", + "https://bcr.bazel.build/modules/grpc/1.74.1/source.json": "8508bcf9bae1b7c647a594e13461ce192240fcdbb409c2741444322d47d01f98", "https://bcr.bazel.build/modules/jsoncpp/1.9.5/MODULE.bazel": "31271aedc59e815656f5736f282bb7509a97c7ecb43e927ac1a37966e0578075", "https://bcr.bazel.build/modules/jsoncpp/1.9.6/MODULE.bazel": "2f8d20d3b7d54143213c4dfc3d98225c42de7d666011528dc8fe91591e2e17b0", "https://bcr.bazel.build/modules/jsoncpp/1.9.6/source.json": "a04756d367a2126c3541682864ecec52f92cdee80a35735a3cb249ce015ca000", @@ -121,10 +127,12 @@ "https://bcr.bazel.build/modules/nlohmann_json/3.11.3/MODULE.bazel": "87023db2f55fc3a9949c7b08dc711fae4d4be339a80a99d04453c4bb3998eefc", "https://bcr.bazel.build/modules/nlohmann_json/3.11.3/source.json": "296c63a90c6813e53b3812d24245711981fc7e563d98fe15625f55181494488a", "https://bcr.bazel.build/modules/nlohmann_json/3.6.1/MODULE.bazel": "6f7b417dcc794d9add9e556673ad25cb3ba835224290f4f848f8e2db1e1fca74", + "https://bcr.bazel.build/modules/opencensus-cpp/0.0.0-20230502-50eb5de.bcr.2/MODULE.bazel": "cc18734138dd18c912c6ce2a59186db28f85d8058c99c9f21b46ca3e0aba0ebe", + "https://bcr.bazel.build/modules/opencensus-cpp/0.0.0-20230502-50eb5de.bcr.2/source.json": "7c135f9d42bb3b045669c3c6ab3bb3c208e00b46aca4422eea64c29811a5b240", "https://bcr.bazel.build/modules/opencensus-cpp/0.0.0-20230502-50eb5de/MODULE.bazel": "02201d2921dadb4ec90c4980eca4b2a02904eddcf6fa02f3da7594fb7b0d821c", - "https://bcr.bazel.build/modules/opencensus-cpp/0.0.0-20230502-50eb5de/source.json": "f50efc07822f5425bd1d3e40e977484f9c0142463052717d40ec85cd6744243e", + "https://bcr.bazel.build/modules/opencensus-proto/0.4.1.bcr.2/MODULE.bazel": "789706a714855f92c5c8cfcf1ef32bbb64dcd3b7c9066756ad7986ec59709d29", + "https://bcr.bazel.build/modules/opencensus-proto/0.4.1.bcr.2/source.json": "aadf3f53e08b72376506b7c4ea3d167010c9efb160d7d6e1e304ed646bac1b36", "https://bcr.bazel.build/modules/opencensus-proto/0.4.1/MODULE.bazel": "4a2e8b4d0b544002502474d611a5a183aa282251e14f6a01afe841c0c1b10372", - "https://bcr.bazel.build/modules/opencensus-proto/0.4.1/source.json": "a7d956700a85b833c43fc61455c0e111ab75bab40768ed17a206ee18a2bbe38f", "https://bcr.bazel.build/modules/openssl/3.3.1.bcr.1/MODULE.bazel": "49c0c07e8fb87b480bccb842cfee1b32617f11dac590f732573c69058699a3d1", "https://bcr.bazel.build/modules/openssl/3.3.1.bcr.1/source.json": "0c0872e048bbea052a9c541fb47019481a19201ba5555a71d762ad591bf94e1f", "https://bcr.bazel.build/modules/opentelemetry-cpp/1.14.2/MODULE.bazel": "089a5613c2a159c7dfde098dabfc61e966889c7d6a81a98422a84c51535ed17d", @@ -146,11 +154,13 @@ "https://bcr.bazel.build/modules/platforms/0.0.8/MODULE.bazel": "9f142c03e348f6d263719f5074b21ef3adf0b139ee4c5133e2aa35664da9eb2d", "https://bcr.bazel.build/modules/platforms/0.0.9/MODULE.bazel": "4a87a60c927b56ddd67db50c89acaa62f4ce2a1d2149ccb63ffd871d5ce29ebc", "https://bcr.bazel.build/modules/prometheus-cpp/1.2.4/MODULE.bazel": "0fbe5dcff66311947a3f6b86ebc6a6d9328e31a28413ca864debc4a043f371e5", + "https://bcr.bazel.build/modules/prometheus-cpp/1.3.0.bcr.1/MODULE.bazel": "116ad46e97c1d2aeb020fe2899a342a7e703574ce7c0faf7e4810f938c974a9a", + "https://bcr.bazel.build/modules/prometheus-cpp/1.3.0.bcr.1/source.json": "e813cce2d450708cfcb26e309c5172583a7440776edf354e83e6788c768e5cca", "https://bcr.bazel.build/modules/prometheus-cpp/1.3.0/MODULE.bazel": "ce82e086bbc0b60267e970f6a54b2ca6d0f22d3eb6633e00e2cc2899c700f3d8", - "https://bcr.bazel.build/modules/prometheus-cpp/1.3.0/source.json": "8cb66b4e535afc718e9d104a3db96ccb71a42ee816a100e50fd0d5ac843c0606", "https://bcr.bazel.build/modules/protobuf/21.7/MODULE.bazel": "a5a29bb89544f9b97edce05642fac225a808b5b7be74038ea3640fae2f8e66a7", "https://bcr.bazel.build/modules/protobuf/23.1/MODULE.bazel": "88b393b3eb4101d18129e5db51847cd40a5517a53e81216144a8c32dfeeca52a", "https://bcr.bazel.build/modules/protobuf/24.4/MODULE.bazel": "7bc7ce5f2abf36b3b7b7c8218d3acdebb9426aeb35c2257c96445756f970eb12", + "https://bcr.bazel.build/modules/protobuf/25.6/MODULE.bazel": "fc0ae073b47c7ede88b825ff79e64f1c058967c7a87a86cdf4abecd9e0516625", "https://bcr.bazel.build/modules/protobuf/26.0.bcr.1/MODULE.bazel": "8f04d38c2da40a3715ff6bdce4d32c5981e6432557571482d43a62c31a24c2cf", "https://bcr.bazel.build/modules/protobuf/26.0.bcr.2/MODULE.bazel": "62e0b84ca727bdeb55a6fe1ef180e6b191bbe548a58305ea1426c158067be534", "https://bcr.bazel.build/modules/protobuf/26.0/MODULE.bazel": "8402da964092af40097f4a205eec2a33fd4a7748dc43632b7d1629bfd9a2b856", @@ -170,6 +180,7 @@ "https://bcr.bazel.build/modules/protoc-gen-validate/1.0.4/MODULE.bazel": "b8913c154b16177990f6126d2d2477d187f9ddc568e95ee3e2d50fc65d2c494a", "https://bcr.bazel.build/modules/protoc-gen-validate/1.2.1.bcr.1/MODULE.bazel": "4bf09676b62fa587ae07e073420a76ec8766dcce7545e5f8c68cfa8e484b5120", "https://bcr.bazel.build/modules/protoc-gen-validate/1.2.1.bcr.1/source.json": "c19071ebc4b53b5f1cfab9c66eefaf6e4179eb8a998970d07b1077687e777f29", + "https://bcr.bazel.build/modules/protoc-gen-validate/1.2.1/MODULE.bazel": "52b51f50533ec4fbd5d613cd093773f979ac2e035d954e02ca11de383f502505", "https://bcr.bazel.build/modules/pybind11_bazel/2.11.1/MODULE.bazel": "88af1c246226d87e65be78ed49ecd1e6f5e98648558c14ce99176da041dc378e", "https://bcr.bazel.build/modules/pybind11_bazel/2.12.0/MODULE.bazel": "e6f4c20442eaa7c90d7190d8dc539d0ab422f95c65a57cc59562170c58ae3d34", "https://bcr.bazel.build/modules/pybind11_bazel/2.12.0/source.json": "6900fdc8a9e95866b8c0d4ad4aba4d4236317b5c1cd04c502df3f0d33afed680", @@ -275,6 +286,7 @@ "https://bcr.bazel.build/modules/rules_python/0.28.0/MODULE.bazel": "cba2573d870babc976664a912539b320cbaa7114cd3e8f053c720171cde331ed", "https://bcr.bazel.build/modules/rules_python/0.29.0/MODULE.bazel": "2ac8cd70524b4b9ec49a0b8284c79e4cd86199296f82f6e0d5da3f783d660c82", "https://bcr.bazel.build/modules/rules_python/0.31.0/MODULE.bazel": "93a43dc47ee570e6ec9f5779b2e64c1476a6ce921c48cc9a1678a91dd5f8fd58", + "https://bcr.bazel.build/modules/rules_python/0.32.2/MODULE.bazel": "01052470fc30b49de91fb8483d26bea6f664500cfad0b078d4605b03e3a83ed4", "https://bcr.bazel.build/modules/rules_python/0.33.2/MODULE.bazel": "3e036c4ad8d804a4dad897d333d8dce200d943df4827cb849840055be8d2e937", "https://bcr.bazel.build/modules/rules_python/0.37.1/MODULE.bazel": "3faeb2d9fa0a81f8980643ee33f212308f4d93eea4b9ce6f36d0b742e71e9500", "https://bcr.bazel.build/modules/rules_python/0.4.0/MODULE.bazel": "9208ee05fd48bf09ac60ed269791cf17fb343db56c8226a720fbb1cdf467166c", @@ -321,8 +333,8 @@ "moduleExtensions": { "@@apple_support+//crosstool:setup.bzl%apple_cc_configure_extension": { "general": { - "bzlTransitiveDigest": "xcBTf2+GaloFpg7YEh/Bv+1yAczRkiCt3DGws4K7kSk=", - "usagesDigest": "39X2JjPCOAk6sThDALGv1L4q85GNjda2yfszm/phxxw=", + "bzlTransitiveDigest": "gv4nokEMGNye4Jvoh7Tw0Lzs63zfklj+n4t0UegI7Ms=", + "usagesDigest": "ub8r+m3BGCamcByx5L10qjTKg7vVqcZtr8MdM+DPR5Y=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, @@ -353,7 +365,7 @@ "@@googleapis+//:extensions.bzl%switched_rules": { "general": { "bzlTransitiveDigest": "vG6fuTzXD8MMvHWZEQud0MMH7eoC4GXY0va7VrFFh04=", - "usagesDigest": "wim8EKEwMC8MGhQFXcQM3CAtCivRhJUZtBgWZtR/3lg=", + "usagesDigest": "Uvwo21LEsEORfk0QiWNM31Xp39pBKi57n878VZ+SJiQ=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, diff --git a/cinterop-c/build_target.sh b/cinterop-c/build_target.sh new file mode 100755 index 000000000..511ca075a --- /dev/null +++ b/cinterop-c/build_target.sh @@ -0,0 +1,36 @@ +#!/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 a specific platform (os/arch). +# +# Usage: +# ./build_target.sh //path:libtarget out_dir +# Example: +# ./build_target.sh :protowire_static out @build_bazel_apple_support//platforms:ios_arm64 ios_arm64 ios +# +# The example will produce ./out/libprotowire_static.ios_arm64.a + +LABEL="${1:?need bazel target label}" +DST="${2:?need output destination}" +PLATFORM="${3:?need a platform for bazel build command}" +OS="${4:?need the operating system of the target platform}" + +CONFIG=release + +mkdir -p $(dirname "$DST") + +echo "==> Building $LABEL to $DST" >&2 +bazel build "$LABEL" --platforms="$PLATFORM" --apple_platform_type="$OS" --config="$CONFIG" --announce_rc >/dev/null + +# Ask Bazel what file(s) this target produced under this platform +out="$(bazel cquery "$LABEL" --platforms="$PLATFORM" --apple_platform_type="$OS" --config="$CONFIG" --output=files | head -n1)" +[[ -n "$out" ]] || { echo "No output for $LABEL ($SHORT)"; exit 1; } + +cp -f "$out" "$DST" + +echo "Done. Binary written to: $DST" diff --git a/gradle-conventions/src/main/kotlin/util/cinterop.kt b/gradle-conventions/src/main/kotlin/util/cinterop.kt index 6a28b9f6c..672c196d6 100644 --- a/gradle-conventions/src/main/kotlin/util/cinterop.kt +++ b/gradle-conventions/src/main/kotlin/util/cinterop.kt @@ -9,16 +9,14 @@ import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project import org.gradle.api.tasks.Exec import org.gradle.internal.extensions.stdlib.capitalized -import org.gradle.kotlin.dsl.extra -import org.gradle.kotlin.dsl.named -import org.gradle.kotlin.dsl.provideDelegate -import org.gradle.kotlin.dsl.register +import org.gradle.kotlin.dsl.* import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.mpp.DefaultCInteropSettings import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.tasks.CInteropProcess +import org.jetbrains.kotlin.konan.target.Family +import org.jetbrains.kotlin.konan.target.KonanTarget import java.io.File -import kotlin.io.resolve // works with the cinterop-c Bazel project fun KotlinMultiplatformExtension.configureCLibCInterop( @@ -43,18 +41,30 @@ fun KotlinMultiplatformExtension.configureCLibCInterop( } } - val buildCinteropCLib = project.tasks.register("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")) + targets.withType().configureEach { + val buildTargetName = bazelTask.split(":").last() + // bazel library build task + val taskName = "buildCLib${buildTargetName.capitalized()}_$targetName" + val buildCinteropCLib = project.tasks.register(taskName) { + val platform = bazelPlatformName + val os = bazelOsName - dependsOn(checkBazel) - } + // the name used for the static library files (e.g. iosSimulatorArm64 -> ios_simulator_arm64) + val platformShortName = konanTarget.visibleName + val fileName = "lib$buildTargetName.$platformShortName.a" + val outFile = cinteropCLib.resolve("out").resolve(fileName) + + group = "build" + workingDir = cinteropCLib + commandLine("bash", "-c", "./build_target.sh $bazelTask $outFile $platform $os") + inputs.files(project.fileTree(cinteropCLib) { exclude("bazel-*/**", "out/**") }) + outputs.files(outFile) - targets.filterIsInstance().forEach { - it.compilations.getByName("main") { + dependsOn(checkBazel) + } + + // cinterop klib build config + compilations.getByName("main") { cinterops { configureCinterop(cinteropCLib) } @@ -62,7 +72,7 @@ fun KotlinMultiplatformExtension.configureCLibCInterop( cinterops.all { val interop = this - val interopTask = "cinterop${interop.name.capitalized()}${it.targetName.capitalized()}" + val interopTask = "cinterop${interop.name.capitalized()}${this@configureEach.targetName.capitalized()}" project.tasks.named(interopTask, CInteropProcess::class) { dependsOn(buildCinteropCLib) } @@ -70,3 +80,48 @@ fun KotlinMultiplatformExtension.configureCLibCInterop( } } } + +/** + * Returns the Bazel platform name for the given [KotlinNativeTarget]. + * + * For Apple targets, compare the following two lists: + * - https://kotlinlang.org/docs/native-target-support.html + * - https://github.com/bazelbuild/apple_support/blob/master/configs/platforms.bzl + */ +private val KotlinNativeTarget.bazelPlatformName: String + get() { + val appleSupport = "@build_bazel_apple_support//platforms" + return when (konanTarget) { + KonanTarget.MACOS_ARM64 -> "$appleSupport:macos_arm64" + KonanTarget.MACOS_X64 -> "$appleSupport:macos_x86_64" + KonanTarget.IOS_ARM64 -> "$appleSupport:ios_arm64" + KonanTarget.IOS_SIMULATOR_ARM64 -> "$appleSupport:ios_sim_arm64" + KonanTarget.IOS_X64 -> "$appleSupport:ios_x86_64" + KonanTarget.WATCHOS_ARM32 -> "$appleSupport:watchos_armv7k" + // WATCHOS_ARM64 is the "older" arm64_32 target, not arm64 (which is WATCH_DEVICE_ARM64) + KonanTarget.WATCHOS_ARM64 -> "$appleSupport:watchos_arm64_32" + KonanTarget.WATCHOS_DEVICE_ARM64 -> "$appleSupport:watchos_device_arm64" + KonanTarget.WATCHOS_SIMULATOR_ARM64 -> "$appleSupport:watchos_arm64" + KonanTarget.WATCHOS_X64 -> "$appleSupport:watchos_x86_64" + KonanTarget.TVOS_ARM64 -> "$appleSupport:tvos_arm64" + KonanTarget.TVOS_SIMULATOR_ARM64 -> "$appleSupport:tvos_sim_arm64" + KonanTarget.TVOS_X64 -> "$appleSupport:tvos_x86_64" + KonanTarget.LINUX_ARM32_HFP -> TODO() + KonanTarget.LINUX_ARM64 -> TODO() + KonanTarget.LINUX_X64 -> TODO() + KonanTarget.ANDROID_ARM32 -> TODO() + KonanTarget.ANDROID_ARM64 -> TODO() + KonanTarget.ANDROID_X64 -> TODO() + KonanTarget.ANDROID_X86 -> TODO() + KonanTarget.MINGW_X64 -> TODO() + } + } + +private val KotlinNativeTarget.bazelOsName + get() = when (konanTarget.family) { + Family.OSX -> "macos" + Family.IOS -> "ios" + Family.TVOS -> "tvos" + Family.WATCHOS -> "watchos" + else -> TODO() + } diff --git a/grpc/grpc-core/build.gradle.kts b/grpc/grpc-core/build.gradle.kts index 828428656..d3cb5e667 100644 --- a/grpc/grpc-core/build.gradle.kts +++ b/grpc/grpc-core/build.gradle.kts @@ -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")}") } } } diff --git a/grpc/grpc-core/gradle.properties b/grpc/grpc-core/gradle.properties index 4ae0c96a1..1eda57d1b 100644 --- a/grpc/grpc-core/gradle.properties +++ b/grpc/grpc-core/gradle.properties @@ -4,9 +4,6 @@ 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 @@ -15,7 +12,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 diff --git a/grpc/grpc-core/src/nativeInterop/cinterop/libkgrpc.def b/grpc/grpc-core/src/nativeInterop/cinterop/libkgrpc.def index 59aa61bcd..2066569dd 100644 --- a/grpc/grpc-core/src/nativeInterop/cinterop/libkgrpc.def +++ b/grpc/grpc-core/src/nativeInterop/cinterop/libkgrpc.def @@ -8,4 +8,11 @@ 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_simulator_arm64.a +staticLibraries.ios_simulator_x64 = libkgrpc_static.ios_simulator_x64.a +# TODO: Uncomment when activating WatchOS +# staticLibraries.watchos_arm64 = libkgrpc_static.watchos_arm64.a +# staticLibraries.watchos_simulator_arm64 = libkgrpc_static.watchos_simulator_arm64.a diff --git a/protobuf/protobuf-core/build.gradle.kts b/protobuf/protobuf-core/build.gradle.kts index 2c71d5306..666079da2 100644 --- a/protobuf/protobuf-core/build.gradle.kts +++ b/protobuf/protobuf-core/build.gradle.kts @@ -59,9 +59,7 @@ kotlin { includeDirs( cinteropCLib.resolve("include") ) - extraOpts( - "-libraryPath", "${cinteropCLib.resolve("bazel-out/darwin_arm64-opt/bin")}", - ) + extraOpts("-libraryPath", "${cinteropCLib.resolve("out")}") } } } diff --git a/protobuf/protobuf-core/gradle.properties b/protobuf/protobuf-core/gradle.properties index 4ae0c96a1..1eda57d1b 100644 --- a/protobuf/protobuf-core/gradle.properties +++ b/protobuf/protobuf-core/gradle.properties @@ -4,9 +4,6 @@ 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 @@ -15,7 +12,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 diff --git a/protobuf/protobuf-core/src/nativeInterop/cinterop/libprotowire.def b/protobuf/protobuf-core/src/nativeInterop/cinterop/libprotowire.def index 3868c5fc6..977acbd9c 100644 --- a/protobuf/protobuf-core/src/nativeInterop/cinterop/libprotowire.def +++ b/protobuf/protobuf-core/src/nativeInterop/cinterop/libprotowire.def @@ -3,4 +3,11 @@ headerFilter = protowire.h noStringConversion = pw_encoder_write_string -staticLibraries = libprotowire_static.a \ No newline at end of file + +staticLibraries.macos_arm64 = libprotowire_static.macos_arm64.a +staticLibraries.ios_arm64 = libprotowire_static.ios_arm64.a +staticLibraries.ios_simulator_arm64 = libprotowire_static.ios_simulator_arm64.a +staticLibraries.ios_simulator_x64 = libprotowire_static.ios_simulator_x64.a +# TODO: Uncomment when activating WatchOS +# staticLibraries.watchos_arm64 = libprotowire_static.watchos_arm64_32.a +# staticLibraries.watchos_simulator_arm64 = libprotowire_static.watchos_sim_arm64.a \ No newline at end of file diff --git a/versions-root/libs.versions.toml b/versions-root/libs.versions.toml index f8575b913..a3771720b 100644 --- a/versions-root/libs.versions.toml +++ b/versions-root/libs.versions.toml @@ -30,7 +30,7 @@ kover = "0.9.1" develocity = "3.19.2" common-custom-user-data = "2.3" compat-patrouille = "0.0.1" -grpc = "1.73.0" +grpc = "1.74.0" grpc-kotlin = "1.4.1" protobuf = "4.31.1" protobuf-gradle = "0.9.5" @@ -62,7 +62,7 @@ serialization-plugin = { module = "org.jetbrains.kotlin:kotlin-serialization-com serialization-plugin-forIde = { module = "org.jetbrains.kotlin:kotlinx-serialization-compiler-plugin-for-ide", version.ref = "kotlin-compiler" } kotlinx-browser = { module = "org.jetbrains.kotlinx:kotlinx-browser", version.ref = "kotlinx-browser" } kotlinx-io-core = { module = "org.jetbrains.kotlinx:kotlinx-io-core", version.ref = "kotlinx-io" } -kotlinx-collections-immutable = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version.ref = "kotlinx-collections"} +kotlinx-collections-immutable = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version.ref = "kotlinx-collections" } # serialization serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "serialization" } @@ -128,7 +128,7 @@ kotlin-js-wrappers = { module = "org.jetbrains.kotlin-wrappers:kotlin-js", versi intellij-util = { module = "com.jetbrains.intellij.platform:util", version.ref = "intellij" } atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version.ref = "atomicfu" } develocity = { module = "com.gradle:develocity-gradle-plugin", version.ref = "develocity" } -common-custom-user-data = { module ="com.gradle:common-custom-user-data-gradle-plugin", version.ref = "common-custom-user-data" } +common-custom-user-data = { module = "com.gradle:common-custom-user-data-gradle-plugin", version.ref = "common-custom-user-data" } # gradle plugins as lib deps detekt-gradle-plugin = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt-gradle-plugin" }