0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-25 00:29:14 -05:00

changes to enable LTO builds (#1664)

This commit is contained in:
snek 2024-12-05 15:11:12 +01:00 committed by GitHub
parent e67f11bf79
commit a54af0413f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 18 deletions

View file

@ -428,10 +428,10 @@ fn static_lib_path() -> PathBuf {
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_checksum_path(path: &Path) -> PathBuf {
let mut path = path.to_path_buf();
path.set_extension("sum");
path
}
fn static_lib_dir() -> PathBuf {
@ -472,6 +472,12 @@ fn download_file(url: String, filename: PathBuf) {
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
// of downloading.
if let Ok(mut path) = home::cargo_home() {
@ -528,12 +534,12 @@ fn download_file(url: String, filename: PathBuf) {
assert!(tmpfile.exists());
// 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);
std::fs::remove_file(&tmpfile).unwrap();
assert!(filename.exists());
assert!(static_checksum_path().exists());
assert!(static_checksum_path(&filename).exists());
assert!(!tmpfile.exists());
}
@ -545,11 +551,6 @@ fn download_static_lib_binaries() {
std::fs::create_dir_all(&dir).unwrap();
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());
}
@ -621,10 +622,10 @@ fn copy_archive(url: &str, filename: &Path) {
src.read_exact(&mut header).unwrap();
src.seek(io::SeekFrom::Start(0)).unwrap();
if header == [0x1f, 0x8b] {
println!("Detected GZIP archive");
println!("Detected GZIP archive: {url}");
decompress_to_writer(&mut src, &mut dst).unwrap();
} else {
println!("Not a GZIP archive");
println!("Not a GZIP archive: {url}");
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);
return;
}
let target = env::var("TARGET").unwrap();
let profile = prebuilt_profile();
let src_binding_path = get_dirs()
.root
.join("gen")
.join(format!("src_binding_{}_{}.rs", profile, target));
let name = format!("src_binding_{}_{}.rs", profile, target);
let src_binding_path = get_dirs().root.join("gen").join(name.clone());
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!(
"cargo:rustc-env=RUSTY_V8_SRC_BINDING_PATH={}",
src_binding_path.display()

0
gen/.gitkeep Normal file
View file

View file

@ -15,7 +15,7 @@ import time
import http.client
from v8_deps import Var
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.parse import urlparse
@ -27,6 +27,8 @@ def get_platform():
machine = platform.machine().lower()
if machine == 'x86_64':
machine = 'amd64'
elif machine == 'aarch64':
machine = 'arm64'
return f'{system}-{machine}'