diff --git a/Cargo.lock b/Cargo.lock index 3962dc8a78f..20d6d73428a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2015,15 +2015,6 @@ dependencies = [ "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "phf_macros" -version = "0.7.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "phf_generator 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", - "phf_shared 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "phf_shared" version = "0.7.20" @@ -2295,7 +2286,8 @@ dependencies = [ "open 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "phf 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", - "phf_macros 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", + "phf_codegen 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", + "phf_shared 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "profile_traits 0.0.1", "range 0.0.1", @@ -2483,7 +2475,6 @@ dependencies = [ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "net_tests 0.0.1", "net_traits_tests 0.0.1", - "phf_macros 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", "plugin_compiletest 0.0.1", "profile_tests 0.0.1", "script_tests 0.0.1", @@ -3541,7 +3532,6 @@ dependencies = [ "checksum phf 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "0c6afb2057bb5f846a7b75703f90bc1cef4970c35209f712925db7768e999202" "checksum phf_codegen 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "6b63f121bf9a128f2172a65d8313a8e0e79d63874eeb4b4b7d82e6dda6b62f7c" "checksum phf_generator 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "50ffbd7970f75afa083c5dd7b6830c97b72b81579c7a92d8134ef2ee6c0c7eb0" -"checksum phf_macros 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "619b2c128703c63376de760377600b924fc0257487f51bc156f596cf8762e497" "checksum phf_shared 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "286385a0e50d4147bce15b2c19f0cf84c395b0e061aaf840898a7bf664c2cfb7" "checksum pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8cee804ecc7eaf201a4a207241472cc870e825206f6c031e3ee2a72fa425f2fa" "checksum pnacl-build-helper 1.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "61c9231d31aea845007443d62fcbb58bb6949ab9c18081ee1e09920e0cf1118b" diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index 22b75316bd8..559ee596a45 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -16,6 +16,9 @@ debugmozjs = ['js/debugmozjs'] [build-dependencies] cmake = "0.1" +phf_codegen = "0.7.18" +phf_shared = "0.7.18" +regex = "0.2" [target.'cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))'.dependencies] tinyfiledialogs = "2.5.9" @@ -57,7 +60,6 @@ offscreen_gl_context = "0.5.0" open = "1.1.1" parking_lot = "0.3" phf = "0.7.18" -phf_macros = "0.7.18" plugins = {path = "../plugins"} profile_traits = {path = "../profile_traits"} range = {path = "../range"} diff --git a/components/script/build.rs b/components/script/build.rs index 019a55f25a6..389468f226c 100644 --- a/components/script/build.rs +++ b/components/script/build.rs @@ -3,7 +3,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ extern crate cmake; +extern crate phf_codegen; +extern crate phf_shared; +extern crate regex; + +use regex::Regex; use std::env; +use std::fmt; +use std::fs::File; +use std::io::{Read, Write}; +use std::path::PathBuf; use std::time::Instant; fn main() { @@ -34,4 +43,43 @@ fn main() { build.build(); println!("Binding generation completed in {}s", start.elapsed().as_secs()); + + convert_phf(); +} + +fn convert_phf() { + let filename = PathBuf::from(env::var("OUT_DIR").unwrap()).join("InterfaceObjectMap.rs"); + let mut source = String::new(); + File::open(&filename).unwrap().read_to_string(&mut source).unwrap(); + let map_macro = Regex::new("phf_map! \\{([^}]+)\\}").unwrap().captures(&source).unwrap(); + let entries_re = Regex::new("b\"([^\"]+)\" => ([^\n]+),\n").unwrap(); + let entries = entries_re.captures_iter(&map_macro[1]); + + let mut map = phf_codegen::Map::new(); + for entry in entries { + map.entry(Bytes(entry.get(1).unwrap().as_str()), entry.get(2).unwrap().as_str()); + } + + let mut file = File::create(&filename).unwrap(); + let map_macro = map_macro.get(0).unwrap(); + file.write_all(source[..map_macro.start()].as_bytes()).unwrap(); + map.build(&mut file).unwrap(); + file.write_all(source[map_macro.end()..].as_bytes()).unwrap(); +} + +#[derive(Eq, PartialEq, Hash)] +struct Bytes<'a>(&'a str); + +impl<'a> fmt::Debug for Bytes<'a> { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("b\"")?; + formatter.write_str(self.0)?; + formatter.write_str("\" as &'static [u8]") + } +} + +impl<'a> phf_shared::PhfHash for Bytes<'a> { + fn phf_hash(&self, hasher: &mut H) { + self.0.as_bytes().phf_hash(hasher) + } } diff --git a/components/script/lib.rs b/components/script/lib.rs index f1fbe6f99c5..0ee202fab01 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -23,7 +23,6 @@ #![doc = "The script crate contains all matters DOM."] -#![plugin(phf_macros)] #![plugin(plugins)] extern crate angle; diff --git a/ports/servo/Cargo.toml b/ports/servo/Cargo.toml index cfaaa2faf1d..54408d25d74 100644 --- a/ports/servo/Cargo.toml +++ b/ports/servo/Cargo.toml @@ -41,7 +41,6 @@ browserhtml = {git = "https://github.com/browserhtml/browserhtml", branch = "cra glutin_app = {path = "../../ports/glutin"} log = "0.3" libservo = {path = "../../components/servo"} -phf_macros = "0.7.19" [target.'cfg(not(target_os = "android"))'.dependencies] sig = "0.1"