mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-02-01 12:15:46 -05:00
parent
9b2d8c68ad
commit
64ce32392a
1 changed files with 64 additions and 32 deletions
66
build.rs
66
build.rs
|
@ -53,10 +53,23 @@ fn main() {
|
||||||
.map(|s| s.starts_with("rls"))
|
.map(|s| s.starts_with("rls"))
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
|
||||||
if !(is_trybuild || is_cargo_doc | is_rls) {
|
// Early exit
|
||||||
|
if is_cargo_doc || is_rls {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_link_flags();
|
||||||
|
|
||||||
|
// Don't attempt rebuild but link
|
||||||
|
if is_trybuild {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build from source
|
||||||
if env::var_os("V8_FROM_SOURCE").is_some() {
|
if env::var_os("V8_FROM_SOURCE").is_some() {
|
||||||
build_v8()
|
return build_v8();
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// utilize a lockfile to prevent linking of
|
// utilize a lockfile to prevent linking of
|
||||||
// only partially downloaded static library.
|
// only partially downloaded static library.
|
||||||
let root = env::current_dir().unwrap();
|
let root = env::current_dir().unwrap();
|
||||||
|
@ -74,12 +87,6 @@ fn main() {
|
||||||
lockfile.lock().expect("Couldn't get lock");
|
lockfile.lock().expect("Couldn't get lock");
|
||||||
download_static_lib_binaries();
|
download_static_lib_binaries();
|
||||||
lockfile.unlock().expect("Couldn't unlock lockfile");
|
lockfile.unlock().expect("Couldn't unlock lockfile");
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !(is_cargo_doc || is_rls) {
|
|
||||||
print_link_flags()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_v8() {
|
fn build_v8() {
|
||||||
|
@ -320,6 +327,12 @@ fn static_lib_path() -> PathBuf {
|
||||||
static_lib_dir().join(static_lib_name())
|
static_lib_dir().join(static_lib_name())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn static_checksum_path() -> PathBuf {
|
||||||
|
let mut t = static_lib_path();
|
||||||
|
t.set_extension("sum");
|
||||||
|
t
|
||||||
|
}
|
||||||
|
|
||||||
fn static_lib_dir() -> PathBuf {
|
fn static_lib_dir() -> PathBuf {
|
||||||
build_dir().join("gn_out").join("obj")
|
build_dir().join("gn_out").join("obj")
|
||||||
}
|
}
|
||||||
|
@ -351,6 +364,17 @@ fn download_file(url: String, filename: PathBuf) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tmp file to download to so we don't clobber the existing one
|
||||||
|
let tmpfile = {
|
||||||
|
let mut t = filename.clone();
|
||||||
|
t.set_extension("tmp");
|
||||||
|
t
|
||||||
|
};
|
||||||
|
if tmpfile.exists() {
|
||||||
|
println!("Deleting old tmpfile {}", tmpfile.display());
|
||||||
|
std::fs::remove_file(&tmpfile).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
// Try downloading with python first. Python is a V8 build dependency,
|
// Try downloading with python first. Python is a V8 build dependency,
|
||||||
// so this saves us from adding a Rust HTTP client dependency.
|
// so this saves us from adding a Rust HTTP client dependency.
|
||||||
println!("Downloading {}", url);
|
println!("Downloading {}", url);
|
||||||
|
@ -359,7 +383,7 @@ fn download_file(url: String, filename: PathBuf) {
|
||||||
.arg("--url")
|
.arg("--url")
|
||||||
.arg(&url)
|
.arg(&url)
|
||||||
.arg("--filename")
|
.arg("--filename")
|
||||||
.arg(&filename)
|
.arg(&tmpfile)
|
||||||
.status();
|
.status();
|
||||||
|
|
||||||
// Python is only a required dependency for `V8_FROM_SOURCE` builds.
|
// Python is only a required dependency for `V8_FROM_SOURCE` builds.
|
||||||
|
@ -372,15 +396,23 @@ fn download_file(url: String, filename: PathBuf) {
|
||||||
.arg("-L")
|
.arg("-L")
|
||||||
.arg("-s")
|
.arg("-s")
|
||||||
.arg("-o")
|
.arg("-o")
|
||||||
.arg(&filename)
|
.arg(&tmpfile)
|
||||||
.arg(&url)
|
.arg(&url)
|
||||||
.status()
|
.status()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Assert DL was successful
|
||||||
assert!(status.success());
|
assert!(status.success());
|
||||||
|
assert!(tmpfile.exists());
|
||||||
|
|
||||||
|
// Write checksum (i.e url) & move file
|
||||||
|
std::fs::write(static_checksum_path(), url).unwrap();
|
||||||
|
std::fs::rename(&tmpfile, &filename).unwrap();
|
||||||
assert!(filename.exists());
|
assert!(filename.exists());
|
||||||
|
assert!(static_checksum_path().exists());
|
||||||
|
assert!(!tmpfile.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn download_static_lib_binaries() {
|
fn download_static_lib_binaries() {
|
||||||
|
@ -391,12 +423,12 @@ fn download_static_lib_binaries() {
|
||||||
std::fs::create_dir_all(&dir).unwrap();
|
std::fs::create_dir_all(&dir).unwrap();
|
||||||
println!("cargo:rustc-link-search={}", dir.display());
|
println!("cargo:rustc-link-search={}", dir.display());
|
||||||
|
|
||||||
let filename = static_lib_path();
|
// Checksum (i.e: url) to avoid redownloads
|
||||||
if filename.exists() {
|
match std::fs::read_to_string(static_checksum_path()) {
|
||||||
println!("Deleting old static lib {}", filename.display());
|
Ok(c) if c == static_lib_url() => return,
|
||||||
std::fs::remove_file(&filename).unwrap();
|
_ => {}
|
||||||
}
|
};
|
||||||
download_file(url, filename);
|
download_file(url, static_lib_path());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_link_flags() {
|
fn print_link_flags() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue