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

can't build futures_util in some cases #83

Closed
bbigras opened this issue Jan 31, 2020 · 6 comments
Closed

can't build futures_util in some cases #83

bbigras opened this issue Jan 31, 2020 · 6 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@bbigras
Copy link
Contributor

bbigras commented Jan 31, 2020

crate2nix 0.7.0-beta.1

[dependencies]
futures = { version = "0.3", default-features = false, features = ["compat"] }
futures01 = { package = "futures", version = "0.1" }
fn main() {
    println!("Hello, world!");
}
Building src/lib.rs (futures_util)
Running rustc --crate-name futures_util src/lib.rs --out-dir target/lib --emit=dep-info,link -L dependency=target/deps --cap-lints allow -C opt-level=3 -C codegen-units=4 --extern futures_01=/nix/store/fy357naqvcp32pwzvfsy8js2656cg3mz-rust_futures-0.1.29-lib/lib/libfutures-b4d31530db.rlib --extern futures_channel=/nix/store/8fawwkmsfka609mrpvh2zkv9xxigsc4i-rust_futures-channel-0.3.1-lib/lib/libfutures_channel-89d404dce0.rlib --extern futures_core=/nix/store/3mkq50ackk1mabrr4jsw4wgxy3r7fywa-rust_futures-core-0.3.1-lib/lib/libfutures_core-b242c18f17.rlib --extern futures_io=/nix/store/8l7aykr100h7wimgq6x533gxgxaj6df0-rust_futures-io-0.3.1-lib/lib/libfutures_io-20eec2fb3b.rlib --extern futures_sink=/nix/store/7k45qsgp7dvs9rwd0p87xhjfb1dmwwjz-rust_futures-sink-0.3.1-lib/lib/libfutures_sink-86f23fc531.rlib --extern futures_task=/nix/store/3nrnys0pvza4asnyzbawczs8jfspr3ll-rust_futures-task-0.3.1-lib/lib/libfutures_task-53a5ce36f5.rlib --extern memchr=/nix/store/cymqzvxvzigisa8q1isjdqqx5y0rm9dx-rust_memchr-2.3.0-lib/lib/libmemchr-ff22be23c8.rlib --extern pin_utils=/nix/store/741ijdwd1w9lcrqp8bim3spkg64r6r6a-rust_pin-utils-0.1.0-alpha.4-lib/lib/libpin_utils-f799508eca.rlib --extern slab=/nix/store/pf4w8jhfbjia2q45ipd0y3z6c2sfnf93-rust_slab-0.4.2-lib/lib/libslab-d13bd9d52c.rlib --cfg feature="alloc" --cfg feature="async-await" --cfg feature="async-await-macro" --cfg feature="channel" --cfg feature="compat" --cfg feature="futures-channel" --cfg feature="futures-core/alloc" --cfg feature="futures-core/std" --cfg feature="futures-io" --cfg feature="futures-macro" --cfg feature="futures-sink" --cfg feature="futures-task/alloc" --cfg feature="futures-task/std" --cfg feature="futures_01" --cfg feature="io" --cfg feature="memchr" --cfg feature="proc-macro-hack" --cfg feature="proc-macro-nested" --cfg feature="sink" --cfg feature="slab" --cfg feature="std" --edition 2018 -C metadata=2d5950350b -C extra-filename=-2d5950350b --crate-type lib --color always
error[E0432]: unresolved import `proc_macro_hack`
 --> src/async_await/join_mod.rs:3:5
  |
3 | use proc_macro_hack::proc_macro_hack;
  |     ^^^^^^^^^^^^^^^ use of undeclared type or module `proc_macro_hack`

error[E0432]: unresolved import `proc_macro_hack`
 --> src/async_await/select_mod.rs:3:5
  |
3 | use proc_macro_hack::proc_macro_hack;
  |     ^^^^^^^^^^^^^^^ use of undeclared type or module `proc_macro_hack`

error[E0432]: unresolved import `futures_macro`
   --> src/async_await/select_mod.rs:162:13
    |
162 |     pub use futures_macro::select;
    |             ^^^^^^^^^^^^^ use of undeclared type or module `futures_macro`

error[E0432]: unresolved import `futures_macro`
  --> src/async_await/join_mod.rs:81:13
   |
81 |     pub use futures_macro::try_join;
   |             ^^^^^^^^^^^^^ use of undeclared type or module `futures_macro`

error[E0432]: unresolved import `futures_macro`
  --> src/async_await/join_mod.rs:78:13
   |
78 |     pub use futures_macro::join;
   |             ^^^^^^^^^^^^^ use of undeclared type or module `futures_macro`

error: cannot determine resolution for the attribute macro `proc_macro_hack`
   --> src/async_await/select_mod.rs:161:7
    |
161 |     #[proc_macro_hack(support_nested)]
    |       ^^^^^^^^^^^^^^^
    |
    = note: import resolution is stuck, try simplifying macro imports

error: cannot determine resolution for the attribute macro `proc_macro_hack`
  --> src/async_await/join_mod.rs:80:7
   |
