rules-proto-grpc / rules_proto_grpc

Bazel rules for building Protobuf and gRPC code and libraries from proto_library targets
https://rules-proto-grpc.com
Apache License 2.0
253 stars 160 forks source link

swift_proto_library fails to build with newest version of Xcode #232

Closed pswaminathan closed 1 year ago

pswaminathan commented 1 year ago

Issue Description

Using the newest version of Xcode, a basic protobuf fails to build. Example here. Checking out main and running bazel build //src/proto:all works. Checking out failing-build (PR branch 1) with the same command (after a bazel clean) should produce the following error:

ERROR: /Users/p/Code/demos/swift-protobuf-xcode-failure/src/proto/BUILD.bazel:16:20: Compiling protoc outputs for swift_plugin plugin on target @//src/proto:example_swift_proto_pb failed: (Exit 1): bash failed: error executing command (from target //src/proto:example_swift_proto_pb) /bin/bash -c ... (remaining 6 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
dyld[38748]: Symbol not found: (_$s10Foundation12CharacterSetV11whitespacesACvgZ)
  Referenced from: '/private/var/tmp/_bazel_p/a2414e84e883c4182b674af589eab4f2/execroot/__main__/bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/com_github_apple_swift_protobuf/ProtoCompilerPlugin'
  Expected in: '/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation'
--swift_plugin_out: protoc-gen-swift_plugin: Plugin killed by signal 6.

Log Output

bazel run src/swift:main
INFO: Analyzed target //src/swift:main (54 packages loaded, 1152 targets configured).
INFO: Found 1 target...
INFO: From Compiling src/google/protobuf/stubs/strutil.cc [for tool]:
external/com_github_protocolbuffers_protobuf/src/google/protobuf/stubs/strutil.cc:506:11: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]
          sprintf(dest + used, (use_hex ? "\\x%02x" : "\\%03o"),
          ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/stdio.h:188:1: note: 'sprintf' has been explicitly marked deprecated here
__deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg'
        #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                      ^
1 warning generated.
ERROR: /Users/p/Code/demos/swift-protobuf-xcode-failure/src/proto/BUILD.bazel:16:20: Compiling protoc outputs for swift_plugin plugin on target @//src/proto:example_swift_proto_pb failed: (Exit 1): bash failed: error executing command (from target //src/proto:example_swift_proto_pb) /bin/bash -c ... (remaining 6 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
dyld[38748]: Symbol not found: (_$s10Foundation12CharacterSetV11whitespacesACvgZ)
  Referenced from: '/private/var/tmp/_bazel_p/a2414e84e883c4182b674af589eab4f2/execroot/__main__/bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/com_github_apple_swift_protobuf/ProtoCompilerPlugin'
  Expected in: '/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation'
--swift_plugin_out: protoc-gen-swift_plugin: Plugin killed by signal 6.
Target //src/swift:main failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 43.706s, Critical Path: 41.77s
INFO: 240 processes: 21 internal, 215 darwin-sandbox, 4 worker.
FAILED: Build did NOT complete successfully
ERROR: Build failed. Not running target

rules_proto_grpc Version

4.3.0

Bazel Version

6.0.0rc1 (though also tested with 6.0.0rc4)

OS

macOS 12.6.1 (21G217)

Link to Demo Repo

https://github.com/pswaminathan/swift-protobuf-xcode-failure

WORKSPACE Content

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_jar")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

http_archive(
    name = "rules_license",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/0.0.3/rules_license-0.0.3.tar.gz",
        "https://github.com/bazelbuild/rules_license/releases/download/0.0.3/rules_license-0.0.3.tar.gz",
    ],
    sha256 = "00ccc0df21312c127ac4b12880ab0f9a26c1cff99442dc6c5a331750360de3c3",
)

http_archive(
    name = "com_github_buildbuddy_io_rules_xcodeproj",
    sha256 = "b4e71c7740bb8cfa4bc0b91c0f18ac512debcc111ebe471280e24f579a3b0782",
    url = "https://github.com/buildbuddy-io/rules_xcodeproj/releases/download/0.10.2/release.tar.gz",
)

load(
    "@com_github_buildbuddy_io_rules_xcodeproj//xcodeproj:repositories.bzl",
    "xcodeproj_rules_dependencies",
)

xcodeproj_rules_dependencies()

load(
    "@build_bazel_rules_apple//apple:repositories.bzl",
    "apple_rules_dependencies",
)

apple_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:repositories.bzl",
    "swift_rules_dependencies",
)

swift_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:extras.bzl",
    "swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

load(
    "@build_bazel_apple_support//lib:repositories.bzl",
    "apple_support_dependencies",
)

apple_support_dependencies()

http_archive(
    name = "cgrindel_rules_spm",
    sha256 = "03718eb865a100ba4449ebcbca6d97bf6ea78fa17346ce6d55532312e8bf9aa8",
    strip_prefix = "rules_spm-0.11.0",
    urls = [
        "http://github.com/cgrindel/rules_spm/archive/v0.11.0.tar.gz",
    ],
)

load(
    "@cgrindel_rules_spm//spm:deps.bzl",
    "spm_rules_dependencies",
)

spm_rules_dependencies()

##### Swiftlint #####
http_archive(
    name = "SwiftLint",
    sha256 = "ef49a8c0dcb70fb5befe549b016735deef72e1ac9f68562b288f23e496c164af",
    url = "https://github.com/realm/SwiftLint/releases/download/0.50.0-rc.4/bazel.tar.gz",
)

load("@SwiftLint//bazel:repos.bzl", "swiftlint_repos")

swiftlint_repos()

load("@SwiftLint//bazel:deps.bzl", "swiftlint_deps")

swiftlint_deps()

http_archive(
    name = "rules_proto_grpc",
    sha256 = "fb7fc7a3c19a92b2f15ed7c4ffb2983e956625c1436f57a3430b897ba9864059",
    strip_prefix = "rules_proto_grpc-4.3.0",
    urls = ["https://github.com/rules-proto-grpc/rules_proto_grpc/archive/4.3.0.tar.gz"],
)

load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_toolchains", "rules_proto_grpc_repos")
rules_proto_grpc_toolchains()
rules_proto_grpc_repos()

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
rules_proto_dependencies()
rules_proto_toolchains()

BUILD Content

load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_proto_grpc//swift:defs.bzl", "swift_proto_library")

package(
    default_visibility = ["//visibility:public"],
)

proto_library(
    name = "example_proto",
    srcs = ["example.proto"],
    deps = [
        "@com_google_protobuf//:timestamp_proto",
    ],
)

swift_proto_library(
    name = "example_swift_proto",
    protos = [
        ":example_proto",
    ],
    options = {
        "@rules_proto_grpc//swift:swift_plugin": ["Visibility=Public"],
    },
    module_name = "ExampleProto",
)

Proto Content

syntax = "proto3";

package example;

import "google/protobuf/timestamp.proto";

message Packet {
    uint32 id = 1;
    google.protobuf.Timestamp timestamp = 2;
}

enum State {
    Idle = 0;
    Ready = 1;
    Started = 2;
    Paused = 3;
    Resumed = 4;
    Ended = 5;
}

message StateNotification {
    State state = 1;
}

Any Other Content

No response

pswaminathan commented 1 year ago

This also failed from rules_swift directly and they gave me some guidance there on setting macOS version flags in .bazelrc—think this can be closed!