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

Add initial optional Rust support #5427

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add initial optional Rust support #5427

wants to merge 1 commit into from

Conversation

hughsie
Copy link
Member

@hughsie hughsie commented Jan 18, 2023

Do not get too excited, this is only to see what breaks.

Type of pull request:

Copy link
Member

@superm1 superm1 left a comment

Choose a reason for hiding this comment

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

Something I genuinely don't understand about rust is with distro packages how do you add extra crates? buildds aren't supposed to have access to the web. So I feel like we should probably be cautious which crates are used and if at all possible configure the build process for distro packages in CI to fail if a crate isn't already installed rather than try to install it.

meson.build Outdated Show resolved Hide resolved
libfwupdplugin/meson.build Outdated Show resolved Hide resolved
!crc
}

fn crc32_full(buf: &[u8], crc_init: u32, polynomial: u32) -> u32 {
Copy link
Member

Choose a reason for hiding this comment

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

this is probably missing comments about the function documentation and parameters. Not sure if the documentation generator will parse the rust files, but another thing worth checking.

libfwupdplugin/fu-crc.rs Outdated Show resolved Hide resolved
@superm1
Copy link
Member

superm1 commented Jan 18, 2023

Something I genuinely don't understand about rust is with distro packages how do you add extra crates?

Answered my own question at least for Debian.
https://wiki.debian.org/Teams/RustPackaging

I think we're still going to have some pain though in getting people setup depending upon what crates we use/depend upon.

@hughsie
Copy link
Member Author

hughsie commented Jan 19, 2023

how do you add extra crates

At the moment I'm not planning to use any crates -- all the stuff here is from std.

@hughsie hughsie force-pushed the wip/rust branch 2 times, most recently from 00e0fab to 70ea154 Compare January 19, 2023 11:44
@superm1
Copy link
Member

superm1 commented Jan 19, 2023

At the moment I'm not planning to use any crates -- all the stuff here is from std.

Right; but it's somethign we need to think about. Once the cat is out of the bag, it's a matter of time until there are rust based plugins and those might need to take crates.

@@ -37,6 +38,7 @@ fu_crc8_full(const guint8 *buf, gsize bufsz, guint8 crc_init, guint8 polynomial)
}
return ~((guint8)(crc >> 8));
}
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't you just have this one ifndef wrap all 3? Or is the concern the documentation?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was worried about the docs. I'll play -- I didn't like the idea of duplicating them in two source files.

Copy link
Member

Choose a reason for hiding this comment

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

If possible I would suggest moving them to the rust files, and then making sure the job that builds docs does it from the rust files too. Then that makes sure that we can scale better too as more rust stuff is added.

meson.build Outdated Show resolved Hide resolved
contrib/ci/rustfmt.py Outdated Show resolved Hide resolved
libfwupdplugin/meson.build Outdated Show resolved Hide resolved
libfwupdplugin/meson.build Outdated Show resolved Hide resolved
libfwupdplugin/fu-crc.rs Show resolved Hide resolved
meson.build Outdated Show resolved Hide resolved
@nyabinary
Copy link

What the status on this?

@hughsie
Copy link
Member Author

hughsie commented Sep 1, 2023

What the status on this?

It's work in progress. It's something I still want to do, but I don't want to make it more difficult to build fwupd.Being super-honest, I'm also somewhat unimpressed with both the binary size and the compile speed when enabling the rust support. You might have also noticed that slowly other parts of the codebase are actually using rust structures and enums, although we transpile them to C before compiling. e.g. see https://fwupd.github.io/libfwupdplugin/tutorial.html#the-rustgen-helper

@nyabinary
Copy link

@hughsie Huh, that isn't normal usually; Rust is pretty fast and can provide super small binary sizes. Maybe ask people in the Rust community to help in optimization?

@hughsie hughsie force-pushed the wip/rust branch 2 times, most recently from 24750e8 to dc253df Compare October 17, 2023 08:59
@hughsie
Copy link
Member Author

hughsie commented Oct 17, 2023

@superm1 can you explain what's wrong with rustc = find_program('rustc', required: get_option('rust').enabled()) -- I don't understand the failure! Thanks.

@superm1 superm1 force-pushed the wip/rust branch 2 times, most recently from 68ba254 to 7a7ed99 Compare October 18, 2023 03:47
@superm1
Copy link
Member

superm1 commented Oct 18, 2023

I've got the meson stuff sorted now at least between this and #6271

@superm1
Copy link
Member

superm1 commented Oct 18, 2023

I'm obviously not experienced in rust but given the error the compiler is throwing, it's just saying there is no point to dropping the ref because it's not allocating the memory, right? so just dropping mem::drop is probably the right action?

@hughsie
Copy link
Member Author

hughsie commented Oct 19, 2023

so just dropping mem::drop is probably the right action

Nah, you have to tell rust explicitly -- otherwise it leaks. I'll have a look after the weekend -- thanks for the buildsystem stuff, it's much appreciated.

Do not too excited, this is only to see what breaks.
@hughsie
Copy link
Member Author

hughsie commented Oct 30, 2023

Nah, you have to tell rust explicitly -- otherwise it leaks

Turns out I was 100% wrong; fixed.

@hughsie hughsie marked this pull request as ready for review October 30, 2023 10:46
@hughsie
Copy link
Member Author

hughsie commented Oct 30, 2023

Note: this raises the meson dep to 1.0 -- this might be a problem for ChromeOS.

@hughsie
Copy link
Member Author

hughsie commented Oct 30, 2023

@superm1 lets branch first -- I don't want to open the gates just yet.

@superm1
Copy link
Member

superm1 commented Oct 30, 2023

Sure no problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants