mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
style: Remove the ability to build Gecko without the bindgen feature.
This is not used for anything, as far as I can tell. Differential Revision: https://phabricator.services.mozilla.com/D38584
This commit is contained in:
parent
137044a3db
commit
66eae2fc81
3 changed files with 369 additions and 422 deletions
|
@ -16,8 +16,7 @@ path = "lib.rs"
|
|||
doctest = false
|
||||
|
||||
[features]
|
||||
gecko = ["style_traits/gecko", "fallible/known_system_malloc"]
|
||||
use_bindgen = ["bindgen", "regex", "toml"]
|
||||
gecko = ["style_traits/gecko", "fallible/known_system_malloc", "bindgen", "regex", "toml"]
|
||||
servo = ["serde", "style_traits/servo", "servo_atoms", "servo_config", "html5ever",
|
||||
"cssparser/serde", "encoding_rs", "malloc_size_of/servo", "arrayvec/use_union",
|
||||
"servo_url", "string_cache", "crossbeam-channel", "to_shmem/servo", "servo_arc/servo"]
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[cfg(feature = "bindgen")]
|
||||
#[cfg(feature = "gecko")]
|
||||
extern crate bindgen;
|
||||
#[cfg(feature = "bindgen")]
|
||||
#[cfg(feature = "gecko")]
|
||||
extern crate log;
|
||||
#[cfg(feature = "bindgen")]
|
||||
#[cfg(feature = "gecko")]
|
||||
extern crate regex;
|
||||
#[cfg(feature = "bindgen")]
|
||||
#[cfg(feature = "gecko")]
|
||||
extern crate toml;
|
||||
extern crate walkdir;
|
||||
|
||||
|
|
|
@ -2,38 +2,29 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
mod common {
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use super::PYTHON;
|
||||
use bindgen::{Builder, CodegenConfig};
|
||||
use regex::Regex;
|
||||
use std::cmp;
|
||||
use std::collections::HashSet;
|
||||
use std::env;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{Read, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{exit, Command};
|
||||
use std::slice;
|
||||
use std::sync::Mutex;
|
||||
use std::time::SystemTime;
|
||||
use toml;
|
||||
use toml::value::Table;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref OUTDIR_PATH: PathBuf =
|
||||
PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("gecko");
|
||||
}
|
||||
lazy_static! {
|
||||
static ref OUTDIR_PATH: PathBuf = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("gecko");
|
||||
}
|
||||
|
||||
#[cfg(feature = "bindgen")]
|
||||
mod bindings {
|
||||
use super::super::PYTHON;
|
||||
use super::common::*;
|
||||
use bindgen::{Builder, CodegenConfig};
|
||||
use regex::Regex;
|
||||
use std::cmp;
|
||||
use std::collections::HashSet;
|
||||
use std::env;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{Read, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{exit, Command};
|
||||
use std::slice;
|
||||
use std::sync::Mutex;
|
||||
use std::time::SystemTime;
|
||||
use toml;
|
||||
use toml::value::Table;
|
||||
const STRUCTS_FILE: &'static str = "structs.rs";
|
||||
|
||||
const STRUCTS_FILE: &'static str = "structs.rs";
|
||||
|
||||
fn read_config(path: &PathBuf) -> Table {
|
||||
fn read_config(path: &PathBuf) -> Table {
|
||||
println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
|
||||
update_last_modified(&path);
|
||||
|
||||
|
@ -46,9 +37,9 @@ mod bindings {
|
|||
Ok(result) => result,
|
||||
Err(e) => panic!("Failed to parse config file: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
lazy_static! {
|
||||
static ref CONFIG: Table = {
|
||||
// Load Gecko's binding generator config from the source tree.
|
||||
let path = PathBuf::from(env::var_os("MOZ_SRC").unwrap())
|
||||
|
@ -77,19 +68,19 @@ mod bindings {
|
|||
static ref LAST_MODIFIED: Mutex<SystemTime> =
|
||||
Mutex::new(get_modified_time(&env::current_exe().unwrap())
|
||||
.expect("Failed to get modified time of executable"));
|
||||
}
|
||||
}
|
||||
|
||||
fn get_modified_time(file: &Path) -> Option<SystemTime> {
|
||||
fn get_modified_time(file: &Path) -> Option<SystemTime> {
|
||||
file.metadata().and_then(|m| m.modified()).ok()
|
||||
}
|
||||
}
|
||||
|
||||
fn update_last_modified(file: &Path) {
|
||||
fn update_last_modified(file: &Path) {
|
||||
let modified = get_modified_time(file).expect("Couldn't get file modification time");
|
||||
let mut last_modified = LAST_MODIFIED.lock().unwrap();
|
||||
*last_modified = cmp::max(modified, *last_modified);
|
||||
}
|
||||
}
|
||||
|
||||
fn search_include(name: &str) -> Option<PathBuf> {
|
||||
fn search_include(name: &str) -> Option<PathBuf> {
|
||||
for path in SEARCH_PATHS.iter() {
|
||||
let file = path.join(name);
|
||||
if file.is_file() {
|
||||
|
@ -98,9 +89,9 @@ mod bindings {
|
|||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn add_headers_recursively(path: PathBuf, added_paths: &mut HashSet<PathBuf>) {
|
||||
fn add_headers_recursively(path: PathBuf, added_paths: &mut HashSet<PathBuf>) {
|
||||
if added_paths.contains(&path) {
|
||||
return;
|
||||
}
|
||||
|
@ -114,22 +105,22 @@ mod bindings {
|
|||
add_headers_recursively(path, added_paths);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn add_include(name: &str) -> String {
|
||||
fn add_include(name: &str) -> String {
|
||||
let mut added_paths = ADDED_PATHS.lock().unwrap();
|
||||
let file = search_include(name).expect("Include not found!");
|
||||
let result = String::from(file.to_str().unwrap());
|
||||
add_headers_recursively(file, &mut *added_paths);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
trait BuilderExt {
|
||||
trait BuilderExt {
|
||||
fn get_initial_builder() -> Builder;
|
||||
fn include<T: Into<String>>(self, file: T) -> Builder;
|
||||
}
|
||||
}
|
||||
|
||||
impl BuilderExt for Builder {
|
||||
impl BuilderExt for Builder {
|
||||
fn get_initial_builder() -> Builder {
|
||||
use bindgen::RustTarget;
|
||||
|
||||
|
@ -177,14 +168,14 @@ mod bindings {
|
|||
fn include<T: Into<String>>(self, file: T) -> Builder {
|
||||
self.clang_arg("-include").clang_arg(file)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Fixup {
|
||||
struct Fixup {
|
||||
pat: String,
|
||||
rep: String,
|
||||
}
|
||||
}
|
||||
|
||||
fn write_binding_file(builder: Builder, file: &str, fixups: &[Fixup]) {
|
||||
fn write_binding_file(builder: Builder, file: &str, fixups: &[Fixup]) {
|
||||
let out_file = OUTDIR_PATH.join(file);
|
||||
if let Some(modified) = get_modified_time(&out_file) {
|
||||
// Don't generate the file if nothing it depends on was modified.
|
||||
|
@ -217,14 +208,14 @@ mod bindings {
|
|||
.unwrap()
|
||||
.write_all(&bytes)
|
||||
.expect("Unable to write output");
|
||||
}
|
||||
}
|
||||
|
||||
struct BuilderWithConfig<'a> {
|
||||
struct BuilderWithConfig<'a> {
|
||||
builder: Builder,
|
||||
config: &'a Table,
|
||||
used_keys: HashSet<&'static str>,
|
||||
}
|
||||
impl<'a> BuilderWithConfig<'a> {
|
||||
}
|
||||
impl<'a> BuilderWithConfig<'a> {
|
||||
fn new(builder: Builder, config: &'a Table) -> Self {
|
||||
BuilderWithConfig {
|
||||
builder,
|
||||
|
@ -289,14 +280,12 @@ mod bindings {
|
|||
}
|
||||
self.builder
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_structs() {
|
||||
fn generate_structs() {
|
||||
let builder = Builder::get_initial_builder()
|
||||
.enable_cxx_namespaces()
|
||||
.with_codegen_config(
|
||||
CodegenConfig::TYPES | CodegenConfig::VARS | CodegenConfig::FUNCTIONS,
|
||||
);
|
||||
.with_codegen_config(CodegenConfig::TYPES | CodegenConfig::VARS | CodegenConfig::FUNCTIONS);
|
||||
let mut fixups = vec![];
|
||||
let builder = BuilderWithConfig::new(builder, CONFIG["structs"].as_table().unwrap())
|
||||
.handle_common(&mut fixups)
|
||||
|
@ -336,9 +325,9 @@ mod bindings {
|
|||
})
|
||||
.get_builder();
|
||||
write_binding_file(builder, STRUCTS_FILE, &fixups);
|
||||
}
|
||||
}
|
||||
|
||||
fn setup_logging() -> bool {
|
||||
fn setup_logging() -> bool {
|
||||
struct BuildLogger {
|
||||
file: Option<Mutex<fs::File>>,
|
||||
filter: String,
|
||||
|
@ -387,9 +376,9 @@ mod bindings {
|
|||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_atoms() {
|
||||
fn generate_atoms() {
|
||||
let script = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap())
|
||||
.join("gecko")
|
||||
.join("regen_atoms.py");
|
||||
|
@ -403,9 +392,11 @@ mod bindings {
|
|||
if !status.success() {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate() {
|
||||
pub fn generate() {
|
||||
println!("cargo:rerun-if-changed=build_gecko.rs");
|
||||
fs::create_dir_all(&*OUTDIR_PATH).unwrap();
|
||||
setup_logging();
|
||||
generate_structs();
|
||||
generate_atoms();
|
||||
|
@ -413,47 +404,4 @@ mod bindings {
|
|||
for path in ADDED_PATHS.lock().unwrap().iter() {
|
||||
println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "bindgen"))]
|
||||
mod bindings {
|
||||
use super::common::*;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::{env, fs, io};
|
||||
|
||||
/// Copy contents of one directory into another.
|
||||
/// It currently only does a shallow copy.
|
||||
fn copy_dir<P, Q, F>(from: P, to: Q, callback: F) -> io::Result<()>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
Q: AsRef<Path>,
|
||||
F: Fn(&Path),
|
||||
{
|
||||
let to = to.as_ref();
|
||||
for entry in from.as_ref().read_dir()? {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
callback(&path);
|
||||
fs::copy(&path, to.join(entry.file_name()))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn generate() {
|
||||
let dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()).join("gecko/generated");
|
||||
println!("cargo:rerun-if-changed={}", dir.display());
|
||||
copy_dir(&dir, &*OUTDIR_PATH, |path| {
|
||||
println!("cargo:rerun-if-changed={}", path.display());
|
||||
})
|
||||
.expect("Fail to copy generated files to out dir");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate() {
|
||||
use self::common::*;
|
||||
use std::fs;
|
||||
println!("cargo:rerun-if-changed=build_gecko.rs");
|
||||
fs::create_dir_all(&*OUTDIR_PATH).unwrap();
|
||||
bindings::generate();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue