thlorenz / rid

Rust integrated Dart framework providing an easy way to build Flutter apps with Rust.
64 stars 4 forks source link

Support cbindgen config #58

Open Roms1383 opened 2 years ago

Roms1383 commented 2 years ago

Hello ! I tried something a bit out of scope but still:

context

Use conditional compiling in rid plugin crate, gated behind a feature flag.

steps to reproduce

Just use a feature flag somewhere in your code to gate some module, e.g. :

// lib.rs
#[cfg(feature = "flutter")]
pub mod plugin; // my plugin with rid store, etc

issue encountered

Not an error in itself, more like a cbindgen warning, e.g. :

2021-11-09 16:05:35,132 WARN [cbindgen::bindgen::ir::cfg] Missing `[defines]` entry for `feature = "flutter"` in cbindgen config.

whenever running ./sh/bindgen

So I looked on internet and found out more informations in cbindgen docs under the section "Defines and Cfgs".

So naturally I went to look for mentions of it in rid sourcecode and ended up landing on rid-build's fn cbingen() which configures cbindgen Builder and naturally the fn with_define() caught my attention: I gave a quick try on a fork's branch of mine, and it works.

summary

Long story short, I'm not gonna open a PR since these changes are only relevant to my own setup and my own project. But I thought worth mentioning that in the future maybe people would like the ability to tweak cbindgen config.

I looked at it briefly, and apologies if there's some existing mechanism to do it already: then I think it would be worth mentioning it in rid docs.

Thanks 🐘

Roms1383 commented 2 years ago

Well, when I said it works, at least it remove the warnings :laughing:

Actually it fails afterwards on flutter run -d macos:

# ...
/Users/romain/Development/sandbox/dataterm/citinet/plugin/macos/Classes/Plugin.swift:100:5: error: cannot find 'rid_msg_Sync' in scope
    rid_msg_Sync(0);
    ^~~~~~~~~~~~
/Users/romain/Development/sandbox/dataterm/citinet/plugin/macos/Classes/Plugin.swift:101:5: error: cannot find 'defined' in scope
    defined(0);
    ^~~~~~~
Roms1383 commented 2 years ago

A quick trick that I did in the meantime, in case it's useful to somebody else:

thlorenz commented 2 years ago

Great work and investigation! First off the cbindgen config is hard coded right now, but we could change things to allow you to pass in a config that it would be extended with. All these things you're discovering just show that rid is still far from being fully features and more work needs to be done to cover more use cases (like yours) 😃

Second, I'm not sure I understand the issue you ran into with Swift (seems unrelated to the first?). The feature flag solution you found for your case looks interesting, but it is difficult to see how it works. Could you please link to a fully working example if you have one?

Thanks for your time digging into this!