@@ -43,6 +43,7 @@ struct BuildsDescription {
4343 builds : Vec < BuildDescription > ,
4444}
4545
46+ /// Build multiple versions of the same binary, each with a different CPU features set, merged into a single portable optimized binary
4647pub struct Multivers {
4748 metadata : Metadata ,
4849 target : String ,
@@ -68,7 +69,7 @@ impl Multivers {
6869 // See https://github.com/rust-lang/cargo/issues/4423
6970 let target = args. target ( ) ?;
7071
71- let cpus = Cpus :: builder ( & target)
72+ let cpus = Cpus :: builder ( & target, args . cpus )
7273 . context ( "Failed to get the set of CPU features for the target" ) ?
7374 . exclude_features ( args. exclude_cpu_features . as_deref ( ) )
7475 . build ( ) ;
@@ -101,19 +102,17 @@ impl Multivers {
101102 } )
102103 }
103104
104- fn build_package ( & self , package : & Package ) -> anyhow:: Result < BuildsDescription > {
105- let triple = Triple :: from_str ( & self . target ) . context ( "Failed to parse the target" ) ?;
106- let manifest_path = package. manifest_path . as_std_path ( ) . to_path_buf ( ) ;
107- let features_list = self . features . features . join ( " " ) ;
108- let mut rust_flags = std:: env:: var ( "RUST_FLAGS" ) . unwrap_or_default ( ) ;
109-
110- let metadata = MultiversMetadata :: from_package ( package)
111- . context ( "Failed to parse package's metadata" ) ?;
112- let cpu_features: Vec < CpuFeatures > = if let Some ( metadata) = metadata {
113- if let Some ( target_metadata) = metadata. targets . get ( & triple. architecture ) {
114- target_metadata
115- . cpus
116- . iter ( )
105+ fn cpu_features (
106+ & self ,
107+ triple : & Triple ,
108+ metadata : Option < & MultiversMetadata > ,
109+ ) -> Vec < CpuFeatures > {
110+ if let Some ( metadata) = metadata {
111+ if let Some ( cpus) = metadata
112+ . get ( & triple. architecture )
113+ . and_then ( |t| t. cpus . as_ref ( ) )
114+ {
115+ cpus. iter ( )
117116 . filter_map ( |cpu| self . cpus . get ( cpu) )
118117 . unique ( )
119118 . cloned ( )
@@ -123,7 +122,19 @@ impl Multivers {
123122 }
124123 } else {
125124 self . cpus . features_sets ( ) . cloned ( ) . collect ( )
126- } ;
125+ }
126+ }
127+
128+ fn build_package ( & self , package : & Package ) -> anyhow:: Result < BuildsDescription > {
129+ let triple: Triple =
130+ Triple :: from_str ( & self . target ) . context ( "Failed to parse the target" ) ?;
131+ let manifest_path = package. manifest_path . as_std_path ( ) . to_path_buf ( ) ;
132+ let features_list = self . features . features . join ( " " ) ;
133+ let mut rust_flags = std:: env:: var ( "RUST_FLAGS" ) . unwrap_or_default ( ) ;
134+
135+ let metadata = MultiversMetadata :: from_package ( package)
136+ . context ( "Failed to parse package's metadata" ) ?;
137+ let cpu_features = self . cpu_features ( & triple, metadata. as_ref ( ) ) ;
127138
128139 self . progress . set_length ( cpu_features. len ( ) as u64 ) ;
129140 self . progress . set_prefix ( "Building" ) ;
0 commit comments