mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
WebIDL codegen: Replace cmake with a single Python script
When playing around with Cargo’s new timing visualization: https://internals.rust-lang.org/t/exploring-crate-graph-build-times-with-cargo-build-ztimings/10975/21 … I was surprised to see the `script` crate’s build script take 76 seconds. I did not expect WebIDL bindings generation to be *that* computationally intensive. It turns out almost all of this time is overhead. The build script uses CMake to generate bindings for each WebIDL file in parallel, but that causes a lot of work to be repeated 366 times: * Starting up a Python VM * Importing (parts of) the Python standard library * Importing ~16k lines of our Python code * Recompiling the latter to bytecode, since we used `python -B` to disable writing `.pyc` file * Deserializing with `cPickle` and recreating in memory the results of parsing all WebIDL files ---- This commit remove the use of CMake and cPickle for the `script` crate. Instead, all WebIDL bindings generation is done sequentially in a single Python process. This takes 2 to 3 seconds.
This commit is contained in:
parent
049527872e
commit
5c60023cb8
9 changed files with 177 additions and 457 deletions
|
@ -27,52 +27,28 @@ mod build_gecko {
|
|||
pub fn generate() {}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn find_python() -> String {
|
||||
if Command::new("python2.7.exe")
|
||||
.arg("--version")
|
||||
.output()
|
||||
.is_ok()
|
||||
{
|
||||
return "python2.7.exe".to_owned();
|
||||
}
|
||||
|
||||
if Command::new("python27.exe")
|
||||
.arg("--version")
|
||||
.output()
|
||||
.is_ok()
|
||||
{
|
||||
return "python27.exe".to_owned();
|
||||
}
|
||||
|
||||
if Command::new("python.exe").arg("--version").output().is_ok() {
|
||||
return "python.exe".to_owned();
|
||||
}
|
||||
|
||||
panic!(concat!(
|
||||
"Can't find python (tried python2.7.exe, python27.exe, and python.exe)! ",
|
||||
"Try fixing PATH or setting the PYTHON env var"
|
||||
));
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn find_python() -> String {
|
||||
if Command::new("python2.7")
|
||||
.arg("--version")
|
||||
.output()
|
||||
.unwrap()
|
||||
.status
|
||||
.success()
|
||||
{
|
||||
"python2.7"
|
||||
} else {
|
||||
"python"
|
||||
}
|
||||
.to_owned()
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref PYTHON: String = env::var("PYTHON").ok().unwrap_or_else(find_python);
|
||||
pub static ref PYTHON: String = env::var("PYTHON").ok().unwrap_or_else(|| {
|
||||
let candidates = if cfg!(windows) {
|
||||
["python2.7.exe", "python27.exe", "python.exe"]
|
||||
} else {
|
||||
["python2.7", "python2", "python"]
|
||||
};
|
||||
for &name in &candidates {
|
||||
if Command::new(name)
|
||||
.arg("--version")
|
||||
.output()
|
||||
.ok()
|
||||
.map_or(false, |out| out.status.success())
|
||||
{
|
||||
return name.to_owned();
|
||||
}
|
||||
}
|
||||
panic!(
|
||||
"Can't find python (tried {})! Try fixing PATH or setting the PYTHON env var",
|
||||
candidates.join(", ")
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
fn generate_properties(engine: &str) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue