Desdaemon / flutter_rust_bridge_template

Template for Flutter + Rust integration with flutter_rust_bridge.
https://desdaemon.github.io/flutter_rust_bridge_template/
Apache License 2.0
120 stars 63 forks source link

Template not running on Linux #45

Closed ZimboPro closed 1 year ago

ZimboPro commented 1 year ago

I have managed to run this template on Windows but it fails on Linux. I have managed to track more or less what the issue is but not sure how to resolve it or why it is required in the first place.

A few things to note, using Clang++ caused CMake to fail to generate the related files. Failed with error:

The C++ compiler
    "/usr/bin/clang++"
  is not able to compile a simple test program

I managed to succeed with g++ and generate all the required files.

However, if I run flutter run or flutter run -d linux then the build fails.

CMake Error at cmake_install.cmake:66 (file):
  file INSTALL cannot copy file
"/path/to/flutter_rust_bridge_template/flutter_rust_bridge_template/build/linux/x64/debug/intermediates_do_not_run/flutter_rust_bridge_template"
  to "/usr/local/flutter_rust_bridge_template": Permission denied.

So naturally this is a permission issue but I am not sure why it is required to install the binary to /usr/local/. I did not find anything in the documentation stating that it is required to run as admin either.

Any help is appreciated.

rustc --version: rustc 1.70.0

cmake --version: cmake version 3.19.7

flutter --version: Flutter 3.10.2 • channel stable

OS: Pop!_OS 22.04 LTS

Thanks do the template.

Desdaemon commented 1 year ago

Not quite sure, are you using a manual or Snap installation of Flutter? Also which version of clang++ do you have installed?

ZimboPro commented 1 year ago

Manual installation of Flutter. Clang I have 13.0.0 and 12.0.1

Desdaemon commented 1 year ago

This issue seems to be Flutter-specific. You may have to nuke the linux directory and recreate it with flutter create . and put back in the Rust CMake files.

May be related to flutter/flutter#115376

ZimboPro commented 1 year ago

No resulting changes to CMakeLists.txt in the end after adding Rust CMake back, I have tried some of the suggestions like clean etc but none have worked.

Also tried create a new Flutter project and just copying some of the missing config, deps etc over, same issue

ZimboPro commented 1 year ago

Managed to get it working, I had to change this section in linux/CMakeLists.txt

set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
endif()

to

set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)

As mentioned in the Flutter issue, not sure why CMake is generating it this way but forcing it managed to resolve it.

EDIT: I also had to update the build/CMakeCache.txt to use g++ instead of clang++

github-actions[bot] commented 1 year ago

This issue has been marked as stale because it has no activity recently. Please remove the 'stale' label, or comment if the issue persists.

github-actions[bot] commented 1 year ago

This issue has been closed after a period of inactivity. Please reopen this issue if the problem persists, or open a new one if you have a similar problem.