Skip to content

Commit

Permalink
add freebsd target (linebender#2249)
Browse files Browse the repository at this point in the history
Co-authored-by: Jakub Panek <[email protected]>
  • Loading branch information
2 people authored and liias committed Sep 20, 2022
1 parent 8859c37 commit 7343455
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 23 deletions.
2 changes: 1 addition & 1 deletion druid-shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ core-graphics = "0.22.0"
foreign-types = "0.3.2"
bitflags = "1.2.1"

[target.'cfg(any(target_os="linux", target_os="openbsd"))'.dependencies]
[target.'cfg(any(target_os = "freebsd", target_os="linux", target_os="openbsd"))'.dependencies]
ashpd = { version = "0.3.0", optional = true }
# TODO(x11/dependencies): only use feature "xcb" if using X11
cairo-rs = { version = "0.14.0", default_features = false, features = ["xcb"] }
Expand Down
3 changes: 2 additions & 1 deletion druid-shell/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ fn main() {
use std::env;
use std::path::PathBuf;

if env::var("CARGO_CFG_TARGET_OS").unwrap() != "linux"
if env::var("CARGO_CFG_TARGET_OS").unwrap() != "freebsd"
&& env::var("CARGO_CFG_TARGET_OS").unwrap() != "linux"
&& env::var("CARGO_CFG_TARGET_OS").unwrap() != "openbsd"
{
return;
Expand Down
36 changes: 27 additions & 9 deletions druid-shell/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,54 @@ pub use mac::*;
#[cfg(target_os = "macos")]
pub(crate) mod shared;

#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "openbsd")))]
#[cfg(all(
feature = "x11",
any(target_os = "freebsd", target_os = "linux", target_os = "openbsd")
))]
mod x11;
#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "openbsd")))]
#[cfg(all(
feature = "x11",
any(target_os = "freebsd", target_os = "linux", target_os = "openbsd")
))]
pub use x11::*;
#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "openbsd")))]
#[cfg(all(
feature = "x11",
any(target_os = "freebsd", target_os = "linux", target_os = "openbsd")
))]
pub(crate) mod shared;

#[cfg(all(feature = "wayland", any(target_os = "linux", target_os = "openbsd")))]
#[cfg(all(
feature = "wayland",
any(target_os = "freebsd", target_os = "linux", target_os = "openbsd")
))]
mod wayland;
#[cfg(all(feature = "wayland", any(target_os = "linux", target_os = "openbsd")))]
#[cfg(all(
feature = "wayland",
any(target_os = "freebsd", target_os = "linux", target_os = "openbsd")
))]
pub use wayland::*;
#[cfg(all(feature = "wayland", any(target_os = "linux", target_os = "openbsd")))]
#[cfg(all(
feature = "wayland",
any(target_os = "freebsd", target_os = "linux", target_os = "openbsd")
))]
pub(crate) mod shared;

#[cfg(all(
not(feature = "x11"),
not(feature = "wayland"),
any(target_os = "linux", target_os = "openbsd")
any(target_os = "freebsd", target_os = "linux", target_os = "openbsd")
))]
mod gtk;
#[cfg(all(
not(feature = "x11"),
not(feature = "wayland"),
any(target_os = "linux", target_os = "openbsd")
any(target_os = "freebsd", target_os = "linux", target_os = "openbsd")
))]
pub use self::gtk::*;
#[cfg(all(
not(feature = "x11"),
not(feature = "wayland"),
any(target_os = "linux", target_os = "openbsd")
any(target_os = "freebsd", target_os = "linux", target_os = "openbsd")
))]
pub(crate) mod shared;

Expand Down
4 changes: 2 additions & 2 deletions druid-shell/src/backend/shared/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use keyboard_types::{Code, Location};
#[cfg(any(
all(
any(feature = "x11", feature = "wayland"),
any(target_os = "linux", target_os = "openbsd")
any(target_os = "freebsd", target_os = "linux", target_os = "openbsd")
),
target_os = "macos"
))]
Expand Down Expand Up @@ -57,7 +57,7 @@ pub fn code_to_location(code: Code) -> Location {
}
}

