deltaphc / raylib-rs

Rust bindings for raylib
Other
715 stars 123 forks source link

Build fails for armv7-unknown-linux-gnueabihf; i8/u8 type mismatch #191

Open maiphi opened 1 month ago

maiphi commented 1 month ago

I'm trying to build raylib-rs master (5.0.0) for armv7-unknown-linux-gnueabihf. The build fails due to type mismatch between u8 and i8. I guess this is the same issue as described here: https://github.com/rust-lang/rust/issues/60226. There are several patches from projects linked that had the same problem.

Build log is attached: build.log

How to reproduce

Dockerfile:

FROM ghcr.io/cross-rs/armv7-unknown-linux-gnueabihf:latest
RUN dpkg --add-architecture armhf
RUN apt-get update -y
RUN apt-get install -y libx11-dev:armhf
RUN apt-get install -y xorg-dev clang libclang1-5.0

podman build -t raylib_rs_env .

Cross.toml:

[build]
default-target = "armv7-unknown-linux-gnueabihf"
[target.armv7-unknown-linux-gnueabihf]
image = "raylib_rs_env"
cargo install cross
cross build --release

(edit: removed packages from Dockerfile which are not needed to build a small example; added libx11-dev:armhf)

maiphi commented 1 month ago

Turns out this is not the only issue.

Replacing i8 by ::std::os::raw::c_char in core/callbacks.rs, core/data.rs and core/input.rs makes the code compile.

But then linking to an example program fails, because it wants to link bcm_host, brcmEGL, brcmGLESv2 and vcos, i.e. Raspberry Pi/Broadcom libraries.

It seems that the build system erroneously detects the platform as "Raspberry Pi" (passed to cmake when building raylib).

maiphi commented 1 month ago

The problem with the platform detection is in raylib-sys/build.rs:359-360. There it is assumed that the target armv7-unknown-linux implies that the platform is "Raspberry Pi". Commenting the two lines, compilation and linking is successful.

While the fix i8::std::os::raw::c_char should be portable, of course, for the platform detection one would need something more sophisticated to detect the RPI. Personally, I'd be happy with a build option to specify the platform.