facebook / buck2

Build system, successor to Buck
https://buck2.build/
Apache License 2.0
3.33k stars 194 forks source link

Question: how to pass dependencies that change state forward across a non-output-changing rule #609

Closed vindard closed 1 month ago

vindard commented 1 month ago

Description

We've come across an interesting challenge where we have the following situation:

How can we get Rule C to rebuild if Rule A's dependencies change and both Rule A and Rule B correctly rebuild?

Two approaches we've explored:

  1. (Non buck-native approach) Take a hash of Rule A's dependencies and include it in the output of Rule B so that it changes from build to build and re-triggers Rule C -> see https://github.com/GaloyMoney/galoy/pull/4169

  2. (Buck-native approach) Pass the dependencies of Rule A into Rule C as well to trigger rebuild in a non-Rule-B-dependent way -> see https://github.com/GaloyMoney/galoy/pull/4172

We've decided to go with the first approach for now since it more accurately reflects the inter-relationship between the rules, but ideally we'd like to figure out if there is some buck-native way to accomplish this without having to hack a changing dependency state in as we've done.

zjturner commented 1 month ago

What’s the point of rebuilding B if it’s just going to generate the same output every time?

vindard commented 1 month ago

What’s the point of rebuilding B if it’s just going to generate the same output every time?

It technically doesn't need to be rebuilt after its first build. But it needs to signal to other rules it's an input of, that its own dependencies have changed.

zjturner commented 1 month ago

What inputs actually influence the output of B? If it really never changes, then I think you should upload the bin file somewhere, and download it with http_archive(). It sounds like B should not have a dependency on anything, since nothing influences the nature of its output, and instead C should have a direct dependency on A as well as a dependency on B.

vindard commented 1 month ago

It sounds like B should not have a dependency on anything, since nothing influences the nature of its output, and instead C should have a direct dependency on A as well as a dependency on B.

Yup this is the approach we sort of took in https://github.com/GaloyMoney/galoy/pull/4172 and now I'm thinking it's probably the correct one for best representing what we have. Closing for now based on this, thanks!