Recommended way to generate two different binaries for release vs debug?

65 views
Skip to first unread message

Reynold Xin

unread,
Jan 30, 2019, 6:28:04 PM1/30/19
to bazel-discuss
I have a C++ project that I'm using Bazel for. One thing I'm trying to figure out is how to get bazel to generate two differently named binary files for debug vs release build. As far as I can tell, -c opt vs -c fastbuild generates the same file name (based on the cc_binary name).

I have thought about two different approaches, and neither of them are ideal:

1. Use a wrapper script to copy the binary file over to different location based on the config profile. The downside with this approach is that there is no way to create a single bazel target that depends on both the release build and the debug build.

2. Create a special_cc_library wrapper that automatically generates two cc_library for each call, one called [name]-debug and one called [name]-release, with different copts. The downside here is that it is very difficult to rewrite dependencies, and also making the -c flag useless in bazel.

Are there better ways to do this? Thanks.

Rong Jie

unread,
Jan 31, 2019, 4:09:23 AM1/31/19
to bazel-discuss
I think Bazel already does what you want.

Try to build a project with "-c opt" then with "-c dbg". Navigate to bazel-out/ folder and you should see x64_windows-opt/ and x64_windows-debug/ folder. Under these folders, you can find your binaries at bin/<package_name>/target.

bazel-bin/ folder is just a symlink to bazel-out/<last-config>/bin for user's convenience.

Greg Estren

unread,
Jan 31, 2019, 11:35:14 AM1/31/19
to Rong Jie, bazel-discuss
Reynold,

See Bazel's configurability roadmap that describes efforts to improve use cases like yours. Technically you can get the wrapper you need today if you're willing to play around some with Starlark rules and a new experimental feature. I could help you prototype 1. if you like.

--
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/2408ae5d-8d5b-45da-9422-885a5aead8f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reynold Xin

unread,
Feb 4, 2019, 2:33:00 PM2/4/19
to Greg Estren, bazel-discuss, Rong Jie
Thanks Greg and Rong. I'm going to try if I can get this working with some wrapper script first, without creating an extension. If it doesn't work, I will try create a rule.

--
rxin


On Thu, Jan 31, 2019 at 8:34 AM, Greg Estren <gre...@google.com> wrote:
Reynold,

See Bazel's configurability roadmap that describes efforts to improve use cases like yours. Technically you can get the wrapper you need today if you're willing to play around some with Starlark rules and a new experimental feature. I could help you prototype 1. if you like.

On Thu, Jan 31, 2019 at 4:09 AM Rong Jie <loorongjie@gmail.com> wrote:
I think Bazel already does what you want.

Try to build a project with "-c opt" then with "-c dbg". Navigate to bazel-out/ folder and you should see x64_windows-opt/ and x64_windows-debug/ folder. Under these folders, you can find your binaries at bin/<package_name>/target.

bazel-bin/ folder is just a symlink to bazel-out/<last-config>/bin for user's convenience.


On Thursday, January 31, 2019 at 7:28:04 AM UTC+8, Reynold Xin wrote:
I have a C++ project that I'm using Bazel for. One thing I'm trying to figure out is how to get bazel to generate two differently named binary files for debug vs release build. As far as I can tell, -c opt vs -c fastbuild generates the same file name (based on the cc_binary name).

I have thought about two different approaches, and neither of them are ideal:

1. Use a wrapper script to copy the binary file over to different location based on the config profile. The downside with this approach is that there is no way to create a single bazel target that depends on both the release build and the debug build.

2. Create a special_cc_library wrapper that automatically generates two cc_library for each call, one called [name]-debug and one called [name]-release, with different copts. The downside here is that it is very difficult to rewrite dependencies, and also making the -c flag useless in bazel.

Are there better ways to do this? Thanks.

--
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-discuss+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "bazel-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bazel-discuss/DtGsxEMG0og/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CABdTCQUADzbsfLzQA%2BzGRr8SjTxAAq0Mwjv%2Be5FVkiYzohaN8A%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages