mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Generate atom bindings for msvc
This commit is contained in:
parent
3c3c32f95e
commit
af3833d674
5 changed files with 16519 additions and 4701 deletions
6
ports/geckolib/Cargo.lock
generated
6
ports/geckolib/Cargo.lock
generated
|
@ -44,6 +44,11 @@ name = "bitflags"
|
|||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "cssparser"
|
||||
version = "0.5.6"
|
||||
|
@ -291,6 +296,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
name = "string_cache"
|
||||
version = "0.2.20"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gecko_bindings 0.0.1",
|
||||
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -15,6 +15,7 @@ unstable = []
|
|||
heap_size = []
|
||||
|
||||
[dependencies]
|
||||
cfg-if = "0.1.0"
|
||||
gecko_bindings = {version = "0.0.1", path = "../gecko_bindings"}
|
||||
heapsize = "0.3.5"
|
||||
libc = "0.2"
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,6 +2,8 @@
|
|||
* 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/. */
|
||||
|
||||
#[macro_use]
|
||||
extern crate cfg_if;
|
||||
extern crate gecko_bindings;
|
||||
extern crate heapsize;
|
||||
extern crate serde;
|
||||
|
|
|
@ -15,22 +15,57 @@ def line_to_atom(line):
|
|||
return (result.group(1), result.group(2))
|
||||
|
||||
|
||||
def symbolify(ident):
|
||||
def map_atom(ident):
|
||||
if ident in {"box", "loop", "match", "mod", "ref",
|
||||
"self", "type", "use", "where", "in"}:
|
||||
return ident + "_"
|
||||
return ident
|
||||
|
||||
|
||||
def gnu_symbolify(ident):
|
||||
return "_ZN9nsGkAtoms" + str(len(ident)) + ident + "E"
|
||||
|
||||
|
||||
def msvc64_symbolify(ident):
|
||||
return "?" + ident + "@nsGkAtoms@@2PEAVnsIAtom@@EA"
|
||||
|
||||
|
||||
def msvc32_symbolify(ident):
|
||||
return "?" + ident + "@nsGkAtoms@@2PAVnsIAtom@@A"
|
||||
|
||||
|
||||
def write_items(f, func):
|
||||
f.write(" extern {\n")
|
||||
for atom in atoms:
|
||||
f.write(TEMPLATE.format(name=map_atom(atom[0]),
|
||||
link_name=func(atom[0])))
|
||||
f.write(" }\n")
|
||||
|
||||
|
||||
with open(objdir_path + "/dist/include/nsGkAtomList.h") as f:
|
||||
lines = [line for line in f.readlines() if line.startswith("GK_ATOM")]
|
||||
atoms = [line_to_atom(line) for line in lines]
|
||||
|
||||
with open("atom_macro.rs", "w") as f:
|
||||
TEMPLATE = """
|
||||
#[link_name = "{link_name}"]
|
||||
pub static {name}: *mut nsIAtom;
|
||||
"""[1:]
|
||||
|
||||
with open("atom_macro.rs", "wb") as f:
|
||||
f.write("use gecko_bindings::structs::nsIAtom;\n\n")
|
||||
f.write("use Atom;\n\n")
|
||||
f.write("pub fn unsafe_atom_from_static(ptr: *mut nsIAtom) -> Atom { unsafe { Atom::from_static(ptr) } }\n\n")
|
||||
for atom in atoms:
|
||||
f.write('extern { pub static %s: *mut nsIAtom; }\n' % symbolify(atom[0]))
|
||||
f.write("cfg_if! {\n")
|
||||
f.write(" if #[cfg(not(target_env = \"msvc\"))] {\n")
|
||||
write_items(f, gnu_symbolify)
|
||||
f.write(" } else if #[cfg(target_pointer_width = \"64\")] {\n")
|
||||
write_items(f, msvc64_symbolify)
|
||||
f.write(" } else {\n")
|
||||
write_items(f, msvc32_symbolify)
|
||||
f.write(" }\n")
|
||||
f.write("}\n\n")
|
||||
f.write("#[macro_export]\n")
|
||||
f.write("macro_rules! atom {\n")
|
||||
f.writelines(['("%s") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::%s) };\n'
|
||||
% (atom[1], symbolify(atom[0])) for atom in atoms])
|
||||
% (atom[1], map_atom(atom[0])) for atom in atoms])
|
||||
f.write("}\n")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue