!FBuJyWXTGcGtHTPphC:nixos.org

Nix Rust

712 Members
Rust163 Servers

Load older messages


SenderMessageTime
28 Sep 2022
@coolshaurya:community.rscoolshaurya changed their profile picture.17:33:40
30 Sep 2022
@codenode:matrix.orgcode node joined the room.02:50:00
@codenode:matrix.orgcode nodeHello ppl, I am trying to setup neovim with lsp, finding it hard to get rust-analyzer working02:52:52
@lara:uwu.isyaya left the room.12:35:15
@louib:matrix.orglouib joined the room.13:01:06
@x10an14:matrix.orgx10an14
In reply to @x10an14:matrix.org

Anyone know of a cross-compilation example that targets musl and uses rust-overlay?

I can't for the life of me figure this out. I've spent the past couple of hours trying to search and read up on it, but I feel like there's some crucial tidbits of ignorance that keep me in the dark.
All the rust docs refer to leveraging rustup, which AFAIU is kinda antheisis to the premise of Nix.

I'm finding the learning curve a bit too steep for me =/

I've attempted:
rust-toolchain.toml;

[toolchain]
targets = ["x86\_64-unknown-linux-musl", "x86\_64-unknown-linux-gnu"]

flake.nix:

  overlays = [
    (import rust-overlay)
    (self: super: {
      rustToolchain =
        let
          rust = super.rust-bin;
        in
        if builtins.pathExists ./rust-toolchain.toml then
          rust.fromRustupToolchainFile ./rust-toolchain.toml
        else if builtins.pathExists ./rust-toolchain then
          rust.fromRustupToolchainFile ./rust-toolchain
        else
          rust.stable.latest.default;
    })
  ]

And finally; cargo build --target 'x86_64-unknown-linux-musl'

I'm not able to make it work for nix build, yet I am able to make it work for cargo build --target... Here's a paste explaining my differences: https://paste.sr.ht/~x10an14/57e8d3d2014e44232692773affc74741b5776ddb

Could some kind samaritan take take a look and see if they can understand and tell me what's going on?

18:01:01
@zhaofeng:zhaofeng.liZhaofeng Li Add openssl to buildInputs, and pkg-config to nativeBuildInputs. This is because unlike the interactive shell, the Nix build environment is sandboxed and only has access to the given inputs. 18:33:12
@x10an14:matrix.orgx10an14 Zhaofeng Li: Do you happen to have an example of how to write a filter like shown here? I'm not sure how to write the match function: https://github.com/ipetkov/crane/blob/master/docs/API.md#libfiltercargosources 22:53:07
@zhaofeng:zhaofeng.liZhaofeng Li Some examples of cleanSourceWith filters are available here: https://github.com/NixOS/nixpkgs/blob/master/lib/sources.nix#L265 22:55:48
@zhaofeng:zhaofeng.liZhaofeng Li And the documentations of builtins.match is at https://nixos.org/manual/nix/stable/language/builtins.html#builtins-match 22:55:55
@zhaofeng:zhaofeng.liZhaofeng Li * Some examples of cleanSourceWith filters are available here: https://github.com/NixOS/nixpkgs/blob/master/lib/sources.nix 22:56:15
1 Oct 2022
@x10an14:matrix.orgx10an14

Thanks, I managed! Now just to figure out why I have this issue when compiling with pkgs.pkgsMusl.openssl.dev...

-> $ nix build && ldd result/bin/assign-item-to-project-field 
warning: Git tree '/home/x10an14/Documents/sr.ht/assign-item-to-project-field' is dirty
        linux-vdso.so.1 (0x00007ffe9ed98000)
        libssl.so.3 => not found
        libcrypto.so.3 => not found
01:34:48
@zhaofeng:zhaofeng.liZhaofeng Li Weird, the ld wrapper should have pinned the libraries. Maybe you can play around with pkgsStatic.openssl with OPENSSL_STATIC=1. 01:51:24
@x10an14:matrix.orgx10an14I tried to move this conversation to the Nix/NixOS channel - as written there this feels less like a Rust issue and more like an OpenSSL/Nix issue.01:51:49
@zhaofeng:zhaofeng.liZhaofeng LiBut if you want a fully static build, it's easier to use rustls instead. Just enabling the rustls feature flags in reqwest as well as graphql_client should work.01:51:52
@x10an14:matrix.orgx10an14Hmm.... I can try again, but I know I already tried once... I'll make one last attempt before heading to bed at 0400 =P01:53:00
@x10an14:matrix.orgx10an14Thanks for the tip!01:53:05
@x10an14:matrix.orgx10an14

Oops these replies were meant for your rustls suggestion.

I already tried pkgsStatic.openssl - but that failed during compilation of something. Gave up on that avenue before I figured out what was wrong.

01:56:19
@x10an14:matrix.orgx10an14

Yeah, no, doesn't seem to work?

Ref:

-> $ git diff Cargo.toml && nix build && ldd result/bin/assign-item-to-project-field && cargo tree -i openssl-sys

Cargo.toml

 10 ⋮ 10 │clap-verbosity-flag = "1"
 11 ⋮ 11 │clap_complete_command = "0.3"
 12 ⋮ 12 │color-eyre = "0.6"
 13 ⋮    │graphql_client = "0.11"
    ⋮ 13 │graphql_client = { version = "0.11", features = ["reqwest-rustls"] }
 14 ⋮ 14 │log = "0.4"
 15 ⋮    │reqwest = { version = "0.11", features = ["json"] }
    ⋮ 15 │reqwest = { version = "0.11", features = ["json", "rustls-tls"] }
 16 ⋮ 16 │serde = "1"
 17 ⋮ 17 │serde_json = "1"
 18 ⋮ 18 │tokio = { version = "1", features = ["macros", "rt-multi-thread", "fs"] }
warning: Git tree '/home/x10an14/Documents/sr.ht/assign-item-to-project-field' is dirty
        linux-vdso.so.1 (0x00007fff27330000)
        libssl.so.3 => not found
        libcrypto.so.3 => not found
openssl-sys v0.9.76
├── native-tls v0.2.10
│   ├── hyper-tls v0.5.0
│   │   └── reqwest v0.11.12
│   │       ├── assign-item-to-project-field v0.1.0 (/home/x10an14/Documents/sr.ht/assign-item-to-project-field)
│   │       └── graphql_client v0.11.0
│   │           └── assign-item-to-project-field v0.1.0 (/home/x10an14/Documents/sr.ht/assign-item-to-project-field)
│   ├── reqwest v0.11.12 (*)
│   └── tokio-native-tls v0.3.0
│       ├── hyper-tls v0.5.0 (*)
│       └── reqwest v0.11.12 (*)
└── openssl v0.10.42
    └── native-tls v0.2.10 (*)
02:02:07
@x10an14:matrix.orgx10an14 I already tried this before, but I saw the same output in cargo tree, so I kinda gave up on that then. 02:02:43
@zhaofeng:zhaofeng.liZhaofeng LiThe paste seems interleaved, could you paste again? What depends on openssl now?02:05:27
@x10an14:matrix.orgx10an14
-> $ cargo tree --help | grep ' --invert'
    -i, --invert [<SPEC>]         Invert the tree direction and focus on the given package
02:08:12
@x10an14:matrix.orgx10an14
-> $ cargo tree --invert openssl-sys
openssl-sys v0.9.76
├── native-tls v0.2.10
│   ├── hyper-tls v0.5.0
│   │   └── reqwest v0.11.12
│   │       ├── assign-item-to-project-field v0.1.0 (/home/x10an14/Documents/sr.ht/assign-item-to-project-field)
│   │       └── graphql_client v0.11.0
│   │           └── assign-item-to-project-field v0.1.0 (/home/x10an14/Documents/sr.ht/assign-item-to-project-field)
│   ├── reqwest v0.11.12 (*)
│   └── tokio-native-tls v0.3.0
│       ├── hyper-tls v0.5.0 (*)
│       └── reqwest v0.11.12 (*)
└── openssl v0.10.42
    └── native-tls v0.2.10 (*)
02:08:32
@x10an14:matrix.orgx10an14
-> $ cargo tree --invert openssl
openssl v0.10.42
└── native-tls v0.2.10
    ├── hyper-tls v0.5.0
    │   └── reqwest v0.11.12
    │       ├── assign-item-to-project-field v0.1.0 (/home/x10an14/Documents/sr.ht/assign-item-to-project-field)
    │       └── graphql_client v0.11.0
    │           └── assign-item-to-project-field v0.1.0 (/home/x10an14/Documents/sr.ht/assign-item-to-project-field)
    ├── reqwest v0.11.12 (*)
    └── tokio-native-tls v0.3.0
        ├── hyper-tls v0.5.0 (*)
        └── reqwest v0.11.12 (*)
02:08:48
@x10an14:matrix.orgx10an14

For completeness:

-> $ git diff Cargo.toml && echo -e "# Git diff of Cargo.toml above\\n---\\n# \`nix build\` and \`ldd\` invocation below" && nix build && ldd result/bin/* 

Cargo.toml

 10 ⋮ 10 │clap-verbosity-flag = "1"
 11 ⋮ 11 │clap_complete_command = "0.3"
 12 ⋮ 12 │color-eyre = "0.6"
 13 ⋮    │graphql_client = "0.11"
    ⋮ 13 │graphql_client = { version = "0.11", features = ["reqwest-rustls"] }
 14 ⋮ 14 │log = "0.4"
 15 ⋮    │reqwest = { version = "0.11", features = ["json"] }
    ⋮ 15 │reqwest = { version = "0.11", features = ["json", "rustls-tls"] }
 16 ⋮ 16 │serde = "1"
 17 ⋮ 17 │serde_json = "1"
 18 ⋮ 18 │tokio = { version = "1", features = ["macros", "rt-multi-thread", "fs"] }
# Git diff of Cargo.toml above
---
# `nix build` and `ldd` invocation below
warning: Git tree '/home/x10an14/Documents/sr.ht/assign-item-to-project-field' is dirty
        linux-vdso.so.1 (0x00007ffef59a3000)
        libssl.so.3 => not found
        libcrypto.so.3 => not found
02:11:12
@zhaofeng:zhaofeng.liZhaofeng LiSorry, on my phone, skipped over the Cargo.toml.02:12:21
@zhaofeng:zhaofeng.liZhaofeng Li You probably want default-features = false for reqwest 02:12:37
@x10an14:matrix.orgx10an14Nps, here's the repo if you wanna take a closer look: https://git.sr.ht/~x10an14/assign-item-to-project-field/tree/9e47a140d950c5d21896f3cdb74ce2ccfdc3e32402:12:51
@x10an14:matrix.orgx10an14Will attempt the default flag tip before I gotta sleep02:13:05
@x10an14:matrix.orgx10an14 The default_features = false fixed it, many many thanks for all your help these last days. Now itis commit, push, and bedtime. 02:20:58

Show newer messages


Back to Room ListRoom Version: 6