Skip to content

Fix OpenBSD compilation of wgpu_hal::vulkan::drm #7810

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

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

Conversation

ErichDonGubler
Copy link
Member

@ErichDonGubler ErichDonGubler commented Jun 16, 2025

Connections

Description

Normally, libc::stat::st_rdev's type and libc::makedev's return type are the same: a dev_t. However, we've needed to work around cases where this isn't true in the past, breaking comparisons between them in the wgpu_hal::vulkan::drm module until a fix was put in place. In #7290, for instance, we needed to work around a weird case in Android where this wasn't true, but converting the *_devid side of the comparison to u64 first worked.

Now, we've discovered another case (OpenBSD) where both sides of the comparison are dev_t, but signed. We've only dealt with unsigned integers until now, so our workaround to convert the *_devid side of the comparison breaks down because i32 is not convertible to u64 using From::from. Sigh! Time to find something else that works.

I think the simplest solution is to use an as cast. 😱 So, do that here: make a to_u64!(…) macro that force-converts things, asserting that we're not casting something bigger than a u64. Then, apply it to both sides of our comparison. Voilà!

Also, document this weirdness, so I don't have to write it out in the event of yet another weird divergence for the types in this comparison. 😅

Testing

  • Confirm that this actually fixes a problem for OpenBSD builds.

For CI going forward, 🤷🏻‍♂️ this is not a configuration we normally care to test! I'm not sure what the right solution here is. My suggestion is that we treat this as a one-off, since this is (AFAIK) the first fix motivated by OpenBSD specifically.

Squash or Rebase?

squush plz

Checklist

  • If this contains user-facing changes, add a CHANGELOG.md entry.

@ErichDonGubler ErichDonGubler requested a review from a team as a code owner June 16, 2025 05:48
@ErichDonGubler ErichDonGubler force-pushed the erichdongubler-push-tkzwmkwnymlu branch 2 times, most recently from 85781c1 to 3216957 Compare June 16, 2025 05:58
Comment on lines +8 to +15
macro_rules! to_u64 {
($expr:expr) => {{
#[allow(trivial_numeric_casts)]
let expr = $expr as u64;
assert!(size_of_val(&expr) <= size_of::<u64>());
expr
}};
}
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 would like to take this opportunity to express my distaste for the lack of portability motivating this workaround, and the workaround itself. 😫

Otherwise, thanks in advance for reviewing~!

@ErichDonGubler ErichDonGubler changed the title fix(openbsd): coerce *_devid and drm_stat.st_rdev to u64 more forcefully Fix OpenBSD compilation of wgpu_hal::vulkan::drm Jun 16, 2025
@ErichDonGubler ErichDonGubler force-pushed the erichdongubler-push-tkzwmkwnymlu branch 2 times, most recently from eab6593 to f03bfc6 Compare June 16, 2025 06:32
@ErichDonGubler ErichDonGubler added type: bug Something isn't working area: infrastructure Testing, building, coordinating issues backend: vulkan Issues with Vulkan labels Jun 16, 2025
@landryb
Copy link

landryb commented Jun 16, 2025

totally not a rust developer so all this is alien to me, but i can confirm that fixes the thunderbird build failure i was seeing on this code (on OpenBSD, ofc).

….st_rdev` to `u64` forcefully before comparison
@ErichDonGubler ErichDonGubler force-pushed the erichdongubler-push-tkzwmkwnymlu branch 2 times, most recently from 3537920 to 606d284 Compare June 17, 2025 04:08
//
// - `armv7-linux-androideabi`: `dev_t` is `c_ulong`, and `*_devid`s are `dev_t`, but
// `st_rdev` is `c_ulonglong`. So, we can't just do a `==` comparison.
// - OpenBSD has `dev_t` on both sides, but is unsigned. Therefore, we can't just use
Copy link

Choose a reason for hiding this comment

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

unsigned, and on 32-bits according to @semarie (our resident rust expert)

Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

Conditionally approving, merge after consideration of the other comments

@cwfitzgerald cwfitzgerald self-assigned this Jun 18, 2025
@jimblandy
Copy link
Member

jimblandy commented Jun 18, 2025

Wait, I thought DRM was a Linux kernel API. The code in wgpu_hal::vulkan::drm is doing stuff like searching through Vulkan physical devices for something with a certain major/minor device number pair. Is this really something that we should be building on OpenBSD at all?

In other words, shouldn't this be sufficient?

modified   wgpu-hal/src/vulkan/mod.rs
@@ -28,6 +28,7 @@ mod adapter;
 mod command;
 mod conv;
 mod device;
+#[cfg(target_os = "linux")]
 mod drm;
 mod instance;
 mod sampler;

I'm pretty sure Thunderbird isn't even actually using WebGPU. They just want it to compile.

@jimblandy
Copy link
Member

Oh, hmm, it seems like OpenBSD does have its own implementation of the DRM API, so that it can run GPU drivers that depend on it. For example:

@landryb
Copy link

landryb commented Jun 19, 2025

Oh, hmm, it seems like OpenBSD does have its own implementation of the DRM API, so that it can run GPU drivers that depend on it. For example:

* https://man.openbsd.org/inteldrm.4

* https://man.openbsd.org/drm

yes we have the drm layers from the linux kernel, and vulkan apparently works on OpenBSD (never looked into it myself, though)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: infrastructure Testing, building, coordinating issues backend: vulkan Issues with Vulkan type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants