Skip to content

Commit 3369f4a

Browse files
committed
Fix clippy lint mismatched_target_os
Fix the deny-by-default clippy lint `mismatched_target_os`. We rename the `linux` cfg option to `free_unix`, which more accurately represents how it is used. The naming follows the cfg names chosen by the `winit` crate. the `wayland` cfg is slightly adjusted, to only be selected as the default if 1. wayland is enabled AND 2. either x11 is disabled, or the `sm-wayland-default` is selected Example clippy error message: ``` error: operating system used in target family position --> surfman/src/platform/unix/mod.rs:13:1 | 13 | #[cfg(linux)] | ^^^^^^-----^^ | | | help: try: `target_os = "linux"` | = help: did you mean `unix`? = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mismatched_target_os ``` Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
1 parent f63f3e4 commit 3369f4a

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

surfman/build.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,26 @@ fn main() {
1212
// Setup aliases for #[cfg] checks
1313
cfg_aliases! {
1414
// Platforms
15-
windows: { target_os = "windows" },
16-
macos: { target_os = "macos" },
17-
android: { target_os = "android" },
18-
// TODO: is `target_os = "linux"` the same as the following check?
19-
linux: { all(unix, not(any(macos, android))) },
15+
android_platform: { target_os = "android" },
16+
web_platform: { all(target_family = "wasm", target_os = "unknown") },
17+
macos_platform: { target_os = "macos" },
18+
ios_platform: { target_os = "ios" },
19+
windows_platform: { target_os = "windows" },
20+
apple: { any(target_os = "ios", target_os = "macos") },
21+
free_unix: { all(unix, not(apple), not(android_platform), not(target_os = "emscripten")) },
22+
23+
// Native displays.
24+
x11_platform: { all(free_unix, feature = "sm-x11") },
25+
wayland_platform: { all(free_unix) },
2026

2127
// Features:
2228
// Here we collect the features that are only valid on certain platforms and
2329
// we add aliases that include checks for the correct platform.
2430
angle: { all(windows, feature = "sm-angle") },
25-
angle_builtin: { all(windows, feature = "sm-angle-builtin") },
26-
angle_default: { all(windows, feature = "sm-angle-default") },
27-
no_wgl: { all(windows, feature = "sm-no-wgl") },
28-
wayland_default: { all(linux, feature = "sm-wayland-default") },
29-
x11: { all(linux, feature = "sm-x11") },
31+
angle_builtin: { all(windows_platform, feature = "sm-angle-builtin") },
32+
angle_default: { all(windows_platform, feature = "sm-angle-default") },
33+
no_wgl: { all(windows_platform, feature = "sm-no-wgl") },
34+
wayland_default: { all(wayland_platform, any(not(x11_platform), feature = "sm-wayland-default")) },
3035
}
3136

3237
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();

surfman/src/platform/generic/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
//! Backends that are not specific to any operating system.
44
5-
#[cfg(any(android, angle, linux))]
5+
#[cfg(any(android_platform, angle, free_unix))]
66
pub(crate) mod egl;
77

88
pub mod multi;

surfman/src/platform/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
55
pub mod generic;
66

7-
#[cfg(android)]
7+
#[cfg(android_platform)]
88
pub mod android;
9-
#[cfg(android)]
9+
#[cfg(android_platform)]
1010
pub use android as default;
1111

12-
#[cfg(macos)]
12+
#[cfg(macos_platform)]
1313
pub mod macos;
14-
#[cfg(macos)]
14+
#[cfg(macos_platform)]
1515
pub use macos::cgl as default;
16-
#[cfg(macos)]
16+
#[cfg(macos_platform)]
1717
pub use macos::system;
1818

19-
#[cfg(linux)]
19+
#[cfg(free_unix)]
2020
pub mod unix;
21-
#[cfg(linux)]
21+
#[cfg(free_unix)]
2222
pub use unix::default;
2323

24-
#[cfg(windows)]
24+
#[cfg(windows_platform)]
2525
pub mod windows;
2626
#[cfg(angle_default)]
2727
pub use windows::angle as default;
28-
#[cfg(all(windows, not(angle_default)))]
28+
#[cfg(all(windows_platform, not(angle_default)))]
2929
pub use windows::wgl as default;

surfman/src/platform/unix/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
//
33
//! Backends specific to Unix-like systems, particularly Linux.
44
5-
// The default when x11 is enabled
6-
#[cfg(x11)]
5+
// The default when x11 is enabled, and wayland default is not explicitly selected.
6+
#[cfg(all(x11_platform, not(wayland_default)))]
77
pub mod default;
88

9-
// The default when x11 is not enabled
10-
#[cfg(not(x11))]
9+
#[cfg(wayland_default)]
1110
pub use wayland as default;
1211

13-
#[cfg(linux)]
12+
#[cfg(free_unix)]
1413
pub mod generic;
1514

16-
#[cfg(linux)]
15+
#[cfg(wayland_platform)]
1716
pub mod wayland;
18-
#[cfg(x11)]
17+
#[cfg(x11_platform)]
1918
pub mod x11;

0 commit comments

Comments
 (0)