Skip to content

Commit

Permalink
feat(bundler): add TAURI_BUNDLER_TOOLS_GITHUB_MIRRORto specify a Gi…
Browse files Browse the repository at this point in the history
…tHub mirror (#10866)


closes #7338
  • Loading branch information
thep0y authored Sep 11, 2024
1 parent d8ccf9d commit 6566182
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changes/bundler-github-mirror-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
---

Add `TAURI_BUNDLER_TOOLS_GITHUB_MIRROR` environment variable to specify a GitHub mirror to download files and tools used by tauri bundler. This is designed for areas like Mainland China where GitHub access can be unreliable.
1 change: 1 addition & 0 deletions crates/tauri-bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ sha1 = "0.10"
sha2 = "0.10"
zip = { version = "2.0", default-features = false, features = ["deflate"] }
dunce = "1"
url = "2"

[target."cfg(target_os = \"windows\")".dependencies]
uuid = { version = "1", features = ["v4", "v5"] }
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_GITHUB_MIRROR") {
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
3 changes: 3 additions & 0 deletions crates/tauri-bundler/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ pub enum Error {
#[cfg(windows)]
#[error("`{0}`")]
Glob(#[from] glob::GlobError),
/// Failed to parse the URL
#[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_GITHUB_MIRROR` - Specify a GitHub mirror to download files and tools used by tauri bundler.
- `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

0 comments on commit 6566182

Please sign in to comment.