bazelbuild / bazelbuild/bazel

Documentation issue: Build Tutorial - C

Open
#12,007 2 comments 2 reactions 1 assignee Claimed by @jdob View on GitHub
P2 team-Documentation team-Rules-CPP type: documentation (cleanup)
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

Documentation URL: https://docs.bazel.build/versions/master/tutorial/cpp.html

There is one task everyone building a C or CPP project needs: to specify the language level. (eg, C99 for C files, C++11 for CPP files). This isn't really optional any more, given the proliferation of standards.

I've spent an hour reading, and what's confusing is Starlark is "coming", or something, but some documents are dated 2018 and some are dated with roadmap items in 2020 so it's very hard to tell what to do _right now_, or based on your version of Starlark and/or Bazel. I read there "is" one way, and there "will be" another way, but the "new way" was checked into the code base in 2018....

At this exact point ( Bazel 3.4.1 ), is one required to place options on the command line? Or environment variables? Or are they safe to put in the build file (which is clearly the result of the roadmap)?

From the documentation, it appears that "copts" is allowed in the cc_binary object, but, confusingly, it applies to "C" and "C++" equally. Of course, language specification strings in C are of the form "-std=c17" and C++ strings are "-std=c++17", so clearly stating in the cc_binary object how to set each independently, again, even for a simple project, is crucial.

Please put this in the tutorial, it is not an advanced topic, it is a necessity for first setting up a basic and initial C/C++ project.

While you are at it, how about updating the documentation here:

https://docs.bazel.build/versions/master/be/c-cpp.html

since it covers details of the cc_binary rules. It contains text like "Deprecated. Use toolchain_identifier attribute instead. It will be a noop after CROSSTOOL migration to Starlark , and will be removed by #7075.
When set, it will be used to perform crosstool_config.toolchain selection. It will take precedence over --cpu Bazel option."

7075 was checked in 2018, so either "compiler" has been removed, either crosstool migration to starlark has been completed, or it's a noop, or it's not. 2018 was a while ago.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.