Auto merge of #15099 - servo:phf-no-macros, r=jdm

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

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15099)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-01-20 08:59:26 -08:00 committed by GitHub
commit eade32ed16
7 changed files with 59 additions and 26 deletions

View file

@ -16,6 +16,9 @@ debugmozjs = ['js/debugmozjs']
[build-dependencies]
cmake = "0.1"
phf_codegen = "0.7.18"
phf_shared = "0.7.18"
serde_json = "0.8"
[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"}

View file

@ -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 serde_json;
use serde_json::Value;
use std::env;
use std::fmt;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::time::Instant;
fn main() {
@ -34,4 +43,33 @@ fn main() {
build.build();
println!("Binding generation completed in {}s", start.elapsed().as_secs());
let json = PathBuf::from(env::var("OUT_DIR").unwrap()).join("build").join("InterfaceObjectMapData.json");
let json: Value = serde_json::from_reader(File::open(&json).unwrap()).unwrap();
let mut map = phf_codegen::Map::new();
for (key, value) in json.as_object().unwrap() {
map.entry(Bytes(key), value.as_str().unwrap());
}
let phf = PathBuf::from(env::var("OUT_DIR").unwrap()).join("InterfaceObjectMapPhf.rs");
let mut phf = File::create(&phf).unwrap();
write!(&mut phf, "pub static MAP: phf::Map<&'static [u8], unsafe fn(*mut JSContext, HandleObject)> = ").unwrap();
map.build(&mut phf).unwrap();
write!(&mut phf, ";\n").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)
}
}

View file

@ -6840,6 +6840,15 @@ class GlobalGenRoots():
], "\n")), pre="pub flags Globals: u8 {\n", post="\n}")
globals_ = CGWrapper(CGIndenter(global_flags), pre="bitflags! {\n", post="\n}")
phf = CGGeneric("include!(concat!(env!(\"OUT_DIR\"), \"/InterfaceObjectMapPhf.rs\"));")
return CGList([
CGGeneric(AUTOGENERATED_WARNING_COMMENT),
CGList([imports, globals_, phf], "\n\n")
])
@staticmethod
def InterfaceObjectMapData(config):
pairs = []
for d in config.getDescriptors(hasInterfaceObject=True, isInline=False):
binding = toBindingNamespace(d.name)
@ -6848,19 +6857,13 @@ class GlobalGenRoots():
pairs.append((ctor.identifier.name, binding, binding))
pairs.sort(key=operator.itemgetter(0))
mappings = [
CGGeneric('b"%s" => codegen::Bindings::%s::%s::DefineDOMInterface as unsafe fn(_, _),' % pair)
CGGeneric('"%s": "codegen::Bindings::%s::%s::DefineDOMInterface as unsafe fn(_, _)"' % pair)
for pair in pairs
]
mapType = "phf::Map<&'static [u8], unsafe fn(*mut JSContext, HandleObject)>"
phf = CGWrapper(
CGIndenter(CGList(mappings, "\n")),
pre="pub static MAP: %s = phf_map! {\n" % mapType,
post="\n};\n")
return CGList([
CGGeneric(AUTOGENERATED_WARNING_COMMENT),
CGList([imports, globals_, phf], "\n\n")
])
return CGWrapper(
CGList(mappings, ",\n"),
pre="{\n",
post="\n}\n")
@staticmethod
def PrototypeList(config):

View file

@ -76,6 +76,7 @@ def main():
('PrototypeList', 'PrototypeList.rs'),
('RegisterBindings', 'RegisterBindings.rs'),
('InterfaceObjectMap', 'InterfaceObjectMap.rs'),
('InterfaceObjectMapData', 'InterfaceObjectMapData.json'),
('InterfaceTypes', 'InterfaceTypes.rs'),
('InheritTypes', 'InheritTypes.rs'),
('Bindings', os.path.join('Bindings', 'mod.rs')),

View file

@ -23,7 +23,6 @@
#![doc = "The script crate contains all matters DOM."]
#![plugin(phf_macros)]
#![plugin(plugins)]
extern crate angle;