Skip to content
This repository has been archived by the owner on Sep 26, 2020. It is now read-only.

Cross compiling for zero from Ubuntu #2

Open
n8henrie opened this issue Jul 23, 2018 · 5 comments
Open

Cross compiling for zero from Ubuntu #2

n8henrie opened this issue Jul 23, 2018 · 5 comments

Comments

@n8henrie
Copy link

n8henrie commented Jul 23, 2018

Are you cross compiling these from Ubuntu as described at https://disconnected.systems/blog/rust-powered-rover/ ?

Essentially:

sudo apt install -y build-essential gcc-arm-linux-gnueabihf libc6-armhf-cross libc6-dev-armhf-cross

curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=stable

source $HOME/.cargo/env

tee $HOME/.cargo/config <<'EOF'
[target.arm-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
EOF

rustup default stable
rustup target add arm-unknown-linux-gnueabihf

Then cargo build --release --target arm-unknown-linux-gnueabihf?

Using those instructions, even hello world segfaults for me when compiled from Ubuntu for Pi Zero (though the same binary runs fine on armv7 like RPi3).

@mdaffin
Copy link
Owner

mdaffin commented Jul 23, 2018

  • What version of Ubuntu are you using locally?
  • What distro/version are you running on the Pi?

Are you cross compiling these from Ubuntu as described at https://disconnected.systems/blog/rust-powered-rover/ ?

I use Arch locally for cross compiling (I don't build anything on the Pi), but the travis build uses trusty (which sadly still seems to be the latest version they support) and when I originally wrote the instructions it worked within a Ubuntu VM (though I forget which version).

I reran the build locally on latest Arch and found no issues. I reran the travis build to create a new image which does appear to suffer from the problem stated. I also ran it using an Ubuntu 18.04 VM and was able to recreate the issue so there is a problem with at least this version.

I will look into it but might take some time to investigate and could be a problem with an Ubuntu package or the rust compiler.

@n8henrie
Copy link
Author

Thanks for getting back to me.

Ubuntu 16.04.3 LTS (on AWS), Raspbian Stretch on Pi Zero.

I don't know much about the issue, but I've been looking into it for a while (BurntSushi/ripgrep#676). Just ran into your blog post above and got excited, thinking you had it working on Ubuntu (without using the rpi-tools repo, which I suppose is a reasonable way to go about it, it just seems like there would be a more generic way to compile for armv6 from Ubuntu).

I also run Arch locally and find that it compiles for the Zero without a problem, which makes the Ubuntu issue seem even more frustrating. My goal is also simpler Travis builds for armv6 / Pi Zero binaries.

I'm happy to close the issue if you'd like, it seems like something out of your control has changed, I was just hoping to find that you'd forgotten to include a step in the instructions.

@mdaffin
Copy link
Owner

mdaffin commented Jul 23, 2018

I did a bit of research and came across this issue which seems to suggest it is the Ubuntu linker not supporting armv6. I will continue to look into it to see if there is a nice way to build on Ubuntu but given that post it seems to be, download another linker and don't use the Ubuntu one.

@n8henrie
Copy link
Author

Yeah, I saw that issue as well.

I'll see if anyone on r/rust has any further light they can shed on the issue: https://www.reddit.com/r/rust/comments/918m2z/how_to_compile_from_ubuntu_for_armv6_without/

@mdaffin
Copy link
Owner

mdaffin commented Jul 23, 2018

As mentioned in the reddit thread above there are not many good options from what I could find.

LLD support was added for wasm

But there are still issues for arm targets

Adding the following to the .cargo/config should allow you to use the native LLVM linker with rust (as far as I can work out, documentation is spotty on this front).

[target.arm-unknown-linux-gnueabihf]
linker = "rust-lld"
rustflags = [
  "-Z", "linker-flavor=ld.lld",
]

Built with cargo +nightly build --release --target=arm-unknown-linux-gnueabihf. But this seems to currently be broken with the latest nightly.

This leaves not using an Ubuntu image or downloading/compiling a working GNU linker, neither of which is ideal.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants