Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbus_codegen: extern location for dbus_codegen does not exist #53

Closed
evanjs opened this issue Nov 25, 2019 · 9 comments
Closed

dbus_codegen: extern location for dbus_codegen does not exist #53

evanjs opened this issue Nov 25, 2019 · 9 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@evanjs
Copy link

evanjs commented Nov 25, 2019

As mentioned in #51 (comment):

When attempting to import dbus_codegen, I get some strange errors.

Here is a minimal reproducible example for this issue

# Cargo.toml

[package]
name = "hello-from-generated-code"
version = "0.1.0"
authors = ["you@example.com"]
build = "src/build.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dbus = { git = "https://github.com/diwic/dbus-rs/" }

[build-dependencies]
dbus-codegen = { git = "https://github.com/diwic/dbus-rs/" }
// src/build.rs
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;

use dbus_codegen;

fn main() {
    let out_dir = env::var("OUT_DIR").unwrap();
    let dest_path = Path::new(&out_dir).join("hello.rs");
    let mut f = File::create(&dest_path).unwrap();

    f.write_all(
        b"
        pub fn message() -> &'static str {
            \"Hello, World!\"
        }
    ",
    )
    .unwrap();
}
// src/main.rs

include!(concat!(env!("OUT_DIR"), "/build.rs"));

fn main() {
    println!("{}", message());
}

This is basically the same source that is presented on https://doc.rust-lang.org/cargo/reference/build-scripts.html#case-study-code-generation, with the addition of use dbus_codegen; to build.rs.

Here is the sort of error message I am getting:

rust_crate2nix> unpacking sources
rust_crate2nix> unpacking source archive /nix/store/l9clysw4na0mb84i9525cyrhg2ams3yn-crate2nix-51rust_crate2nix> source root is crate2nix-51rust_crate2nix> patching sources
rust_crate2nix> configuring
rust_crate2nix> Building src/build.rs (crate2nix-51)
rust_crate2nix> Running rustc --crate-name build_script_build src/build.rs --crate-type bin -C opt-level=3 -C codegen-units=8 --edition 2018 --cfg feature="default" --out-dir target/build/crate2nix-51 --emit=dep-info,link -L dependency=target/buildDeps --extern dbus_codegen=/nix/store/w89xkakvva5mz8zmp85v35hvdl0l3jq1-rust_dbus-codegen-0.4.1/lib/libdbus_codegen-6c8a034000.rlib --cap-lints allow --color always
rust_crate2nix> error: extern location for dbus_codegen does not exist: /nix/store/w89xkakvva5mz8zmp85v35hvdl0l3jq1-rust_dbus-codegen-0.4.1/lib/libdbus_codegen-6c8a034000.rlib
rust_crate2nix> error[E0463]: can't find crate for `dbus_codegen`
rust_crate2nix>  --> src/build.rs:3:5
rust_crate2nix>   |
rust_crate2nix> 3 | use dbus_codegen;rust_crate2nix>   |     ^^^^^^^^^^^^ can't find craterust_crate2nix> error: aborting due to 2 previous errors
rust_crate2nix> For more information about this error, try `rustc --explain E0463`.
builder for '/nix/store/7izm2fi5xvlspv73srvsnanm8iksf9ss-rust_crate2nix-51-0.1.0.drv' failed with exit code 1; last 10 log lines:
  
  error[E0463]: can't find crate for `dbus_codegen`
   --> src/build.rs:3:5
    |
  3 | use dbus_codegen;
    |     ^^^^^^^^^^^^ can't find crate
  
  error: aborting due to 2 previous errors
  
  For more information about this error, try `rustc --explain E0463`.
[0 built (1 failed)]
error: build of '/nix/store/7izm2fi5xvlspv73srvsnanm8iksf9ss-rust_crate2nix-51-0.1.0.drv' failed

This error seems to be slightly different from that mentioned in #51 (comment).

@kolloch
Copy link
Collaborator

kolloch commented Nov 27, 2019

Thank you! I can reproduce.

This is due to the crate being in a subpath. Cargo actually looks for a matching Cargo.toml, apparently:

rust-lang/cargo#1462 (comment)

That is a bit crazy but should be supportable in buildRustCrate.

Feel free to add.

@kolloch kolloch added bug Something isn't working help wanted Extra attention is needed labels Nov 27, 2019
@ebkalderon
Copy link