#[cfg(any(target_os = "linux", target_os = "openbsd"))]
#[cfg(any(target_os = "freebsd", target_os = "linux", target_os = "openbsd"))]
/// Map hardware keycode to code.
///
/// In theory, the hardware keycode is device dependent, but in
Expand Down
4 changes: 2 additions & 2 deletions druid-shell/src/backend/shared/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
//! Logic that is shared by more than one backend.
cfg_if::cfg_if! {
if #[cfg(any(target_os = "macos", target_os = "linux", target_os = "openbsd"))] {
if #[cfg(any(target_os = "freebsd", target_os = "macos", target_os = "linux", target_os = "openbsd"))] {
mod keyboard;
pub use keyboard::*;
}
}
cfg_if::cfg_if! {
if #[cfg(all(target_os = "linux", any(feature = "x11", feature = "wayland")))] {
if #[cfg(all(any(target_os = "freebsd", target_os = "linux"), any(feature = "x11", feature = "wayland")))] {
mod timer;
pub(crate) use timer::*;
pub(crate) mod xkb;
Expand Down
2 changes: 1 addition & 1 deletion druid-shell/src/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ cfg_if::cfg_if! {
} else {
impl ClipboardFormat {
cfg_if::cfg_if! {
if #[cfg(any(target_os = "linux", target_os = "openbsd"))] {
if #[cfg(any(target_os = "freebsd", target_os = "linux", target_os = "openbsd"))] {
// trial and error; this is the most supported string type for gtk?
pub const TEXT: &'static str = "UTF8_STRING";
} else {
Expand Down
5 changes: 4 additions & 1 deletion druid-shell/src/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ pub struct FileInfo {

/// Type of file dialog.
#[cfg(not(any(
all(feature = "x11", any(target_os = "linux", target_os = "openbsd")),
all(
feature = "x11",
any(target_os = "freebsd", target_os = "linux", target_os = "openbsd")
),
feature = "wayland"
)))]
#[derive(Clone, Copy, PartialEq, Eq)]
Expand Down
5 changes: 4 additions & 1 deletion druid-shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
// Rename `gtk_rs` back to `gtk`.
// This allows us to use `gtk` as the feature name.
// The `target_os` requirement is there to exclude anything `wasm` like.
#[cfg(all(any(target_os = "linux", target_os = "openbsd"), feature = "gtk"))]
#[cfg(all(
any(target_os = "freebsd", target_os = "linux", target_os = "openbsd"),
feature = "gtk"
))]
extern crate gtk_rs as gtk;

// Reexport the version of `image` we are using.
Expand Down
5 changes: 4 additions & 1 deletion druid-shell/src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

//! Platorm specific extensions.
#[cfg(any(doc, any(target_os = "linux", target_os = "openbsd")))]
#[cfg(any(
doc,
any(target_os = "freebsd", target_os = "linux", target_os = "openbsd")
))]
pub mod linux;

#[cfg(any(doc, target_os = "macos"))]
Expand Down
7 changes: 6 additions & 1 deletion druid/examples/markdown_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,12 @@ fn make_menu<T: Data>(_window_id: Option<WindowId>, _app_state: &AppState, _env:
{
base = base.entry(druid::platform_menus::mac::application::default())
}
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "openbsd"))]
#[cfg(any(
target_os = "windows",
target_os = "freebsd",
target_os = "linux",
target_os = "openbsd"
))]
{
base = base.entry(druid::platform_menus::win::file::default());
}
Expand Down
7 changes: 6 additions & 1 deletion druid/examples/multiwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,12 @@ fn make_menu(_: Option<WindowId>, state: &State, _: &Env) -> Menu<State> {
{
base = druid::platform_menus::mac::menu_bar();
}
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "openbsd"))]
#[cfg(any(
target_os = "windows",
target_os = "freebsd",
target_os = "linux",
target_os = "openbsd"
))]
{
base = base.entry(druid::platform_menus::win::file::default());
}
Expand Down
7 changes: 6 additions & 1 deletion druid/examples/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ fn make_menu<T: Data>(_window: Option<WindowId>, _data: &AppState, _env: &Env) -
{
base = base.entry(druid::platform_menus::mac::application::default())
}
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "openbsd"))]
#[cfg(any(
target_os = "windows",
target_os = "freebsd",
target_os = "linux",
target_os = "openbsd"
))]
{
base = base.entry(druid::platform_menus::win::file::default());
}
Expand Down
7 changes: 6 additions & 1 deletion druid/src/menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ impl<T: Data> MenuManager<T> {
#[cfg(target_os = "macos")]
return Some(MenuManager::new(|_, _, _| sys::mac::menu_bar()));

#[cfg(any(target_os = "windows", target_os = "linux", target_os = "openbsd"))]
#[cfg(any(
target_os = "windows",
target_os = "freebsd",
target_os = "linux",
target_os = "openbsd"
))]
return None;

// we want to explicitly handle all platforms; log if a platform is missing.
Expand Down
1 change: 1 addition & 0 deletions druid/src/widget/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use super::LabelText;

const CURSOR_BLINK_DURATION: Duration = Duration::from_millis(500);
const MAC_OR_LINUX_OR_OBSD: bool = cfg!(any(
target_os = "freebsd",
target_os = "macos",
target_os = "linux",
target_os = "openbsd"
Expand Down

0 comments on commit 7343455

Please sign in to comment.