Skip to content

Commit 5d38167

Browse files
committed
grpc-native: Add build_all_targets.sh
Signed-off-by: Johannes Zottele <[email protected]>
1 parent a57d438 commit 5d38167

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

cinterop-c/build_all_targets.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
4+
#
5+
6+
set -Eeuo pipefail
7+
trap 'echo "ERROR: Build failed at ${BASH_SOURCE}:${LINENO}" >&2' ERR
8+
9+
# Builds a static library for all platforms (os/arch).
10+
#
11+
# Usage:
12+
# ./build_all.sh //path:libtarget out_dir
13+
# Example:
14+
# ./build_all.sh :protowire_static out
15+
16+
17+
LABEL="${1:?need bazel label}"
18+
OUTDIR="${2:?need output dir}"
19+
mkdir -p "$OUTDIR"
20+
21+
# Compilation Config
22+
CONFIG=release
23+
24+
# Platform labels
25+
MACOS=@build_bazel_apple_support//platforms:macos_arm64
26+
IOS_DEV=@build_bazel_apple_support//platforms:ios_arm64
27+
IOS_SIM=@build_bazel_apple_support//platforms:ios_sim_arm64
28+
WATCHOS_ARM64_32_DEV=@build_bazel_apple_support//platforms:watchos_arm64_32
29+
WATCHOS_ARM64_SIM=@build_bazel_apple_support//platforms:watchos_arm64
30+
31+
build_one() {
32+
local plat="$1" short="$2" os="$3"
33+
echo "==> Building $LABEL for $short" >&2
34+
bazel build "$LABEL" --platforms="$plat" --apple_platform_type="$os" --config="$CONFIG" --announce_rc >/dev/null
35+
36+
# Ask Bazel what file(s) this target produced under this platform
37+
local out
38+
out="$(bazel cquery "$LABEL" --platforms="$plat" --apple_platform_type="$os" --config="$CONFIG" --output=files | head -n1)"
39+
[[ -n "$out" ]] || { echo "No output for $LABEL ($short)"; exit 1; }
40+
41+
local dst="$OUTDIR/$(basename "$out" .a).${short}.a"
42+
cp -f "$out" "$dst"
43+
}
44+
45+
build_one "$MACOS" macos_arm64 macos
46+
build_one "$IOS_DEV" ios_arm64 ios
47+
build_one "$IOS_SIM" ios_sim_arm64 ios
48+
# TODO: Uncomment when activating WatchOS
49+
#build_one "$WATCHOS_ARM64_32_DEV" watchos_arm64_32 watchos
50+
#build_one "$WATCHOS_ARM64_SIM" watchos_sim_arm64 watchos
51+
52+
echo "Done. Artifacts in $OUTDIR"

0 commit comments

Comments
 (0)