bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.21k stars 4.06k forks source link

while compiling cc_library from DefaultInfo bazel ignores bazelrc #15623

Closed onelxj closed 2 months ago

onelxj commented 2 years ago

Description of the bug:

I have a rule that returns DefaultInfo(depset(...)) - folder that consists of c++ sources and headers, then I'm trying to compile it with

cc_library(
    name = "route-guide-eventuals-library",
    srcs = [
        ":route-guide-eventuals-generated",  # Default info with srcs
    ],
    hdrs = [
        ":route-guide-eventuals-generated",  # Default info with srcs
    ],
    # Can't get .bazelrc settings for generated files.
    # copts = ["-std=c++17"],
    alwayslink = True,
    deps =[
        ":route-guide-grpc",
    ]
)

The sources require c++17, in bazelrc I have

build:linux --cxxopt='-std=c++17'
build:linux --host_cxxopt=-std=c++17

but whenever I try to run - it uses C++11 instead of 17 if uncomment copts, that includes '-std=c++17' - it works

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

No response

Which operating system are you running Bazel on?

Linux Ubuntu 22.04

What is the output of bazel info release?

release 5.1.1

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 master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

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

No response

onelxj commented 2 years ago

Fixed via adding build --action_env=BAZEL_CXXOPTS="-std=c++17" to bazelrc

Thanks =)

fmeum commented 2 years ago

Fixed via adding build --action_env=BAZEL_CXXOPTS="-std=c++17" to bazelrc

Thanks =)

--repo_env should work better as it doesn't pollute the environment of every action. Also, please keep in mind that what counts for the deps of a cc_library is what's in the CcInfo of your custom rule, not in DefaultInfo. If all you do is generate files, you may want to reference the custom rule from srcs, not deps.

onelxj commented 2 years ago

Fixed via adding build --action_env=BAZEL_CXXOPTS="-std=c++17" to bazelrc Thanks =)

--repo_env should work better as it doesn't pollute the environment of every action. Also, please keep in mind that what counts for the deps of a cc_library is what's in the CcInfo of your custom rule, not in DefaultInfo. If all you do is generate files, you may want to reference the custom rule from srcs, not deps.

That my fault, generated stuff is :route-guide-eventuals-generated, it is in srcs and hdrs already, thanks!

onelxj commented 2 years ago

@fmeum Could you please explain, why defaul bazel:linux --cxxopt='-std=c++17' is not valid for this build? Other srcs in the repo that copliling also with cc_library work fine

fmeum commented 2 years ago

@onelxj Do you have a complete example reproducing the issue you could share? In a local example I tried --cxxopt did apply to generated files with e.g. .cpp extensions.

onelxj commented 2 years ago

@fmeum the thing there that target provided in :route-guide-eventuals-generated is a folder (generated via declare_folder()), I'm not sure, but it can be the reason

fmeum commented 2 years ago

That makes a big difference and is likely the reason. However, I'm not familiar enough with the C++ rules to say whether it can be fixed.

@onelxj Could you reopen the issue so that it can be proberly triaged to the C++ team?

onelxj commented 2 years ago

That makes a big difference and is likely the reason. However, I'm not familiar enough with the C++ rules to say whether it can be fixed.

@onelxj Could you reopen the issue so that it can be probably triaged to the C++ team?

Thank you for your time!

Mizux commented 1 year ago

Trying to force C++ dialect (std c++17) in subcommands on various platforms and using various bazel build arguments…

Project \  Platform gLinux
Linux github
gMacOS (Intel/M1) MacOS github (intel) gWindows
Windows github
Repo:bazel-cpp
Branch: arg
–cxxopt=”-std=c++17”
APPEND APPEND APPEND ADDED
Repo:bazel-cpp
Branch: env
–action_env=BAZEL_CXXOPTS=”-std=c++17”
REPLACE REPLACE IGNORED IGNORED
         
Repo:bazel-proto
protobuf v21.12
–cxxopt=”-std=c++17”
APPEND APPEND APPEND ADDED
Repo:bazel-proto
protobuf v21.12
–action_env=BAZEL_CXXOPTS=”-std=c++17”
REPLACE REPLACE IGNORED
C++11 used -> absl build fail
IGNORED
         
Repo:bazel-proto
Branch: arg
protobuf v22.2 + Fix #12320
–cxxopt=”-std=c++17”
IGNORED
C++0x used absl build fail
IGNORED
C++0x used -> absl build fail
APPEND IGNORED
Repo: bazel-proto
Branch: env
protobuf v22.2 + Fix #12320
–action_env=BAZEL_CXXOPTS=”-std=c++17”
REPLACE REPLACE
bug #12306
IGNORED
C++11 used -> absl build fail
IGNORED

Legend:

dev note: use --subcommands=true or -s to get # SUBCOMMAND ... trace log repo: https://mizux.dev/bazel-cpp repo: https://mizux.dev/bazel-proto

github-actions[bot] commented 5 months ago

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

github-actions[bot] commented 2 months ago

This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please post @bazelbuild/triage in a comment here and we'll take a look. Thanks!