Setting up a C++ project

400 views
Skip to first unread message

sbilk...@gmail.com

unread,
May 20, 2015, 12:20:36 AM5/20/15
to bazel-...@googlegroups.com
Hi,

I've used bazel when I was working at Google. I'm trying to get things started on my C++ project and would appreciate some help.

The Google C++ styleguide says to use <> includes over "". Yet no where in your samples do I see how to set the include dirs for ALL rules. I know we can add it on a rule or BUILD file basis but how to do it for the entire project?

A more general problem is how do you recommend setting up different config files to define different builds? For example one file would look like:

development config file:
macros: DEBUG
include dirs: xxx yyy
compiler: gcc

testing development config file 1:
macros:
include dirs: xxx yyy
compiler: gcc

testing development config file 2:
macros:
include dirs: xxx yyy
compiler: clang

The objective is to have different config files for different targets (Unix, Windows, embeded devices), compilers (gcc, clang, emscripten), debug/release, etc.

Any help would be useful. Thanks.

Kristina Chodorow

unread,
May 20, 2015, 10:13:38 AM5/20/15
to sbilk...@gmail.com, bazel-...@googlegroups.com
On Wed, May 20, 2015 at 12:20 AM, <sbilk...@gmail.com> wrote:
Hi,

I've used bazel when I was working at Google. I'm trying to get things started on my C++ project and would appreciate some help.

The Google C++ styleguide says to use <> includes over "". Yet no where in your samples do I see how to set the include dirs for ALL rules. I know we can add it on a rule or BUILD file basis but how to do it for the entire project?

AFAIK, you cannot set default include dirs for all rules.  That said, if you needed, maybe you could define a macro that that you used instead of cc_library that always set includes=[] the way you want.

(Include dirs are orthogonal to <> vs "": #include "whatever" uses an implementation-specific search and then falls back on <>'s include dirs.  See http://stackoverflow.com/a/77092/4243.)

 

A more general problem is how do you recommend setting up different config files to define different builds? For example one file would look like:

development config file:
macros: DEBUG
include dirs: xxx yyy
compiler: gcc

testing development config file 1:
macros:
include dirs: xxx yyy
compiler: gcc

testing development config file 2:
macros:
include dirs: xxx yyy
compiler: clang

The objective is to have different config files for different targets (Unix, Windows, embeded devices), compilers (gcc, clang, emscripten), debug/release, etc.

We don't really support config files for different builds, would using http://bazel.io/docs/build-encyclopedia.html#config_setting and http://bazel.io/docs/build-encyclopedia.html#select work for you?  You could have config presets like:

config_setting(
    name = "arm_debug",
    values = {"compiler": "gcc", "compilation_mode": "debug", "define": "ARCH=arm64"}
)

Then set up your rules to select the right values.

Austin Schuh

unread,
May 20, 2015, 1:12:03 PM5/20/15
to sbilk...@gmail.com, bazel-...@googlegroups.com
If you are willing to pay the complexity cost, you can modify the CROSSTOOL file or put a custom one in your repo (docs are light/are the code) to configure various compilers and add new ones.


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/b71db5ee-460b-47f0-87f4-254b7278bcbf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sbilkoloft

unread,
May 24, 2015, 6:32:30 PM5/24/15
to bazel-...@googlegroups.com
Thanks for the replies.

I'm wondering what's google's internal equivalent to autoconf? How do you compute platform specific macros to be used inside the code? (I know it's not recommended but sometimes it's inevitable.)

For my case I was thinking of using cmake to generate me the configs and then bazel to do the actual compiling.

Damien Martin-guillerez

unread,
May 26, 2015, 3:54:39 AM5/26/15
to sbilkoloft, bazel-...@googlegroups.com
There is no equivalent to autoconf for google as we control the environment inside google so there is no need for such a thing.
We are working on a way to generate package using a skylark-like language to have autoconf-like features. I don't know when it will be ready though.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Damien
Message has been deleted

Damien Martin-guillerez

unread,
Sep 10, 2016, 3:09:58 AM9/10/16
to sbilkoloft, bazel-discuss
Hi,

This feature is working now (still has a few issues though). See 
https://www.bazel.io/blog/2016/03/31/autoconfiguration.html for an explanation on how it works.

On Sat, Sep 10, 2016, 9:02 AM sbilkoloft <sbilk...@gmail.com> wrote:
Hi Damian,

Any updates on this or alternative solutions?

Thanks.
Reply all
Reply to author
Forward
0 new messages