Comments (8)
The fix is here: NixOS/nixpkgs#60127
from crate2nix.
Excellent stuff, thanks for the debugging info too!
from crate2nix.
Can confirm that this now works for url-bot-rs, now that the Nixpkgs patch has been merged.
from crate2nix.
This is a bit more difficult to track down since we do not have a stack trace with line numbers. Do you know what exactly failed? I don't see a plain "unwrap" in write_built_file_with_opts.
The primary reason for build.rs to fail so far has been differing environment variables between buildRustCrate
and cargo
. Here are the most obvious environment variables of buildRustCrate
.
If you have any time to debug this issue, it would be nice to track down the exact line that fails.
from crate2nix.
There are a couple of unwraps in built::write_built_file, precisely dealing with obtaining environment variables, but it seems that both the env vars needed are exported according to the link you posted.
I need to study some more Nix to work out how to enter the build environment to introspect any more, i think.
from crate2nix.
Since it might come in handy in other situations, this is how I debugged this.
- I cloned the built crate from github and improved its error handling:
diff --git a/src/lib.rs b/src/lib.rs
index 52f7034..eae149c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -380,7 +380,7 @@ fn write_env<T: io::Write>(envmap: &EnvironmentMap, w: &mut T) -> io::Result<()>
macro_rules! write_env_str {
($(($name:ident, $env_name:expr,$doc:expr)),*) => {$(
writeln!(w, "#[doc={}]\npub const {}: &str = \"{}\";",
- stringify!($doc), stringify!($name), envmap.get($env_name).unwrap())?;
+ stringify!($doc), stringify!($name), envmap.get($env_name).expect(stringify!($env_name)))?;
)*}
}
- I patched your Cargo.toml to use my patched version of that crate:
diff --git a/Cargo.toml b/Cargo.toml
index 15ca171..54696bd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,7 +9,7 @@ readme = "README.md"
build = "build.rs"
[build-dependencies]
-built = "0.3.0"
+built = { path = "../built" }
man = "0.3.0"
[dev-dependencies]
-
I ran
nix run -f ../crate2nix
to have crate2nix in my path -
I regenerated the nix build file with
crate2nix generate -n '<nixos-unstable>' -o Cargo.nix
-
I ran
nix build -f Cargo.nix
, resulting in this error:
builder for '/nix/store/8sdinmsvh88c539s1lx25zlsiip1i76s-rust_url-bot-rs-0.2.0.drv' failed with exit code 101; last 10 log lines:
14: __rust_maybe_catch_panic
at src/libpanic_unwind/lib.rs:92
15: std::rt::lang_start_internal
at src/libstd/panicking.rs:276
at src/libstd/panic.rs:388
at src/libstd/rt.rs:48
16: main
17: __libc_start_main
18: _start
at ../sysdeps/x86_64/start.S:120
[0 built (1 failed)]
error: build of '/nix/store/8sdinmsvh88c539s1lx25zlsiip1i76s-rust_url-bot-rs-0.2.0.drv' failed
- I used
nix log /nix/store/8sdinmsvh88c539s1lx25zlsiip1i76s-rust_url-bot-rs-0.2.0.drv
to see the full error:
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/kry1kyhxgh5md24skmncf7xzm83rnnd2-url-bot-rs
source root is url-bot-rs
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
Building build.rs (url-bot-rs)
Running rustc --crate-name build_script_build build.rs --crate-type bin -C opt-level=3 -C codegen-units=>
thread 'main' panicked at '"CARGO_PKG_VERSION_PRE"', src/libcore/option.rs:1038:5
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
1: std::sys_common::backtrace::print
at src/libstd/sys_common/backtrace.rs:70
at src/libstd/sys_common/backtrace.rs:58
2: std::panicking::default_hook::{{closure}}
at src/libstd/panicking.rs:200
3: std::panicking::default_hook
at src/libstd/panicking.rs:215
4: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:478
5: std::panicking::continue_panic_fmt
at src/libstd/panicking.rs:385
6: rust_begin_unwind
at src/libstd/panicking.rs:312
7: core::panicking::panic_fmt
at src/libcore/panicking.rs:85
8: core::option::expect_failed
at src/libcore/option.rs:1038
9: built::write_built_file_with_opts
10: built::write_built_file
11: build_script_build::main
12: std::rt::lang_start::{{closure}}
13: std::panicking::try::do_call
at src/libstd/rt.rs:49
at src/libstd/panicking.rs:297
14: __rust_maybe_catch_panic
at src/libpanic_unwind/lib.rs:92
15: std::rt::lang_start_internal
at src/libstd/panicking.rs:276
at src/libstd/panic.rs:388
at src/libstd/rt.rs:48
16: main
17: __libc_start_main
18: _start
at ../sysdeps/x86_64/start.S:120
-
I provided the env variable via overrideAttrs in a separate
default.nix
and repeated the exercise -
I ended up with the following default.nix:
{ pkgs? import <nixos-unstable> { config = {}; }, callPackage? pkgs.callPackage }:
let cargo = callPackage ./Cargo.nix {};
in cargo.root_crate.overrideAttrs (attrs: {
CARGO_PKG_VERSION_PRE = "";
CARGO_PKG_HOMEPAGE = "";
})
With this, the crate builds (via nix build
using the default.nix).
from crate2nix.
(This means that we have to patch buildRustCrate to always provide this env variables)
from crate2nix.
Thanks for checking the fix! :)
from crate2nix.
Related Issues (20)
- Specify the toolchain used to build the main project HOT 6
- Panic when running `crate2nix generate` HOT 6
- crate2nix stumbles over arbitrary #[cfg] conditionals HOT 4
- error inheriting `version` from workspace root manifest's `workspace.package.version` HOT 1
- Set custom environment variables in `packages` and `devShells` HOT 1
- rustc 1.73 breaks crate2nix cross compilation HOT 5
- 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
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.