80 |     #[proc_macro_hack(support_nested)]
   |       ^^^^^^^^^^^^^^^
   |
   = note: import resolution is stuck, try simplifying macro imports

error: cannot determine resolution for the attribute macro `proc_macro_hack`
  --> src/async_await/join_mod.rs:77:7
   |
77 |     #[proc_macro_hack(support_nested)]
   |       ^^^^^^^^^^^^^^^
   |
   = note: import resolution is stuck, try simplifying macro imports

error: aborting due to 8 previous errors

For more information about this error, try `rustc --explain E0432`.
builder for '/nix/store/kxngwa4nxvkb59f69fbjvcf87na5wz0r-rust_futures-util-0.3.1.drv' failed with exit code 1
cannot build derivation '/nix/store/4pv8kbnfgl8ixkx5wsyi06wz317gs1f8-rust_test-crate2nix-0.1.0.drv': 1 dependencies couldn't be built
error: build of '/nix/store/4pv8kbnfgl8ixkx5wsyi06wz317gs1f8-rust_test-crate2nix-0.1.0.drv' failed
@kolloch
Copy link
Collaborator

kolloch commented Mar 29, 2020

Thank you for the report and the sample! I could reproduce it and I think that it is something that is useful and should be supported.

I also verified quickly that each of these dependencies builds seperately.

The generated code is already quite obviously wrong:

{
        # ...
        dependencies = [
          {
            name = "futures";
            packageId = "futures 0.1.29";
            usesDefaultFeatures = false;
            features = [ "compat" ];
          }
          {
            name = "futures";
            packageId = "futures 0.1.29";
            rename = "futures01";
          }
          {
            name = "futures";
            packageId = "futures 0.3.4";
            usesDefaultFeatures = false;
            features = [ "compat" ];
          }
          {
            name = "futures";
            packageId = "futures 0.3.4";
            rename = "futures01";
          }
        ];
}

The rename support in buildRustCrate is keyed by crate name so it will also be a problem:

       let # ...
            crateRenames =
              builtins.listToAttrs
                (map (d: { name = d.name; value = d.rename; }) dependenciesWithRenames);
        in 
           # This is the `buildRustCrate` call -- just that users can override it.
           buildRustCrateFunc (
              crateConfig // {
                src = crateConfig.src or (
                  pkgs.fetchurl {
                    name = "${crateConfig.crateName}-${crateConfig.version}.tar.gz";
                    url = "https://crates.io/api/v1/crates/${crateConfig.crateName}/${crateConfig.version}/download";
                    sha256 = crateConfig.sha256;
                  }
                );
                inherit features dependencies buildDependencies crateRenames release;
              }
            )

@kolloch kolloch self-assigned this Mar 29, 2020
kolloch added a commit that referenced this issue Mar 29, 2020
kolloch added a commit that referenced this issue Apr 2, 2020
crate generate the correct ResolvedDependencies.

`cargo metadata` really does not make this easy as there is not direct
link between `NodeDep` and `Dependency`.
kolloch added a commit that referenced this issue Apr 2, 2020
that it actually checks it got the right crates to compile.
@kolloch kolloch added bug Something isn't working enhancement New feature or request labels Apr 3, 2020
@kolloch kolloch added this to the 0.9 milestone Apr 3, 2020
kolloch added a commit that referenced this issue Apr 3, 2020
@kolloch
Copy link
Collaborator

kolloch commented Apr 3, 2020

I have fixed this but I need to wait for the related nixpkgs review and eventual merge: NixOS/nixpkgs#84179

cargo metadata makes this rediculously difficult. I had to rematch the version requirements of the dependencies against the resolved packages for a package.

10d8de9

@bbigras
Copy link
Contributor Author

bbigras commented May 28, 2020

It seems I'm not able to reproduce with my test case. Thanks!

@kolloch
Copy link
Collaborator

kolloch commented May 29, 2020

In #51, it seems like this issue is occurring again.

The generated code in Cargo.nix looks as expected:

      "futures-renamed-test" = rec {
        crateName = "futures-renamed-test";
        version = "0.1.0";
        edition = "2018";
        crateBin = [
          { name = "futures-renamed-test"; path = "src/main.rs"; }
        ];
        src = lib.cleanSourceWith { filter = sourceFilter;  src = ./.; };
        authors = [
          "Peter Kolloch <info@eigenvalue.net>"
        ];
        dependencies = [
          {
            name = "futures";
            packageId = "futures 0.1.29";
            rename = "futures01";
          }
          {
            name = "futures";
            packageId = "futures 0.3.5";
            usesDefaultFeatures = false;
            features = [ "compat" ];
          }
        ];
        
      };

kolloch added a commit that referenced this issue May 29, 2020
@kolloch
Copy link
Collaborator

kolloch commented May 29, 2020

Hah! I didn't merge the fix to the master. That explains why it doesn't work. The integration test wasn't yet activated.

Thank you for your insistance, @bbigras. I merge the fix now, sorry.

@bbigras
Copy link
Contributor Author

bbigras commented May 29, 2020

hehe.

It works and now I can use crate2nix with another project. Sweet.

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants