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

while compiling cc_library from DefaultInfo bazel ignores bazelrc #15623

Closed
onelxj opened this issue Jun 6, 2022 · 11 comments
Closed

while compiling cc_library from DefaultInfo bazel ignores bazelrc #15623

onelxj opened this issue Jun 6, 2022 · 11 comments
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-CPP Issues for C++ rules type: bug

Comments

@onelxj
Copy link

onelxj commented Jun 6, 2022

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
Copy link
Author

onelxj commented Jun 6, 2022

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

Thanks =)

@onelxj onelxj closed this as completed Jun 6, 2022
@fmeum
Copy link
Collaborator

fmeum commented Jun 6, 2022

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
Copy link
Author

onelxj commented Jun 6, 2022

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
Copy link
Author

onelxj commented Jun 7, 2022

@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
Copy link
Collaborator

fmeum commented Jun 7, 2022

@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
Copy link
Author

onelxj commented Jun 7, 2022

@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
Copy link
Collaborator

fmeum commented Jun 7, 2022

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 onelxj reopened this Jun 7, 2022
@onelxj
Copy link
Author

onelxj commented Jun 7, 2022

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!

@oquenchil oquenchil added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) and removed untriaged labels Jul 7, 2022
@Mizux
Copy link

Mizux commented Mar 31, 2023

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:

  • ADDED: the c++17 flag is added to the subcommand
  • APPEND: std=c++17 is appended in the subcommand (i.e. the default flag is still present)
  • REPLACE: the default flag is replaced by the one passed as argument
  • IGNORED: the flags argument seems completely ignored/dropped and I can’t find it in any subcommand trace log

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

Copy link

github-actions bot commented Jun 4, 2024

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 github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Jun 4, 2024
Copy link

github-actions bot commented Sep 2, 2024

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!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-CPP Issues for C++ rules type: bug
Projects
None yet
Development

No branches or pull requests

5 participants