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

feat: Replace use of the libc crate with the rustix crate #582

Merged
merged 1 commit into from
Jul 10, 2023

Conversation

thaodt
Copy link
Contributor

@thaodt thaodt commented Jun 26, 2023

This PR is served for this issue #521.

As discussed some days ago, I will leave the time functions as it is for the time being, as these can easily be ported to Inko itself using the new FFI.

Also, there's a function I can't find an alternative to in rustix, see the code below:

inko/rt/src/runtime.rs

Lines 31 to 43 in 59578a1

fn ignore_sigpipe() {
// Broken pipe errors default to terminating the entire program, making it
// impossible to handle such errors. This is especially problematic for
// sockets, as writing to a socket closed on the other end would terminate
// the program.
//
// While Rust handles this for us when compiling an executable, it doesn't
// do so when compiling it to a static library and linking it to our
// generated code, so we must handle this ourselves.
unsafe {
libc::signal(libc::SIGPIPE, libc::SIG_IGN);
}
}

Therefore, I still keep it in libc. If you have any ideas, please review and advise, I will update my PR.

How Has This Been Tested?

Existing tests pass.

What process can a PR reviewer use to test or verify this change?

Check the new rustix replacements are correct.

@thaodt thaodt marked this pull request as draft June 26, 2023 11:04
@thaodt thaodt changed the title [WIP] feat: Replace use of the libc crate with the rustix crate feat: Replace use of the libc crate with the rustix crate Jul 3, 2023
@thaodt thaodt marked this pull request as ready for review July 3, 2023 13:53
@thaodt
Copy link
Contributor Author

thaodt commented Jul 4, 2023

It seems it didn't assign to you 😅 once I changed it into "Open for review". @yorickpeterse could you please help me take a look on my PR?

@yorickpeterse yorickpeterse self-assigned this Jul 4, 2023
@yorickpeterse yorickpeterse self-requested a review July 4, 2023 10:57
Copy link
Collaborator

@yorickpeterse yorickpeterse left a comment

Choose a reason for hiding this comment

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

Regarding the signal() call:

We can just use an extern "C" block. We only need this on Unix platforms, and the SIG* constants have the same values on the different Unix systems. This way we don't need to keep the direct dependency on libc around.

Cargo.toml Outdated Show resolved Hide resolved
rt/Cargo.toml Outdated Show resolved Hide resolved
rt/src/memory_map.rs Outdated Show resolved Hide resolved
rt/src/memory_map.rs Outdated Show resolved Hide resolved
rt/src/memory_map.rs Outdated Show resolved Hide resolved
rt/src/runtime.rs Outdated Show resolved Hide resolved
rt/src/runtime/time.rs Outdated Show resolved Hide resolved
rt/src/socket/socket_address.rs Outdated Show resolved Hide resolved
rt/src/socket/socket_address.rs Outdated Show resolved Hide resolved
rt/src/socket/socket_address.rs Outdated Show resolved Hide resolved
@yorickpeterse yorickpeterse assigned thaodt and unassigned yorickpeterse Jul 4, 2023
@thaodt
Copy link
Contributor Author

thaodt commented Jul 4, 2023

Thank for your review @yorickpeterse 😄 i will update soon

@thaodt thaodt requested a review from yorickpeterse July 5, 2023 14:12
@thaodt
Copy link
Contributor Author

thaodt commented Jul 6, 2023

@yorickpeterse ping you again in case you maybe missed it 😛

rt/src/runtime.rs Outdated Show resolved Hide resolved
@thaodt
Copy link
Contributor Author

thaodt commented Jul 6, 2023

@yorickpeterse I've pushed the fix. Could you please take a look again? Hopefully my PR can gooo bruuhh

rt/src/runtime.rs Outdated Show resolved Hide resolved
rt/src/scheduler/mod.rs Outdated Show resolved Hide resolved
rt/src/socket/socket_address.rs Outdated Show resolved Hide resolved
rt/src/runtime.rs Outdated Show resolved Hide resolved
rt/src/runtime.rs Outdated Show resolved Hide resolved
rt/src/runtime.rs Outdated Show resolved Hide resolved
@yorickpeterse yorickpeterse added feature New things to add to Inko, such as a new standard library module runtime Changes related to the Rust-based runtime library labels Jul 7, 2023
@yorickpeterse
Copy link
Collaborator

yorickpeterse commented Jul 7, 2023

@thaodt I left some more comments. Once the necessary changes are made, please rebase the commits into a single one and stick a Changelog trailer at the end of the commit, this way it will make its way into the changelog. You can find some details on that here and here 😃

@thaodt
Copy link
Contributor Author

thaodt commented Jul 10, 2023

@thaodt I left some more comments. Once the necessary changes are made, please rebase the commits into a single one and stick a Changelog trailer at the end of the commit, this way it will make its way into the changelog. You can find some details on that here and here smiley

I've pushed the fix, change the commit message following the guideline. Please help me review @yorickpeterse

@thaodt thaodt requested a review from yorickpeterse July 10, 2023 07:22
Copy link
Collaborator

@yorickpeterse yorickpeterse left a comment

Choose a reason for hiding this comment

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

I've made three small formatting changes (just some wrapping of comments, which rustfmt doesn't do, and some whitespace), the rest looks fine. I think clippy will have some complaints, but I'll add the necessary changes to the commit myself. Thanks! 😃

@yorickpeterse yorickpeterse force-pushed the feat/rustix branch 2 times, most recently from c9d4a51 to 11ea13f Compare July 10, 2023 23:23
In the interest of reducing 3rd-party dependencies and maintaining
control over our code, I would not only like to restore our old polling
code in favour of the polling crate (inko-lang#344), but also switch to using
rustix. The benefit of using rustix is that at least on Linux we can
avoid libc calls. While this may result in a performance improvement,
it's really more about slowly reducing our dependencies on 3rd-party
libraries, including libc. The API might also be a bit more pleasant
to use compared to using the libc crate directly.

Changelog: changed
@yorickpeterse yorickpeterse merged commit f2379c6 into inko-lang:main Jul 10, 2023
@yorickpeterse
Copy link
Collaborator

@thaodt Thanks for working on this! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New things to add to Inko, such as a new standard library module runtime Changes related to the Rust-based runtime library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants