Git Product home page Git Product logo

Comments (8)

kolloch avatar kolloch commented on June 25, 2024 1

The fix is here: NixOS/nixpkgs#60127

from crate2nix.

nuxeh avatar nuxeh commented on June 25, 2024 1

Excellent stuff, thanks for the debugging info too!

from crate2nix.

nuxeh avatar nuxeh commented on June 25, 2024 1

Can confirm that this now works for url-bot-rs, now that the Nixpkgs patch has been merged.

from crate2nix.

kolloch avatar kolloch commented on June 25, 2024

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.

nuxeh avatar nuxeh commented on June 25, 2024

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.

kolloch avatar kolloch commented on June 25, 2024

Since it might come in handy in other situations, this is how I debugged this.

  1. 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)))?;
         )*}
     } 
  1. 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]
  1. I ran nix run -f ../crate2nix to have crate2nix in my path

  2. I regenerated the nix build file with crate2nix generate -n '<nixos-unstable>' -o Cargo.nix

  3. 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
  1. 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
  1. I provided the env variable via overrideAttrs in a separate default.nix and repeated the exercise

  2. 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.

kolloch avatar kolloch commented on June 25, 2024

(This means that we have to patch buildRustCrate to always provide this env variables)

from crate2nix.

kolloch avatar kolloch commented on June 25, 2024

Thanks for checking the fix! :)

from crate2nix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.