Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create dynamic libraries with C interfaces for Dart FFI #3098

Merged
merged 2 commits into from
Aug 14, 2023

Conversation

andrei-toterman
Copy link
Contributor

@andrei-toterman andrei-toterman commented May 25, 2023

This PR adds a new shared library called dart_ffi which contains C interfaces of some of our C++ functions which we'd like to call from Dart using FFI.
Some additional refactoring was needed in order decouple the generation of certificates from the creation of the gRPC channel, so that certificate data can be more easily retrieved using a C interface.

@andrei-toterman andrei-toterman force-pushed the dyn-libs-with-c-interfaces branch 6 times, most recently from 6b2e90f to b1b1eb9 Compare May 31, 2023 13:10
@codecov
Copy link

codecov bot commented May 31, 2023

Codecov Report

❗ No coverage uploaded for pull request base (desktop-gui@d382be2). Click here to learn what that means.
The diff coverage is n/a.

@@              Coverage Diff               @@
##             desktop-gui    #3098   +/-   ##
==============================================
  Coverage               ?   88.48%           
==============================================
  Files                  ?      239           
  Lines                  ?    12107           
  Branches               ?        0           
==============================================
  Hits                   ?    10713           
  Misses                 ?     1394           
  Partials               ?        0           

Copy link
Contributor

@luis4a0 luis4a0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @andrei-toterman! Great job here. I see us using extensively this library in the future, so we'd need to be careful in the design. But until now, I don't see any flaws in design nor in code. So please rebase the base branch from main and make sure this will merge fine into it, answer please the few questions and we are good to go!

@@ -74,7 +74,7 @@ auto make_handler_unregisterer(mp::SettingsHandler* handler)
} // namespace

mp::Client::Client(ClientConfig& config)
: stub{mp::Rpc::NewStub(mp::client::make_channel(config.server_address, config.cert_provider.get()))},
: stub{mp::Rpc::NewStub(mp::client::make_channel(config.server_address, *config.cert_provider))},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this config->cert_provider?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. We need to pass a reference to make_channel and cert_provider in this case is a unique_ptr, so we need * to get that reference.

Comment on lines -194 to +193
mp::CertProvider* cert_provider)
const mp::CertProvider& cert_provider)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thnk this interface update is a drive-by change. But nevermind, it's a good change so I'm perfectly OK with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we could've kept the pointer but since after this refactoring we never pass a null pointer to this function, we can use a reference instead for more safety

@@ -86,6 +86,7 @@ option(YAML_CPP_BUILD_CONTRIB OFF)
option(YAML_CPP_BUILD_TESTS OFF)

add_subdirectory(yaml-cpp EXCLUDE_FROM_ALL)
set_target_properties(yaml-cpp PROPERTIES POSITION_INDEPENDENT_CODE ON)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need PIC here? Anyway, I'm OK with it, especially because it's third party. Just asking out of curiosity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it, I was simply getting a compilation error that said it needs PIC to compile some functions in that library :)

@luis4a0
Copy link
Contributor

luis4a0 commented Aug 14, 2023

bors r+

bors bot added a commit that referenced this pull request Aug 14, 2023
3098: Create dynamic libraries with C interfaces for Dart FFI r=luis4a0 a=andrei-toterman

This PR adds a new shared library called `dart_ffi` which contains C interfaces of some of our C++ functions which we'd like to call from Dart using FFI.
Some additional refactoring was needed in order decouple the generation of certificates from the creation of the gRPC channel, so that certificate data can be more easily retrieved using a C interface.

Co-authored-by: Andrei Toterman <[email protected]>
@luis4a0
Copy link
Contributor

luis4a0 commented Aug 14, 2023

bors cancel

@bors
Copy link
Contributor

bors bot commented Aug 14, 2023

Canceled.

@luis4a0 luis4a0 merged commit 590e625 into desktop-gui Aug 14, 2023
12 of 14 checks passed
@bors bors bot deleted the dyn-libs-with-c-interfaces branch August 14, 2023 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants