Skip to content

Commit 346afa4

Browse files
authored
[ObjC]fix c++14 errors in bazel objC (grpc#30448)
* fix c++14 errors in bazel objC * fix CI error
1 parent 6845327 commit 346afa4

File tree

7 files changed

+27
-15
lines changed

7 files changed

+27
-15
lines changed

bazel/grpc_build_system.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,13 @@ def grpc_objc_library(
611611
name,
612612
srcs = [],
613613
hdrs = [],
614+
non_arc_srcs = [],
614615
textual_hdrs = [],
616+
testonly = False,
615617
data = [],
616618
deps = [],
617619
defines = [],
620+
sdk_frameworks = [],
618621
includes = [],
619622
visibility = ["//visibility:public"]):
620623
"""The grpc version of objc_library, only used for the Objective-C library compilation
@@ -623,9 +626,12 @@ def grpc_objc_library(
623626
name: name of target
624627
hdrs: public headers
625628
srcs: all source files (.m)
629+
non_arc_srcs: list of Objective-C files that DO NOT use ARC.
626630
textual_hdrs: private headers
631+
testonly: Whether the binary is for tests only.
627632
data: any other bundle resources
628633
defines: preprocessors
634+
sdk_frameworks: sdks
629635
includes: added to search path, always [the path to objc directory]
630636
deps: dependencies
631637
visibility: visibility, default to public
@@ -635,11 +641,15 @@ def grpc_objc_library(
635641
name = name,
636642
hdrs = hdrs,
637643
srcs = srcs,
644+
non_arc_srcs = non_arc_srcs,
638645
textual_hdrs = textual_hdrs,
646+
copts = GRPC_DEFAULT_COPTS + ["-ObjC++", "-std=gnu++14"],
647+
testonly = testonly,
639648
data = data,
640649
deps = deps,
641650
defines = defines,
642651
includes = includes,
652+
sdk_frameworks = sdk_frameworks,
643653
visibility = visibility,
644654
)
645655

src/objective-c/GRPCClient/private/GRPCCore/ChannelArgsUtil.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ void GRPCFreeChannelArgs(grpc_channel_args *channel_args) {
5959
NSArray *keys = [dictionary allKeys];
6060
NSUInteger argCount = [keys count];
6161

62-
grpc_channel_args *channelArgs = gpr_malloc(sizeof(grpc_channel_args));
63-
channelArgs->args = gpr_malloc(argCount * sizeof(grpc_arg));
62+
grpc_channel_args *channelArgs = (grpc_channel_args *)gpr_malloc(sizeof(grpc_channel_args));
63+
channelArgs->args = (grpc_arg *)gpr_malloc(argCount * sizeof(grpc_arg));
6464

6565
// TODO(kriswuollett) Check that keys adhere to GRPC core library requirements
6666

src/objective-c/GRPCClient/private/GRPCCore/GRPCSecureChannelFactory.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,18 @@ - (instancetype)initWithPEMRootCerts:(NSString *)rootCerts
8686

8787
grpc_channel_credentials *creds = NULL;
8888
if (privateKey.length == 0 && certChain.length == 0) {
89-
creds = grpc_ssl_credentials_create(rootsASCII.bytes, NULL, NULL, NULL);
89+
creds = grpc_ssl_credentials_create((const char *)rootsASCII.bytes, NULL, NULL, NULL);
9090
} else {
9191
grpc_ssl_pem_key_cert_pair key_cert_pair;
9292
NSData *privateKeyASCII = [self nullTerminatedDataWithString:privateKey];
9393
NSData *certChainASCII = [self nullTerminatedDataWithString:certChain];
94-
key_cert_pair.private_key = privateKeyASCII.bytes;
95-
key_cert_pair.cert_chain = certChainASCII.bytes;
94+
key_cert_pair.private_key = (const char *)privateKeyASCII.bytes;
95+
key_cert_pair.cert_chain = (const char *)certChainASCII.bytes;
9696
if (key_cert_pair.private_key == NULL || key_cert_pair.cert_chain == NULL) {
97-
creds = grpc_ssl_credentials_create(rootsASCII.bytes, NULL, NULL, NULL);
97+
creds = grpc_ssl_credentials_create((const char *)rootsASCII.bytes, NULL, NULL, NULL);
9898
} else {
99-
creds = grpc_ssl_credentials_create(rootsASCII.bytes, &key_cert_pair, NULL, NULL);
99+
creds =
100+
grpc_ssl_credentials_create((const char *)rootsASCII.bytes, &key_cert_pair, NULL, NULL);
100101
}
101102
}
102103

src/objective-c/GRPCClient/private/GRPCCore/GRPCWrappedCall.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ - (instancetype)initWithMetadata:(NSDictionary *)metadata
6868
_op.data.send_initial_metadata.count = metadata.count;
6969
_op.data.send_initial_metadata.metadata = metadata.grpc_metadataArray;
7070
_op.data.send_initial_metadata.maybe_compression_level.is_set = false;
71-
_op.data.send_initial_metadata.maybe_compression_level.level = 0;
71+
_op.data.send_initial_metadata.maybe_compression_level.level = GRPC_COMPRESS_LEVEL_NONE;
7272
_op.flags = flags;
7373
_handler = handler;
7474
}
@@ -274,7 +274,7 @@ - (void)startBatchWithOperations:(NSArray *)operations errorHandler:(void (^)(vo
274274
@synchronized(self) {
275275
if (_call != NULL) {
276276
size_t nops = operations.count;
277-
grpc_op *ops_array = gpr_malloc(nops * sizeof(grpc_op));
277+
grpc_op *ops_array = (grpc_op *)gpr_malloc(nops * sizeof(grpc_op));
278278
size_t i = 0;
279279
for (GRPCOperation *operation in operations) {
280280
ops_array[i++] = operation.op;

src/objective-c/GRPCClient/private/GRPCCore/NSData+GRPC.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void MallocAndCopyByteBufferToCharArray(grpc_byte_buffer *buffer, size_t
4040
// because the reader takes care of automatically decompressing it
4141
grpc_slice slice = grpc_byte_buffer_reader_readall(&reader);
4242
size_t uncompressed_length = GRPC_SLICE_LENGTH(slice);
43-
char *result = malloc(uncompressed_length);
43+
char *result = (char *)malloc(uncompressed_length);
4444
if (result) {
4545
memcpy(result, GRPC_SLICE_START_PTR(slice), uncompressed_length);
4646
}

src/objective-c/GRPCClient/private/GRPCCore/NSDictionary+GRPC.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ + (instancetype)grpc_dataFromMetadataValue:(grpc_metadata *)metadata {
3737
}
3838

3939
- (void)grpc_initMetadata:(grpc_metadata *)metadata {
40-
metadata->value = grpc_slice_from_copied_buffer(self.bytes, self.length);
40+
metadata->value = grpc_slice_from_copied_buffer((const char *)self.bytes, self.length);
4141
}
4242
@end
4343

@@ -94,7 +94,7 @@ + (instancetype)grpc_dictionaryFromMetadata:(grpc_metadata *)entries count:(size
9494
// Preconditions: All keys are ASCII strings. Keys ending in -bin have NSData values; the others
9595
// have NSString values.
9696
- (grpc_metadata *)grpc_metadataArray {
97-
grpc_metadata *metadata = gpr_malloc([self count] * sizeof(grpc_metadata));
97+
grpc_metadata *metadata = (grpc_metadata *)gpr_malloc([self count] * sizeof(grpc_metadata));
9898
grpc_metadata *current = metadata;
9999
for (NSString *key in self) {
100100
id value = self[key];

src/objective-c/grpc_objc_internal_library.bzl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ load(
3131
"generate_objc_non_arc_srcs",
3232
"generate_objc_srcs",
3333
)
34+
load("//bazel:grpc_build_system.bzl", "grpc_objc_library")
3435
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test")
3536
load(
3637
"@build_bazel_rules_apple//apple/testing/default_runner:ios_test_runner.bzl",
@@ -111,7 +112,7 @@ def grpc_objc_examples_library(
111112
includes: added to search path, always [the path to objc directory]
112113
deps: dependencies
113114
"""
114-
native.objc_library(
115+
grpc_objc_library(
115116
name = name,
116117
srcs = srcs,
117118
hdrs = hdrs,
@@ -153,7 +154,7 @@ def grpc_objc_testing_library(
153154
if not name == "TestConfigs":
154155
additional_deps.append(":TestConfigs")
155156

156-
native.objc_library(
157+
grpc_objc_library(
157158
name = name,
158159
hdrs = hdrs,
159160
srcs = srcs,
@@ -211,7 +212,7 @@ def local_objc_grpc_library(name, deps, testing = True, srcs = [], use_well_know
211212
else:
212213
library_deps.append("//src/objective-c:proto_objc_rpc")
213214

214-
native.objc_library(
215+
grpc_objc_library(
215216
name = name,
216217
hdrs = [":" + objc_grpc_library_name + "_hdrs"],
217218
non_arc_srcs = [":" + objc_grpc_library_name + "_non_arc_srcs"],

0 commit comments

Comments
 (0)