feat: Allow to download CEF binaries with custom base url set in env variable

This commit is contained in:
max authored and max committed 2025-09-21 13:33:14 +02:00
1 parent 52ea55d2b4
commit e4e67efe24
6 files changed
+43 -23

No files matched your search

+16 -9
View File
@@ -126,7 +126,7 @@ where
location.as_ref().join("archive.json")
}
const URL: &str = "https://cef-builds.spotifycdn.com";
pub const DEFAULT_CDN_URL: &str = "https://cef-builds.spotifycdn.com";
#[derive(Clone, PartialEq, Eq, Deserialize, Serialize, ValueEnum)]
#[serde(rename_all = "lowercase")]
@@ -157,8 +157,8 @@ pub struct CefIndex {
}
impl CefIndex {
pub fn download() -> Result<Self> {
Ok(ureq::get(&format!("{URL}/index.json"))
pub fn download(url: &str) -> Result<Self> {
Ok(ureq::get(&format!("{url}/index.json"))
.call()?
.into_body()
.read_json()?)
@@ -224,7 +224,12 @@ pub struct CefVersion {
}
impl CefVersion {
pub fn download_archive<P>(&self, location: P, show_progress: bool) -> Result<PathBuf>
pub fn download_archive<P>(
&self,
url: &str,
location: P,
show_progress: bool,
) -> Result<PathBuf>
where
P: AsRef<Path>,
{
@@ -250,7 +255,7 @@ impl CefVersion {
fs::remove_file(&corrupted_file)?;
}
let cef_url = format!("{URL}/{file}");
let cef_url = format!("{url}/{file}");
if show_progress {
println!("Using archive url: {cef_url}");
}
@@ -308,6 +313,7 @@ impl CefVersion {
pub fn download_archive_with_retry<P>(
&self,
url: &str,
location: P,
show_progress: bool,
retry_delay: Duration,
@@ -316,7 +322,7 @@ impl CefVersion {
where
P: AsRef<Path>,
{
let mut result = self.download_archive(&location, show_progress);
let mut result = self.download_archive(&url, &location, show_progress);
let mut retry = 0;
while let Err(Error::Io(_)) = &result {
@@ -327,7 +333,7 @@ impl CefVersion {
retry += 1;
thread::sleep(retry_delay * retry);
result = self.download_archive(&location, show_progress);
result = self.download_archive(&url, &location, show_progress);
}
result
@@ -387,6 +393,7 @@ impl TryFrom<&Path> for CefFile {
}
pub fn download_target_archive<P>(
url: &str,
target: &str,
cef_version: &str,
location: P,
@@ -399,11 +406,11 @@ where
println!("Downloading CEF archive for {target}...");
}
let index = CefIndex::download()?;
let index = CefIndex::download(&url)?;
let platform = index.platform(target)?;
let version = platform.version(cef_version)?;
version.download_archive_with_retry(location, show_progress, Duration::from_secs(15), 3)
version.download_archive_with_retry(url, location, show_progress, Duration::from_secs(15), 3)
}
pub fn extract_target_archive<P, Q>(
+11 -4
View File
@@ -1,7 +1,7 @@
#![doc = include_str!("../README.md")]
use clap::Parser;
use download_cef::{CefFile, CefIndex, OsAndArch, DEFAULT_TARGET};
use download_cef::{CefFile, CefIndex, OsAndArch, DEFAULT_CDN_URL, DEFAULT_TARGET};
use std::{
fs,
path::{Path, PathBuf},
@@ -35,6 +35,8 @@ struct Args {
fn main() -> anyhow::Result<()> {
let args = Args::parse();
let output = PathBuf::from(args.output);
let url = std::env::var("CEF_DOWNLOAD_URL").unwrap_or(DEFAULT_CDN_URL.into());
let parent = PathBuf::from(
output
.parent()
@@ -84,12 +86,17 @@ fn main() -> anyhow::Result<()> {
}
None => {
let cef_version = args.version.as_str();
let index = CefIndex::download()?;
let index = CefIndex::download(url.as_str())?;
let platform = index.platform(target)?;
let version = platform.version(cef_version)?;
let archive =
version.download_archive_with_retry(&parent, true, Duration::from_secs(15), 3)?;
let archive = version.download_archive_with_retry(
url.as_str(),
&parent,
true,
Duration::from_secs(15),
3,
)?;
let extracted_dir =
download_cef::extract_target_archive(target, &archive, &parent, true)?;
+5 -2
View File
@@ -4,7 +4,9 @@
extern crate thiserror;
use clap::Parser;
use download_cef::{CefIndex, Channel, LINUX_TARGETS, MACOS_TARGETS, WINDOWS_TARGETS};
use download_cef::{
CefIndex, Channel, DEFAULT_CDN_URL, LINUX_TARGETS, MACOS_TARGETS, WINDOWS_TARGETS,
};
use git_cliff::args::*;
use regex::Regex;
use semver::{BuildMetadata, Version};
@@ -54,8 +56,9 @@ fn main() -> Result<()> {
let args = Args::parse();
let channel = args.channel;
let url = std::env::var("CEF_DOWNLOAD_URL").unwrap_or(DEFAULT_CDN_URL.into());
let index = CefIndex::download()?;
let index = CefIndex::download(url.as_str())?;
let latest_versions: Vec<_> = LINUX_TARGETS
.iter()
.chain(MACOS_TARGETS.iter())
+4 -3
View File
@@ -1,12 +1,13 @@
#[cfg(not(feature = "dox"))]
fn main() -> anyhow::Result<()> {
use download_cef::{CefIndex, OsAndArch};
use download_cef::{CefIndex, OsAndArch, DEFAULT_CDN_URL};
use std::{env, fs, path::PathBuf};
println!("cargo::rerun-if-changed=build.rs");
let target = env::var("TARGET")?;
let os_arch = OsAndArch::try_from(target.as_str())?;
let url = std::env::var("CEF_DOWNLOAD_URL").unwrap_or(DEFAULT_CDN_URL.into());
println!("cargo::rerun-if-env-changed=FLATPAK");
println!("cargo::rerun-if-env-changed=CEF_PATH");
@@ -28,11 +29,11 @@ fn main() -> anyhow::Result<()> {
if !fs::exists(&cef_dir)? {
let cef_version = download_cef::default_version(&env::var("CARGO_PKG_VERSION")?);
let index = CefIndex::download()?;
let index = CefIndex::download(url.as_str())?;
let platform = index.platform(&target)?;
let version = platform.version(&cef_version)?;
let archive = version.download_archive(&out_dir, false)?;
let archive = version.download_archive(url.as_str(), &out_dir, false)?;
let extracted_dir =
download_cef::extract_target_archive(&target, &archive, &out_dir, false)?;
if extracted_dir != cef_dir {
+3 -2
View File
@@ -4,7 +4,7 @@
extern crate thiserror;
use clap::Parser;
use download_cef::DEFAULT_TARGET;
use download_cef::{DEFAULT_CDN_URL, DEFAULT_TARGET};
use std::{fs, io::Read, path::Path, sync::OnceLock};
#[derive(Debug, Error)]
@@ -54,10 +54,11 @@ struct Args {
fn main() -> Result<()> {
let args = Args::parse();
let target = args.target.as_str();
let url = std::env::var("CEF_DOWNLOAD_URL").unwrap_or(DEFAULT_CDN_URL.into());
if args.bindgen {
if args.download {
let _ = upgrade::download(target, args.version.as_str());
let _ = upgrade::download(url.as_str(), target, args.version.as_str());
}
upgrade::sys_bindgen(target)?;
+4 -3
View File
@@ -18,11 +18,12 @@ const TARGETS: &[&str] = &[
"arm-unknown-linux-gnueabi",
];
pub fn download(target: &str, version: &str) -> PathBuf {
pub fn download(url: &str, target: &str, version: &str) -> PathBuf {
assert!(TARGETS.contains(&target), "unsupported target {target}");
let archive = download_cef::download_target_archive(target, version, dirs::get_out_dir(), true)
.expect("download failed");
let archive =
download_cef::download_target_archive(url, target, version, dirs::get_out_dir(), true)
.expect("download failed");
download_cef::extract_target_archive(target, &archive, dirs::get_out_dir(), true)
.expect("extraction failed")