cunarist / rinf

Rust for native business logic, Flutter for flexible and beautiful GUI
MIT License
1.89k stars 66 forks source link

Patching Flutter SDK may not for the best. #253

Closed stegrams closed 7 months ago

stegrams commented 9 months ago

Report

NixOS does not allow one package to modify the files of another.

Steps to Reproduce

rinf wasm --release

System Information

rinf 4.20.0

rustc 1.74.1 (a28077b28 2023-12-04)
libprotoc 24.4
[✓] Flutter (Channel stable, 3.13.8, on NixOS 23.11 (Tapir) 6.1.66, locale
    en_US.UTF-8)
[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from:
      https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK
      components.
      (or visit
      https://flutter.dev/docs/get-started/install/linux#android-setup for
      detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[!] Android Studio (not installed)
[✓] Connected device (2 available)
[✓] Network resources

Actually there are 2 issues here since, when Rinf scans for Flutter, it dereferences the link that gets from which, but the result path does not contain the target file devfs_web.dart (NixOS magic). That was easy, I commented out the dereferencing source line.

During the next steps, Rinf creates new content and patches the target file. That's a no-go on NixOS. Files inside packages provide strictly read-only access.

Generally though, I hope there will be a more "rusty" solution than patching code that do not control, because that may lead to undefined behavior.

E.g. a comment that contains the "httpServer = await" may be placed near the end of the file and people will start to report incomprehensible issues on Flutter project.

Thank you for sharing, and I hope to enjoy Rinf on my system one day.

temeddix commented 8 months ago

For now, we wanted to provide flutter run for web development as well. It's easier to just simply provide a custom web server, but we cannot use Flutter's debug tools in that case. Hope we can find a solution in-between :)

temeddix commented 8 months ago

From the next version of Flutter, it seems it would be possible to run Flutter web server with custom HTTP headers without modification. This change is already in the master channel of Flutter, but it's not released yet.

temeddix commented 8 months ago

@stegrams , may I ask if rinf wasm --release produces error? If so, could you share the output here?

stegrams commented 8 months ago

Hello @temeddix! Before I comment out the line that resolves links, the error is the following:

Unhandled exception:
PathNotFoundException: Cannot open file, path = '/nix/store/aq3y538nnn0v0fdya9xcnv8nl6flcngn-flutter-wrapped-3.13.8/packages/flutter_tools/lib/src/isolated/devfs_web.dart' (OS Error: No such file or directory, errno = 2)
#0      _checkForErrorResponse (dart:io/common.dart:55:9)
#1      _File.open.<anonymous closure> (dart:io/file_impl.dart:381:7)
<asynchronous suspension>
#2      _File.readAsString (dart:io/file_impl.dart:621:18)
<asynchronous suspension>
#3      _verifyServerHeaders (file:///home/user/.pub-cache/hosted/pub.dev/rinf-5.3.1/bin/rinf.dart:374:27)
<asynchronous suspension>
#4      _buildWebassembly (file:///home/user/.pub-cache/hosted/pub.dev/rinf-5.3.1/bin/rinf.dart:317:3)
<asynchronous suspension>
#5      main (file:///home/user/.pub-cache/hosted/pub.dev/rinf-5.3.1/bin/rinf.dart:29:9)
<asynchronous suspension>

After:

Unhandled exception:
FileSystemException: Cannot open file, path = '/nix/store/3a8nj8xg0g4xna89md5l0isajv5qas8a-flutter-wrapped-3.13.8-sdk-links/packages/flutter_tools/lib/src/isolated/devfs_web.dart' (OS Error: Read-only file system, errno = 30)
#0      _checkForErrorResponse (dart:io/common.dart:55:9)
#1      _File.open.<anonymous closure> (dart:io/file_impl.dart:381:7)
<asynchronous suspension>
#2      _verifyServerHeaders (file:///home/user/.pub-cache/hosted/pub.dev/rinf-5.3.1/bin/rinf.dart:396:3)
<asynchronous suspension>
#3      _buildWebassembly (file:///home/user/.pub-cache/hosted/pub.dev/rinf-5.3.1/bin/rinf.dart:317:3)
<asynchronous suspension>
#4      main (file:///home/user/.pub-cache/hosted/pub.dev/rinf-5.3.1/bin/rinf.dart:29:9)
<asynchronous suspension>
temeddix commented 8 months ago

I see. Once Flutter supports custom web server headers(Maybe in version 3.19), I will make that code skippable. For now, there's no way to provide our HTTP server headers if we cannot modify that Flutter file. We could make our own web server, but that would be overengineering :)

For your information, HTTP headers need to be set in order to make some web APIs work.

temeddix commented 7 months ago

Sharing the latest status: