sony / flutter-elinux

Flutter tools for embedded Linux (eLinux)
BSD 3-Clause "New" or "Revised" License
429 stars 43 forks source link

broken cross compile work around added #129

Closed Taha-Firoz closed 2 years ago

Taha-Firoz commented 2 years ago

Cross compile from x86 to arm is broken atleast for me, every since CMAKE_SYSROOT was passed directly the try_compile uses an arm compiler instead of a cross compiler which makes it fail everytime.

I have tried creating new projects and this is a reproducible error, compile any new flutter-elinux project with:

flutter-elinux build elinux -v --target-backend-type=gbm --target-compiler-triple=aarch64-linux-gnu  --target-arch=arm64  --target-sysroot=/home/me/rsc/arm64-sysroot --system-include-directories=/usr/aarch64-linux-gnu/include/c++/9/aarch64-linux-gnu

You will get this error:

Run Build Command(s):/home/me/rsc/arm64-sysroot/usr/bin/make cmTC_b676e/fast && /lib/ld-linux-aarch64.so.1: No such file or directory

This is because when CMAKE_SYSROOT is set before the project statement cmakes try_compile uses make from the arm64 sysroot which won't run on x86. My work around is simple just so I don't have to revert everything done in #105 set a temporary variable as CMAKE_SYSROOT, unset CMAKE_SYSROOT, let try_compile succeed then set CMAKE_SYSROOT to temp variable and set CMAKE_FIND_ROOT_PATH.

This is only a work around but it finally works, also you need to update the documentation that specifying --target-compiler-triple=aarch64-linux-gnu for regular x86-arm is required now, the previous versions would add this flag automatically but this current version no longer adds it automatically and thus builds fail.

Taha-Firoz commented 2 years ago

This should close #128

HidenoriMatsubayashi commented 2 years ago

Please check https://github.com/sony/flutter-elinux/blob/main/CONTRIBUTING.md.

HidenoriMatsubayashi commented 2 years ago

And also, please add Developer Certificate of Origin (DCO).

Taha-Firoz commented 2 years ago

I followed the CONTRIBUTING guide but I don't know how to add a DCO, it says I should just add this to my commit message Signed-off-by: Taha Firoz mtahafiroz@gmail.com

🤷‍♂️

andreadaoud commented 2 years ago

I disagree with this change. In https://cmake.org/cmake/help/latest/variable/CMAKE_SYSROOT.html , it says that this variable can only be set with toolchain file (or, be passed in commandline arguments).

What I recommend you to try, is to put this line: set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) before project. In this way cmake probably won't try to find the make tool in your sysroot. Please tell me if this works.

Taha-Firoz commented 2 years ago

Okay this works, I'm also adding an update in the wiki because now specifying compiler triple is also required now.

Taha-Firoz commented 2 years ago

I disagree with this change.

Of course I disagree with it too but I don't know too much about cmake and I just needed my code to compile which is why I made that work around. Your proposed solution fixes it properly, I also think maybe we can add a new parameter to flutter-elinux as an optional string to pass any arbitrary flags to cmake.

HidenoriMatsubayashi commented 2 years ago

Is the PR ready to be reviewed/merged or still a draft?

Taha-Firoz commented 2 years ago

Ready for review

HidenoriMatsubayashi commented 2 years ago

Thanks a lot.

Taha-Firoz commented 2 years ago

You forgot to add the wiki entries

HidenoriMatsubayashi commented 2 years ago

Updated.