Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bundler): add TAURI_BUNDLER_TOOLS_GITHUB_MIRRORto specify a GitHub mirror #10866

Merged
merged 16 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/bundler-github-cdn-from-env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-bundler": patch:feat
"tauri-cli": patch:feat
---

Use the environment variable `TAURI_BUNDLER_TOOLS_DOWNLOAD_GITHUB_CDN` to specify a GitHub CDN for faster downloads of necessary files. This is designed for areas like Mainland China where GitHub access can be unreliable.
thep0y marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions crates/tauri-bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ uuid = { version = "1", features = ["v4", "v5"] }
bitness = "0.4"
windows-registry = "0.2.0"
glob = "0.3"
url = "2"

[target."cfg(target_os = \"windows\")".dependencies.windows-sys]
version = "0.59"
Expand Down
21 changes: 19 additions & 2 deletions crates/tauri-bundler/src/bundle/windows/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use std::{
};

use sha2::Digest;
use ureq::AgentBuilder;
use url::Url;
use zip::ZipArchive;

pub const WEBVIEW2_BOOTSTRAPPER_URL: &str = "https://go.microsoft.com/fwlink/p/?LinkId=2124703";
Expand Down Expand Up @@ -67,11 +69,26 @@ pub fn download_webview2_offline_installer(base_path: &Path, arch: &str) -> crat
Ok(file_path)
}

fn create_agent_and_url(url: &str) -> crate::Result<(ureq::Agent, String)> {
match std::env::var("TAURI_BUNDLER_TOOLS_DOWNLOAD_GITHUB_CDN") {
thep0y marked this conversation as resolved.
Show resolved Hide resolved
Ok(cdn) if url.starts_with("https://github.com/") => {
let mut parsed_cdn = Url::parse(&cdn)?;
parsed_cdn.set_path(url);
Ok((AgentBuilder::new().build(), parsed_cdn.into()))
}
_ => Ok((
AgentBuilder::new().try_proxy_from_env(true).build(),
url.to_owned(),
)),
}
}

pub fn download(url: &str) -> crate::Result<Vec<u8>> {
log::info!(action = "Downloading"; "{}", url);

let agent = ureq::AgentBuilder::new().try_proxy_from_env(true).build();
let response = agent.get(url).call().map_err(Box::new)?;
let (agent, final_url) = create_agent_and_url(url)?;

let response = agent.get(&final_url).call().map_err(Box::new)?;
let mut bytes = Vec::new();
response.into_reader().read_to_end(&mut bytes)?;
Ok(bytes)
Expand Down
4 changes: 4 additions & 0 deletions crates/tauri-bundler/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ pub enum Error {
#[cfg(windows)]
#[error("`{0}`")]
Glob(#[from] glob::GlobError),
/// Failed to parse the github cdn
thep0y marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(windows)]
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
#[error("`{0}`")]
UrlParse(#[from] url::ParseError),
/// Failed to validate downloaded file hash.
#[error("hash mismatch of downloaded file")]
HashError,
Expand Down
1 change: 1 addition & 0 deletions crates/tauri-cli/ENVIRONMENT_VARIABLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ These environment variables are inputs to the CLI which may have an equivalent C
- `TAURI_CLI_NO_DEV_SERVER_WAIT` — Skip waiting for the frontend dev server to start before building the tauri application.
- `TAURI_LINUX_AYATANA_APPINDICATOR` — Set this var to `true` or `1` to force usage of `libayatana-appindicator` for system tray on Linux.
- `TAURI_BUNDLER_WIX_FIPS_COMPLIANT` — Specify the bundler's WiX `FipsCompliant` option.
- `TAURI_BUNDLER_TOOLS_DOWNLOAD_GITHUB_CDN ` - Specify a GitHub CDN to speed up the download of necessary files.
thep0y marked this conversation as resolved.
Show resolved Hide resolved
- `TAURI_SKIP_SIDECAR_SIGNATURE_CHECK` - Skip signing sidecars.
- `TAURI_SIGNING_PRIVATE_KEY` — Private key used to sign your app bundles, can be either a string or a path to the file.
- `TAURI_SIGNING_PRIVATE_KEY_PASSWORD` — The signing private key password, see `TAURI_SIGNING_PRIVATE_KEY`.
Expand Down