mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
script: copy include! files from script_bindings to script's OUT_DIR (#36384)
copy generated `include!`d files from script_bindings's OUT_DIR, to script's OUT_DIR to allow Rust Analyzer to load them. This is done to bypass limitation of Rust Analyzer: https://github.com/rust-lang/rust-analyzer/issues/17040 Also build script will now be rerun only when there are actual changes to concrete bindings due to emitted `cargo::rerun-if-changed` (not for each change in script crate). Testing: It compiles so it works, I tested manually and RA now works as expected (although we need to from type alias to concrete union-types definitions) Fixes: https://servo.zulipchat.com/#narrow/channel/263398-general/topic/rust-analyzer.20failed.20to.20include.20codes.20in.20script_bindings --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
7fd004adce
commit
4d4f94936f
4 changed files with 53 additions and 15 deletions
|
@ -3,10 +3,54 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
fn main() {
|
||||
// copy include! files from script_bindings's OUT_DIR, to script's OUT_DIR
|
||||
// this is done to bypass limitation of Rust Analyzer: https://github.com/rust-lang/rust-analyzer/issues/17040
|
||||
let script_bindings_out_dir =
|
||||
PathBuf::from(env::var_os("DEP_SCRIPT_BINDINGS_CRATE_OUT_DIR").unwrap());
|
||||
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||
// copy concrete files
|
||||
[
|
||||
"InterfaceTypes.rs",
|
||||
"DomTypeHolder.rs",
|
||||
"InterfaceObjectMap.rs",
|
||||
"ConcreteInheritTypes.rs",
|
||||
"UnionTypes.rs",
|
||||
"InterfaceObjectMapPhf.rs",
|
||||
]
|
||||
.iter()
|
||||
.map(Path::new)
|
||||
.for_each(|file| {
|
||||
println!(
|
||||
"cargo::rerun-if-changed={}",
|
||||
script_bindings_out_dir.join(file).display()
|
||||
);
|
||||
std::fs::copy(
|
||||
script_bindings_out_dir.join(file),
|
||||
out_dir.join(file.file_name().unwrap()),
|
||||
)
|
||||
.unwrap();
|
||||
});
|
||||
// copy ConcreteBindings folder
|
||||
let _ = std::fs::create_dir(out_dir.join("ConcreteBindings"));
|
||||
let script_concrete_bindings_out_dir = script_bindings_out_dir.join("ConcreteBindings");
|
||||
println!(
|
||||
"cargo:rustc-env=BINDINGS_OUT_DIR={}",
|
||||
env::var("DEP_SCRIPT_BINDINGS_CRATE_OUT_DIR").unwrap(),
|
||||
"cargo::rerun-if-changed={}",
|
||||
script_concrete_bindings_out_dir.display()
|
||||
);
|
||||
std::fs::read_dir(script_concrete_bindings_out_dir)
|
||||
.unwrap()
|
||||
.filter_map(|res| res.map(|e| e.path()).ok())
|
||||
.filter(|path| path.is_file())
|
||||
.for_each(|file| {
|
||||
std::fs::copy(
|
||||
&file,
|
||||
out_dir
|
||||
.join("ConcreteBindings")
|
||||
.join(file.file_name().unwrap()),
|
||||
)
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -166,28 +166,22 @@ pub(crate) use script_bindings::{callback, iterable, num};
|
|||
#[allow(missing_docs, non_snake_case)]
|
||||
pub(crate) mod codegen {
|
||||
pub(crate) mod DomTypeHolder {
|
||||
include!(concat!(env!("BINDINGS_OUT_DIR"), "/DomTypeHolder.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/DomTypeHolder.rs"));
|
||||
}
|
||||
pub(crate) use script_bindings::codegen::GenericBindings;
|
||||
#[allow(dead_code)]
|
||||
pub(crate) mod Bindings {
|
||||
include!(concat!(
|
||||
env!("BINDINGS_OUT_DIR"),
|
||||
"/ConcreteBindings/mod.rs"
|
||||
));
|
||||
include!(concat!(env!("OUT_DIR"), "/ConcreteBindings/mod.rs"));
|
||||
}
|
||||
pub(crate) mod InterfaceObjectMap {
|
||||
include!(concat!(env!("BINDINGS_OUT_DIR"), "/InterfaceObjectMap.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/InterfaceObjectMap.rs"));
|
||||
}
|
||||
pub(crate) mod ConcreteInheritTypes {
|
||||
include!(concat!(
|
||||
env!("BINDINGS_OUT_DIR"),
|
||||
"/ConcreteInheritTypes.rs"
|
||||
));
|
||||
include!(concat!(env!("OUT_DIR"), "/ConcreteInheritTypes.rs"));
|
||||
}
|
||||
pub(crate) use script_bindings::codegen::{PrototypeList, RegisterBindings};
|
||||
#[allow(dead_code)]
|
||||
pub(crate) mod UnionTypes {
|
||||
include!(concat!(env!("BINDINGS_OUT_DIR"), "/UnionTypes.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/UnionTypes.rs"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -207,7 +207,7 @@ pub(crate) mod macros;
|
|||
|
||||
#[allow(unused_imports)]
|
||||
pub(crate) mod types {
|
||||
include!(concat!(env!("BINDINGS_OUT_DIR"), "/InterfaceTypes.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/InterfaceTypes.rs"));
|
||||
}
|
||||
|
||||
pub(crate) mod abortcontroller;
|
||||
|
|
|
@ -8522,7 +8522,7 @@ class GlobalGenRoots():
|
|||
]
|
||||
imports = CGList([CGGeneric(f"use {mod};") for mod in mods], "\n")
|
||||
|
||||
phf = CGGeneric("include!(concat!(env!(\"BINDINGS_OUT_DIR\"), \"/InterfaceObjectMapPhf.rs\"));")
|
||||
phf = CGGeneric("include!(concat!(env!(\"OUT_DIR\"), \"/InterfaceObjectMapPhf.rs\"));")
|
||||
|
||||
return CGList([
|
||||
CGGeneric(AUTOGENERATED_WARNING_COMMENT),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue