mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-12-25 08:39:15 -05:00
changes to enable LTO builds (#1664)
This commit is contained in:
parent
e67f11bf79
commit
a54af0413f
3 changed files with 28 additions and 18 deletions
42
build.rs
42
build.rs
|
@ -428,10 +428,10 @@ fn static_lib_path() -> PathBuf {
|
||||||
static_lib_dir().join(static_lib_name(""))
|
static_lib_dir().join(static_lib_name(""))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn static_checksum_path() -> PathBuf {
|
fn static_checksum_path(path: &Path) -> PathBuf {
|
||||||
let mut t = static_lib_path();
|
let mut path = path.to_path_buf();
|
||||||
t.set_extension("sum");
|
path.set_extension("sum");
|
||||||
t
|
path
|
||||||
}
|
}
|
||||||
|
|
||||||
fn static_lib_dir() -> PathBuf {
|
fn static_lib_dir() -> PathBuf {
|
||||||
|
@ -472,6 +472,12 @@ fn download_file(url: String, filename: PathBuf) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checksum (i.e: url) to avoid redownloads
|
||||||
|
match std::fs::read_to_string(static_checksum_path(&filename)) {
|
||||||
|
Ok(c) if c == static_lib_url() => return,
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
|
||||||
// If there is a `.cargo/.rusty_v8/<escaped URL>` file, use that instead
|
// If there is a `.cargo/.rusty_v8/<escaped URL>` file, use that instead
|
||||||
// of downloading.
|
// of downloading.
|
||||||
if let Ok(mut path) = home::cargo_home() {
|
if let Ok(mut path) = home::cargo_home() {
|
||||||
|
@ -528,12 +534,12 @@ fn download_file(url: String, filename: PathBuf) {
|
||||||
assert!(tmpfile.exists());
|
assert!(tmpfile.exists());
|
||||||
|
|
||||||
// Write checksum (i.e url) & move file
|
// Write checksum (i.e url) & move file
|
||||||
std::fs::write(static_checksum_path(), url).unwrap();
|
std::fs::write(static_checksum_path(&filename), url).unwrap();
|
||||||
copy_archive(&tmpfile.to_string_lossy(), &filename);
|
copy_archive(&tmpfile.to_string_lossy(), &filename);
|
||||||
std::fs::remove_file(&tmpfile).unwrap();
|
std::fs::remove_file(&tmpfile).unwrap();
|
||||||
|
|
||||||
assert!(filename.exists());
|
assert!(filename.exists());
|
||||||
assert!(static_checksum_path().exists());
|
assert!(static_checksum_path(&filename).exists());
|
||||||
assert!(!tmpfile.exists());
|
assert!(!tmpfile.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,11 +551,6 @@ 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());
|
||||||
|
|
||||||
// Checksum (i.e: url) to avoid redownloads
|
|
||||||
match std::fs::read_to_string(static_checksum_path()) {
|
|
||||||
Ok(c) if c == static_lib_url() => return,
|
|
||||||
_ => {}
|
|
||||||
};
|
|
||||||
download_file(url, static_lib_path());
|
download_file(url, static_lib_path());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,10 +622,10 @@ fn copy_archive(url: &str, filename: &Path) {
|
||||||
src.read_exact(&mut header).unwrap();
|
src.read_exact(&mut header).unwrap();
|
||||||
src.seek(io::SeekFrom::Start(0)).unwrap();
|
src.seek(io::SeekFrom::Start(0)).unwrap();
|
||||||
if header == [0x1f, 0x8b] {
|
if header == [0x1f, 0x8b] {
|
||||||
println!("Detected GZIP archive");
|
println!("Detected GZIP archive: {url}");
|
||||||
decompress_to_writer(&mut src, &mut dst).unwrap();
|
decompress_to_writer(&mut src, &mut dst).unwrap();
|
||||||
} else {
|
} else {
|
||||||
println!("Not a GZIP archive");
|
println!("Not a GZIP archive: {url}");
|
||||||
io::copy(&mut src, &mut dst).unwrap();
|
io::copy(&mut src, &mut dst).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -685,12 +686,19 @@ fn print_prebuilt_src_binding_path() {
|
||||||
println!("cargo:rustc-env=RUSTY_V8_SRC_BINDING_PATH={}", binding);
|
println!("cargo:rustc-env=RUSTY_V8_SRC_BINDING_PATH={}", binding);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let target = env::var("TARGET").unwrap();
|
let target = env::var("TARGET").unwrap();
|
||||||
let profile = prebuilt_profile();
|
let profile = prebuilt_profile();
|
||||||
let src_binding_path = get_dirs()
|
let name = format!("src_binding_{}_{}.rs", profile, target);
|
||||||
.root
|
|
||||||
.join("gen")
|
let src_binding_path = get_dirs().root.join("gen").join(name.clone());
|
||||||
.join(format!("src_binding_{}_{}.rs", profile, target));
|
|
||||||
|
if let Ok(base) = env::var("RUSTY_V8_MIRROR") {
|
||||||
|
let version = env::var("CARGO_PKG_VERSION").unwrap();
|
||||||
|
let url = format!("{}/v{}/{}", base, version, name);
|
||||||
|
download_file(url, src_binding_path.clone());
|
||||||
|
}
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"cargo:rustc-env=RUSTY_V8_SRC_BINDING_PATH={}",
|
"cargo:rustc-env=RUSTY_V8_SRC_BINDING_PATH={}",
|
||||||
src_binding_path.display()
|
src_binding_path.display()
|
||||||
|
|
0
gen/.gitkeep
Normal file
0
gen/.gitkeep
Normal file
|
@ -15,7 +15,7 @@ import time
|
||||||
import http.client
|
import http.client
|
||||||
from v8_deps import Var
|
from v8_deps import Var
|
||||||
from urllib.error import HTTPError, URLError
|
from urllib.error import HTTPError, URLError
|
||||||
from stat import ST_MODE, S_IXOTH, S_IXGRP, S_IXUSR
|
from stat import ST_MODE
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
@ -27,6 +27,8 @@ def get_platform():
|
||||||
machine = platform.machine().lower()
|
machine = platform.machine().lower()
|
||||||
if machine == 'x86_64':
|
if machine == 'x86_64':
|
||||||
machine = 'amd64'
|
machine = 'amd64'
|
||||||
|
elif machine == 'aarch64':
|
||||||
|
machine = 'arm64'
|
||||||
|
|
||||||
return f'{system}-{machine}'
|
return f'{system}-{machine}'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue