lv_binding_rust icon indicating copy to clipboard operation
lv_binding_rust copied to clipboard

The demos do not compile on MacOS with Apple Silicon (ARM) CPU

Open SketchPiece opened this issue 10 months ago • 6 comments

Summary

I'm trying to run the demo examples of this project on my MacBook Pro (M1 Pro, macOS Sequoia 15.2) but encounter issues related to SDL2 during compilation, linking, and runtime. Despite following the setup instructions and troubleshooting extensively, I end up with a segmentation fault.

Could you help me identify what's missing in my setup or how to resolve this?

Environment:

  • Device: MacBook Pro (M1 Pro)
  • OS: macOS Sequoia 15.2
  • Toolchain:
    • Rust (stable version)
    • Homebrew-installed SDL2

Steps to Reproduce

Before running the demo examples I update all git submodules and as stated in the documentation and other issue #35 I install sdl2 for the simulator display to work properly on macOS

$ brew install sdl2
$ git submodule init
$ git submodule update 

When I'm trying to run the demo with the following command

$ DEP_LV_CONFIG_PATH=`pwd`/examples/include cargo run --example demo --features="alloc"

During the lvgl-sys compilation I'm getting an error that SDL2/SDL.h cannot be found

...
sys/vendor/lv_drivers/sdl/sdl_common_internal.h:21:10: fatal error: 'SDL2/SDL.h' file not found
warning: [email protected]:    21 | #include SDL_INCLUDE_PATH
warning: [email protected]:       |          ^~~~~~~~~~~~~~~~
warning: [email protected]: /Users/sketchpiece/Documents/Hacking/temp/lv_binding_rust/examples/include/lv_drv_conf.h:109:31: note: expanded from macro 'SDL_INCLUDE_PATH'
warning: [email protected]:   109 | #  define SDL_INCLUDE_PATH    <SDL2/SDL.h>
warning: [email protected]:       |                               ^~~~~~~~~~~~
warning: [email protected]: <scratch space>:498:1: note: expanded from here
warning: [email protected]:   498 | <SDL2/SDL.h>
warning: [email protected]:       | ^~~~~~~~~~~~
warning: [email protected]: 1 error generated.
...
error occurred in cc-rs: Command env -u IPHONEOS_DEPLOYMENT_TARGET LC_ALL="C" "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-2" "-fno-omit-frame-pointer" "--target=arm64-apple-macosx15.2" "-I" "/Users/sketchpiece/Documents/Hacking/temp/lv_binding_rust/lvgl-sys/vendor/lvgl/src" "-I" "/Users/sketchpiece/Documents/Hacking/temp/lv_binding_rust/lvgl-sys/vendor" "-I" "/Users/sketchpiece/Documents/Hacking/temp/lv_binding_rust/examples/include" "-I" "/Users/sketchpiece/Documents/Hacking/temp/lv_binding_rust/fonts" "-I" "/Users/sketchpiece/Documents/Hacking/temp/lv_binding_rust/lvgl-sys/vendor/lv_drivers" "-I" "/usr/include" "-I" "/usr/local/include" "-DLV_CONF_INCLUDE_SIMPLE=1" "-o" "/Users/sketchpiece/Documents/Hacking/temp/lv_binding_rust/target/debug/build/lvgl-sys-1fba6286d2a9502f/out/5dda4e2b23dfaa0a-sdl_common.o" "-c" "/Users/sketchpiece/Documents/Hacking/temp/lv_binding_rust/lvgl-sys/vendor/lv_drivers/sdl/sdl_common.c" with args cc did not execute successfully (status code exit status: 1).

Full output

I noticed that during compilation no include libraries from brew were added which were moved from /usr/include to /opt/homebrew/lib for the arm macOS And I tried adding this folder with LVGL_INCLUDE.

$ DEP_LV_CONFIG_PATH=`pwd`/examples/include LVGL_INCLUDE="/usr/include,/usr/local/include,/opt/homebrew/include" cargo run --example demo --features="alloc"

But I was getting yet another error regarding linux frame buffer

...
sys/vendor/lv_drivers/display/fbdev.c:26:10: fatal error: 'linux/fb.h' file not found
warning: [email protected]:    26 | #include <linux/fb.h>
warning: [email protected]:       |          ^~~~~~~~~~~~
warning: [email protected]: 1 error generated.
...

Full output

I changed USE_FBDEV in the lv_drv_conf.h to 0

/*-----------------------------------------
 *  Linux frame buffer device (/dev/fbx)
 *-----------------------------------------*/
#ifndef USE_FBDEV
#  define USE_FBDEV           0 // was 1 before
#endif

After running the same command with brew include paths I was still getting now linker errors regarding SDL2

 = note: ld: library 'SDL2' not found
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

I was able to resolve the linker error by exporting explicitly to the linker and cpp compiler the location of the lib and include folders

$ export LDFLAGS="-L/opt/homebrew/lib"
$ export CPPFLAGS="-I/opt/homebrew/include"
$ export LIBRARY_PATH="$LIBRARY_PATH:$(brew --prefix)/lib"

But eventually I was still getting seg fault

warning: `lvgl` (example "demo") generated 4 warnings (run `cargo fix --example "demo"` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.16s
     Running `target/debug/examples/demo`
[1]    29339 segmentation fault  DEP_LV_CONFIG_PATH=`pwd`/examples/include LVGL_INCLUDE= cargo run --example

I would be happy to know what could be done to solve this issue and compile demo example on the mac. Thank you!

SketchPiece avatar Jan 15 '25 07:01 SketchPiece

Hi, just to let you know that I've read the issue and it's been added to a list of TODO items. I don't own a Mac and it might be a bit difficult for me to try replicate, but I'll try.

C47D avatar Jan 17 '25 02:01 C47D

@C47D Maybe something I could help you with or some more info I could provide?

SketchPiece avatar Jan 17 '25 17:01 SketchPiece

Can you run it with valgrind and provide us the dump here ?

AlixANNERAUD avatar Jan 17 '25 18:01 AlixANNERAUD

It looks like valgrind is not currently compatible with mac

https://www.reddit.com/r/cs50/comments/meq16w/how_to_get_valgrind_on_macos/

When I try to install valgrind executables it throws with following error:

➜  ~ brew install valgrind

...

valgrind: Linux is required for this software.
Error: valgrind: An unsatisfied requirement failed this build.

Do you know any other software that could help?

SketchPiece avatar Jan 19 '25 20:01 SketchPiece

Well ... this is very surprising; Can you try with leaks instead as described here ?

AlixANNERAUD avatar Jan 21 '25 19:01 AlixANNERAUD

I had the same problem as you, then I tried your method but failed, until one time it worked.

OS: macOS Sequoia 15.4 Host: Mac Mini (2024) with Apple M4 (10)

(Actually the version information is not the key) Git HEAD: d83b37407ad6c1b673c82bb9ca6cf442abac96ed sdl2: 2.32.6

My steps:

  1. Clone the repo, then you don't need to run the git submodule commands manually (it should be handled automatically)

  2. Make sure you have sdl2 installed

$ brew install sdl2
  1. Modify examples/include/lv_drv_conf.h
--- a/examples/include/lv_drv_conf.h
+++ b/examples/include/lv_drv_conf.h
@@ -316,7 +316,7 @@
  *  Linux frame buffer device (/dev/fbx)
  *-----------------------------------------*/
 #ifndef USE_FBDEV
-#  define USE_FBDEV           1
+#  define USE_FBDEV           0
 #endif
  1. Run the demo with these environment variables
LIBRARY_PATH=/opt/homebrew/lib CPPFLAGS=-I/opt/homebrew/include LVGL_INCLUDE=/opt/homebrew/include DEP_LV_CONFIG_PATH=`PWD`/examples/include cargo run --example demo --features="alloc"
  1. Now you should see the window.

Image

I accidentally compiled successfully after a brew install something. And I discovered these diffs using printenv, so I think the key is, it's missing these LIBRARY/INCLUDE path flags that includes the sdl2

< LDFLAGS=-L/opt/homebrew/lib
< CPPFLAGS=-I/opt/homebrew/include
---
> LDFLAGS=-L/opt/homebrew/opt/ruby/lib
> CPPFLAGS=-I/opt/homebrew/opt/ruby/include
64d63
< LIBRARY_PATH=:/opt/homebrew/lib

@SketchPiece @C47D Hey guys, this issue should be closed now, but I suggest you update the README file with reference to this instruction.

JyCyunMe avatar May 18 '25 09:05 JyCyunMe