naersk
naersk copied to clipboard
How do you select `--bin` targets?
I've got a program here that has two [[bin]]
targets in its Cargo.lock: deploy
and activate
, and only one of them, deploy
, can build on macOS (both of them build on Linux); so I have to run cargo build
with --bin deploy
to get the binary output on the command-line, and I would love to do the same in Naersk.
I thought that I could achieve victory here by doing:
darwinOptions = pkgs.lib.optionalAttrs stdenv.isDarwin {
cargoBuildOptions = opts: opts ++ [ "--bin" "deploy" ]; # The "activate" binary is linux-only.
}
That, however, causes dependency builds to get the --bin
option passed as well, which breaks the build; it also feels weird.
A work-around for this is to also pass singleStep = true;
, but that is also un-ideal. (No incremental builds!)
What I'd really like here is to have an option in Naersk that lets users select the --bin
targets to output.
Alternatively, it would also be ok to have a way to override the cargo options on dependency builds (defaulting to the overall cargo options function). That way too, we could select the options applying to the "build" of the top-level system, and the options that apply to the system's dependencies.
What do you think?
Hey @antifuchs,
I didn't think about this, but yes, that would be nice. We already override some build options for dependencies internally, but we could make this more broadly available.
Just as we allow overriding the derivation's attributes (override
, overrideMain
) we could allow overriding some naersk options as well - which, IIUC, is what you suggest! Let me know if you have some UX in mind.
I'm also running into this.
Finding a solution here would be great.
I'm getting around this for now by setting copyBinsFilter
:
copyBinsFilter = ''
select(.reason == "compiler-artifact" and .executable != null and .profile.test == false and .target.name == "${name}")'';
however, this only works because I'm treating it as a packaging thing only—all the targets in my virtual manifest are still getting built (despite setting targets
?)
Hi, any update on this? Would be really nice to be able to build single binaries :)
Hi,
No progress has been done on this yet - I think adding something like cargoBuildOptionsButOnlyForTheMainDerivationNotTheDependenciesOne
should be pretty straightforward, so I'll try tackling it within a few days 🙂