@@ -5,15 +5,15 @@ use std::collections::HashSet;
55use std:: path:: Path ;
66
77use super :: locale:: shipped_locale;
8- use super :: { io, Event , InstallError , Options } ;
8+ use super :: { io, Cpu , Event , InstallError , Options } ;
99use crate :: net:: Http ;
1010use crate :: product:: ProductCode ;
1111use crate :: tact:: archive:: FileIndex ;
1212use crate :: tact:: cdn:: Client ;
1313use crate :: tact:: config:: { BuildConfig , CdnConfig , KeyPair } ;
1414use crate :: tact:: encoding:: Encoding ;
1515use crate :: tact:: indices:: { IndexCache , Locations } ;
16- use crate :: tact:: manifest:: { DownloadEntry , DownloadManifest , InstallManifest , TagSet } ;
16+ use crate :: tact:: manifest:: { DownloadEntry , DownloadManifest , InstallManifest , Tag , TagSet } ;
1717use crate :: tact:: plan:: { reverse_encoding, Options as PlanOptions , Plan } ;
1818use crate :: tact:: storage:: { EKey , Storage } ;
1919use crate :: tact:: version;
@@ -147,6 +147,7 @@ pub async fn offerings(
147147 let ekey = pair. ekey . ok_or ( InstallError :: MissingManifest ( "download" ) ) ?;
148148 let manifest =
149149 DownloadManifest :: parse ( & client. fetch_loose ( http, & ekey, & pair. ckey ) . await ?) ?;
150+ require_cpu ( options. cpu , code, manifest. tags ( ) ) ?;
150151
151152 let locale = shipped_locale ( & options. locale , manifest. tags ( ) ) ;
152153 let base_tags = TagSet :: parse ( & options. tag_column_for ( & locale) ) ;
@@ -192,7 +193,14 @@ pub async fn prepare(
192193 . inspect_err ( |e| tracing:: warn!( "product config {}: {e}" , remote. product_config) )
193194 . ok ( ) ,
194195 } ;
195- let executable = product. as_ref ( ) . and_then ( |p| p. executable . clone ( ) ) ;
196+ let executable = product. as_ref ( ) . and_then ( |p| match options. cpu {
197+ Cpu :: X86_64 => p. executable . clone ( ) ,
198+ Cpu :: Arm64 => p. executable_arm64 . clone ( ) ,
199+ } ) ;
200+ // The fallback name is the x86 binary, which an ARM install leaves out.
201+ if options. cpu == Cpu :: Arm64 && executable. is_none ( ) {
202+ return Err ( no_client ( options. cpu , code) ) ;
203+ }
196204 let flavor = match ( options. flavor . is_empty ( ) , product. and_then ( |p| p. install_dir ) ) {
197205 ( false , _) => options. flavor . clone ( ) ,
198206 ( true , Some ( dir) ) => dir,
@@ -239,6 +247,7 @@ pub async fn prepare(
239247 let download_manifest =
240248 DownloadManifest :: parse ( & fetch_manifest ( build. download , "download" ) . await ?) ?;
241249 let install = InstallManifest :: parse ( & fetch_manifest ( build. install , "install" ) . await ?) ?;
250+ require_cpu ( options. cpu , code, download_manifest. tags ( ) ) ?;
242251 let locale = shipped_locale ( & options. locale , download_manifest. tags ( ) ) ;
243252 let tag_column = options. tag_column_for ( & locale) ;
244253 let tags = TagSet :: parse ( & tag_column) . with_optional ( options. optional_tags . clone ( ) ) ;
@@ -355,3 +364,39 @@ pub async fn prepare(
355364 executable,
356365 } )
357366}
367+
368+ /// An ARM build has to be on offer: without its tag the selection drops
369+ /// every architecture's binaries and the install could never start. x86_64
370+ /// is not checked, so a build that predates the tag still installs.
371+ fn require_cpu ( cpu : Cpu , code : & ProductCode , tags : & [ Tag ] ) -> Result < ( ) , InstallError > {
372+ match cpu == Cpu :: X86_64 || tags. iter ( ) . any ( |tag| tag. name == cpu. tag ( ) ) {
373+ true => Ok ( ( ) ) ,
374+ false => Err ( no_client ( cpu, code) ) ,
375+ }
376+ }
377+
378+ fn no_client ( cpu : Cpu , code : & ProductCode ) -> InstallError {
379+ InstallError :: NoClientFor { code : code. as_str ( ) . to_owned ( ) , cpu : cpu. tag ( ) }
380+ }
381+
382+ #[ cfg( test) ]
383+ mod cpu_tests {
384+ use super :: * ;
385+
386+ const ARCH : u16 = 2 ;
387+
388+ #[ test]
389+ fn an_arm_install_needs_a_build_that_offers_arm ( ) {
390+ let retail = ProductCode :: Retail ;
391+ let x86_only = [ Tag :: named ( "Windows" , 1 ) , Tag :: named ( "x86_64" , ARCH ) ] ;
392+ let both = [ Tag :: named ( "Windows" , 1 ) , Tag :: named ( "x86_64" , ARCH ) , Tag :: named ( "arm64" , ARCH ) ] ;
393+
394+ assert ! ( matches!( require_cpu( Cpu :: Arm64 , & retail, & x86_only) , Err ( InstallError :: NoClientFor { .. } ) ) ) ;
395+ assert ! ( require_cpu( Cpu :: Arm64 , & retail, & both) . is_ok( ) ) ;
396+ }
397+
398+ #[ test]
399+ fn an_x86_install_is_never_refused_for_a_missing_tag ( ) {
400+ assert ! ( require_cpu( Cpu :: X86_64 , & ProductCode :: Retail , & [ Tag :: named( "Windows" , 1 ) ] ) . is_ok( ) ) ;
401+ }
402+ }
0 commit comments