@evanjs Just wondering, but in this particular line of Rust:

include!(concat!(env!("OUT_DIR"), "/build.rs"));

Did you intend to write this?

include!(concat!(env!("OUT_DIR"), "/hello.rs"));

I don't think it makes sense to include!() a build script into your src/main.rs and expect it to successfully compile.

@evanjs
Copy link
Author

evanjs commented Feb 17, 2020

Ah yes I suppose that wasn't the best example.
For some extra context, this is literally what I'm using right now.

pub mod systemd_manager {
    #![allow(unused)]
    include!(concat!(env!("OUT_DIR"), "/systemd_manager.rs"));
}

pub mod systemd_service {
    #![allow(unused)]
    include!(concat!(env!("OUT_DIR"), "/systemd_service.rs"));
}

I must have gotten too caught up in having a minimum reproducible example.

@ebkalderon
Copy link

It's okay! Looks like that line was fixed when the example was committed into master anyway. ☺️

@emilazy
Copy link

emilazy commented Feb 25, 2020

Is there any workaround for this? It's not even possible to override the src attribute for dependencies properly without patching the generated Nix file, as far as I can tell.

@kolloch
Copy link
Collaborator

kolloch commented Feb 28, 2020

@emilazy Did you try overriding the source with defaultCrateOverrides? To be honest, I am not sure if it works but it could. I'd be really happy if you tried that out and if it worked documented it as a workaround!

I want to work on this anyways, though.

kolloch added a commit to kolloch/nixpkgs that referenced this issue Mar 9, 2020
…sub directories

This is what cargo does for git repositories.

See related issues:

* nix-community/crate2nix#53
* nix-community/crate2nix#33
@kolloch
Copy link
Collaborator

kolloch commented Mar 9, 2020

I submitted a pull request for that to nixpkgs: NixOS/nixpkgs#82155

If you do not want to wait for this, you can override the "workspace_member" argument of buildRustCrate which allows specifying a subdirectory.

@kolloch
Copy link
Collaborator

kolloch commented Mar 11, 2020

It landed on master but not yet on nixpkgs-unstable. nixpkgs-unstable is behind roughly a week currently.

Fix is waiting here:

https://github.com/kolloch/crate2nix/tree/pkolloch-auto-workspace-member

kolloch added a commit that referenced this issue Mar 11, 2020
Cargo does this for git repositories as well:

rust-lang/cargo#1462 (comment)

This will fix #33, #53 -- integration tests pending.

It depends on a nixpkgs buildRustCrate feature PR:

NixOS/nixpkgs#82155
kolloch added a commit that referenced this issue Mar 11, 2020
Added tests for real crates depending on workspace_member = null.
kolloch added a commit that referenced this issue Mar 11, 2020
Added tests for real crates depending on workspace_member = null.
kolloch added a commit that referenced this issue Mar 12, 2020
Cargo does this for git repositories as well:

rust-lang/cargo#1462 (comment)

This will fix #33, #53 -- integration tests pending.

It depends on a nixpkgs buildRustCrate feature PR:

NixOS/nixpkgs#82155
kolloch added a commit that referenced this issue Mar 12, 2020
Added tests for real crates depending on workspace_member = null.
kolloch added a commit that referenced this issue Mar 12, 2020
Cargo does this for git repositories as well:

rust-lang/cargo#1462 (comment)

This will fix #33, #53 -- integration tests pending.

It depends on a nixpkgs buildRustCrate feature PR:

NixOS/nixpkgs#82155
kolloch added a commit that referenced this issue Mar 12, 2020
Added tests for real crates depending on workspace_member = null.
@kolloch
Copy link
Collaborator

kolloch commented Mar 16, 2020

Merged :)

@kolloch kolloch closed this as completed Mar 16, 2020
andir pushed a commit to andir/nixpkgs that referenced this issue Mar 28, 2020
…sub directories

This is what cargo does for git repositories.

See related issues:

* nix-community/crate2nix#53
* nix-community/crate2nix#33

(cherry picked from commit 8a6638d)
stigok pushed a commit to stigok/nixpkgs that referenced this issue Jun 12, 2020
…sub directories

This is what cargo does for git repositories.

See related issues:

* nix-community/crate2nix#53
* nix-community/crate2nix#33

(cherry picked from commit 8a6638d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants