Open Roms1383 opened 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);
^~~~~~~
A quick trick that I did in the meantime, in case it's useful to somebody else:
rid
specifc code behind e.g. a flutter
feature flag with e.g. #[cfg(feature = "flutter")]
rid
unrelated code behind another feature flag, e.g. other
set default feature to "flutter"
like:
# Cargo.toml
# ...
[features]
default = ["flutter"]
flutter = [
# specify rid-only dependencies ...
"rid",
"rid-build"
]
other = [
# specify other-only dependencies, if any ...
]
This way, I can just ignore cbindgen
feature-related warnings (since flutter
is the default, rid
still get all the dependencies and code that it needs, and the app runs just fine), while keeping the option to use the plugin in another context (e.g. other
) and reusing shared code.
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!
Hello ! I tried something a bit out of scope but still:
context
Use conditional compiling in
rid
plugin crate, gated behind afeature flag
.steps to reproduce
Just use a feature flag somewhere in your code to gate some module, e.g. :
issue encountered
Not an error in itself, more like a
cbindgen
warning, e.g. :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 onrid-build
's fn cbingen() which configurescbindgen
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 🐘