diff options
Diffstat (limited to 'components/util')
-rw-r--r-- | components/util/Cargo.toml | 21 | ||||
-rw-r--r-- | components/util/geometry.rs | 8 | ||||
-rw-r--r-- | components/util/lib.rs | 56 | ||||
-rw-r--r-- | components/util/opts.rs | 11 | ||||
-rw-r--r-- | components/util/prefs.rs | 6 | ||||
-rw-r--r-- | components/util/thread.rs | 13 | ||||
-rw-r--r-- | components/util/vec.rs | 5 |
7 files changed, 61 insertions, 59 deletions
diff --git a/components/util/Cargo.toml b/components/util/Cargo.toml index 40c8f56a64b..c8974dfd583 100644 --- a/components/util/Cargo.toml +++ b/components/util/Cargo.toml @@ -8,28 +8,31 @@ publish = false name = "util" path = "lib.rs" +[features] +# servo as opposed to geckolib +servo = ["serde", "serde_macros", "backtrace", "ipc-channel", "app_units/plugins", + "euclid/plugins", "euclid/unstable", "url/heap_size", "url/serde"] + [dependencies] -app_units = {version = "0.2.3", features = ["plugins"]} -backtrace = "0.2.1" +app_units = "0.2.3" +backtrace = {version = "0.2.1", optional = true} bitflags = "0.7" deque = "0.3.1" -euclid = {version = "0.6.4", features = ["unstable", "plugins"]} +euclid = "0.6.4" getopts = "0.2.11" heapsize = "0.3.0" -heapsize_plugin = "0.1.2" -ipc-channel = {git = "https://github.com/servo/ipc-channel"} +ipc-channel = {git = "https://github.com/servo/ipc-channel", optional = true} lazy_static = "0.2" libc = "0.2" log = "0.3.5" num_cpus = "0.2.2" num-traits = "0.1.32" -plugins = {path = "../plugins"} rand = "0.3" rustc-serialize = "0.3" -serde = "0.7" -serde_macros = "0.7" +serde = {version = "0.7", optional = true} +serde_macros = {version = "0.7", optional = true} smallvec = "0.1" -url = {version = "1.0.0", features = ["heap_size", "serde"]} +url = "1.0.0" [target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))'.dependencies] xdg = "2.0" diff --git a/components/util/geometry.rs b/components/util/geometry.rs index 813cad3aa3d..d750131f151 100644 --- a/components/util/geometry.rs +++ b/components/util/geometry.rs @@ -23,7 +23,7 @@ use std::i32; /// /// The ratio between ScreenPx and DevicePixel for a given display be found by calling /// `servo::windowing::WindowMethods::hidpi_factor`. -#[derive(Clone, Copy, Debug, HeapSizeOf)] +#[derive(Clone, Copy, Debug)] pub enum ScreenPx {} /// One CSS "px" in the coordinate system of the "initial viewport": @@ -35,7 +35,7 @@ pub enum ScreenPx {} /// /// At the default zoom level of 100%, one PagePx is equal to one ScreenPx. However, if the /// document is zoomed in or out then this scale may be larger or smaller. -#[derive(Clone, Copy, Debug, HeapSizeOf)] +#[derive(Clone, Copy, Debug)] pub enum ViewportPx {} /// One CSS "px" in the root coordinate system for the content document. @@ -44,9 +44,11 @@ pub enum ViewportPx {} /// This is the mobile-style "pinch zoom" that enlarges content without reflowing it. When the /// viewport zoom is not equal to 1.0, then the layout viewport is no longer the same physical size /// as the viewable area. -#[derive(Clone, Copy, Debug, HeapSizeOf)] +#[derive(Clone, Copy, Debug)] pub enum PagePx {} +known_heap_size!(0, ScreenPx, ViewportPx, PagePx); + // In summary, the hierarchy of pixel units and the factors to convert from one to the next: // // DevicePixel diff --git a/components/util/lib.rs b/components/util/lib.rs index 6417fe40a45..ff1a18ab712 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -2,39 +2,31 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#![feature(box_syntax)] -#![feature(core_intrinsics)] -#![feature(custom_derive)] -#![feature(fnbox)] -#![feature(plugin)] -#![feature(reflect_marker)] -#![feature(step_by)] - -#![plugin(heapsize_plugin, plugins, serde_macros)] +#![cfg_attr(feature = "servo", feature(core_intrinsics))] +#![cfg_attr(feature = "servo", feature(custom_derive))] +#![cfg_attr(feature = "servo", feature(fnbox))] +#![cfg_attr(feature = "servo", feature(plugin))] +#![cfg_attr(feature = "servo", feature(reflect_marker))] +#![cfg_attr(feature = "servo", plugin(serde_macros))] #![deny(unsafe_code)] extern crate app_units; -extern crate backtrace; -#[allow(unused_extern_crates)] -#[macro_use] -extern crate bitflags; +#[cfg(feature = "servo")] extern crate backtrace; +#[allow(unused_extern_crates)] #[macro_use] extern crate bitflags; extern crate deque; extern crate euclid; extern crate getopts; -extern crate heapsize; -extern crate ipc_channel; -#[allow(unused_extern_crates)] -#[macro_use] -extern crate lazy_static; +#[macro_use] extern crate heapsize; +#[cfg(feature = "servo")] extern crate ipc_channel; +#[allow(unused_extern_crates)] #[macro_use] extern crate lazy_static; extern crate libc; -#[macro_use] -extern crate log; +#[macro_use] extern crate log; extern crate num_cpus; extern crate num_traits; extern crate rand; extern crate rustc_serialize; -extern crate serde; +#[cfg(feature = "servo")] extern crate serde; extern crate smallvec; extern crate url; #[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))] @@ -44,28 +36,24 @@ use std::sync::Arc; pub mod basedir; pub mod cache; -#[allow(unsafe_code)] -pub mod debug_utils; +#[allow(unsafe_code)] pub mod debug_utils; pub mod geometry; -#[allow(unsafe_code)] -pub mod ipc; -pub mod linked_list; -#[allow(unsafe_code)] -pub mod opts; -pub mod panicking; +#[cfg(feature = "servo")] #[allow(unsafe_code)] pub mod ipc; +#[cfg(feature = "servo")] pub mod linked_list; +#[allow(unsafe_code)] pub mod opts; +#[cfg(feature = "servo")] pub mod panicking; pub mod prefs; -pub mod print_tree; +#[cfg(feature = "servo")] pub mod print_tree; pub mod resource_files; -#[allow(unsafe_code)] pub mod str; pub mod thread; pub mod thread_state; pub mod tid; -pub mod time; +#[cfg(feature = "servo")] pub mod time; pub mod vec; -#[allow(unsafe_code)] -pub mod workqueue; +#[allow(unsafe_code)] pub mod workqueue; +#[cfg(feature = "servo")] #[allow(unsafe_code)] pub fn breakpoint() { unsafe { ::std::intrinsics::breakpoint() }; diff --git a/components/util/opts.rs b/components/util/opts.rs index 323abc19d62..711782ab3ea 100644 --- a/components/util/opts.rs +++ b/components/util/opts.rs @@ -23,7 +23,8 @@ use url::{self, Url}; /// Global flags for Servo, currently set on the command line. -#[derive(Clone, Deserialize, Serialize)] +#[derive(Clone)] +#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] pub struct Opts { pub is_running_problem_test: bool, @@ -379,7 +380,8 @@ pub fn print_debug_usage(app: &str) -> ! { process::exit(0) } -#[derive(Clone, Deserialize, Serialize)] +#[derive(Clone)] +#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] pub enum OutputOptions { FileName(String), Stdout(f64) @@ -404,7 +406,8 @@ enum UserAgent { Android, } -#[derive(Clone, Debug, Eq, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] pub enum RenderApi { GL, ES2, @@ -858,7 +861,7 @@ pub fn set_defaults(opts: Opts) { unsafe { assert!(DEFAULT_OPTIONS.is_null()); assert!(DEFAULT_OPTIONS != INVALID_OPTIONS); - let box_opts = box opts; + let box_opts = Box::new(opts); DEFAULT_OPTIONS = Box::into_raw(box_opts); } } diff --git a/components/util/prefs.rs b/components/util/prefs.rs index 9c713df02e9..55c856fa747 100644 --- a/components/util/prefs.rs +++ b/components/util/prefs.rs @@ -20,7 +20,8 @@ lazy_static! { }; } -#[derive(PartialEq, Clone, Debug, Deserialize, Serialize)] +#[derive(PartialEq, Clone, Debug)] +#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] pub enum PrefValue { Boolean(bool), String(String), @@ -91,7 +92,8 @@ impl ToJson for PrefValue { } } -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug)] +#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] pub enum Pref { NoDefault(Arc<PrefValue>), WithDefault(Arc<PrefValue>, Option<Arc<PrefValue>>) diff --git a/components/util/thread.rs b/components/util/thread.rs index 87d8954dcf9..571d3529d9f 100644 --- a/components/util/thread.rs +++ b/components/util/thread.rs @@ -2,13 +2,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use backtrace::Backtrace; -use ipc_channel::ipc::IpcSender; -use panicking; -use serde::Serialize; -use std::any::Any; +#[cfg(feature = "servo")] use backtrace::Backtrace; +#[cfg(feature = "servo")] use ipc_channel::ipc::IpcSender; +#[cfg(feature = "servo")] use panicking; +#[cfg(feature = "servo")] use serde::Serialize; +#[cfg(feature = "servo")] use std::any::Any; +#[cfg(feature = "servo")] use thread_state; use std::thread; -use thread_state; pub fn spawn_named<F>(name: String, f: F) where F: FnOnce() + Send + 'static @@ -17,6 +17,7 @@ pub fn spawn_named<F>(name: String, f: F) } /// Arrange to send a particular message to a channel if the thread fails. +#[cfg(feature = "servo")] pub fn spawn_named_with_send_on_panic<F, Id>(name: String, state: thread_state::ThreadState, f: F, diff --git a/components/util/vec.rs b/components/util/vec.rs index 5342d452020..639e1c260da 100644 --- a/components/util/vec.rs +++ b/components/util/vec.rs @@ -9,10 +9,13 @@ use super::smallvec::VecLike; // TODO(pcwalton): Speed up with SIMD, or better yet, find some way to not do this. pub fn byte_swap(data: &mut [u8]) { let length = data.len(); - for i in (0..length).step_by(4) { + // FIXME(rust #27741): Range::step_by is not stable yet as of this writing. + let mut i = 0; + while i < length { let r = data[i + 2]; data[i + 2] = data[i + 0]; data[i + 0] = r; + i += 4; } } |