Open oddlama opened 10 months ago
Hi @oddlama thanks for the report!
Haven't worked with embedded rust projects before so I'm not exactly sure what is missing off the top of my head, but I wonder if we're filtering out something which needs to be present given that overriding the source dummification appears to fix things :thinking:
Do you have a(n ideally minimal) flake I can check out and reproduce directly? I tried to look at the example you linked and paste (a fixed up) version of your flake excerpt, but there was just too many other stuff to try to iron out so I couldn't reproduce it in a time-boxed manner :sweat_smile:
Sure, I've made a small template project where the issue is reproduced here: https://github.com/oddlama/nrf-template I've included my current workaround below the cargoArtifacts
definition.
If you enter the devshell, you should be able to cargo build
successfully, but nix build
will fail until the the cargoArtifacts
are replaced with the workaround.
@oddlama thank you for the reproduction!
I see the issue, it has to do with our handling of dummy binary targets which has caused problems in the past... I need to take a closer look at making this dummification smarter (e.g. only stub targets that actually exist as some builds don't expect extra binaries to show up).
In the meantime, you can get unblocked by using
extraDummyScript = ''
cp -a ${./memory.x} $out/memory.x
rm -rf $out/src/bin/crane-dummy-*
'';
I've been trying to get crane to compile an embedded rust project, but unfortunately encountered some issues that I was unable to solve. Embedded projects often use an alternative linker called
flip-link
which adds stack overflow safety to embedded devices. The issue is that crane doesn't expect this to happen at some places:flip-link
usually searches for amemory.x
linker script in the current directory, but even though I added the file to my filters, it is missing in thebuildDepsOnly
becausemkDummySrc
filter the source again and discards thememory.x
file. My workaround was to add anextraDummyScript
to eachbuild*
function:After adding this, the error goes away, but
flip-link
still fails with the following message (and here I wasn't able to find out what it was missing exactly). It looks like it was linking to the standard library even though we are usingthumbv7a-none-eabihf
which should cause no_std and no_main to be added to the dummy if I'm reading it correctly:cargo build
does work fine in a devshell, and I can also get crane to compile the project correctly by disabling the dummy dependency building by addingcargoArtifacts = pkgs.runCommand "disable-deps" {} "mkdir -p $out/target";
.Have a look at this example project if you want to reproduce this. This is the relevant part of my flake.nix: