Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template fails on NixOS with 'collect2: ld not found' because -fuse-ld=mold is injected into the build process #257

Closed
leonhma opened this issue Jan 23, 2025 · 3 comments

Comments

@leonhma
Copy link

leonhma commented Jan 23, 2025

I just generated a project using the template and the cargo option. Building it fails at the final linking step because ld (the linker) could not be found. After doing cargo build -vv and running the final link command manually with strace, i could see which paths collect2 searches for ld. due to -fuse-ld=mold being (somehow) added to RUSTFLAGS and in turn ldproxy (which then calls gcc, which then calls collect2, which then wrongfully looks for ld.mold), it only searches for ld.mold in the compiler directories (.embuild/espressif/...)- which predictably can't be found. When running the final link command manually without the -fuse-ld argument, the linker can proceed, although it then fails due to some strings in the cargo build -vv output like "<4 objects omitted>". Do you know where the -fuse-ld=mold is set in the build process and how I can unset it?

Here's a repro (including nix flake): https://github.com/leonhma/esprs/tree/6f2da8f16b3646e9498190e5c3835647f4550f2d

@ivmarkov
Copy link
Collaborator

I do not run nixos so I cannot really try to reproduce your problem.

With that said,

due to -fuse-ld=mold being (somehow) added to RUSTFLAGS

This is not done by esp-idf-sys nor the template. If you are (somehow) doing this yourself, please don't. Ideally, you should figure out what on your os is polluting your RUSTFLAGS and you should remove the offender.

@ivmarkov
Copy link
Collaborator

if this is not clear, esp-idf-sys expects a very concrete linker (the espressif flavor of gcc-ld) to be used, and ldproxy is there to be exactly able to locate that linker. If you are forcing (via RUSTFLAGS) a different type of linker, there is no way it would work.

@leonhma
Copy link
Author

leonhma commented Jan 23, 2025

Turns out the problem was a default in devenv that overrrode the RUSTFLAGS to force mold as the linker. This way the modified ld couldn't be found and so on. So, literally RUSTFLAGS="-C -fuse-ld=mold" was the issue 🤦. For anyone else using NixOS and devenv with the same issue, just set mold.enable to false:

languages.rust = {
    enable = true;
    channel = "nightly";
    components = [ "rustc" "rust-src" "cargo" "clippy" "rustfmt" "rust-analyzer" ];
    mold.enable = false;
};

Personally I think making it the default behaviour to override the default settings of another program is nonsense and i am going to open up an issue over there.

Thanks for your help and confirming this is not an esp-rs/esp-idf issue.

@leonhma leonhma closed this as completed Jan 23, 2025
@github-project-automation github-project-automation bot moved this from Todo to Done in esp-rs Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants