From 303082bd6e3e8466be3471178de5662f8379f1d1 Mon Sep 17 00:00:00 2001 From: Charles Saracco Date: Mon, 25 May 2020 18:23:47 -0400 Subject: [PATCH 1/3] Create GitHub action for building project Tries to build on all three platforms we're targeting (Linux, Windows, MacOS) --- .github/workflows/rust.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..057290e --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,22 @@ +name: Rust + +on: [push] + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + + steps: + - uses: actions/checkout@v2 + - name: install rust stable + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose From f087efefe225d97ad0892a9c4c73541f7cd5af91 Mon Sep 17 00:00:00 2001 From: Charles Saracco Date: Mon, 25 May 2020 18:28:38 -0400 Subject: [PATCH 2/3] fix lib.rs so that it builds on all three targeted platforms --- src/lib.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index aacc02a..16820da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,14 @@ -mod win; - -pub use win::*; - use std::ffi::c_void; +#[cfg(target_os = "windows")] +mod win; +#[cfg(target_os = "windows")] +pub use win::*; +#[cfg(target_os = "linux")] mod x11; - +#[cfg(target_os = "macos")] mod macos; +#[cfg(target_os = "macos")] pub use macos::Window; pub enum Parent { @@ -24,6 +26,7 @@ pub struct WindowOpenOptions<'a> { pub parent: Parent, } +#[cfg(target_os = "linux")] pub fn run(options: WindowOpenOptions) { x11::run(options); } From ff5b7fee79683c2653703abeca415968e6be3a69 Mon Sep 17 00:00:00 2001 From: Charles Saracco Date: Mon, 25 May 2020 18:44:15 -0400 Subject: [PATCH 3/3] make example platform-independent (ish) --- .github/workflows/rust.yml | 5 +++++ examples/macos.rs | 10 ---------- examples/open_window.rs | 25 +++++++++++++++++++++++++ examples/windows.rs | 21 --------------------- examples/x11.rs | 10 ---------- src/x11.rs | 1 + 6 files changed, 31 insertions(+), 41 deletions(-) delete mode 100644 examples/macos.rs create mode 100644 examples/open_window.rs delete mode 100644 examples/windows.rs delete mode 100644 examples/x11.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 057290e..746c672 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,6 +11,11 @@ jobs: steps: - uses: actions/checkout@v2 + - name: install XCB dependencies + run: | + sudo apt update + sudo apt install libx11-xcb-dev libxcb-dri2-0-dev + if: contains(matrix.os, 'ubuntu') - name: install rust stable uses: actions-rs/toolchain@v1 with: diff --git a/examples/macos.rs b/examples/macos.rs deleted file mode 100644 index 924a382..0000000 --- a/examples/macos.rs +++ /dev/null @@ -1,10 +0,0 @@ -fn main() { - let window_open_options = baseview::WindowOpenOptions { - title: "baseview", - width: 512, - height: 512, - parent: baseview::Parent::None, - }; - - baseview::Window::open(window_open_options); -} diff --git a/examples/open_window.rs b/examples/open_window.rs new file mode 100644 index 0000000..e85d516 --- /dev/null +++ b/examples/open_window.rs @@ -0,0 +1,25 @@ +use std::ptr::null_mut; + +fn main() { + let window_open_options = baseview::WindowOpenOptions { + title: "baseview", + width: 512, + height: 512, + parent: baseview::Parent::None, + }; + + #[cfg(target_os = "macos")] { + baseview::Window::open(window_open_options); + } + #[cfg(target_os = "windows")] { + baseview::create_window(window_open_options); + loop { + if !baseview::handle_msg(null_mut()) { + break; + } + } + } + #[cfg(target_os = "linux")] { + baseview::run(window_open_options); + } +} diff --git a/examples/windows.rs b/examples/windows.rs deleted file mode 100644 index 9d32316..0000000 --- a/examples/windows.rs +++ /dev/null @@ -1,21 +0,0 @@ -use std::ptr::null_mut; - -use baseview::Parent; -use baseview::{create_window, handle_msg, WindowOpenOptions}; - -fn main() { - let window = WindowOpenOptions { - title: "Baseview", - width: 800, - height: 400, - parent: Parent::None, - }; - - create_window(window); - - loop { - if !handle_msg(null_mut()) { - break; - } - } -} diff --git a/examples/x11.rs b/examples/x11.rs deleted file mode 100644 index e147269..0000000 --- a/examples/x11.rs +++ /dev/null @@ -1,10 +0,0 @@ -fn main() { - let window_open_options = baseview::WindowOpenOptions { - title: "baseview", - width: 512, - height: 512, - parent: baseview::Parent::None, - }; - - baseview::run(window_open_options); -} diff --git a/src/x11.rs b/src/x11.rs index d9febf7..14e62dd 100644 --- a/src/x11.rs +++ b/src/x11.rs @@ -113,6 +113,7 @@ pub fn run(options: WindowOpenOptions) { // Figure out the DPI scaling by opening a new temporary connection and asking XCB // TODO: currently returning (96, 96) on my system, even though I have 4k screens. Problem with my setup perhaps? +#[allow(dead_code)] pub fn get_scaling() -> (u32, u32) { let (conn, screen_num) = xcb::Connection::connect_with_xlib_display().unwrap();