crate2nix
crate2nix copied to clipboard
Can't build wayland-protocols
https://github.com/Smithay/wayland-rs/tree/master/wayland-protocols
Building build.rs (wayland-protocols)
Running rustc --crate-name build_script_build build.rs --crate-type bin -C opt-level=3 -C codegen-units=12 --edition 2015 --cfg feature="client" --cfg feature="default" --cfg feature="unstable_protocols" --cfg feature="wayland-client" --out-dir target/build/wayland-protocols --emit=dep-info,link -L dependency=target/buildDeps --extern wayland_scanner=/nix/store/glbyxrk60pbjs3yxdgfjqzp43hl3w6d2-rust_wayland-scanner-0.23.6-lib/lib/libwayland_scanner-1c13d53c5a.rlib --cap-lints allow --color always
building
Building src/lib.rs (wayland-protocols)
Running rustc --crate-name wayland_protocols src/lib.rs --out-dir target/lib -L dependency=target/deps --cap-lints allow -C opt-level=3 -C codegen-units=12 --remap-path-prefix=/build=/ --extern bitflags=/nix/store/nls4h05b7dp74nm47s530wg04qfygdvh-rust_bitflags-1.2.1-lib/lib/libbitflags-e23f6fc71a.rlib --extern wayland_client=/nix/store/x053yagzcrl4akxlkvsdvv9c3l0rl1w0-rust_wayland-client-0.23.6-lib/lib/libwayland_client-be167b4be8.rlib --extern wayland_commons=/nix/store/sbgb0128a5mpjkjypx7b8yivj5fmkrgj-rust_wayland-commons-0.23.6-lib/lib/libwayland_commons-1b2280ba5b.rlib --cfg feature="client" --cfg feature="default" --cfg feature="unstable_protocols" --cfg feature="wayland-client" --edition 2015 -C metadata=b2e0132ede -C extra-filename=-b2e0132ede --crate-type lib -L /build/wayland-protocols-0.23.6/target/build/wayland-protocols.out -L native=/nix/store/saa0lbm6vr2an0w6flg8z17h7ca3l5qz-rust_libloading-0.5.2-lib/lib/libloading.out -l dl -l static=global_static --color always
error: couldn't read /build/wayland-protocols-0.23.6/target/build/wayland-protocols.out/fullscreen-shell-v1_client_api.rs: No such file or directory (os error 2)
--> src/protocol_macro.rs:28:17
|
28 | include!(concat!(env!("OUT_DIR"), "/", $name, "_client_api.rs"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
::: src/unstable.rs:22:5
|
22 | / wayland_protocol_versioned!(
23 | | "fullscreen-shell",
24 | | [v1],
25 | | [
... |
29 | | []
30 | | );
| |______- in this macro invocation
error: aborting due to previous error
builder for '/nix/store/0j33svrh06qj4q4z62z0vyl1w5x47hig-rust_wayland-protocols-0.23.6.drv' failed with exit code 1
This currently impedes crate2nix from working with any packages that have winit in their dependency tree.
Thank you for your report! With which version did you try? On which OS? Or am I doing things wrong?
This is what works for me on master:
❯ git clone https://github.com/Smithay/wayland-rs/
❯ cd wayland-rs
❯ cargo generate-lockfile
❯ crate2nix generate
❯ nix build -f Cargo.nix workspaceMembers.wayland-protocols
Obviously, that doesn't test if it actually build the right thing but I am also not getting into the error above. (I am using nixpkgs-unstable which unfortunately is required because there is still a steady stream of bug fixed to buildRustCrate)
I'm on crate2nix master and on the latest nixos-unstable-small channel of NixOS.
It actually took me quite a while to reproduce this this morning. Compiling wayland-rs as you did seems to work; the failure happens when you compile a reverse dependency. How to repro:
❯ git clone [email protected]:rust-windowing/glutin.git
❯ cd glutin
❯ cargo generate-lockfile
❯ crate2nix generate
❯ nix build -f Cargo.nix workspaceMembers.glutin
This will explode on the right dep:
❯ nix build -f Cargo.nix workspaceMembers.glutin
builder for '/nix/store/ja31kdxri7180915aqzyc6llj9apgcni-rust_wayland-protocols-0.23.6.drv' failed with exit code 1; last 10 log lines:
23 | | "fullscreen-shell",
24 | | [v1],
25 | | [
... |
29 | | []
30 | | );
| |______- in this macro invocation
error: aborting due to previous error
cannot build derivation '/nix/store/2ww07cin8ffj57c6c8gfsyj7mhsmb8vd-rust_glutin-0.24.0.drv': 1 dependencies couldn't be built
[2 built (1 failed)]
error: build of '/nix/store/2ww07cin8ffj57c6c8gfsyj7mhsmb8vd-rust_glutin-0.24.0.drv' failed
Believe it or not this is the cause: https://github.com/rust-lang/rustfmt/issues/3988
@kolloch How can I configure rustfmt for crate2nix?
You mean that rustfmt is called in the build somehow normally? And in crate2nix, it is not called or called with the wrong arguments?
crate2nix/buildRustCrate does not have specific code for rustfmt as far as I know...
That's correct, rustfmt is somehow involved here, and setting normalize_doc_attributes = false in your .rustfmt.toml solves the issue.
How exactly this happens I don't fully understand, it's some macro magic. cc. @nagisa who knows things.
I have the same issue but adding normalize_doc_attributes = false doesn't seem to solve the issue. My rustfmt.toml:
unstable_features = true
wrap_comments = false
max_width = 80
normalize_comments = false
normalize_doc_attributes = false
I'm using NixOS on nixos-unstable channel. I have used nightly Rust, as unstable_features require nightly. Also tried stable, but same issue. These are all tried within the glutin repo. No idea what's going on.
I solved this by adding a crate override like this:
wayland-protocols = attrs: {
CARGO_FEATURE_UNSTABLE_PROTOCOLS = "";
CARGO_FEATURE_CLIENT = "";
postConfigure = (attrs.postConfigure or "") + ''
sed -i 's/-/_/g' target/env
'';
};
The normalize_doc_attributes was a red herring, the real issue is buildRustCrate doesn't yet correctly set all of the envvars that Cargo normally exports, one of them being the CARGO_FEATURE_$NAME flag.
The
normalize_doc_attributeswas a red herring, the real issue isbuildRustCratedoesn't yet correctly set all of the envvars that Cargo normally exports, one of them being theCARGO_FEATURE_$NAMEflag.
I also ran into this issue a while ago and submitted a PR against buildRustCrate to fix this:
https://github.com/NixOS/nixpkgs/pull/90193
The PR solved the issue, everything builds perfectly now. Thanks for the great work!