cmake-rs icon indicating copy to clipboard operation
cmake-rs copied to clipboard

Allow building multiple targets at once

Open dcsommer opened this issue 4 years ago • 6 comments
trafficstars

The current API only allows specifying a single build target. However, the cmake CLI allows specifying multiple targets.

       --target <tgt>..., -t <tgt>...
              Build <tgt> instead of the default target.  Multiple targets may
              be given, separated by spaces.

It would be convenient to allow this in cmake-rs. Calling build_target("target1 target2") does not work with the build() API which only returns a single path.

The workaround is to invoke cmake once for each target, but this is slow.

dcsommer avatar Apr 27 '21 18:04 dcsommer

Perhaps each call to build_target can be collected into a vector?

alexcrichton avatar Apr 28 '21 14:04 alexcrichton

Perhaps each call to build_target can be collected into a vector?

build_target() mutates self, so I'd need to copy the config for each. But yeah, you can build multiple targets today if you call build_target() and then build() once per target. I didn't quite grok how your idea helps with the usecase of building multiple targets at once though.

dcsommer avatar Apr 28 '21 15:04 dcsommer

Er what I mean is that cmake_target internally could become a Vec whereas it's now an Option. We could then pass all those down all at once when calling cmake to avoid having to call cmake multiple times. There could be some sort of alternate API or something or other for building to learn about all the paths if you'd like multiple returned (although I though the return value was just the output directory, not the actual artifacts...)

alexcrichton avatar Apr 28 '21 16:04 alexcrichton

Ah yes, you are right about the output directory. That makes me hopeful for this issue since it seems doable without a public API change. Internally using a vector seems like the right approach to me.

On Wed, Apr 28, 2021 at 9:29 AM Alex Crichton @.***> wrote:

Er what I mean is that cmake_target internally could become a Vec whereas it's now an Option. We could then pass all those down all at once when calling cmake to avoid having to call cmake multiple times. There could be some sort of alternate API or something or other for building to learn about all the paths if you'd like multiple returned (although I though the return value was just the output directory, not the actual artifacts...)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/alexcrichton/cmake-rs/issues/115#issuecomment-828596469, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIIKIHKD5AM2M5SE3EFVPDTLAZXTANCNFSM43VRJE2Q .

dcsommer avatar Apr 28 '21 16:04 dcsommer

@alexcrichton are you open to PRs for this issue using the vector approach?

dcsommer avatar May 03 '21 20:05 dcsommer

indeed!

alexcrichton avatar May 04 '21 15:05 alexcrichton