ipetkov / crane

A Nix library for building cargo projects. Never build twice thanks to incremental artifact caching.
https://crane.dev
MIT License
962 stars 92 forks source link

"error: no bin target named `api`. Available bin targets: crane-dummy-cherami" #590

Closed samuela closed 7 months ago

samuela commented 7 months ago

The documentation suggests that adding cargoExtraArgs = "--bin=api"; will cause crane to only build the api binary, as in cargo build --bin=api. However, I'm seeing the following error when doing so:

error: builder for '/nix/store/nv80m22mn133gmsg2fraggxcl001nlpd-cherami-build.drv' failed with exit code 101;
       last 25 log lines:
       >     Checking color-eyre v0.6.2
       >     Checking hyper-rustls v0.24.2
       >     Checking cliclack v0.1.13
       >     Checking parse_duration v2.1.1
       >     Checking chrono-humanize v0.2.3
       >     Checking aws-smithy-runtime v1.1.4
       >     Checking email_address v0.2.4
       >    Compiling sqlx-macros-core v0.7.3
       >     Checking tower-http v0.5.2
       >    Compiling async-recursion v1.0.5
       >     Checking reqwest v0.11.23
       >     Checking clap v4.4.18
       >    Compiling sqlx-macros v0.7.3
       >     Checking aws-sdk-sts v1.12.0
       >     Checking aws-sdk-sso v1.12.0
       >     Checking aws-sdk-ssooidc v1.12.0
       >     Checking aws-sdk-ec2 v1.17.0
       >     Checking aws-config v1.1.4
       >     Checking sqlx v0.7.3
       >     Finished release [optimized] target(s) in 1m 45s
       > ++ command cargo build --release --bin=api
       > error: no bin target named `api`.
       > Available bin targets:
       >     crane-dummy-cherami
       >
       For full logs, run 'nix log /nix/store/nv80m22mn133gmsg2fraggxcl001nlpd-cherami-build.drv'.
error: 1 dependencies of derivation '/nix/store/gjsaicr5k4r09c983k46vxw6xn3ccvi5-cherami-build.drv' failed to build
root@b62e2017d34d:/workspaces/bitbop/cherami# cargo build --bin=api
    Finished dev [unoptimized + debuginfo] target(s) in 0.47s
root@b62e2017d34d:/workspaces/bitbop/cherami#

Am I missing something? Is this functioning as intended?

dpc commented 7 months ago

Given that I see 3rd party dependencies, it could be that pasing of args to implicit XDepsOnly is breaking. Make sure to split your build into explicit build-deps-only and build steps using cargoArtifacts passing.

samuela commented 7 months ago

Why do I have to do this? Why doesn't it happen automatically?

dpc commented 7 months ago

I think it is happening automatically and going wrong. :D

ipetkov commented 7 months ago

Why do I have to do this? Why doesn't it happen automatically?

The short answer is when buildDepsOnly runs we strip out all sources and stub out any binary targets so that if you were to add a new target it would not require rebuilding the entire workspace from scratch. There's an existing issue for this (https://github.com/ipetkov/crane/issues/268) so will dedup this to there