Skip to content

Commit 6566182

Browse files
authored
feat(bundler): add TAURI_BUNDLER_TOOLS_GITHUB_MIRRORto specify a GitHub mirror (#10866)
closes #7338
1 parent d8ccf9d commit 6566182

5 files changed

Lines changed: 30 additions & 2 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-bundler": patch:feat
3+
"tauri-cli": patch:feat
4+
---
5+
6+
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.

crates/tauri-bundler/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ sha1 = "0.10"
4242
sha2 = "0.10"
4343
zip = { version = "2.0", default-features = false, features = ["deflate"] }
4444
dunce = "1"
45+
url = "2"
4546

4647
[target."cfg(target_os = \"windows\")".dependencies]
4748
uuid = { version = "1", features = ["v4", "v5"] }

crates/tauri-bundler/src/bundle/windows/util.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use std::{
99
};
1010

1111
use sha2::Digest;
12+
use ureq::AgentBuilder;
13+
use url::Url;
1214
use zip::ZipArchive;
1315

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

72+
fn create_agent_and_url(url: &str) -> crate::Result<(ureq::Agent, String)> {
73+
match std::env::var("TAURI_BUNDLER_TOOLS_GITHUB_MIRROR") {
74+
Ok(cdn) if url.starts_with("https://github.com/") => {
75+
let mut parsed_cdn = Url::parse(&cdn)?;
76+
parsed_cdn.set_path(url);
77+
Ok((AgentBuilder::new().build(), parsed_cdn.into()))
78+
}
79+
_ => Ok((
80+
AgentBuilder::new().try_proxy_from_env(true).build(),
81+
url.to_owned(),
82+
)),
83+
}
84+
}
85+
7086
pub fn download(url: &str) -> crate::Result<Vec<u8>> {
7187
log::info!(action = "Downloading"; "{}", url);
7288

73-
let agent = ureq::AgentBuilder::new().try_proxy_from_env(true).build();
74-
let response = agent.get(url).call().map_err(Box::new)?;
89+
let (agent, final_url) = create_agent_and_url(url)?;
90+
91+
let response = agent.get(&final_url).call().map_err(Box::new)?;
7592
let mut bytes = Vec::new();
7693
response.into_reader().read_to_end(&mut bytes)?;
7794
Ok(bytes)

crates/tauri-bundler/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ pub enum Error {
5858
#[cfg(windows)]
5959
#[error("`{0}`")]
6060
Glob(#[from] glob::GlobError),
61+
/// Failed to parse the URL
62+
#[error("`{0}`")]
63+
UrlParse(#[from] url::ParseError),
6164
/// Failed to validate downloaded file hash.
6265
#[error("hash mismatch of downloaded file")]
6366
HashError,

crates/tauri-cli/ENVIRONMENT_VARIABLES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ These environment variables are inputs to the CLI which may have an equivalent C
1515
- `TAURI_CLI_NO_DEV_SERVER_WAIT` — Skip waiting for the frontend dev server to start before building the tauri application.
1616
- `TAURI_LINUX_AYATANA_APPINDICATOR` — Set this var to `true` or `1` to force usage of `libayatana-appindicator` for system tray on Linux.
1717
- `TAURI_BUNDLER_WIX_FIPS_COMPLIANT` — Specify the bundler's WiX `FipsCompliant` option.
18+
- `TAURI_BUNDLER_TOOLS_GITHUB_MIRROR` - Specify a GitHub mirror to download files and tools used by tauri bundler.
1819
- `TAURI_SKIP_SIDECAR_SIGNATURE_CHECK` - Skip signing sidecars.
1920
- `TAURI_SIGNING_PRIVATE_KEY` — Private key used to sign your app bundles, can be either a string or a path to the file.
2021
- `TAURI_SIGNING_PRIVATE_KEY_PASSWORD` — The signing private key password, see `TAURI_SIGNING_PRIVATE_KEY`.

0 commit comments

Comments
 (0)