diff --git a/build.rs b/build.rs index 4aead477..7836614b 100644 --- a/build.rs +++ b/build.rs @@ -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/` 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() diff --git a/gen/.gitkeep b/gen/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/tools/ninja_gn_binaries.py b/tools/ninja_gn_binaries.py index 029be98e..315d33a7 100755 --- a/tools/ninja_gn_binaries.py +++ b/tools/ninja_gn_binaries.py @@ -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}'