简体   繁体   中英

How do you aggregate Bazel build artifacts together that have been built with different configurations?

I am using Bazel to build binaries using many different configurations and then zip those binaries up together.

Initially I tried writing a genrule to do this by adding each binary rule to the srcs and then run zip on them by referencing $(location :binary-target) .

The problem with doing it this way is the genrule itself can only be built with one specific configuration, meaning multiple :some-binary-target srcs using different configs cannot successfully build together.

Is there a way to reference a build artifact of a rule under a configuration different than the rule requesting said artifact?

This can be a little involved, depending on exactly what you need to do.

What you need here is a Starlark rule that has an attribute with a "split configuration transition". With such a transition, the targets in that attribute can be evaluated in some other configuration or configurations. So you can have

some_rule(
  name = "foo",
  deps = [":dep1", ":dep2"]
)

where the deps attribute has a transition which goes from configuration "a" (the configuration in which foo is being evaluated) to "b" and "c", and foo gets two versions of dep1, one from configuration b and another from c, and similarly two versions of dep2. foo can then do what it needs to with them, like put them in a zip file.

Much of this is explained here:
https://docs.bazel.build/versions/master/skylark/config.html

in particular:
https://docs.bazel.build/versions/master/skylark/config.html#user-defined-transitions

There's a thread here that has an example how to do most of this:
https://groups.google.com/d/topic/bazel-discuss/H8lS3JL2jt8/discussion

That thread mentions a missing piece for "how to access the configuration information of the different versions of each dep", which you might need, depending on what you need to do. That's actively being worked on, and will probably be available in the next bazel release (whatever comes after 3.0.0, specifically when this is rolled forward )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM