-
-
Notifications
You must be signed in to change notification settings - Fork 13.4k
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
Incorrect linker flags passed to Rust riscv32imc-unknown-none-elf cross-compiler #281527
Comments
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/packaging-qemu-with-support-for-esp32c3/38285/6 |
I looked a bit more into this: the problem is fixed when |
Alternatively, forcing the use of EDIT: I understand this a bit better now: I didn't set the
the flags in my |
Workaround that works for me: cargoBuildFlags = [
"--config target.riscv32imc-unknown-none-elf.linker='${pkgsCross.pkgsBuildHost.llvmPackages.bintools}/bin/${pkgsCross.stdenv.cc.targetPrefix}ld.lld'"
]; as used in https://github.com/SFrijters/nix-qemu-esp32c3-rust-example . |
Bump. I also had this issue when cross compiling to Some thoughts:
Another workaround is to patch the cargo-build-hook directly: cargoBuildHook = (rustPlatform.cargoBuildHook).overrideAttrs
(
let envVars = pkgsCross.rust.envVars; in {
setEnv = ''
${envVars.setEnv} \
CARGO_TARGET_THUMBV7EM_NONE_EABIHF_LINKER=arm-none-eabi-ld \
'';
}
);
buildRustPackage = rustPlatform.buildRustPackage.override {
inherit cargoBuildHook;
}; |
Huh, I have no idea how I missed the notification on this post. I've recently tried to get a new project for the esp32c3 compiling, and I've had to review my own blog post multiple times. I'm still having to use the oxalica overlay (in order to get a rust compiler with the appropriate toolchain), but I've been able to get it to compile with the new (crates.io-available) I would be interested in dropping the oxalica dependency and building with pure nixpkgs / rust if possible. However, it looks like https://github.com/SFrijters/esp32-c3-nix-rust-test is using oxalica as well, I'm not sure if there is currently a process to get an
I'm primarily on aarch64-darwin (though I also use aarch64-linux and x86_64-linux), and I've had to pin nixpkgs to 23.05 due to this issue. Interesting that a separate issue is blocking gcc-based toolchains from updating as well. |
@n8henrie The https://github.com/SFrijters/esp32-c3-nix-rust-test repo contains the information about my debugging process, but a much cleaner example currently lives in https://github.com/SFrijters/nix-qemu-esp32c3-rust-example/ . I recently bumped the toolchain to 1.78.0, But, it also still uses the oxalica overlay. I still don't know enough to want to try and get rid of that as well, I'm pretty happy with the current situation, apart from the linker flag hack. @liarokapisv It feels like there must be some smallish tweak to the code you linked and/or adjacent code that can be made to fix the issue, but I don't know enough about the impacts on other platforms that I don't use myself. |
Looking at https://github.com/SFrijters/nix-qemu-esp32c3-rust-example/blob/master/flake.nix
Because we're using rust to cross-compile, not nix. If you were just using a standard rustup / rust install, you'd have an x86_64-linux rust binary, Setting Speaking of which, I had used |
The main issue is that |
I see, thank you! |
Describe the bug
I've been trying to expand on @n8henrie blog post "Compiling Rust for the ESP32 with Nix" and update nixpkgs to a more recent version. Changing the nixpkgs input from
release-23.05
torelease-23.11
and updating the lock file broke the linker.After some bisecting it looks like 6980e6b is the last working commit, after which the cross compiler infrastructure experiences a regression and the gcc compiler doesn't build and I don't even get to the Rust part. This is fixed in 36f5b2e but then I get the linker error on my final executable that I still see on master:
Steps To Reproduce
The simplified flake I use is available at https://github.com/SFrijters/esp32-c3-nix-rust-test and
nix build github:SFrijters/esp32-c3-nix-rust-test
reproduces the error - at least from myx86_64-linux
base system.Using the dev shell and
cargo build
works correctly.Expected behavior
The program links correctly.
Additional context
Add any other context about the problem here.
Notify maintainers
@amjoseph-nixpkgs
Maybe @yu-re-ka or @alyssais know anything about this, recently having worked on the rust build-support files?
Metadata
Please run
nix-shell -p nix-info --run "nix-info -m"
and paste the result.Add a 👍 reaction to issues you find important.
The text was updated successfully, but these errors were encountered: