Skip to content

[WIP] Adding C interop sections #23

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

Merged
merged 4 commits into from
Oct 16, 2018
Merged

Conversation

spacekookie
Copy link
Contributor

This is still WIP, missing a bunch of stuff.

This PR adds sections to the book about how to embed Rust code into C/C++ projects and how to interact between Rust and C, transforming data into the appropriate formats.

@spacekookie spacekookie requested a review from a team as a code owner September 12, 2018 10:12
on transforming data between the two languages.
For this purposes there are two dedicated modules
in the `stdlib` called `std::ffi` and `std::raw`.
Copy link
Member

Choose a reason for hiding this comment

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

Do you plan to elaborate more on what ffi and raw do?

@andre-richter
Copy link
Member

Thanks for starting this. I left a little inline comment.

Copy link
Member

@posborne posborne left a comment

Choose a reason for hiding this comment

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

Good stuff. I left a few comments but this is a great start and good stuff in general.

We'll definitely want to link back to the FFI portion of the Rustonomicon which has some great content: https://doc.rust-lang.org/nomicon/ffi.html

### `extern "C"`

By default, any function you write in Rust will use the
Rust ABI (which is also no stabilised).
Copy link
Member

Choose a reason for hiding this comment

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

sp: also not stabilized.

on transforming data between the two languages.
For this purposes there are two dedicated modules
in the `stdlib` called `std::ffi` and `std::raw`.
Copy link
Member

Choose a reason for hiding this comment

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

Making these hyperlinks to the docs would probably be handy.

| etc | ... | ... |

Primitive types can simply be cast to Rust types.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe instead of "cast" the wording "converted into" would be more appropriate for the example shown. In this case, c_uint and u32 end up being the same type but that won't always be the case.

Just thinking the audience might react negatively to the idea of a "cast" being required (which often implies unsafety).

@spacekookie
Copy link
Contributor Author

Apologies for the long delay before getting back to this!

I fixed the marked sections in the existing text, but I'll try to finish the rest of it by the end of the week!

@japaric japaric added T-resources S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. labels Sep 25, 2018
bors bot added a commit that referenced this pull request Oct 15, 2018
45: First pass at "C with Rust" r=ryankurte a=jamesmunns

Took a first pass at this, I feel like there are probably a few places where I could use more/better examples or links to external information.

Please feel free to review and suggest changes.

Companion to @spacekookie's work in #23.

Co-authored-by: James Munns <james.munns@ferrous-systems.com>
Copy link
Member

@jamesmunns jamesmunns left a comment

Choose a reason for hiding this comment

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

Thanks @spacekookie!
bors r+

bors bot added a commit that referenced this pull request Oct 16, 2018
23: [WIP] Adding C interop sections r=jamesmunns a=spacekookie

*This is still WIP, missing a bunch of stuff.*

This PR adds sections to the book about how to embed Rust code into C/C++ projects and how to interact between Rust and C, transforming data into the appropriate formats.

Co-authored-by: Katharina Fey <kookie@spacekookie.de>
Co-authored-by: James Munns <james.munns@ferrous-systems.com>
Co-authored-by: Katharina <kookie@spacekookie.de>
@bors
Copy link
Contributor

bors bot commented Oct 16, 2018

Build succeeded

@bors bors bot merged commit 1f5e51a into rust-embedded:master Oct 16, 2018
njmartin10 pushed a commit to njmartin10/book that referenced this pull request Nov 10, 2018
45: First pass at "C with Rust" r=ryankurte a=jamesmunns

Took a first pass at this, I feel like there are probably a few places where I could use more/better examples or links to external information.

Please feel free to review and suggest changes.

Companion to @spacekookie's work in rust-embedded#23.

Co-authored-by: James Munns <james.munns@ferrous-systems.com>
njmartin10 pushed a commit to njmartin10/book that referenced this pull request Nov 10, 2018
23: [WIP] Adding C interop sections r=jamesmunns a=spacekookie

*This is still WIP, missing a bunch of stuff.*

This PR adds sections to the book about how to embed Rust code into C/C++ projects and how to interact between Rust and C, transforming data into the appropriate formats.

Co-authored-by: Katharina Fey <kookie@spacekookie.de>
Co-authored-by: James Munns <james.munns@ferrous-systems.com>
Co-authored-by: Katharina <kookie@spacekookie.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. T-resources
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants