Skip to content

Building for ESP32 #102

Open
Open
@madwizard-thomas

Description

@madwizard-thomas

Hi,

I'm trying to get lvgl-rs to run on ESP32 (m5stack core2 module to be precise) on a windows host and ran into some issues with cc and bindgen in lvlg-sys. The esp32 environment does not need cross but normally works out of the box with the correct target (xtensa-esp32-elf in my case). Most issues were fixable by specifying the right environment variables. For anyone playing along at home, besides the .\export-esp.ps1 script you will need:

CROSS_COMPILE, CC, AR for cc to pick the right compiler, and C_INCLUDE_PATH for bindgen to find the system headers. In powershell (for my specific version):

$ENV:CROSS_COMPILE="xtensa-esp32-elf"

$ENV:CC="xtensa-esp32-elf-cc"
$ENV:AR="xtensa-esp32-elf-ar"

$ENV:C_INCLUDE_PATH = (@(
 "lib\gcc\xtensa-esp32-elf\8.4.0\include", 
 "lib\gcc\xtensa-esp32-elf\8.4.0\include-fixed",
 "xtensa-esp32-elf\sys-include", 
 "xtensa-esp32-elf\include"
) | % { Join-Path "$HOME\.rustup\toolchains\esp\xtensa-esp32-elf\esp-2021r2-patch5-8_4_0\xtensa-esp32-elf\" $_ }) -join ";"

However bindgen cc still had an issue that env vars could not solve. Because the lvgl crate uses a magic trick to read the raw bindings.rs from the lvgl-sys crate, it has a build dependency on lvgl-sys. Because the build scripts executables themselves are built for the host platform rather than the target platform, this will build lvgl-sys twice, one for the host (windows in my case) to link to the build script of lvgl and one for the target platform to link in the final executable. Building lvgl-sys (for a windows target) fails on windows. cc actually uses the xtensa compiler (only because of the $CC env var) but the TARGET env is set to windows (the target is a windows executable) and it will pass the wrong flags to the compiler (like -m64) because it thinks it is msvc.

The bindgen step actually works because it uses clang and the active clang configuration set by the ESP environment targets ESP.

My workaround (and possible solution) is to put the compiling (cc) step in lvgl-sys behind a specific default feature while keeping the bindgen step, then disabling this feature in lvgl's lvgl-sys build-dependency (because it only needs the bindings and not the full lib). Although I wonder if on other platforms like linux the build and normal dependencies may generate bindings for different targets?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions