Skip to content

Commit 7c3e364

Browse files
committed
grpc-native: Build cache, not working
Signed-off-by: Johannes Zottele <[email protected]>
1 parent ce62f16 commit 7c3e364

File tree

104 files changed

+9429
-73
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+9429
-73
lines changed

cinterop-c/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
/.clwb/
1414
.idea/
1515

16-
out/
16+
out/
17+
tmp/

cinterop-c/BUILD.bazel

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
12
load("@rules_cc//cc:defs.bzl", "cc_library")
23

34
cc_static_library(
4-
name = "kgrpc_static",
5+
name = "kgrpc_fat",
56
deps = [
67
":kgrpc",
8+
"//grpc_dep:grpc_core_prebuilt",
79
],
810
)
911

@@ -15,12 +17,12 @@ cc_library(
1517
includes = ["include"],
1618
visibility = ["//visibility:public"],
1719
deps = [
18-
"@com_github_grpc_grpc//:grpc",
20+
"//grpc_dep:grpc_core_prebuilt",
1921
],
2022
)
2123

2224
cc_static_library(
23-
name = "protowire_static",
25+
name = "protowire_fat",
2426
deps = [
2527
":protowire",
2628
],
@@ -34,6 +36,13 @@ cc_library(
3436
includes = ["include"],
3537
visibility = ["//visibility:public"],
3638
deps = [
37-
"@com_google_protobuf//:protobuf_lite",
39+
"@com_github_protobuffers_protobuf//:protobuf_lite",
40+
],
41+
)
42+
43+
cc_binary(
44+
name = "grpc_flat",
45+
deps = [
46+
"//grpc_dep:grpc_core_prebuilt",
3847
],
3948
)

cinterop-c/MODULE.bazel

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module(
33
version = "0.1",
44
)
55

6+
http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
7+
68
# rules_cc for cc_library support
79
bazel_dep(
810
name = "rules_cc",
@@ -11,17 +13,53 @@ bazel_dep(
1113

1214
# required to build for apple targets (like iOS)
1315
bazel_dep(name = "apple_support", version = "1.22.1", repo_name = "build_bazel_apple_support")
16+
bazel_dep(name = "platforms", version = "1.0.0")
1417

1518
# Protobuf
1619
bazel_dep(
1720
name = "protobuf",
1821
version = "31.1",
19-
repo_name = "com_google_protobuf",
22+
repo_name = "com_github_protobuffers_protobuf",
2023
)
2124

2225
# gRPC library
26+
GRPC_VERSION = "1.74.1"
27+
28+
GRPC_BASE = (
29+
"https://packages.jetbrains.team/files/p/" +
30+
"krpc/bazel-build-deps/com_github_grpc_grpc/v" + GRPC_VERSION + "/libgrpc_fat."
31+
)
32+
33+
## gRPC source dependency
34+
2335
bazel_dep(
2436
name = "grpc",
25-
version = "1.74.1",
37+
version = GRPC_VERSION,
2638
repo_name = "com_github_grpc_grpc",
2739
)
40+
41+
## gRPC pre-built
42+
43+
http_file(
44+
name = "grpc_ios_arm64",
45+
sha256 = "7bc13a15c59850048e77b5719ea262a6fcc22884ab42c9f14f38859200faac9b",
46+
urls = [GRPC_BASE + "ios_arm64.a"],
47+
)
48+
49+
http_file(
50+
name = "grpc_ios_sim_arm64",
51+
sha256 = "55fde875508372860125ee8505ef4e84b95c9620744378a99f8f4095292dcae5",
52+
urls = [GRPC_BASE + "ios_simulator_arm64.a"],
53+
)
54+
55+
http_file(
56+
name = "grpc_ios_x64",
57+
sha256 = "7544113fe9b6c9d0a57c8b8864b5272e01e3a64ea36cd0802d4a76e98ad5e232",
58+
urls = [GRPC_BASE + "ios_x64.a"],
59+
)
60+
61+
http_file(
62+
name = "grpc_macos_arm64",
63+
sha256 = "6cf466a285832ecd0f41041164c412e9b541388210058310d7bb59f6a27d09de",
64+
urls = [GRPC_BASE + "macos_arm64.a"],
65+
)

cinterop-c/MODULE.bazel.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 (fat) library dependency (e.g. protobuf or grpc) and publishes to the space file registry.
10+
#
11+
# Usage:
12+
# ./build_and_publish_dep.sh <bazel_target> <out_dir> <platform> <short> <os>
13+
# Example:
14+
# ./build_and_publish_dep.sh @com_github_protobuffers_protobuf//:protobuf_lite_static out @build_bazel_apple_support//platforms:ios_arm64 ios_arm64 ios
15+
#
16+
# The example will produce ./out/com_github_protobuffers_protobuf/v31.1/libprotobuf_lite_fat.ios_arm64.a
17+
18+
LABEL="${1:?need bazel target label}"
19+
OUTDIR="${2:?need output directory}"
20+
PLATFORM="${3:?need a platform for bazel build command}"
21+
SHORT="${4:?need the short name of the target}"
22+
OS="${4:?need the operating system of the target platform}"
23+

cinterop-c/build_target.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ out="$(bazel cquery "$LABEL" --platforms="$PLATFORM" --apple_platform_type="$OS"
3333

3434
cp -f "$out" "$DST"
3535

36-
echo "Done. Binary written to: $DST"
36+
echo "Done. Binary written to: $DST" >&2

cinterop-c/grpc_dep/BUILD.bazel

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_import", "cc_library")
2+
load("//:tools/collect_headers.bzl", "zip_include")
3+
4+
#### Compile gRPC from scratch ####
5+
6+
cc_static_library(
7+
name = "grpc_fat",
8+
deps = [
9+
"@com_github_grpc_grpc//:grpc",
10+
],
11+
)
12+
13+
zip_include(
14+
name = "grpc_include",
15+
target = "@com_github_grpc_grpc//:grpc",
16+
)
17+
18+
#### Targets for pre-built dependency ####
19+
20+
cc_library(
21+
name = "grpc_core_prebuilt",
22+
hdrs = glob(["include/**"]),
23+
includes = ["include"],
24+
visibility = ["//visibility:public"],
25+
# pick the right prebuilt .a:
26+
deps = select({
27+
":ios_device_arm64": [":grpc_core_ios_arm64"],
28+
":ios_simulator_arm64": [":grpc_core_ios_sim_arm64"],
29+
":ios_simulator_x64": [":grpc_core_ios_x64"],
30+
":macos_arm64": [":grpc_core_macos_arm64"],
31+
"//conditions:default": [],
32+
}),
33+
)
34+
35+
config_setting(
36+
name = "ios_device_arm64",
37+
constraint_values = [
38+
"@platforms//os:ios",
39+
"@platforms//cpu:arm64",
40+
"@build_bazel_apple_support//constraints:device",
41+
],
42+
)
43+
44+
config_setting(
45+
name = "ios_simulator_arm64",
46+
constraint_values = [
47+
"@platforms//os:ios",
48+
"@platforms//cpu:arm64",
49+
"@build_bazel_apple_support//constraints:simulator",
50+
],
51+
)
52+
53+
config_setting(
54+
name = "ios_simulator_x64",
55+
constraint_values = [
56+
"@platforms//os:ios",
57+
"@platforms//cpu:x86_64",
58+
"@build_bazel_apple_support//constraints:simulator",
59+
],
60+
)
61+
62+
config_setting(
63+
name = "macos_arm64",
64+
constraint_values = [
65+
"@platforms//os:macos",
66+
"@platforms//cpu:arm64",
67+
],
68+
)
69+
70+
cc_import(
71+
name = "grpc_core_ios_arm64",
72+
static_library = "@grpc_ios_arm64//file",
73+
visibility = ["//visibility:public"],
74+
)
75+
76+
cc_import(
77+
name = "grpc_core_ios_sim_arm64",
78+
static_library = "@grpc_ios_sim_arm64//file",
79+
visibility = ["//visibility:public"],
80+
)
81+
82+
cc_import(
83+
name = "grpc_core_ios_x64",
84+
static_library = "@grpc_ios_x64//file",
85+
visibility = ["//visibility:public"],
86+
)
87+
88+
cc_import(
89+
name = "grpc_core_macos_arm64",
90+
static_library = "@grpc_macos_arm64//file",
91+
visibility = ["//visibility:public"],
92+
)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
3+
#ifndef GRPC_BYTE_BUFFER_H
4+
#define GRPC_BYTE_BUFFER_H
5+
6+
#include <grpc/impl/grpc_types.h>
7+
#include <grpc/slice_buffer.h>
8+
#include <grpc/support/port_platform.h>
9+
10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
14+
/** Returns a RAW byte buffer instance over the given slices (up to \a nslices).
15+
*
16+
* Increases the reference count for all \a slices processed. The user is
17+
* responsible for invoking grpc_byte_buffer_destroy on the returned instance.*/
18+
GRPCAPI grpc_byte_buffer* grpc_raw_byte_buffer_create(grpc_slice* slices,
19+
size_t nslices);
20+
21+
/** Returns a *compressed* RAW byte buffer instance over the given slices (up to
22+
* \a nslices). The \a compression argument defines the compression algorithm
23+
* used to generate the data in \a slices.
24+
*
25+
* Increases the reference count for all \a slices processed. The user is
26+
* responsible for invoking grpc_byte_buffer_destroy on the returned instance.*/
27+
GRPCAPI grpc_byte_buffer* grpc_raw_compressed_byte_buffer_create(
28+
grpc_slice* slices, size_t nslices, grpc_compression_algorithm compression);
29+
30+
/** Copies input byte buffer \a bb.
31+
*
32+
* Increases the reference count of all the source slices. The user is
33+
* responsible for calling grpc_byte_buffer_destroy over the returned copy. */
34+
GRPCAPI grpc_byte_buffer* grpc_byte_buffer_copy(grpc_byte_buffer* bb);
35+
36+
/** Returns the size of the given byte buffer, in bytes. */
37+
GRPCAPI size_t grpc_byte_buffer_length(grpc_byte_buffer* bb);
38+
39+
/** Destroys \a byte_buffer deallocating all its memory. */
40+
GRPCAPI void grpc_byte_buffer_destroy(grpc_byte_buffer* bb);
41+
42+
/** Reader for byte buffers. Iterates over slices in the byte buffer */
43+
struct grpc_byte_buffer_reader;
44+
typedef struct grpc_byte_buffer_reader grpc_byte_buffer_reader;
45+
46+
/** Initialize \a reader to read over \a buffer.
47+
* Returns 1 upon success, 0 otherwise. */
48+
GRPCAPI int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader,
49+
grpc_byte_buffer* buffer);
50+
51+
/** Cleanup and destroy \a reader */
52+
GRPCAPI void grpc_byte_buffer_reader_destroy(grpc_byte_buffer_reader* reader);
53+
54+
/** Updates \a slice with the next piece of data from from \a reader and returns
55+
* 1. Returns 0 at the end of the stream. Caller is responsible for calling
56+
* grpc_slice_unref on the result. */
57+
GRPCAPI int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader* reader,
58+
grpc_slice* slice);
59+
60+
/** EXPERIMENTAL API - This function may be removed and changed, in the future.
61+
*
62+
* Updates \a slice with the next piece of data from from \a reader and returns
63+
* 1. Returns 0 at the end of the stream. Caller is responsible for making sure
64+
* the slice pointer remains valid when accessed.
65+
*
66+
* NOTE: Do not use this function unless the caller can guarantee that the
67+
* underlying grpc_byte_buffer outlasts the use of the slice. This is only
68+
* safe when the underlying grpc_byte_buffer remains immutable while slice
69+
* is being accessed. */
70+
GRPCAPI int grpc_byte_buffer_reader_peek(grpc_byte_buffer_reader* reader,
71+
grpc_slice** slice);
72+
73+
/** Merge all data from \a reader into single slice */
74+
GRPCAPI grpc_slice
75+
grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader* reader);
76+
77+
/** Returns a RAW byte buffer instance from the output of \a reader. */
78+
GRPCAPI grpc_byte_buffer* grpc_raw_byte_buffer_from_reader(
79+
grpc_byte_buffer_reader* reader);
80+
81+
#ifdef __cplusplus
82+
}
83+
#endif
84+
85+
#endif /* GRPC_BYTE_BUFFER_H */
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
3+
#ifndef GRPC_BYTE_BUFFER_READER_H
4+
#define GRPC_BYTE_BUFFER_READER_H
5+
6+
#include <grpc/support/port_platform.h>
7+
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
12+
struct grpc_byte_buffer;
13+
14+
struct grpc_byte_buffer_reader {
15+
struct grpc_byte_buffer* buffer_in;
16+
struct grpc_byte_buffer* buffer_out;
17+
/** Different current objects correspond to different types of byte buffers */
18+
union grpc_byte_buffer_reader_current {
19+
/** Index into a slice buffer's array of slices */
20+
unsigned index;
21+
} current;
22+
};
23+
24+
#ifdef __cplusplus
25+
}
26+
#endif
27+
28+
#endif /* GRPC_BYTE_BUFFER_READER_H */
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
3+
#ifndef GRPC_CENSUS_H
4+
#define GRPC_CENSUS_H
5+
6+
#include <grpc/grpc.h>
7+
#include <grpc/support/port_platform.h>
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
/**
14+
A Census Context is a handle used by Census to represent the current tracing
15+
and stats collection information. Contexts should be propagated across RPC's
16+
(this is the responsibility of the local RPC system). */
17+
typedef struct census_context census_context;
18+
19+
#ifdef __cplusplus
20+
}
21+
#endif
22+
23+
#endif /* GRPC_CENSUS_H */

0 commit comments

Comments
 (0)