Skip to content

Commit 119fc25

Browse files
authored
Add additional CI checks (#182)
1 parent bcbdb89 commit 119fc25

10 files changed

Lines changed: 61 additions & 34 deletions

File tree

.github/workflows/rust.yml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
11
name: Rust
22

33
on: [push, pull_request]
4+
env:
5+
CARGO_TERM_COLOR: always
46

57
jobs:
68
build:
7-
runs-on: ${{ matrix.os }}
89
strategy:
910
matrix:
1011
os: [ubuntu-latest, windows-latest, macOS-latest]
11-
12+
runs-on: ${{ matrix.os }}
13+
env:
14+
RUSTFLAGS: -D warnings
15+
RUSTDOCFLAGS: -D warnings
1216
steps:
13-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v4
1418
- name: Install XCB and GL dependencies
15-
run: |
16-
sudo apt update
17-
sudo apt install libx11-xcb-dev libxcb-dri2-0-dev libgl1-mesa-dev libxcb-icccm4-dev libxcursor-dev
1819
if: contains(matrix.os, 'ubuntu')
20+
run: sudo apt-get install libx11-xcb-dev libxcb-dri2-0-dev libgl1-mesa-dev libxcb-icccm4-dev libxcursor-dev
1921
- name: Install rust stable
20-
uses: actions-rs/toolchain@v1
22+
uses: dtolnay/rust-toolchain@stable
2123
with:
2224
toolchain: stable
23-
override: true
24-
- name: Build with default features
25-
run: cargo build --examples --workspace --verbose
26-
- name: Build again with all features
27-
run: cargo build --examples --workspace --all-features --verbose
25+
components: rustfmt, clippy
26+
- name: Build Default
27+
run: cargo build --workspace --all-targets --verbose
28+
- name: Build All Features
29+
run: cargo build --workspace --all-targets --all-features --verbose
2830
- name: Run tests
29-
run: cargo test --examples --workspace --all-features --verbose
31+
run: cargo test --workspace --all-targets --all-features --verbose
32+
- name: Check docs
33+
run: cargo doc --examples --all-features --no-deps
34+
- name: Clippy
35+
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
36+
- name: Check Formatting (rustfmt)
37+
run: cargo fmt --all -- --check
38+
39+

Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,16 @@ softbuffer = "0.3.4"
4343

4444
[workspace]
4545
members = ["examples/render_femtovg"]
46+
47+
[lints.clippy]
48+
missing-safety-doc = "allow"
49+
50+
[[example]]
51+
name = "open_window"
52+
test = true
53+
doctest = true
54+
55+
[[example]]
56+
name = "open_parented"
57+
test = true
58+
doctest = true

clippy.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
msrv = '1.59'
2+
check-private-items = true

examples/open_window.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl WindowHandler for OpenWindowExample {
4040
fn on_event(&mut self, _window: &mut Window, event: Event) -> EventStatus {
4141
match &event {
4242
#[cfg(target_os = "macos")]
43-
Event::Mouse(MouseEvent::ButtonPressed { .. }) => copy_to_clipboard(&"This is a test!"),
43+
Event::Mouse(MouseEvent::ButtonPressed { .. }) => copy_to_clipboard("This is a test!"),
4444
Event::Window(WindowEvent::Resized(info)) => {
4545
println!("Resized: {:?}", info);
4646
let new_size = info.physical_size();
@@ -78,7 +78,7 @@ fn main() {
7878
std::thread::spawn(move || loop {
7979
std::thread::sleep(Duration::from_secs(5));
8080

81-
if let Err(_) = tx.push(Message::Hello) {
81+
if tx.push(Message::Hello).is_err() {
8282
println!("Failed sending message");
8383
}
8484
});

src/gl/macos.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,8 @@ impl GlContext {
121121
let framework_name = CFString::from_str("com.apple.opengl").unwrap();
122122
let framework =
123123
unsafe { CFBundleGetBundleWithIdentifier(framework_name.as_concrete_TypeRef()) };
124-
let addr = unsafe {
125-
CFBundleGetFunctionPointerForName(framework, symbol_name.as_concrete_TypeRef())
126-
};
127-
addr as *const c_void
124+
125+
unsafe { CFBundleGetFunctionPointerForName(framework, symbol_name.as_concrete_TypeRef()) }
128126
}
129127

130128
pub fn swap_buffers(&self) {

src/macos/window.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ impl WindowHandle {
4343
pub fn is_open(&self) -> bool {
4444
self.state.window_inner.open.get()
4545
}
46-
4746
}
4847

4948
unsafe impl HasRawWindowHandle for WindowHandle {
@@ -289,7 +288,9 @@ impl<'a> Window<'a> {
289288
unsafe {
290289
let view = self.inner.ns_view.as_mut().unwrap();
291290
let window: id = msg_send![view, window];
292-
if window == nil { return false; };
291+
if window == nil {
292+
return false;
293+
};
293294
let first_responder: id = msg_send![window, firstResponder];
294295
let is_key_window: BOOL = msg_send![window, isKeyWindow];
295296
let is_focused: BOOL = msg_send![view, isEqual: first_responder];

src/win/drop_target.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use winapi::um::oleidl::{
1515
IDropTarget, IDropTargetVtbl, DROPEFFECT_COPY, DROPEFFECT_LINK, DROPEFFECT_MOVE,
1616
DROPEFFECT_NONE, DROPEFFECT_SCROLL,
1717
};
18-
use winapi::um::shellapi::DragQueryFileW;
18+
use winapi::um::shellapi::{DragQueryFileW, HDROP};
1919
use winapi::um::unknwnbase::{IUnknown, IUnknownVtbl};
2020
use winapi::um::winuser::CF_HDROP;
2121
use winapi::Interface;
@@ -135,7 +135,7 @@ impl DropTarget {
135135
return;
136136
}
137137

138-
let hdrop = transmute((*medium.u).hGlobal());
138+
let hdrop = *(*medium.u).hGlobal() as HDROP;
139139

140140
let item_count = DragQueryFileW(hdrop, 0xFFFFFFFF, null_mut(), 0);
141141
if item_count == 0 {
@@ -153,7 +153,7 @@ impl DropTarget {
153153
DragQueryFileW(
154154
hdrop,
155155
i,
156-
transmute(buffer.spare_capacity_mut().as_mut_ptr()),
156+
buffer.spare_capacity_mut().as_mut_ptr().cast(),
157157
buffer_size as u32,
158158
);
159159
buffer.set_len(buffer_size);
@@ -175,7 +175,7 @@ impl DropTarget {
175175
return S_OK;
176176
}
177177

178-
return E_NOINTERFACE;
178+
E_NOINTERFACE
179179
}
180180

181181
unsafe extern "system" fn add_ref(this: *mut IUnknown) -> ULONG {

src/win/window.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use winapi::um::ole2::{OleInitialize, RegisterDragDrop, RevokeDragDrop};
66
use winapi::um::oleidl::LPDROPTARGET;
77
use winapi::um::winuser::{
88
AdjustWindowRectEx, CreateWindowExW, DefWindowProcW, DestroyWindow, DispatchMessageW,
9-
GetDpiForWindow, GetMessageW, GetWindowLongPtrW, LoadCursorW, PostMessageW, RegisterClassW,
10-
ReleaseCapture, SetCapture, SetProcessDpiAwarenessContext, SetTimer, SetWindowLongPtrW,
11-
SetWindowPos, SetFocus, GetFocus, TrackMouseEvent, TranslateMessage, UnregisterClassW, CS_OWNDC,
9+
GetDpiForWindow, GetFocus, GetMessageW, GetWindowLongPtrW, LoadCursorW, PostMessageW,
10+
RegisterClassW, ReleaseCapture, SetCapture, SetFocus, SetProcessDpiAwarenessContext, SetTimer,
11+
SetWindowLongPtrW, SetWindowPos, TrackMouseEvent, TranslateMessage, UnregisterClassW, CS_OWNDC,
1212
GET_XBUTTON_WPARAM, GWLP_USERDATA, IDC_ARROW, MSG, SWP_NOMOVE, SWP_NOZORDER, TRACKMOUSEEVENT,
1313
WHEEL_DELTA, WM_CHAR, WM_CLOSE, WM_CREATE, WM_DPICHANGED, WM_INPUTLANGCHANGE, WM_KEYDOWN,
1414
WM_KEYUP, WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MBUTTONDOWN, WM_MBUTTONUP, WM_MOUSEHWHEEL,
@@ -174,7 +174,7 @@ unsafe fn wnd_proc_inner(
174174
if *mouse_was_outside_window {
175175
// this makes Windows track whether the mouse leaves the window.
176176
// When the mouse leaves it results in a `WM_MOUSELEAVE` event.
177-
let mut track_mouse =TRACKMOUSEEVENT {
177+
let mut track_mouse = TRACKMOUSEEVENT {
178178
cbSize: std::mem::size_of::<TRACKMOUSEEVENT>() as u32,
179179
dwFlags: winapi::um::winuser::TME_LEAVE,
180180
hwndTrack: hwnd,
@@ -186,7 +186,12 @@ unsafe fn wnd_proc_inner(
186186
*mouse_was_outside_window = false;
187187

188188
let enter_event = Event::Mouse(MouseEvent::CursorEntered);
189-
window_state.handler.borrow_mut().as_mut().unwrap().on_event(&mut window, enter_event);
189+
window_state
190+
.handler
191+
.borrow_mut()
192+
.as_mut()
193+
.unwrap()
194+
.on_event(&mut window, enter_event);
190195
}
191196

192197
let x = (lparam & 0xFFFF) as i16 as i32;

src/window.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct WindowHandle {
2323

2424
impl WindowHandle {
2525
fn new(window_handle: platform::WindowHandle) -> Self {
26-
Self { window_handle, phantom: PhantomData::default() }
26+
Self { window_handle, phantom: PhantomData }
2727
}
2828

2929
/// Close the window

src/x11/xcb_connection.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,8 @@ impl XcbConnection {
9191
let _xres = width_px * 25.4 / width_mm;
9292
let yres = height_px * 25.4 / height_mm;
9393

94-
let yscale = yres / 96.0;
95-
9694
// TODO: choose between `xres` and `yres`? (probably both are the same?)
97-
yscale
95+
yres / 96.0
9896
}
9997

10098
#[inline]

0 commit comments

Comments
 (0)