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

bazel_tools 13.14 compile error on macOS with --cxxopt="-std=c++14" #24957

Open
mbland opened this issue Jan 17, 2025 · 6 comments
Open

bazel_tools 13.14 compile error on macOS with --cxxopt="-std=c++14" #24957

mbland opened this issue Jan 17, 2025 · 6 comments
Labels
team-Core Skyframe, bazel query, BEP, options parsing, bazelrc type: bug untriaged

Comments

@mbland
Copy link

mbland commented Jan 17, 2025

Description of the bug:

Building the following with rules_java 8.7.0 or 8.7.1, which use bazel_tools 13.14 (see bazelbuild/rules_java: Update rules_java to 8.7.0 and java_tools to 13.14), fails on macOS with:

$ bazel build --cxxopt="-std=c++14" @remote_java_tools//:filesystem

[ ...snip... ]
external/rules_java++toolchains+remote_java_tools/java_tools/src/main/cpp/util/file_posix.cc:137:7: error: no matching function for call to 'mkdtemp'
  137 |   if (mkdtemp(&path.data()[0]) == nullptr) {                                                                                                         
      |       ^~~~~~~                                                         
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/unistd.h:665:7: note: candidate function not v
iable: 1st argument ('const value_type *' (aka 'const char *')) would lose const qualifier
  665 | char    *mkdtemp(char *);
      |          ^       ~~~~~~
1 error generated.
Error in child process '/usr/bin/xcrun'. 1

We hit this in our build while calling default_java_toolchain with dependencies on @remote_java_tools//:ijar_cc_binary and @remote_java_tools//:singlejar_cc_bin. Both of these apparently depend on @remote_java_tools//:filesystem.

I selected the "Core" category since I didn't see one for bazel_tools. Cross-reference: bazelbuild/java_tools#93 (comment)

cc: @saraadams

Which category does this issue belong to?

Core

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Update rules_java to 8.7.0 (or 8.7.1) in any project, and import the remote_java_tools repo:

bazel_dep(name = "rules_java", version = "8.7.1")
    
java_toolchains = use_extension(
    "@rules_java//java:extensions.bzl", "toolchains"
)
use_repo(java_toolchains, "remote_java_tools")

Then build on macOS using the macOS SDKs for 14.5 or 15.2:

bazel build --cxxopt="-std=c++14" @remote_java_tools//:filesystem

Which operating system are you running Bazel on?

macOS 15.2 (24C101)

What is the output of bazel info release?

release 9.0.0-pre.20250106.2

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?


If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

This appears due to the following change: 6906ba6#diff-83cfe165f1bd78a7736edc353ec60148796236c9076c75ed152d35e25a70077bL136-L137 (doesn't jump; search for mkdtemp)

This changes lines 136-137 of src/main/cpp/util/file_posix.cc from:

std::string result(prefix + "XXXXXX");
if (mkdtemp(&result[0]) == nullptr) {

to:

std::string path(other_path.AsNativePath() + ".tmp.XXXXXX");
if (mkdtemp(&path.data()[0]) == nullptr) {

std::string.data() returns a const char *, whereas the previous &result[0] returns char *.

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

The full compile command:

ERROR: .../external/rules_java++toolchains+remote_java_tools/BUILD:256:11:
  Compiling java_tools/src/main/cpp/util/file_posix.cc [for tool] failed: (Exit 1):
  wrapped_clang_pp failed:
  error executing CppCompile command
 (from target @@rules_java++toolchains+remote_java_tools//:filesystem)
  (cd .../sandbox/darwin-sandbox/1292/execroot/_main && \                                        
  exec env - \                                                                                                                                               
    APPLE_SDK_PLATFORM=MacOSX \                                                                                                                              
    APPLE_SDK_VERSION_OVERRIDE=15.2 \                                                                                                                        
    BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 \                                                                                                                    
    PATH=/bin:/usr/bin:/usr/local/bin \                                                                                                                      
    XCODE_VERSION_OVERRIDE=16.2.0.16C5032a \                                                                                                                 
    ZERO_AR_DATE=1 \                                                                                                                                         
  external/apple_support++apple_cc_configure_extension+local_config_apple_cc/wrapped_clang_pp 
  '-D_FORTIFY_SOURCE=1' -fstack-protector -fcolor-diagnostics -Wall 
  -Wthread-safety -Wself-assign -fno-omit-frame-pointer -g0 -O2 -DNDEBUG
  '-DNS_BLOCK_ASSERTIONS=1' '-std=c++14'
  '-fdebug-prefix-map=__BAZEL_EXECUTION_ROOT__=.'
  '-fdebug-prefix-map=__BAZEL_XCODE_DEVELOPER_DIR__=/PLACEHOLDER_DEVELOPER_DIR'
  -iquote external/rules_java++toolchains+remote_java_tools
  -iquote bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_java++toolchains+remote_java_tools
  -Ibazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_java++toolchains+remote_java_tools/_virtual_includes/filesystem
  -Ibazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_java++toolchains+remote_java_tools/_virtual_includes/blaze_exit_code
  -Ibazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_java++toolchains+remote_java_tools/_virtual_includes/errors
  -Ibazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_java++toolchains+remote_java_tools/_virtual_includes/logging
  -Ibazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_java++toolchains+remote_java_tools/_virtual_includes/strings
  -Ibazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_java++toolchains+remote_java_tools/_virtual_includes/port
  -MD -MF
  bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_java++toolchains+remote_java_tools/_objs/filesystem/file_posix.d
  -DBLAZE_OPENSOURCE
  '-frandom-seed=bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_java++toolchains+remote_java_tools/_objs/filesystem/file_posix.o'
  -isysroot __BAZEL_XCODE_SDKROOT__
  -F__BAZEL_XCODE_SDKROOT__/System/Library/Frameworks
  -F__BAZEL_XCODE_DEVELOPER_DIR__/Platforms/MacOSX.platform/Developer/Library/Frameworks
  -no-canonical-prefixes -pthread '-Werror=sign-compare' -g0 '-std=c++14'
  -fno-exceptions '-fvisibility=hidden' '-Werror=reorder'
  '-Werror=unused-function' '-Werror=return-type' '-Werror=sign-compare' -g0
  -no-canonical-prefixes -Wno-builtin-macro-redefined '-D__DATE__="redacted"'
  '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"'
  -target arm64-apple-macosx15.2
  -c external/rules_java++toolchains+remote_java_tools/java_tools/src/main/cpp/util/file_posix.cc
  -o bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_java++toolchains+remote_java_tools/_objs/filesystem/file_posix.o)                                                                                       # Configuration: ...
# Execution platform: @@platforms//host:host                                                                                                                 
@fmeum
Copy link
Collaborator

fmeum commented Jan 17, 2025

@tjgq

@mbland mbland changed the title bazel_tools 13.14 compile error on macOS bazel_tools 13.14 compile error on macOS with --cxxopt="-std=c++14" Jan 17, 2025
@benjaminp
Copy link
Collaborator

6906ba6 added code that requires C++17.

@mbland
Copy link
Author

mbland commented Jan 17, 2025

6906ba6 added code that requires C++17.

Huh, can confirm it builds with: bazel build --cxxopt="-std=c++17" @remote_java_tools//:filesystem.

@mbland
Copy link
Author

mbland commented Jan 17, 2025

OK, we've been able to move forward by setting --cxxopt="-std=c++17" on all our platforms and having everything pass CI with rules_java 8.7.1 (and bazel_tools 13.14).

Feel free to close this if you think it's working as intended. For me, though, it's interesting that -std=c++14 breaks, and -std=c++17 doesn't. There appears to be a clear constness mismatch between std::string::data() and mkdtemp(), and I'd expect C++17 to be more strict. (If anyone can explain what I might be missing, I'd be delighted!)

@benjaminp
Copy link
Collaborator

C++17 specifies a non-const override of basic_string::data().

@mbland
Copy link
Author

mbland commented Jan 17, 2025

@benjaminp Ah, good to know—and a bit scary, but I guess it makes sense to enable easier adaptation to legacy C APIs without const_cast everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Core Skyframe, bazel query, BEP, options parsing, bazelrc type: bug untriaged
Projects
None yet
Development

No branches or pull requests

6 participants