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

Fix FreeBSD compiler error #377

Merged
merged 2 commits into from
Mar 21, 2024

Conversation

oleiade
Copy link
Contributor

@oleiade oleiade commented Mar 18, 2024

Hi @stanislav-tkach 👋🏻

While putting together a FreeBSD port for one of my rust crates, I encountered compilation errors from the os_info crate. Both with the OS' (FreeBSD 14.0) rust pkg, embedding the rust compiler version 1.72, and with the rustup default stable compiler version 1.76.

This Pull Request applies the fix recommended by the compiler and replaces the -s flag passed into the uname command by the -r flag, which does return the release number on FreeBSD (just like on OpenBSD), as opposed to -s which only returns the name of the os "FreeBSD". I assumed this wasn't intentional, but if it was, let me know, and I'll happily drop the change from the PR.

For reference, here's the compiler error I was encountering:

error[E0308]: mismatched types
  --> os_info/src/freebsd/mod.rs:28:9
   |
27 |     match uname("-s").as_deref() {
   |           ---------------------- this expression has type `std::option::Option<&str>`
28 |         "MidnightBSD" => Type::MidnightBSD,
   |         ^^^^^^^^^^^^^ expected `Option<&str>`, found `&str`
   |
   = note:   expected enum `std::option::Option<&str>`
           found reference `&'static str`
help: try wrapping the pattern in `Some`
   |
28 |         Some("MidnightBSD") => Type::MidnightBSD,
   |         +++++             +

error[E0308]: mismatched types
  --> os_info/src/freebsd/mod.rs:29:9
   |
27 |     match uname("-s").as_deref() {
   |           ---------------------- this expression has type `std::option::Option<&str>`
28 |         "MidnightBSD" => Type::MidnightBSD,
29 |         "FreeBSD" => {
   |         ^^^^^^^^^ expected `Option<&str>`, found `&str`
   |
   = note:   expected enum `std::option::Option<&str>`
           found reference `&'static str`
help: try wrapping the pattern in `Some`
   |
29 |         Some("FreeBSD") => {
   |         +++++         +

For more information about this error, try `rustc --explain E0308`.
error: could not compile `os_info` (lib) due to 2 previous errors

Let me know what you think and if you'd prefer any done differently 👍🏻

Thank you 🙇🏻

@oleiade oleiade changed the title Use -r uname flag to obtain FreeBSD version Fix FreeBSD compiler error Mar 18, 2024
@stanislav-tkach
Copy link
Owner

stanislav-tkach commented Mar 19, 2024

Thank you for the pull request! This is once again a result of my last minute refactoring before the release. 🙃 I think that -s should be used in the get_os function because in that case we are matching over the operating system name, but you are right that -r should be used to obtain a version.

@oleiade oleiade force-pushed the fix/freebsd-build branch from 7495397 to 395360a Compare March 21, 2024 08:01
oleiade added 2 commits March 21, 2024 09:02
On FreeBSD 14, uname -s returns the name of the operating system.

Whereas I believe the intention was to have a similar behavior to
the OpenBSD module implementation, and use the -r flag which does
also return the current release level of the kernel: "14.0-RELEASE".
@oleiade oleiade force-pushed the fix/freebsd-build branch from 395360a to 3147a61 Compare March 21, 2024 08:03
@oleiade
Copy link
Contributor Author

oleiade commented Mar 21, 2024

Good catch, you're absolutely right 👀 👍🏻

I've adjusted the PR to reflect the changes suggested in your comment indeed 🙇🏻

@stanislav-tkach stanislav-tkach merged commit c6f8294 into stanislav-tkach:master Mar 21, 2024
20 checks passed
@davidkna
Copy link
Contributor

I would appreciate a release with this.

This has caused the FreeBSD-build for the recent starship release to fail, and I may need to do another patch-up release soon, where it would be nice to have FreeBSD-builds again.

@stanislav-tkach
Copy link
Owner

@davidkna I have published the 3.8.2 version and yanked both 3.8.0 and 3.8.1. Sorry for the inconvenience!

@davidkna
Copy link
Contributor

Thanks!

@oleiade
Copy link
Contributor Author

oleiade commented Mar 23, 2024

Thank you @stanislav-tkach much appreciated 🙇🏻

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