cunarist / rinf

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

Automatic generate protobuf messages during compilation #169

Closed bookshiyi closed 11 months ago

bookshiyi commented 1 year ago

Changes

Integrate command dart run rust_in_flutter message to compilation process, without run it manually.

temeddix commented 1 year ago

Interesting attempt :) but isn't it possible to do this with build.rs file?

temeddix commented 1 year ago

Also, what do you think about inspecting the issue that you've left a month ago? I will be happy to fix that problem with you for good 👀

bookshiyi commented 1 year ago

Interesting attempt :) but isn't it possible to do this with build.rs file?

Yeah, it is a good idea than implements in pod, Gradle, cmake separately. But I don's think clearly how to organize these codes yet.

Also, what do you think about inspecting the issue that you've left a month ago? I will be happy to fix that problem with you for good 👀

Glad to hear that. The heteromorphism build CI feature and arm macOS build bug is need more continuous time for me. I only have a little spare time recently, so the focus of programming is not on those two issues. Do you think these two issues have greatly improved the whole project? If it's not big, could we consider delaying it?

btw, I also want to fixed them and make the issues list clean.

bookshiyi commented 1 year ago

Interesting attempt :) but isn't it possible to do this with build.rs file?

In your opinion, where build.rs is placed is an appropriate path?

temeddix commented 1 year ago

It's a Rust module that's invoked on compilation

https://doc.rust-lang.org/cargo/reference/build-scripts.html https://doc.rust-lang.org/cargo/reference/build-script-examples.html

temeddix commented 1 year ago

In my opinion, always generating the message code automatically whenever building or running the app can be kind of aggressive. We've been using 'manual message code generation' with rifs message because it's more clear and explicit.

rifs message is used on various situations:

and only automating the situation where the user is running or building the app, let alone implicitly, can be kind of confusing..

I appreciate your effort, but maybe we can think about the development experience first. Right now, I believe we can tell users how to write optional ./native/hub/build.rs to automate the message generation in the docs, which runs rifs message :)

I believe the guided ./native/hub/build.rs content would be something like this(not tested yet):

use std::process::Command;
use std::env;

fn main() {
    // Set the working directory to ../../
    let working_dir = env::current_dir().unwrap().join("../../");

    // Run the "rifs message" command
    let _ = Command::new("rifs")
        .arg("message")
        .current_dir(&working_dir)
        .status()
        .expect("Failed to run 'rifs message'");
}
bookshiyi commented 1 year ago

In my humble opinion, protobuf messages generation should seem like RIF itself —— users don't need to care about the build process.

At the same time, maybe there are two direction to improve:

  1. Make dart run rust_in_flutter message support .proto files changes detection to decrease create message files frequency and the time spent on build.
  2. We can provide commands to manually generate messages, similar to rifs msg gen, rifs msg clean

How do you think about it?

Whether it's implemented using Rust, Dart, Python, or separately implemented in pod, Gradle, or CMake. I just think the generation of messages should be automated, but it should also support manual generation methods.

temeddix commented 1 year ago

I see your point. For 'change detection', I think it's worth implementing.

For automated message code generation, I believe we need to allow this scenario to happen.

  1. Developer changes the .proto file.
  2. Somehow the .proto files are automatically compiled into Dart and Rust code.
  3. The developer can rely on Rust-analyzer and Dart language server's linting in realtime, while writing code.

In short, if we are going to introduce automatic message code generation, I think it should be done in WRITE TIME, rather than COMPILE TIME. Also, being explicit would be better than being implicit. Maybe some kind of rifs message --watch will do the trick. What do you think?

bookshiyi commented 1 year ago

Thank you for your patient reply.

In terms of my personal development habits, I prefer Coding(dart, rust, protobuf) -> Flutter run -> Coding(dart, rust, protobuf)-> Flutter run, the files which dart or rust or protobuf both are source code of project for me.

But I also agree you mentioned that stages when auto generate message while WRITE TIME is better than COMPILE TIME.

rifs message --watch is a elegant implement, it should bring a good user experience.