forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
40 lines (37 loc) · 1.26 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() {
process_python_libs("../vm/Lib/python_builtins/*");
process_python_libs("../vm/Lib/core_modules/*");
#[cfg(feature = "freeze-stdlib")]
if cfg!(windows) {
process_python_libs("../Lib/**/*");
} else {
process_python_libs("./Lib/**/*");
}
if cfg!(windows) {
if let Ok(real_path) = std::fs::read_to_string("Lib") {
let canonicalized_path = std::fs::canonicalize(real_path)
.expect("failed to resolve RUSTPYTHONPATH during build time");
println!(
"cargo:rustc-env=win_lib_path={}",
canonicalized_path.to_str().unwrap()
);
}
}
}
// remove *.pyc files and add *.py to watch list
fn process_python_libs(pattern: &str) {
let glob = glob::glob(pattern).unwrap_or_else(|e| panic!("failed to glob {pattern:?}: {e}"));
for entry in glob.flatten() {
if entry.is_dir() {
continue;
}
let display = entry.display();
if display.to_string().ends_with(".pyc") {
if std::fs::remove_file(&entry).is_err() {
println!("cargo:warning=failed to remove {display}")
}
continue;
}
println!("cargo:rerun-if-changed={display}");
}
}