naersk icon indicating copy to clipboard operation
naersk copied to clipboard

How do you select `--bin` targets?

Open antifuchs opened this issue 4 years ago • 5 comments

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?

antifuchs avatar Nov 25 '20 02:11 antifuchs

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.

nmattia avatar Nov 30 '20 12:11 nmattia

I'm also running into this.

Finding a solution here would be great.

theduke avatar Apr 23 '21 00:04 theduke

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?)

BrianHicks avatar Apr 25 '22 15:04 BrianHicks

Hi, any update on this? Would be really nice to be able to build single binaries :)

tiagolobocastro avatar Oct 28 '22 09:10 tiagolobocastro

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 🙂

Patryk27 avatar Oct 30 '22 19:10 Patryk27