@@ -48,10 +48,10 @@ fn expose_app_version() {
4848
4949/// Ensure the sidecar binary exists for the current build target.
5050///
51- /// Binaries are committed to the repo under `src-tauri/binaries/` for all
52- /// platforms. The download is only a fallback: it runs when the binary is
53- /// missing or has zero size (e.g. git-lfs placeholder or corrupt file).
54- /// This means offline builds and CI caching work out of the box .
51+ /// Tries to download the latest binary from GitHub releases first. If the
52+ /// download fails (offline, network error, bad URL), falls back to the
53+ /// committed binary in `src-tauri/binaries/`. The committed binaries act
54+ /// as a safety net so builds never fail due to network issues .
5555fn download_sidecar ( ) {
5656 let target = std:: env:: var ( "TARGET" ) . expect ( "TARGET env var not set by Cargo" ) ;
5757 let manifest_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
@@ -70,51 +70,48 @@ fn download_sidecar() {
7070
7171 let output = binaries_dir. join ( sidecar_name) ;
7272
73- // Use the committed binary if it exists and has non-zero size
74- if output. exists ( ) {
75- let size = std:: fs:: metadata ( & output) . map ( |m| m. len ( ) ) . unwrap_or ( 0 ) ;
76- if size > 0 {
77- println ! ( "Sidecar binary already exists ({size} bytes): {}" , output. display( ) ) ;
78- return ;
79- }
80- println ! ( "Sidecar binary exists but is empty, re-downloading: {}" , output. display( ) ) ;
81- }
82-
83- // Fallback: download from GitHub releases
73+ // Try downloading from GitHub releases first (gets the latest for this version)
8474 let version = sidecar_version ( ) ;
8575 let url = format ! ( "https://github.com/{REPO}/releases/download/{version}/{asset}" ) ;
8676 println ! ( "Downloading display-dj {version} for {sidecar_name}..." ) ;
8777
88- let status = Command :: new ( "curl" )
89- . args ( [ "-fSL" , & url, "-o" ] )
78+ let downloaded = Command :: new ( "curl" )
79+ . args ( [ "-fSL" , "--connect-timeout" , "10" , & url, "-o" ] )
9080 . arg ( & output)
91- . status ( ) ;
81+ . status ( )
82+ . ok ( )
83+ . map ( |s| s. success ( ) )
84+ . unwrap_or ( false ) ;
9285
93- match status {
94- Ok ( s) if s. success ( ) => {
95- // Verify the download produced a non-empty file
96- let size = std:: fs:: metadata ( & output) . map ( |m| m. len ( ) ) . unwrap_or ( 0 ) ;
97- if size == 0 {
98- panic ! ( "Downloaded sidecar is empty (0 bytes): {url}" ) ;
99- }
86+ if downloaded {
87+ let size = std:: fs:: metadata ( & output) . map ( |m| m. len ( ) ) . unwrap_or ( 0 ) ;
88+ if size > 0 {
10089 println ! ( "Downloaded: {} ({size} bytes)" , output. display( ) ) ;
90+ // Make executable on Unix
91+ #[ cfg( unix) ]
92+ {
93+ use std:: os:: unix:: fs:: PermissionsExt ;
94+ let mut perms = std:: fs:: metadata ( & output)
95+ . expect ( "failed to read sidecar metadata" )
96+ . permissions ( ) ;
97+ perms. set_mode ( 0o755 ) ;
98+ std:: fs:: set_permissions ( & output, perms) . expect ( "failed to chmod sidecar" ) ;
99+ }
100+ return ;
101101 }
102- Ok ( _) => {
103- panic ! ( "curl failed to download {url} — check the version and network" ) ;
104- }
105- Err ( e) => {
106- panic ! ( "failed to run curl: {e} — is curl installed?" ) ;
107- }
102+ println ! ( "Download produced empty file, falling back to committed binary" ) ;
103+ } else {
104+ println ! ( "Download failed, falling back to committed binary" ) ;
108105 }
109106
110- // Make executable on Unix
111- #[ cfg( unix) ]
112- {
113- use std:: os:: unix:: fs:: PermissionsExt ;
114- let mut perms = std:: fs:: metadata ( & output)
115- . expect ( "failed to read sidecar metadata" )
116- . permissions ( ) ;
117- perms. set_mode ( 0o755 ) ;
118- std:: fs:: set_permissions ( & output, perms) . expect ( "failed to chmod sidecar" ) ;
107+ // Fallback: use the committed binary already in the repo
108+ if output. exists ( ) {
109+ let size = std:: fs:: metadata ( & output) . map ( |m| m. len ( ) ) . unwrap_or ( 0 ) ;
110+ if size > 0 {
111+ println ! ( "Using committed sidecar binary ({size} bytes): {}" , output. display( ) ) ;
112+ return ;
113+ }
119114 }
115+
116+ panic ! ( "No sidecar binary available for {sidecar_name} — download failed and no committed binary found" ) ;
120117}
0 commit comments