rustshop / flakebox

Flakebox is to your Rust project dev environment, what NixOS is to your OS, or home-manager to your home directory.
96 stars 5 forks source link

Issues with building/testing multiple binaries #159

Closed GetPsyched closed 1 week ago

GetPsyched commented 1 week ago

Hey, firstly, thanks for this tool; it's been of great help!

My issue is simple: I'm outputting 2 binaries from my Rust app and I want to not only expose both as packages but also have CI run on it (unsure if it doesn't though, I don't have many leads to debug this)

To avoid the XY problem, here's what I tried:

Still unsure if this is an issue with my setup/configuration or flakebox not supporting this OOTB.

dpc commented 1 week ago

@GetPsyched pickBinary is what we use in Fedimint, and that's the only way I'm aware to take stuff from a single build into particular binaries.

https://github.com/fedimint/fedimint/blob/af3f82711df6535968e7a646f3598a9cba66fafd/nix/flakebox.nix#L555

Running any of the build variations like nix build .#ci.foo only work for the default package output and not my non-default package output.

In Fedimint we export whole result of craneMultiBuild as legacyPackages

https://github.com/fedimint/fedimint/blob/af3f82711df6535968e7a646f3598a9cba66fafd/flake.nix#L379

https://github.com/fedimint/fedimint/blob/af3f82711df6535968e7a646f3598a9cba66fafd/flake.nix#L201

craneMultiBuild is what creates this nested attrset of various combinations of toolchains and build profiles.

As long as you export something as a result of what craneMultiBuild is wrapping, it will appear in this nested attrset.

https://github.com/fedimint/fedimint/blob/af3f82711df6535968e7a646f3598a9cba66fafd/nix/flakebox.nix#L534

GetPsyched commented 1 week ago

Thanks for the quick reply. I've looked into this and it might take a bit for me to understand enough to test. Will get back here once I've fiddled around with the suggestions.

dpc commented 1 week ago

@GetPsyched I have another project that is much simpler that exposes two nix packages: https://github.com/rustshop/perfit/blob/56b33333bd7e38b503841a528e6207dab8748fff/flake.nix#L61

GetPsyched commented 1 week ago

Perfect! Tried that solution and it works nicely!

Probably a final question, will I have to edit the workflow file to also build the new package output (nix build .#ci.foo) manually or can I regenerate it using Flakebox somehow?

dpc commented 1 week ago

@GetPsyched If you don't set manually this https://github.com/rustshop/perfit/blob/56b33333bd7e38b503841a528e6207dab8748fff/flake.nix#L26 the default generated github workflow will do this: https://github.com/rustshop/flakebox/blob/12d5ee4f6c47bc01f07ec6f5848a83db265902d3/lib/modules/github.nix#L280

I must warn you that the workflows generated by flakebox only go so far, and if you need something more customized, you should just disable and create them manually.

GetPsyched commented 1 week ago

That's fair. I've manually edited the existing workflow to compile each binary against every architecture.

Thanks for all the help!