Comments (8)
This is a different issue than the one that I was encountering. The issue here is that in the output of cargo metadata
the flate2
crate contains the miniz_oxide
dependency twice:
{
"name": "miniz_oxide",
"source": "registry+https://github.com/rust-lang/crates.io-index",
"req": "^0.3.2",
"kind": null,
"rename": null,
"optional": true,
"uses_default_features": true,
"features": [],
"target": null,
"registry": null
},
[...]
{
"name": "miniz_oxide",
"source": "registry+https://github.com/rust-lang/crates.io-index",
"req": "^0.3.2",
"kind": null,
"rename": null,
"optional": false,
"uses_default_features": true,
"features": [],
"target": "cfg(all(target_arch = \"wasm32\", not(target_os = \"emscripten\")))",
"registry": null
}
So, the logic seems to be: miniz_oxide
is optional on all platforms except wasm32 - emscripten
, where it is a required dependency. Relevant lines from flate2
's Cargo.toml
:
[dependencies]
[...]
miniz_oxide = { version = "0.3.2", optional = true}
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
miniz_oxide = "0.3.2"
The output generated by crate2nix
only uses the second variant:
dependencies = {
"crc32fast" = "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)"
;
"libc" = "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)";
"miniz_oxide" = {
packageId = "miniz_oxide 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)";
target = ((target."arch" == "wasm32") && (!(target."os" == "emscripten")));
};
};
So, miniz_oxide
is never added as a dependency, although it should when flate2
's rust_backend
option is set.
from crate2nix.
This should now work on master...
from crate2nix.
from crate2nix.
Thank you very much for reporting this!
Usually build errors are due to differences in the rustc
command line between crate2nix
and cargo
. The things that look like hashes don't matter but feature selection etc. does. If you can isolate that difference, it would help me a lot.
from crate2nix.
cargo
rustc --crate-name flate2 /home/tilpner/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.11/src/lib.rs --color always --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="miniz-sys"' --cfg 'feature="miniz_oxide"' --cfg 'feature="rust_backend"' -C metadata=f617164663f537ba -C extra-filename=-f617164663f537ba --out-dir /home/tilpner/dev/crate2nix-testcases/flate-test/target/debug/deps -L dependency=/home/tilpner/dev/crate2nix-testcases/flate-test/target/debug/deps --extern crc32fast=/home/tilpner/dev/crate2nix-testcases/flate-test/target/debug/deps/libcrc32fast-9cbc2ae3f9c5c1f7.rlib --extern libc=/home/tilpner/dev/crate2nix-testcases/flate-test/target/debug/deps/liblibc-2a24069ae9cc47fd.rlib --extern miniz_sys=/home/tilpner/dev/crate2nix-testcases/flate-test/target/debug/deps/libminiz_sys-12111c0588ad7829.rlib --extern miniz_oxide=/home/tilpner/dev/crate2nix-testcases/flate-test/target/debug/deps/libminiz_oxide-7a103db29777ac3d.rlib --cap-lints allow -L native=/home/tilpner/dev/crate2nix-testcases/flate-test/target/debug/build/miniz-sys-68053c9fa6362326/out
crate2nix
rustc --crate-name flate2 src/lib.rs --crate-type lib -C opt-level=3 -C codegen-units=1 --edition 2015 -C metadata=e6022b985d -C extra-filename=-e6022b985d --cfg feature="default" --cfg feature="miniz-sys" --cfg feature="miniz_oxide" --cfg feature="rust_backend" --out-dir target/lib --emit=dep-info,link -L dependency=target/deps --extern crc32fast=/nix/store/aanv44l347baav3kqdz7mn7snwb8pr4f-rust_crc32fast-1.2.0/lib/libcrc32fast-093f96a061.rlib --extern libc=/nix/store/iiz26qj3ygqpfba4h73lh1z8nm3j8g3k-rust_libc-0.2.62/lib/liblibc-68f9c48770.rlib --extern miniz_sys=/nix/store/7kym1zycmv38sm2gs1d8p6q6qvh76qcb-rust_miniz-sys-0.1.12/lib/libminiz_sys-f656099c58.rlib --cap-lints allow -L native=/nix/store/7kym1zycmv38sm2gs1d8p6q6qvh76qcb-rust_miniz-sys-0.1.12/lib/miniz-sys.out -l static=miniz --color always
cargo (interesting)
rustc --emit=dep-info,metadata,link --out-dir /target/debug/deps -L dependency=target/debug/deps --extern crc32fast=target/debug/deps/libcrc32fast-9cbc2ae3f9c5c1f7.rlib --extern libc=liblibc-2a24069ae9cc47fd.rlib --extern miniz_sys=libminiz_sys-12111c0588ad7829.rlib --extern miniz_oxide=libminiz_oxide-7a103db29777ac3d.rlib -L native=target/debug/build/miniz-sys-68053c9fa6362326/out
crate2nix (interesting)
rustc --edition 2015 --out-dir target/lib --emit=dep-info,link -L dependency=target/deps --extern crc32fast=libcrc32fast-093f96a061.rlib --extern libc=liblibc-68f9c48770.rlib --extern miniz_sys=libminiz_sys-f656099c58.rlib -L native=miniz-sys.out -l static=miniz
cargo passes --extern miniz_oxide=...
, crate2nix doesn't.
from crate2nix.
It seems that I ran same problem. I think the reason is that cargo metadata
only includes crates that are reachable through the default feature configurations. According to the cargo-metadata documentation:
When no feature options are given, the default feature is activated for every selected package.
In my case I could solve the problem by having crate2nix
generate metadata for all features, with this simple patch:
diff --git a/src/lib.rs b/src/lib.rs
index 5104267..f7eb976 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -10,6 +10,7 @@ use std::env;
use std::path::PathBuf;
use cargo_metadata::Metadata;
+use cargo_metadata::CargoOpt;
use cargo_metadata::PackageId;
use failure::format_err;
use failure::Error;
@@ -121,6 +122,7 @@ impl BuildInfo {
/// Call `cargo metadata` and return result.
fn cargo_metadata(config: &GenerateConfig) -> Result<Metadata, Error> {
let mut cmd = cargo_metadata::MetadataCommand::new();
+ cmd.features(CargoOpt::AllFeatures);
cmd.manifest_path(&config.cargo_toml);
cmd.exec().map_err(|e| {
format_err!(
I could submit a proper PR, but maybe you (@tilpner) could test if this fixes the problem in your case as well?
from crate2nix.
I have the same problem (and created a duplicate issue, shame on me).
Here's my testcase (almost the same as your's) and my build output:
Update: On the carnix
branch in the testcase, I used carnix generate-nix --standalone --src .
to generate the build files and built using nix-build Cargo.nix --attr nix_test
and it works fine.
Build output
nix-build Cargo.nix --attr rootCrate.build | tee ~/nlog
these derivations will be built:
/nix/store/8h7pwmcjs609qndm5p6hjjj6aa3pdp2w-rust_flate2-1.0.12.drv
/nix/store/867xl42ma2hzzkaiaqdn2153y2akw07l-rust_nix-test-0.1.0.drv
building '/nix/store/8h7pwmcjs609qndm5p6hjjj6aa3pdp2w-rust_flate2-1.0.12.drv'...
unpacking sources
unpacking source archive /nix/store/wmnaidz3za0642pianadw8w3y68cxxp0-flate2-1.0.12.tar.gz
source root is flate2-1.0.12.tar.gz
patching sources
configuring
building
Building src/lib.rs (flate2)
Running rustc --crate-name flate2 src/lib.rs --crate-type lib -C opt-level=3 -C codegen-units=2 --edition 2018 -C metadata=a55c485f99 -C extra-filename=-a55c485f99 --cfg
feature="default" --cfg feature="miniz_oxide" --cfg feature="rust_backend" --out-dir target/lib --emit=dep-info,link -L dependency=target/deps --extern cfg_if=/nix/store/
c3lddq79d9cwbl92via76pp3zs2mih4l-rust_cfg-if-0.1.10/lib/libcfg_if-271c7a6275.rlib --extern crc32fast=/nix/store/bjdk5m7gwx8wz72ccz3c38pp2pzrhzwr-rust_crc32fast-1.2.0/lib/
libcrc32fast-0e271bcda6.rlib --extern libc=/nix/store/5k4amvz95vz4b9v3bs7kwzs06yhj0hw6-rust_libc-0.2.65/lib/liblibc-325f2598fe.rlib --cap-lints allow --color always
error[E0432]: unresolved import `miniz_oxide`
--> src/ffi/rust.rs:8:9
|
8 | pub use miniz_oxide::*;
| ^^^^^^^^^^^ use of undeclared type or module `miniz_oxide`
error[E0433]: failed to resolve: use of undeclared type or module `MZFlush`
--> src/ffi/rust.rs:10:32
|
10 | pub const MZ_NO_FLUSH: isize = MZFlush::None as isize;
| ^^^^^^^ use of undeclared type or module `MZFlush`
error[E0433]: failed to resolve: use of undeclared type or module `MZFlush`
--> src/ffi/rust.rs:11:37
|
11 | pub const MZ_PARTIAL_FLUSH: isize = MZFlush::Partial as isize;
| ^^^^^^^ use of undeclared type or module `MZFlush`
error[E0433]: failed to resolve: use of undeclared type or module `MZFlush`
--> src/ffi/rust.rs:12:34
|
13 | pub const MZ_FULL_FLUSH: isize = MZFlush::Full as isize;
| ^^^^^^^ use of undeclared type or module `MZFlush`
error[E0433]: failed to resolve: use of undeclared type or module `MZFlush`
--> src/ffi/rust.rs:14:30
|
14 | pub const MZ_FINISH: isize = MZFlush::Finish as isize;
| ^^^^^^^ use of undeclared type or module `MZFlush`
error[E0433]: failed to resolve: use of undeclared type or module `DataFormat`
--> src/ffi/rust.rs:21:9
|
21 | DataFormat::Zlib
| ^^^^^^^^^^ use of undeclared type or module `DataFormat`
error[E0433]: failed to resolve: use of undeclared type or module `DataFormat`
--> src/ffi/rust.rs:23:9
|
23 | DataFormat::Raw
| ^^^^^^^^^^ use of undeclared type or module `DataFormat`
error[E0433]: failed to resolve: use of undeclared type or module `InflateState`
--> src/ffi/rust.rs:53:20
|
53 | inner: InflateState::new_boxed(format),
| ^^^^^^^^^^^^ use of undeclared type or module `InflateState`
error[E0433]: failed to resolve: use of undeclared type or module `MZFlush`
--> src/ffi/rust.rs:65:21
|
65 | let flush = MZFlush::new(flush as i32).unwrap();
| ^^^^^^^ use of undeclared type or module `MZFlush`
error[E0433]: failed to resolve: use of undeclared type or module `inflate`
--> src/ffi/rust.rs:67:19
|
67 | let res = inflate::stream::inflate(&mut self.inner, input, output, flush);
| ^^^^^^^ use of undeclared type or module `inflate`
error[E0433]: failed to resolve: use of undeclared type or module `MZStatus`
--> src/ffi/rust.rs:73:17
|
73 | MZStatus::Ok => Ok(Status::Ok),
| ^^^^^^^^ use of undeclared type or module `MZStatus`
error[E0433]: failed to resolve: use of undeclared type or module `MZStatus`
--> src/ffi/rust.rs:74:17
|
74 | MZStatus::StreamEnd => Ok(Status::StreamEnd),
| ^^^^^^^^ use of undeclared type or module `MZStatus`
error[E0433]: failed to resolve: use of undeclared type or module `MZStatus`
--> src/ffi/rust.rs:75:17
|
75 | MZStatus::NeedDict => {
| ^^^^^^^^ use of undeclared type or module `MZStatus`
error[E0433]: failed to resolve: use of undeclared type or module `MZError`
--> src/ffi/rust.rs:80:17
|
80 | MZError::Buf => Ok(Status::BufError),
| ^^^^^^^ use of undeclared type or module `MZError`
error[E0433]: failed to resolve: use of undeclared type or module `MZFlush`
--> src/ffi/rust.rs:148:21
|
148 | let flush = MZFlush::new(flush as i32).unwrap();
| ^^^^^^^ use of undeclared type or module `MZFlush`
error[E0433]: failed to resolve: use of undeclared type or module `deflate`
--> src/ffi/rust.rs:149:19
|
149 | let res = deflate::stream::deflate(&mut self.inner, input, output, flush);
| ^^^^^^^ use of undeclared type or module `deflate`
error[E0433]: failed to resolve: use of undeclared type or module `MZStatus`
--> src/ffi/rust.rs:155:17
|
155 | MZStatus::Ok => Ok(Status::Ok),
| ^^^^^^^^ use of undeclared type or module `MZStatus`
error[E0433]: failed to resolve: use of undeclared type or module `MZStatus`
--> src/ffi/rust.rs:156:17
|
156 | MZStatus::StreamEnd => Ok(Status::StreamEnd),
| ^^^^^^^^ use of undeclared type or module `MZStatus`
error[E0433]: failed to resolve: use of undeclared type or module `MZStatus`
--> src/ffi/rust.rs:157:17
|
157 | MZStatus::NeedDict => Err(CompressError(())),
| ^^^^^^^^ use of undeclared type or module `MZStatus`
error[E0433]: failed to resolve: use of undeclared type or module `MZError`
--> src/ffi/rust.rs:160:17
|
160 | MZError::Buf => Ok(Status::BufError),
| ^^^^^^^ use of undeclared type or module `MZError`
error[E0412]: cannot find type `DataFormat` in this scope
--> src/ffi/rust.rs:19:43
|
19 | fn format_from_bool(zlib_header: bool) -> DataFormat {
| ^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `InflateState` in this scope
--> src/ffi/rust.rs:28:16
|
28 | inner: Box<InflateState>,
| ^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `CompressorOxide` in this scope
--> src/ffi/rust.rs:106:16
|
106 | inner: Box<CompressorOxide>,
| ^^^^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `CompressorOxide` in this scope
--> src/ffi/rust.rs:131:28
|
131 | let mut inner: Box<CompressorOxide> = Box::default();
| ^^^^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find value `MZ_DEFAULT_WINDOW_BITS` in module `ffi`
--> src/mem.rs:191:59
|
191 | inner: Deflate::make(level, zlib_header, ffi::MZ_DEFAULT_WINDOW_BITS as u8),
| ^^^^^^^^^^^^^^^^^^^^^^ not found in `ffi`
error[E0425]: cannot find value `MZ_DEFAULT_WINDOW_BITS` in module `ffi`
--> src/mem.rs:337:52
|
337 | inner: Inflate::make(zlib_header, ffi::MZ_DEFAULT_WINDOW_BITS as u8),
| ^^^^^^^^^^^^^^^^^^^^^^ not found in `ffi`
error[E0080]: evaluation of constant value failed
--> src/mem.rs:50:12
|
50 | None = ffi::MZ_NO_FLUSH as isize,
| ^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: evaluation of constant value failed
--> src/mem.rs:59:12
|
59 | Sync = ffi::MZ_SYNC_FLUSH as isize,
| ^^^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: evaluation of constant value failed
--> src/mem.rs:69:15
|
69 | Partial = ffi::MZ_PARTIAL_FLUSH as isize,
| ^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: evaluation of constant value failed
--> src/mem.rs:76:12
|
76 | Full = ffi::MZ_FULL_FLUSH as isize,
| ^^^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: evaluation of constant value failed
--> src/mem.rs:82:14
|
82 | Finish = ffi::MZ_FINISH as isize,
| ^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: evaluation of constant value failed
--> src/mem.rs:95:12
|
95 | None = ffi::MZ_NO_FLUSH as isize,
| ^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: evaluation of constant value failed
--> src/mem.rs:104:12
|
104 | Sync = ffi::MZ_SYNC_FLUSH as isize,
| ^^^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: evaluation of constant value failed
--> src/mem.rs:110:14
|
110 | Finish = ffi::MZ_FINISH as isize,
| ^^^^^^^^^^^^^^ referenced constant has errors
error: aborting due to 35 previous errors
Some errors have detailed explanations: E0080, E0412, E0425, E0432, E0433.
For more information about an error, try `rustc --explain E0080`.
builder for '/nix/store/8h7pwmcjs609qndm5p6hjjj6aa3pdp2w-rust_flate2-1.0.12.drv' failed with exit code 1
cannot build derivation '/nix/store/867xl42ma2hzzkaiaqdn2153y2akw07l-rust_nix-test-0.1.0.drv': 1 dependencies couldn't be built
error: build of '/nix/store/867xl42ma2hzzkaiaqdn2153y2akw07l-rust_nix-test-0.1.0.drv' failed
Edit:
- #40 seems to solve the problem: https://github.com/vbrandl/crate2nix-testcase/tree/pr/40
- #41 does not solve the problem: https://github.com/vbrandl/crate2nix-testcase/tree/pr/41
from crate2nix.
Are there plans to make a new release containing these changes or should we just use the potentially unstable master
branch?
from crate2nix.
Related Issues (20)
- Cargo.nix includes references to ./crate2nix-sources with cargo workspaces HOT 1
- nixpkgs update breaks empty_cross test due to missing `rust` arguement HOT 7
- rstests adds a stray "/sources" to all globbed #[files] HOT 1
- Support path to Cargo.toml/Cargo.lock in fetched sources
- Tarball issue when building or trying to use template. HOT 1
- Error with dep that has a local dep
- Some sort of support for .cargo/config.toml ? HOT 1
- Overriding `crateConfig` for generated `Cargo.nix`
- Crate hash loading from Cargo.lock is broken in Rust 1.77
- Respect cargo profiles / enable debug info in release mode HOT 1
- Allow some crates to access more files than just those in their folder
- IFD is crazy slow due to copying the entire tree HOT 2
- IFD does not work with git deps HOT 2
- Installs `rustc` from nixpkgs when already installed HOT 4
- error: invalid metadata version found HOT 6
- How to push build artifacts to Cachix?
- Crate overides with IFD HOT 1
- Add `crateDescription` to generated crate definition
- Cross-compiling requires `NIXPKGS_ALLOW_BROKEN=1` to be set HOT 2
- Build fails when using `rust-overlay` due to some dependencies being built with Nixpkgs Rust when cross-compiling HOT 16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crate2nix.