Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Failed to build with Bazel on macOS #5376

Closed
hcoona opened this issue Nov 18, 2018 · 14 comments
Closed

[Question] Failed to build with Bazel on macOS #5376

hcoona opened this issue Nov 18, 2018 · 14 comments
Assignees
Labels
inactive Denotes the issue/PR has not seen activity in the last 90 days.

Comments

@hcoona
Copy link

hcoona commented Nov 18, 2018

What version of protobuf and what language are you using?
Version: v3.5.2,v3.6.1,master(4361398)
Language: C++/Java/Python/C#/Ruby/PHP/Objective-C/Javascript

What operating system (Linux, Windows, ...) and version?
macOS 10.14.1

What runtime / compiler are you using (e.g., python version or gcc version)
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Build label: 0.19.1
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Nov 12 15:30:36 2018 (1542036636)
Build timestamp: 1542036636
Build timestamp as int: 1542036636

What did you do?
Steps to reproduce the behavior:

  1. Download https://github.com/google/protobuf/archive/v3.5.2.zip
  2. bazel build :protoc_lib

What did you expect to see
Building it successfully

What did you see instead?
The building failed with a few errors.

ERROR: /private/tmp/protobuf-3.5.2/BUILD:274:1: C++ compilation of rule '//:protoc_lib' failed (Exit 1) cc_wrapper.sh failed: error executing command external/local_config_cc/cc_wrapper.sh -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -fcolor-diagnostics -fno-omit-frame-pointer '-std=c++0x' -MD -MF ... (remaining 36 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
In file included from src/google/protobuf/compiler/javanano/javanano_helpers.cc:38:
src/google/protobuf/compiler/javanano/javanano_helpers.h:57:37: error: unknown type name 'OneofDescriptor'
string UnderscoresToCamelCase(const OneofDescriptor* oneof);
                                    ^
src/google/protobuf/compiler/javanano/javanano_helpers.h:59:48: error: unknown type name 'OneofDescriptor'
string UnderscoresToCapitalizedCamelCase(const OneofDescriptor* oneof);
                                               ^
src/google/protobuf/compiler/javanano/javanano_helpers.h:188:32: error: no member named 'map_entry' in 'google::protobuf::MessageOptions'
  return descriptor->options().map_entry() &&
         ~~~~~~~~~~~~~~~~~~~~~ ^
src/google/protobuf/compiler/javanano/javanano_helpers.h:189:27: error: no member named 'syntax' in 'google::protobuf::FileDescriptor'
      descriptor->file()->syntax() == FileDescriptor::SYNTAX_PROTO3;
      ~~~~~~~~~~~~~~~~~~  ^
src/google/protobuf/compiler/javanano/javanano_helpers.h:189:55: error: no member named 'SYNTAX_PROTO3' in 'google::protobuf::FileDescriptor'
      descriptor->file()->syntax() == FileDescriptor::SYNTAX_PROTO3;
                                      ~~~~~~~~~~~~~~~~^
src/google/protobuf/compiler/javanano/javanano_helpers.cc:157:37: error: unknown type name 'OneofDescriptor'
string UnderscoresToCamelCase(const OneofDescriptor* oneof) {
                                    ^
src/google/protobuf/compiler/javanano/javanano_helpers.cc:161:48: error: unknown type name 'OneofDescriptor'
string UnderscoresToCapitalizedCamelCase(const OneofDescriptor* oneof) {
                                               ^
7 errors generated.
Target //:protoc_lib failed to build

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

Anything else we should know about your project / environment

@hcoona
Copy link
Author

hcoona commented Nov 18, 2018

More detail logs:

$ bazel build :protoc_lib --sandbox_debug
INFO: Analysed target //:protoc_lib (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /Users/shuaiz/GitEnlistments/protobuf/BUILD:267:1: C++ compilation of rule '//:protoc_lib' failed (Exit 1) sandbox-exec failed: error executing command
  (cd /private/var/tmp/_bazel_shuaiz/ae04e1f10b8f3926b76085f9860189fe/execroot/com_google_protobuf && \
  exec env - \
    PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Users/shuaiz/Library/Python/2.7/bin \
    PWD=/proc/self/cwd \
    TMPDIR=/var/folders/hq/b0nns16s27787bqjkmbd0wnr0000gn/T/ \
  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_shuaiz/ae04e1f10b8f3926b76085f9860189fe/sandbox/darwin-sandbox/4/sandbox.sb /private/var/tmp/_bazel_shuaiz/ae04e1f10b8f3926b76085f9860189fe/execroot/com_google_protobuf/_bin/process-wrapper '--timeout=0' '--kill_delay=15' external/local_config_cc/cc_wrapper.sh -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -fcolor-diagnostics -fno-omit-frame-pointer '-std=c++0x' -MD -MF bazel-out/darwin-fastbuild/bin/_objs/protoc_lib/cpp_enum.pic.d '-frandom-seed=bazel-out/darwin-fastbuild/bin/_objs/protoc_lib/cpp_enum.pic.o' -fPIC -iquote . -iquote bazel-out/darwin-fastbuild/genfiles -iquote bazel-out/darwin-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/darwin-fastbuild/genfiles/external/bazel_tools -iquote bazel-out/darwin-fastbuild/bin/external/bazel_tools -isystem src -isystem bazel-out/darwin-fastbuild/genfiles/src -isystem bazel-out/darwin-fastbuild/bin/src -DHAVE_PTHREAD -Wall -Woverloaded-virtual -Wno-sign-compare -Wno-unused-function -Wno-writable-strings -Wno-write-strings -no-canonical-prefixes -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c src/google/protobuf/compiler/cpp/cpp_enum.cc -o bazel-out/darwin-fastbuild/bin/_objs/protoc_lib/cpp_enum.pic.o)
In file included from src/google/protobuf/compiler/cpp/cpp_enum.cc:38:
In file included from src/google/protobuf/compiler/cpp/cpp_helpers.h:44:
In file included from src/google/protobuf/compiler/scc.h:36:
In file included from src/google/protobuf/stubs/logging.h:34:
In file included from src/google/protobuf/stubs/macros.h:34:
src/google/protobuf/stubs/port.h:159:20: error: redefinition of 'kint32max'
static const int32 kint32max = 0x7FFFFFFF;
                   ^
/usr/local/include/google/protobuf/stubs/common.h:197:20: note: previous definition is here
static const int32 kint32max = 0x7FFFFFFF;
                   ^
In file included from src/google/protobuf/compiler/cpp/cpp_enum.cc:38:
In file included from src/google/protobuf/compiler/cpp/cpp_helpers.h:44:
In file included from src/google/protobuf/compiler/scc.h:36:
In file included from src/google/protobuf/stubs/logging.h:34:
In file included from src/google/protobuf/stubs/macros.h:34:
src/google/protobuf/stubs/port.h:160:20: error: redefinition of 'kint32min'
static const int32 kint32min = -kint32max - 1;
                   ^
/usr/local/include/google/protobuf/stubs/common.h:198:20: note: previous definition is here
static const int32 kint32min = -kint32max - 1;
                   ^
In file included from src/google/protobuf/compiler/cpp/cpp_enum.cc:38:
In file included from src/google/protobuf/compiler/cpp/cpp_helpers.h:44:
In file included from src/google/protobuf/compiler/scc.h:36:
In file included from src/google/protobuf/stubs/logging.h:34:
In file included from src/google/protobuf/stubs/macros.h:34:
src/google/protobuf/stubs/port.h:161:20: error: redefinition of 'kint64max'
static const int64 kint64max = PROTOBUF_LONGLONG(0x7FFFFFFFFFFFFFFF);
                   ^
/usr/local/include/google/protobuf/stubs/common.h:199:20: note: previous definition is here
static const int64 kint64max = GOOGLE_LONGLONG(0x7FFFFFFFFFFFFFFF);
                   ^
In file included from src/google/protobuf/compiler/cpp/cpp_enum.cc:38:
In file included from src/google/protobuf/compiler/cpp/cpp_helpers.h:44:
In file included from src/google/protobuf/compiler/scc.h:36:
In file included from src/google/protobuf/stubs/logging.h:34:
In file included from src/google/protobuf/stubs/macros.h:34:
src/google/protobuf/stubs/port.h:162:20: error: redefinition of 'kint64min'
static const int64 kint64min = -kint64max - 1;
                   ^
/usr/local/include/google/protobuf/stubs/common.h:200:20: note: previous definition is here
static const int64 kint64min = -kint64max - 1;
                   ^
In file included from src/google/protobuf/compiler/cpp/cpp_enum.cc:38:
In file included from src/google/protobuf/compiler/cpp/cpp_helpers.h:44:
In file included from src/google/protobuf/compiler/scc.h:36:
In file included from src/google/protobuf/stubs/logging.h:34:
In file included from src/google/protobuf/stubs/macros.h:34:
src/google/protobuf/stubs/port.h:163:21: error: redefinition of 'kuint32max'
static const uint32 kuint32max = 0xFFFFFFFFu;
                    ^
/usr/local/include/google/protobuf/stubs/common.h:201:21: note: previous definition is here
static const uint32 kuint32max = 0xFFFFFFFFu;
                    ^
In file included from src/google/protobuf/compiler/cpp/cpp_enum.cc:38:
In file included from src/google/protobuf/compiler/cpp/cpp_helpers.h:44:
In file included from src/google/protobuf/compiler/scc.h:36:
In file included from src/google/protobuf/stubs/logging.h:34:
In file included from src/google/protobuf/stubs/macros.h:34:
src/google/protobuf/stubs/port.h:164:21: error: redefinition of 'kuint64max'
static const uint64 kuint64max = PROTOBUF_ULONGLONG(0xFFFFFFFFFFFFFFFF);
                    ^
/usr/local/include/google/protobuf/stubs/common.h:202:21: note: previous definition is here
static const uint64 kuint64max = GOOGLE_ULONGLONG(0xFFFFFFFFFFFFFFFF);
                    ^
In file included from src/google/protobuf/compiler/cpp/cpp_enum.cc:38:
In file included from src/google/protobuf/compiler/cpp/cpp_helpers.h:44:
In file included from src/google/protobuf/compiler/scc.h:36:
In file included from src/google/protobuf/stubs/logging.h:34:
src/google/protobuf/stubs/macros.h:110:8: error: redefinition of 'CompileAssert'
struct CompileAssert {
       ^
/usr/local/include/google/protobuf/stubs/common.h:374:8: note: previous definition is here
struct CompileAssert {
       ^
In file included from src/google/protobuf/compiler/cpp/cpp_enum.cc:38:
In file included from src/google/protobuf/compiler/cpp/cpp_helpers.h:44:
In file included from src/google/protobuf/compiler/scc.h:36:
src/google/protobuf/stubs/logging.h:45:6: error: redefinition of 'LogLevel'
enum LogLevel {
     ^
/usr/local/include/google/protobuf/stubs/common.h:622:6: note: previous definition is here
enum LogLevel {
     ^
In file included from src/google/protobuf/compiler/cpp/cpp_enum.cc:38:
In file included from src/google/protobuf/compiler/cpp/cpp_helpers.h:44:
In file included from src/google/protobuf/compiler/scc.h:36:
src/google/protobuf/stubs/logging.h:75:23: error: redefinition of 'LogMessage'
class PROTOBUF_EXPORT LogMessage {
                      ^
/usr/local/include/google/protobuf/stubs/common.h:647:26: note: previous definition is here
class LIBPROTOBUF_EXPORT LogMessage {
                         ^
In file included from src/google/protobuf/compiler/cpp/cpp_enum.cc:38:
In file included from src/google/protobuf/compiler/cpp/cpp_helpers.h:44:
In file included from src/google/protobuf/compiler/scc.h:36:
src/google/protobuf/stubs/logging.h:107:23: error: redefinition of 'LogFinisher'
class PROTOBUF_EXPORT LogFinisher {
                      ^
/usr/local/include/google/protobuf/stubs/common.h:673:26: note: previous definition is here
class LIBPROTOBUF_EXPORT LogFinisher {
                         ^
In file included from src/google/protobuf/compiler/cpp/cpp_enum.cc:38:
In file included from src/google/protobuf/compiler/cpp/cpp_helpers.h:44:
In file included from src/google/protobuf/compiler/scc.h:36:
src/google/protobuf/stubs/logging.h:165:4: error: redefinition of 'CheckNotNull'
T* CheckNotNull(const char* /* file */, int /* line */,
   ^
/usr/local/include/google/protobuf/stubs/common.h:723:4: note: previous definition is here
T* CheckNotNull(const char *file, int line, const char *name, T* val) {
   ^
In file included from src/google/protobuf/compiler/cpp/cpp_enum.cc:38:
In file included from src/google/protobuf/compiler/cpp/cpp_helpers.h:44:
In file included from src/google/protobuf/compiler/scc.h:36:
src/google/protobuf/stubs/logging.h:230:23: error: redefinition of 'LogSilencer'
class PROTOBUF_EXPORT LogSilencer {
                      ^
/usr/local/include/google/protobuf/stubs/common.h:784:26: note: previous definition is here
class LIBPROTOBUF_EXPORT LogSilencer {
                         ^
In file included from src/google/protobuf/compiler/cpp/cpp_enum.cc:38:
In file included from src/google/protobuf/compiler/cpp/cpp_helpers.h:50:
In file included from src/google/protobuf/stubs/strutil.h:39:
In file included from src/google/protobuf/stubs/stringpiece.h:154:
src/google/protobuf/port_def.inc:74:2: error: PROTOBUF_DEPRECATED was previously defined
#error PROTOBUF_DEPRECATED was previously defined
 ^
In file included from src/google/protobuf/compiler/cpp/cpp_enum.cc:38:
src/google/protobuf/compiler/cpp/cpp_helpers.h:252:27: error: no member named 'syntax' in 'google::protobuf::FileDescriptor'
  return message->file()->syntax() != FileDescriptor::SYNTAX_PROTO3;
         ~~~~~~~~~~~~~~~  ^
src/google/protobuf/compiler/cpp/cpp_helpers.h:252:55: error: no member named 'SYNTAX_PROTO3' in 'google::protobuf::FileDescriptor'
  return message->file()->syntax() != FileDescriptor::SYNTAX_PROTO3;
                                      ~~~~~~~~~~~~~~~~^
src/google/protobuf/compiler/cpp/cpp_helpers.h:371:32: error: no member named 'map_entry' in 'google::protobuf::MessageOptions'
  return descriptor->options().map_entry();
         ~~~~~~~~~~~~~~~~~~~~~ ^
src/google/protobuf/compiler/cpp/cpp_helpers.h:380:16: error: no member named 'syntax' in 'google::protobuf::FileDescriptor'
  return file->syntax() != FileDescriptor::SYNTAX_PROTO3;
         ~~~~  ^
src/google/protobuf/compiler/cpp/cpp_helpers.h:380:44: error: no member named 'SYNTAX_PROTO3' in 'google::protobuf::FileDescriptor'
  return file->syntax() != FileDescriptor::SYNTAX_PROTO3;
                           ~~~~~~~~~~~~~~~~^
src/google/protobuf/compiler/cpp/cpp_helpers.h:386:16: error: no member named 'syntax' in 'google::protobuf::FileDescriptor'
  return file->syntax() == FileDescriptor::SYNTAX_PROTO3;
         ~~~~  ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
Target //:protoc_lib failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.977s, Critical Path: 0.78s, Remote (0.00% of the time): [queue: 0.00%, setup: 0.00%, process: 0.00%]
INFO: 0 processes.
FAILED: Build did NOT complete successfully

@hcoona
Copy link
Author

hcoona commented Nov 19, 2018

Cannot reproduce it on another mac machine. I think there was a deeper cause for this issue.

@hcoona hcoona changed the title Bazel build broken on Mac for llvm-10 [Question] Failed to build with Bazel on macOS Nov 19, 2018
@acozzette
Copy link
Member

@hcoona I think the problem is that you have some local protobuf headers in ./src/google/protobuf/... conflicting with global headers in /usr/local/include.

@acozzette acozzette self-assigned this Nov 19, 2018
@mennanov
Copy link

Deleting /usr/local/Cellar/protobuf directory resolved a similar issue for me.

@EronWright
Copy link

Expanding on the useful tip from @mennanov, here's the commands that I used:

  1. Verify that nothing is using the installed formula:
$ brew uses protobuf --installed
  1. Remove the protobuf formula from your system:
$ brew uninstall protobuf 

I believe that this formula is routinely installed for use of the protoc tool, in case you're trying to remember why you installed it in the first place.

@dyrone
Copy link

dyrone commented Mar 18, 2020

Deleting /usr/local/Cellar/protobuf directory resolved a similar issue for me.

This works for me.

Thanks!

@wesleyjellis
Copy link

Why is deleting /usr/local/Cellar/protobuf the correct thing here? I have brew formulae installed that depend on protobuf so deleting it seems like a Bad Idea ™️

Are there any other alternatives I could try?

@kjeet
Copy link

kjeet commented Mar 16, 2022

@acozzette Should be reopened? As far as I can tell, depending on files from outside of the build is a bug in the usage of bazel. It probably breaks all sorts of reproducibility and remote caching expectations

@acozzette
Copy link
Member

I'm afraid I don't know enough about Bazel to know the right way to keep it from accessing system headers, but I would be happy to review a fix if you want to send a pull request.

@acozzette acozzette reopened this Mar 16, 2022
@kjeet
Copy link

kjeet commented Mar 17, 2022

@hcoona I think the problem is that you have some local protobuf headers in ./src/google/protobuf/... conflicting with global headers in /usr/local/include.

@acozzette With respect to this, a quick search showed that -nostdinc is supported by gcc and llvm, so you could probably pass that as an option to however cc is called.

Alternatively, from bazelbuild/bazel#8053 (comment):

I've worked around the issue by adding build --sandbox_block_path=/usr/local to my .bazelrc per @philwo above, but it seems suboptimal that Bazel doesn't prioritise its sandboxed headers over system ones.

Perhaps the protobuf bazel build can explicitly sandbox out these paths?

This is my first time dealing with Bazel myself so I'm not sure how reasonable these suggestions are.

@acozzette
Copy link
Member

@kjeet Thank you for the suggestions. The --sandbox_block_path flag sounds like it technically solves the problem, but I don't think we can solve it in a central location because we don't have any way to control the flags that other projects pass to Bazel. We could potentially add -nostdinc in our own BUILD files and address the problem that way, though. But before we do anything I would feel better about this if we had some kind of guidance from the Bazel team about best practices. It seems like this kind of problem could affect almost any project, so hopefully the Bazel team has ideas about how to handle it.

Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

@github-actions github-actions bot added the inactive Denotes the issue/PR has not seen activity in the last 90 days. label May 12, 2024
Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 26, 2024
@wesleyjellis
Copy link

I believe this is still a problem that can and should be addressed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inactive Denotes the issue/PR has not seen activity in the last 90 days.
Projects
None yet
Development

No branches or pull requests

8 participants
@kjeet @hcoona @acozzette @mennanov @EronWright @dyrone @wesleyjellis and others