From 6d805fced62c7ec332fd664484280f94a787aff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 9 Mar 2017 22:24:00 +0100 Subject: [PATCH] platform: Allow not depending on x11 and using only OSMesa. Fixes #88 --- Cargo.toml | 6 +++--- build.rs | 2 +- src/lib.rs | 5 +++-- src/platform/mod.rs | 7 +++++-- src/tests.rs | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 116982d..f06f8f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "offscreen_gl_context" license = "MIT / Apache-2.0" -version = "0.8.0" +version = "0.8.1" authors = ["Emilio Cobos Álvarez ", "The Servo Project Developers"] description = "Creation and manipulation of HW accelerated offscreen rendering contexts in multiple platforms. Originally intended for the Servo project's WebGL implementation." repository = "https://github.com/emilio/rust-offscreen-rendering-context" @@ -11,11 +11,10 @@ build = "build.rs" gl_generator = "0.5" [features] -default = [] +default = ["x11"] osmesa = ["osmesa-sys"] # NOTE: Just for testing use, there are no other changes test_egl_in_linux = [] -test_osmesa = [] [dependencies] log = "0.3" @@ -29,6 +28,7 @@ core-foundation = "0.3.0" cgl = "0.2" [target.'cfg(target_os = "linux")'.dependencies.x11] +optional = true version = "2.3.0" features = ["xlib"] diff --git a/build.rs b/build.rs index 3acc153..839cf65 100644 --- a/build.rs +++ b/build.rs @@ -9,7 +9,7 @@ fn main() { let target = env::var("TARGET").unwrap(); let dest = PathBuf::from(&env::var("OUT_DIR").unwrap()); - if target.contains("linux") { + if target.contains("linux") && cfg!(feature = "x11") { let mut file = File::create(&dest.join("glx_bindings.rs")).unwrap(); Registry::new(Api::Glx, (1, 4), Profile::Core, Fallbacks::All, []) .write_bindings(gl_generator::StaticGenerator, &mut file).unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 4f257f8..3ec4422 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ extern crate log; #[cfg(feature="serde")] extern crate serde; -#[cfg(target_os="linux")] +#[cfg(all(target_os="linux", feature="x11"))] extern crate x11; #[cfg(target_os="macos")] extern crate cgl; @@ -29,6 +29,7 @@ extern crate lazy_static; mod platform; pub use platform::{NativeGLContext, NativeGLContextMethods, NativeGLContextHandle}; + #[cfg(feature="osmesa")] pub use platform::{OSMesaContext, OSMesaContextHandle}; @@ -53,7 +54,7 @@ pub use gl_formats::GLFormats; mod gl_limits; pub use gl_limits::GLLimits; -#[cfg(target_os="linux")] +#[cfg(all(target_os="linux", feature="x11"))] #[allow(improper_ctypes)] mod glx { include!(concat!(env!("OUT_DIR"), "/glx_bindings.rs")); diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 9086208..06c4a85 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -30,15 +30,18 @@ pub trait NativeGLContextMethods: Sized { fn is_osmesa(&self) -> bool { false } } -#[cfg(target_os="linux")] +#[cfg(all(target_os="linux", feature="x11"))] pub mod with_glx; -#[cfg(target_os="linux")] +#[cfg(all(target_os="linux", feature="x11"))] pub use self::with_glx::{NativeGLContext, NativeGLContextHandle}; #[cfg(feature="osmesa")] pub mod with_osmesa; #[cfg(feature="osmesa")] pub use self::with_osmesa::{OSMesaContext, OSMesaContextHandle}; +#[cfg(all(target_os="linux", not(feature="x11")))] +pub use self::with_osmesa::{OSMesaContext as NativeGLContext, OSMesaContextHandle as NativeGLContextHandle}; + #[cfg(any(target_os="android", all(target_os="linux", feature = "test_egl_in_linux")))] pub mod with_egl; diff --git a/src/tests.rs b/src/tests.rs index 230d827..c8a0f26 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -18,7 +18,7 @@ use std::sync::mpsc; #[link(name="OpenGL", kind="framework")] extern {} -#[cfg(target_os="linux")] +#[cfg(all(target_os="linux", feature="x11"))] #[link(name="GL")] extern {}