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

Cross-compiling for ARMV7? #21

Open
bwesen opened this issue Jul 6, 2021 · 6 comments
Open

Cross-compiling for ARMV7? #21

bwesen opened this issue Jul 6, 2021 · 6 comments

Comments

@bwesen
Copy link

bwesen commented Jul 6, 2021

Hi! There are some suggestions in the README that this perf-version was designed with cross compilation in mind etc and there are some very brief instructions on how to cross compile it. Could you please expand this into a working example?

For example, on Ubuntu 20.04 you can install gcc-9-arm-linux-gnueabihf and in it you can find a gcc (the "linker" for Rust .config) but where do you find the "sys-root"?

@koute
Copy link
Owner

koute commented Jul 8, 2021

You might not necessarily need to specify the sysroot. (It depends on how the compiler was configured/built.)

For Ubuntu Focal something like this should work I think:

  1. Install the cross compiler: apt install g++-arm-linux-gnueabihf libc6-dev-armhf-cross
  2. Install Rust.
  3. Install Rust's ARM target: rustup target add armv7-unknown-linux-gnueabihf
  4. Put this in your .cargo/.config:
[target.armv7-unknown-linux-gnueabihf]
linker = "/usr/bin/arm-linux-gnueabihf-gcc"
  1. Compile with cargo build --release --target=armv7-unknown-linux-gnueabihf.

@bwesen
Copy link
Author

bwesen commented Jul 8, 2021

Thanks, yeah I eventually managed to compile it but I had to spend many hours scourging stack overflow confused posts from a lot of other people who also had problems cross-compiling with Rust :) (not compiling not-perf in particular)

The main issue is that when you install the Ubuntu 20.04 rust packages you don't get rustup and they don't provide the necessary pre-built std/core crates for armv7 either, so you get confused and nothing works and the various tutorials on the net are confusing if you try to use the Debian packages; there are multiple ways to set this up it seems. And you just get weird error messages from rust about the std/core crates missing and if you don't know anything about Rust this just adds to the confusion :)

I ended up having to remove all of the Ubuntu rust-related packages, and instead use the rust shell script to set it up, do the rustup target add and added the cross compiler to the .config like you wrote and then it compiled.

@bwesen
Copy link
Author

bwesen commented Jul 8, 2021

However, while it compiled properly, I never got any binaries. In the release dir there are only a couple of libs it seems, any suggestions?


~/tmp/not-perf/target/armv7-unknown-linux-gnueabihf/release$ ls -l
total 7904
drwxrwxr-x 28 bjorn bjorn    4096 Jul  7 18:05 build
drwxrwxr-x  2 bjorn bjorn   16384 Jul  7 18:06 deps
drwxrwxr-x  2 bjorn bjorn    4096 Jul  7 17:11 examples
drwxrwxr-x  2 bjorn bjorn    4096 Jul  7 17:11 incremental
-rw-rw-r--  1 bjorn bjorn    2290 Jul  7 18:06 libnperf_core.d
-rw-rw-r--  2 bjorn bjorn 8058580 Jul  7 18:06 libnperf_core.rlib

@bjorn3
Copy link

bjorn3 commented Jul 8, 2021

Try cargo build --release --target=armv7-unknown-linux-gnueabihf --workspace. The root dir defines the nperf_core crate it seems. The cli is found in a different crate in a subdirectory. --workspace causes the whole workspace to be built instead of just the root nperf_core.

@koute
Copy link
Owner

koute commented Jul 8, 2021

Ah, right, I forgot to update README after that change! Yes, the bin crate is no longer in the root; if you go into the cli directory and build from there it will build properly.

@bwesen
Copy link
Author

bwesen commented Jul 8, 2021

Thanks both, going into cli/ and running the build with the appropriate --target produced the nperf binary (in the top-level target/ structure). And it seems to execute on my target.

Now for finding out how to use the tool :)

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

No branches or pull requests

3 participants