From 7a64bd3774bdaa7f9ac8e09dbd6f057540047159 Mon Sep 17 00:00:00 2001 From: Leopold Luley Date: Fri, 18 Sep 2020 08:28:44 +0200 Subject: [PATCH 1/3] Make GTK dependency optional. --- CHANGELOG.md | 2 ++ druid-shell/Cargo.toml | 38 +++++++++++++++----------------------- druid/Cargo.toml | 4 +++- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c474f92e6..3419d79ca8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,7 @@ You can find its changes [documented below](#060---2020-06-01). - Switch widget: Toggle animation being window refresh rate dependent ([#1145] by [@ForLoveOfCats]) - Multi-click on Windows, partial fix for #859 ([#1157] by [@raphlinus]) - Windows: fix crash on resize from incompatible resources ([#1191 by [@raphlinus]]) +- GTK: Related dependencies are now optional, facilitating a pure X11 build. ([#1241] by [@finnerale]) ### Visual @@ -459,6 +460,7 @@ Last release without a changelog :( [#1231]: https://github.com/linebender/druid/pull/1231 [#1220]: https://github.com/linebender/druid/pull/1220 [#1238]: https://github.com/linebender/druid/pull/1238 +[#1241]: https://github.com/linebender/druid/pull/1241 [Unreleased]: https://github.com/linebender/druid/compare/v0.6.0...master [0.6.0]: https://github.com/linebender/druid/compare/v0.5.0...v0.6.0 diff --git a/druid-shell/Cargo.toml b/druid-shell/Cargo.toml index e75ce1548f..d4e045d552 100644 --- a/druid-shell/Cargo.toml +++ b/druid-shell/Cargo.toml @@ -14,7 +14,9 @@ rustdoc-args = ["--cfg", "docsrs"] default-target = "x86_64-pc-windows-msvc" [features] -x11 = ["x11rb", "nix", "cairo-sys-rs"] +x11 = ["x11rb", "nix", "cairo-sys-rs", "cairo-rs"] +GTK = ["cairo-rs", "gio", "gdk", "gdk-sys", "glib", "glib-sys", "gtk-sys", "gtk"] +default = ["GTK"] [dependencies] # NOTE: When changing the piet or kurbo versions, ensure that @@ -30,19 +32,6 @@ instant = { version = "0.1.6", features = ["wasm-bindgen"] } anyhow = "1.0.32" keyboard-types = { version = "0.5.0", default_features = false } -# Optional dependencies -cairo-rs = { version = "0.9.1", default_features = false, optional = true } -cairo-sys-rs = { version = "0.10.0", default_features = false, optional = true } -gio = { version = "0.9.1", optional = true } -gdk = { version = "0.13.2", optional = true } -gdk-sys = { version = "0.10.0", optional = true } -gtk = { version = "0.9.2", optional = true } -glib = { version = "0.10.1", optional = true } -glib-sys = { version = "0.10.0", optional = true } -gtk-sys = { version = "0.10.0", optional = true } -nix = { version = "0.18.0", optional = true } -x11rb = { version = "0.6.0", features = ["allow-unsafe-code", "present", "randr", "xfixes"], optional = true } - [target.'cfg(target_os="windows")'.dependencies] wio = "0.2.2" @@ -59,16 +48,19 @@ core-graphics = "0.22.0" foreign-types = "0.3.2" bitflags = "1.2.1" -# TODO(x11/dependencies): only use feature "xcb" if using X11 [target.'cfg(target_os="linux")'.dependencies] -cairo-rs = { version = "0.9.1", default_features = false, features = ["xcb"] } -gio = "0.9.1" -gdk = "0.13.2" -gdk-sys = "0.10.0" -glib = "0.10.1" -glib-sys = "0.10.0" -gtk-sys = "0.10.0" -gtk = { version = "0.9.2", features = ["v3_22"] } +# TODO(x11/dependencies): only use feature "xcb" if using X11 +cairo-rs = { version = "0.9.1", default_features = false, features = ["xcb"], optional = true } +cairo-sys-rs = { version = "0.10.0", default_features = false, optional = true } +gio = { version = "0.9.1", optional = true } +gdk = { version = "0.13.2", optional = true } +gdk-sys = { version = "0.10.0", optional = true } +gtk = { version = "0.9.2", features = ["v3_22"], optional = true } +glib = { version = "0.10.1", optional = true } +glib-sys = { version = "0.10.0", optional = true } +gtk-sys = { version = "0.10.0", optional = true } +nix = { version = "0.18.0", optional = true } +x11rb = { version = "0.6.0", features = ["allow-unsafe-code", "present", "randr", "xfixes"], optional = true } [target.'cfg(target_arch="wasm32")'.dependencies] wasm-bindgen = "0.2.67" diff --git a/druid/Cargo.toml b/druid/Cargo.toml index 10d02dec9c..64c8e50f26 100644 --- a/druid/Cargo.toml +++ b/druid/Cargo.toml @@ -21,10 +21,12 @@ default-target = "x86_64-pc-windows-msvc" [features] x11 = ["druid-shell/x11"] +GTK = ["druid-shell/GTK"] svg = ["usvg", "harfbuzz-sys"] +default = ["GTK"] [dependencies] -druid-shell = { version = "0.6.0", path = "../druid-shell" } +druid-shell = { version = "0.6.0", default-features = false, path = "../druid-shell" } druid-derive = { version = "0.3.1", path = "../druid-derive" } log = "0.4.11" From 76bd73b8bbc26bf2307a53b611e3058084ea151b Mon Sep 17 00:00:00 2001 From: Leopold Luley Date: Sat, 19 Sep 2020 17:22:12 +0200 Subject: [PATCH 2/3] Rename 'GTK' feature to 'gtk' and make cairo available on macos again. --- druid-shell/Cargo.toml | 12 +++++++----- druid-shell/src/lib.rs | 5 +++++ druid/Cargo.toml | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/druid-shell/Cargo.toml b/druid-shell/Cargo.toml index d4e045d552..457a0025b6 100644 --- a/druid-shell/Cargo.toml +++ b/druid-shell/Cargo.toml @@ -15,8 +15,8 @@ default-target = "x86_64-pc-windows-msvc" [features] x11 = ["x11rb", "nix", "cairo-sys-rs", "cairo-rs"] -GTK = ["cairo-rs", "gio", "gdk", "gdk-sys", "glib", "glib-sys", "gtk-sys", "gtk"] -default = ["GTK"] +gtk = ["cairo-rs", "gio", "gdk", "gdk-sys", "glib", "glib-sys", "gtk-sys", "gtk-rs"] +default = ["gtk"] [dependencies] # NOTE: When changing the piet or kurbo versions, ensure that @@ -32,6 +32,9 @@ instant = { version = "0.1.6", features = ["wasm-bindgen"] } anyhow = "1.0.32" keyboard-types = { version = "0.5.0", default_features = false } +# TODO(x11/dependencies): only use feature "xcb" if using X11 +cairo-rs = { version = "0.9.1", default_features = false, features = ["xcb"], optional = true } + [target.'cfg(target_os="windows")'.dependencies] wio = "0.2.2" @@ -49,13 +52,12 @@ foreign-types = "0.3.2" bitflags = "1.2.1" [target.'cfg(target_os="linux")'.dependencies] -# TODO(x11/dependencies): only use feature "xcb" if using X11 -cairo-rs = { version = "0.9.1", default_features = false, features = ["xcb"], optional = true } cairo-sys-rs = { version = "0.10.0", default_features = false, optional = true } gio = { version = "0.9.1", optional = true } gdk = { version = "0.13.2", optional = true } gdk-sys = { version = "0.10.0", optional = true } -gtk = { version = "0.9.2", features = ["v3_22"], optional = true } +# `gtk` gets renamed to `gtk-rs` so that we can use `gtk` as the feature name. +gtk-rs = { version = "0.9.2", features = ["v3_22"], package = "gtk", optional = true } glib = { version = "0.10.1", optional = true } glib-sys = { version = "0.10.0", optional = true } gtk-sys = { version = "0.10.0", optional = true } diff --git a/druid-shell/src/lib.rs b/druid-shell/src/lib.rs index f2fbd7fcc0..6b0687c023 100644 --- a/druid-shell/src/lib.rs +++ b/druid-shell/src/lib.rs @@ -30,6 +30,11 @@ #![allow(clippy::new_without_default)] #![deny(clippy::trivially_copy_pass_by_ref)] +// Rename `gtk_rs` back to `gtk`. +// This allows us to use `gtk` as the feature name. +#[cfg(feature = "gtk")] +extern crate gtk_rs as gtk; + pub use kurbo; pub use piet_common as piet; diff --git a/druid/Cargo.toml b/druid/Cargo.toml index 64c8e50f26..0989fed61e 100644 --- a/druid/Cargo.toml +++ b/druid/Cargo.toml @@ -21,9 +21,9 @@ default-target = "x86_64-pc-windows-msvc" [features] x11 = ["druid-shell/x11"] -GTK = ["druid-shell/GTK"] +gtk = ["druid-shell/gtk"] svg = ["usvg", "harfbuzz-sys"] -default = ["GTK"] +default = ["gtk"] [dependencies] druid-shell = { version = "0.6.0", default-features = false, path = "../druid-shell" } From 54ce8834fcd148d0e5f949714d4914cf5e210bfc Mon Sep 17 00:00:00 2001 From: Leopold Luley Date: Sat, 19 Sep 2020 17:34:32 +0200 Subject: [PATCH 3/3] Fix wasm build. --- druid-shell/Cargo.toml | 10 +++++----- druid-shell/src/lib.rs | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/druid-shell/Cargo.toml b/druid-shell/Cargo.toml index 457a0025b6..9af3c8da6a 100644 --- a/druid-shell/Cargo.toml +++ b/druid-shell/Cargo.toml @@ -14,8 +14,8 @@ rustdoc-args = ["--cfg", "docsrs"] default-target = "x86_64-pc-windows-msvc" [features] -x11 = ["x11rb", "nix", "cairo-sys-rs", "cairo-rs"] -gtk = ["cairo-rs", "gio", "gdk", "gdk-sys", "glib", "glib-sys", "gtk-sys", "gtk-rs"] +x11 = ["x11rb", "nix", "cairo-sys-rs"] +gtk = ["gio", "gdk", "gdk-sys", "glib", "glib-sys", "gtk-sys", "gtk-rs"] default = ["gtk"] [dependencies] @@ -32,9 +32,6 @@ instant = { version = "0.1.6", features = ["wasm-bindgen"] } anyhow = "1.0.32" keyboard-types = { version = "0.5.0", default_features = false } -# TODO(x11/dependencies): only use feature "xcb" if using X11 -cairo-rs = { version = "0.9.1", default_features = false, features = ["xcb"], optional = true } - [target.'cfg(target_os="windows")'.dependencies] wio = "0.2.2" @@ -50,8 +47,11 @@ objc = "0.2.7" core-graphics = "0.22.0" foreign-types = "0.3.2" bitflags = "1.2.1" +cairo-rs = { version = "0.9.1", default_features = false, optional = true } [target.'cfg(target_os="linux")'.dependencies] +# TODO(x11/dependencies): only use feature "xcb" if using X11 +cairo-rs = { version = "0.9.1", default_features = false, features = ["xcb"] } cairo-sys-rs = { version = "0.10.0", default_features = false, optional = true } gio = { version = "0.9.1", optional = true } gdk = { version = "0.13.2", optional = true } diff --git a/druid-shell/src/lib.rs b/druid-shell/src/lib.rs index 6b0687c023..5d3b62425f 100644 --- a/druid-shell/src/lib.rs +++ b/druid-shell/src/lib.rs @@ -32,7 +32,8 @@ // Rename `gtk_rs` back to `gtk`. // This allows us to use `gtk` as the feature name. -#[cfg(feature = "gtk")] +// The `target_os` requirement is there to exclude anything `wasm` like. +#[cfg(all(target_os = "linux", feature = "gtk"))] extern crate gtk_rs as gtk; pub use kurbo;