mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Remove usage of phf_macros.
It’s a compiler plugin that uses unstable compiler APIs that are not on a path to stabilization. With this changes, there is one less thing that might break when we update the compiler. For example: https://github.com/sfackler/rust-phf/pull/101
This commit is contained in:
parent
80c6383140
commit
71fb02953c
5 changed files with 53 additions and 15 deletions
|
@ -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"}
|
||||
|
|
|
@ -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<H: std::hash::Hasher>(&self, hasher: &mut H) {
|
||||
self.0.as_bytes().phf_hash(hasher)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
#![doc = "The script crate contains all matters DOM."]
|
||||
|
||||
#![plugin(phf_macros)]
|
||||
#![plugin(plugins)]
|
||||
|
||||
extern crate angle;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue