nixify icon indicating copy to clipboard operation
nixify copied to clipboard

generate an `app` per Rust workspace binary

Open haraldh opened this issue 4 months ago • 4 comments

$ nix run 'github:rvolosatovs/nixify?dir=examples/rust-hello-multibin'
[...]

error: unable to execute '/nix/store/gm2sj4fii5pfyj0ghlfs5h2d5adg4bkx-rust-hello-multibin-0.1.0/bin/rust-hello-multibin': No such file or directory

haraldh avatar Feb 13 '24 14:02 haraldh

Thanks for the report and sorry for a late response! The fact that nix run does not work for this one is expected. cargo run also does not work with that crate:

error: `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key.
available binaries: bye, hello-other-path

The error message should certainly be improved though

rvolosatovs avatar Mar 19 '24 14:03 rvolosatovs

$ nix flake show --no-write-lock-file  'github:rvolosatovs/nixify?dir=examples/rust-hello-multibin'
[...]
github:rvolosatovs/nixify/e7295eaafb29bdb709fd449118c7cec30d4bbce3?dir=examples/rust-hello-multibin
├───apps
│   ├───aarch64-darwin
│   │   ├───default: app
│   │   ├───rust-hello-multibin: app
│   │   └───rust-hello-multibin-debug: app
│   ├───aarch64-linux
│   │   ├───default: app
│   │   ├───rust-hello-multibin: app
│   │   └───rust-hello-multibin-debug: app
│   ├───x86_64-darwin
│   │   ├───default: app
│   │   ├───rust-hello-multibin: app
│   │   └───rust-hello-multibin-debug: app
│   └───x86_64-linux
│       ├───default: app
│       ├───rust-hello-multibin: app
│       └───rust-hello-multibin-debug: app
[...]

Seems like there should be some app ... right?

haraldh avatar Mar 19 '24 15:03 haraldh

$ nix flake show --no-write-lock-file  'github:rvolosatovs/nixify?dir=examples/rust-hello-multibin'
[...]
github:rvolosatovs/nixify/e7295eaafb29bdb709fd449118c7cec30d4bbce3?dir=examples/rust-hello-multibin
├───apps
│   ├───aarch64-darwin
│   │   ├───default: app
│   │   ├───rust-hello-multibin: app
│   │   └───rust-hello-multibin-debug: app
│   ├───aarch64-linux
│   │   ├───default: app
│   │   ├───rust-hello-multibin: app
│   │   └───rust-hello-multibin-debug: app
│   ├───x86_64-darwin
│   │   ├───default: app
│   │   ├───rust-hello-multibin: app
│   │   └───rust-hello-multibin-debug: app
│   └───x86_64-linux
│       ├───default: app
│       ├───rust-hello-multibin: app
│       └───rust-hello-multibin-debug: app
[...]

Seems like there should be some app ... right?

Right, so cases where there are multiple binaries in a workspace are a bit tricky, right now, for example, we have this funky logic for OCI where, if there is a binary with the same name as the crate we're building or there's only one binary being built, then we assume that's the command we want to execute. https://github.com/rvolosatovs/nixify/blob/c2134e5775c8cc640a3ce4578530b9ae8bc069a0/lib/rust/mkAttrs.nix#L735-L740

I think what really should happen here is that there should be a Nix app generated per binary in the workspace (with appropriate executable being run on nix run) and a Nix package per workspace to build all of it

We already know exactly which binaries cargo will build https://github.com/rvolosatovs/nixify/blob/c2134e5775c8cc640a3ce4578530b9ae8bc069a0/lib/rust/crateBins.nix#L106-L150, it's just the matter of setting up the plumbing to extract those binaries from the workspace package. Those packages should be Nix "apps", the workspace package should be just that - a Nix package, not an "app" as it's marked now.

So, in result, rust-hello-multibin and rust-hello-multibin-debug would not show up in apps, those would keep only being available in packages. We would, however have bye and hello-other-path apps available. For rust-hello-multibin specifically, there would be no default app (but there would be a default package - the workspace build), but otherwise I think default app should be set if either:

  • there is only one binary in the workspace
  • there is a binary with the same name as the top-level crate being built

basically, the same logic that already exists for OCI

Does that make sense?

rvolosatovs avatar Mar 20 '24 11:03 rvolosatovs

totally makes sense and would be exactly what I need :-)

haraldh avatar Mar 20 '24 12:03 haraldh