-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add instructions for cross compilation #17
Comments
Usually with Rust cross-compilation is quite easy:
Yes, this is likely due to 32-bit target. I guess we could add ifdefs to problematic headers. Btw, what raspberry are you using? Both RPi 3 and 4 support 64-bit architecture. Also, could you explain your workflow? Do you cross-compile and then copy binaries over to raspberry? I only found |
Yes, actually I find developing with a remote SSH session in VS Code is a really nice workflow.
I'm specifically targeting raspberry pi 0Ws, though which is armv6 32-bit. (`arm-unknown-linux-gnueabihf` on rust).
…________________________________
From: Jurgis ***@***.***>
Sent: Saturday, February 18, 2023 7:34:38 PM
To: lit-robotics/libcamera-rs ***@***.***>
Cc: Michael Freeborn ***@***.***>; Author ***@***.***>
Subject: Re: [lit-robotics/libcamera-rs] Add instructions for cross compilation (Issue #17)
Usually with Rust cross-compilation is quite easy:
* rustup target add aarch64-unknown-linux-gnu
* cargo build --target aarch64-unknown-linux-gnu
bindgen and cc should support cross-compilation out of the box, but the problem is libcamera. I couldn't find any info on cross-compiling except this issue<raspberrypi/documentation#1529>. But for some reason libcamera doesn't want to use different toolchain and still compiles using system gcc. Didn't investigate further.
There is one more oddity that I have come across, regarding stream.h. The static assertion on line 24 static_assert(sizeof(struct libcamera_stream_configuration) == sizeof(libcamera_stream_configuration_t)); fails (112 == 88)... and I'm not sure why (something to do with host being 64-bit and target being 32-bit?) . Naively commenting the line out at least lets me compile camera_c_api, before getting the errors numbered above. I don't know why that static assertion is required in the first place, or why those two sizes would be different.
Yes, this is likely due to 32-bit target. I guess we could add ifdefs to problematic headers. Btw, what raspberry are you using? Both RPi 3 and 4 support 64-bit architecture.
Also, could you explain your workflow? Do you cross-compile and then copy binaries over to raspberry? I only found rust-analyzer with vscode to be slow on RPi 4, but regular incremental builds for libcamera are just a couple of seconds.
—
Reply to this email directly, view it on GitHub<#17 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AHSVKWGWJQENA3VQM35U5C3WYEP45ANCNFSM6AAAAAAVAO5RWY>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
libcamera uses meson as it's build system. If you want to cross compile libcamera to aarch64 you have to provide a suitable cross file and environment for that. Meson documents this at: |
Thanks for the tip, I actually succeeded in cross-compiling libcamera, but didn't have time to update. Here are the steps on Ubuntu 20.04 if anyone is interested:
I got stuck on
I will update if I get any further. |
Remember if you're cross compiling like that - then it will only 'work' if you're cross compiling on ubuntu-20.04 on your 'host', and your target device is also running ubuntu-20.04. You can't expect to cross compile on ubuntu-20.04 (x86) and target raspberry-pi-bullseye like that for instance. There will be all sorts of conflicts with different library versions and other dragons. You can however have a bullseye-arm64 root filesystem set as the sysroot to compile against if it matches what the target will have. That's what sysroots are for. I had an intern tackle this with docker to handle the requirements in the past which might have something helpful/useful: https://github.com/CactiChameleon9/Libcamera-RPiOS-Build-Enviroment |
I've spent too long on this - I managed to get it working transiently, but I think the cost-benefit isn't there. Cross compiling either rust or At one stage I ended up juggling the Ubuntu build system's filesystem, a So my conclusion is that whilst it's possible, it's not practical. If one is targeting a higher end Raspberry Pi, just use something like VS Codes SSH remote development. If one is targeting e.g. a Raspberry Pi 0 (like me), then just develop the application on your development machine (I need to research how to use the vimc driver, or use a cheapo usb camera) and make a coffee whilst you do your one final native compilation on the Pi. |
for vimc ... just 'sudo modprobe vimc'. |
If you have energy left, It could still be worth retrying what you've done with the docker image from https://github.com/CactiChameleon9/Libcamera-RPiOS-Build-Enviroment and extending that instead of https://github.com/tttapa/docker-arm-cross-toolchain as the cross compiler we use is installed directly from the bullseye repo, where as the 'docker-arm-cross-toolchain' is custom creating something. |
Thanks for the tip about vimc. I believe that one of the issues that |
Ah, wait - are you trying to use the rpi-zero *original? Or the RPi zero 2 ? |
The original, although I have stock alerts set up for the zero 2, which
would make things simpler. At least, compiling on it would be much quicker,
although it doesn't have enough RAM to do remote development on it
practically.
…On Tue, 21 Feb 2023 at 16:34, Kieran Bingham ***@***.***> wrote:
Ah, wait - are you trying to use the rpi-zero *original? Or the RPi zero 2
?
—
Reply to this email directly, view it on GitHub
<#17 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHSVKWBLN3V4TXM2GVLXJ3DWYTVCLANCNFSM6AAAAAAVAO5RWY>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Hi I have been doing some embedded projects and have cross compiled one of your examples in my experimental integration tool https://gitlab.com/pointswaves/girderstream-test-project/-/blob/264bd9a4ea87da9af8cd9ccdc724e153087ae85d/elements/libcamera-rs.grd (the only reason i have not build more of your examples is because my cross tool chain does not have a update enough rust for your other ones. Updating this is on my todo list lol) I use yocto/buildstream/buildroot at work but i have done the above with my experimental project girderstream. I only mention this so i can show you my example while also noting that its not the common way but that i do do quite a lot of embedded. My way of cross building libcamera-rs, in plain english, so you don't need to go look at my example in a unusual build file is as follows. Place your previously cross-compiled libcamera and its dependencies in a directory, in this case /targetfs/ You will then need to configure pkgconfig to find your cross compiled libcamera, ie were is the libcamera.pc file etc
At this point pkgconfig can find everything so you should just need to tell cargo that you want to cross compile First update your
Tell cargo/rustc how to build the C wrapper in libcamera-rs-sys by telling it what c++ compiler to use. Then compile the example The above is all pretty standard for cross building a I have had to manually set the rpath, so the linker can find the .so files of the dependnecies in the /targetfs/ which is not on the default linker path As you can see the
The way i think this should work is that you should provide both the -L (linker) and the -I (include) paths instead of just the -I .clang_arg(format!("-I{}", libcamera_include_path.display())) The docs for pkgconfig https://docs.rs/pkg-config/latest/pkg_config/struct.Library.html talk about the -I and -L paths. I think the reason you don't normally need to set the link path is because up until now all the required .so files were on the default link paths, but if you ever tried to build libcamera-rs-sys on a system were the .so of the deps were not on the default link path, i think you would have this issue. So would you like me to write some patches to:
|
@fishrockz wow, thanks for the in depth explanation.
Sure
Maybe you could write this as a separate file (i.e. CROSSCOMPILING.md) and link it from the main README? Also, could you include how to cross-compile libcamera itself? Unless there is a howto somwhere else that we can link to. |
I think a sizeable use-case for this library is to develop
libcamera
applications for raspberry pi devices - at least that is my use case. The problem is that these devices can be very underpowered with regards to software development and compiling programs.I have therefore been spending the last couple of days on and off trying to get cross compilation working - I think I'm getting pretty close now.
I am using this repo to provide the cross compilation toolchain binaries, as well as a basic
sysroot
directory. It is missing a couple of things:GLIBC is v2.27, but we need at least v2.30. I think this is just a case of updating the configs and re-running the github action on the above-linked repo.
It doesn't have an up to date
libcamera
compiled within it. I have currently circumvented this problem by compilinglibcamera
on my raspberry pi 0 and copy the appropriate files to thesysroot
of the above toolchain.There is one more oddity that I have come across, regarding
stream.h
. The static assertion on line 24static_assert(sizeof(struct libcamera_stream_configuration) == sizeof(libcamera_stream_configuration_t));
fails (112 == 88)... and I'm not sure why (something to do with host being 64-bit and target being 32-bit?) . Naively commenting the line out at least lets me compilecamera_c_api
, before getting the errors numbered above. I don't know why that static assertion is required in the first place, or why those two sizes would be different.The text was updated successfully, but these errors were encountered: