11use std:: {
22 env,
33 fs:: File ,
4- io,
4+ io:: { self , BufWriter } ,
55 path:: { Path , PathBuf } ,
66} ;
77
88use flate2:: { write:: GzEncoder , Compression } ;
99use xshell:: { cmd, Shell } ;
10+ use zip:: { write:: FileOptions , DateTime , ZipWriter } ;
1011
1112use crate :: { date_iso, flags, project_root} ;
1213
@@ -89,6 +90,9 @@ fn dist_server(sh: &Shell, release: &str, target: &Target) -> anyhow::Result<()>
8990
9091 let dst = Path :: new ( "dist" ) . join ( & target. artifact_name ) ;
9192 gzip ( & target. server_path , & dst. with_extension ( "gz" ) ) ?;
93+ if target_name. contains ( "-windows-" ) {
94+ zip ( & target. server_path , target. symbols_path . as_ref ( ) , & dst. with_extension ( "zip" ) ) ?;
95+ }
9296
9397 Ok ( ( ) )
9498}
@@ -101,6 +105,38 @@ fn gzip(src_path: &Path, dest_path: &Path) -> anyhow::Result<()> {
101105 Ok ( ( ) )
102106}
103107
108+ fn zip ( src_path : & Path , symbols_path : Option < & PathBuf > , dest_path : & Path ) -> anyhow:: Result < ( ) > {
109+ let file = File :: create ( dest_path) ?;
110+ let mut writer = ZipWriter :: new ( BufWriter :: new ( file) ) ;
111+ writer. start_file (
112+ src_path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ,
113+ FileOptions :: default ( )
114+ . last_modified_time (
115+ DateTime :: from_time ( std:: fs:: metadata ( src_path) ?. modified ( ) ?. into ( ) ) . unwrap ( ) ,
116+ )
117+ . unix_permissions ( 0o755 )
118+ . compression_method ( zip:: CompressionMethod :: Deflated )
119+ . compression_level ( Some ( 9 ) ) ,
120+ ) ?;
121+ let mut input = io:: BufReader :: new ( File :: open ( src_path) ?) ;
122+ io:: copy ( & mut input, & mut writer) ?;
123+ if let Some ( symbols_path) = symbols_path {
124+ writer. start_file (
125+ symbols_path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ,
126+ FileOptions :: default ( )
127+ . last_modified_time (
128+ DateTime :: from_time ( std:: fs:: metadata ( src_path) ?. modified ( ) ?. into ( ) ) . unwrap ( ) ,
129+ )
130+ . compression_method ( zip:: CompressionMethod :: Deflated )
131+ . compression_level ( Some ( 9 ) ) ,
132+ ) ?;
133+ let mut input = io:: BufReader :: new ( File :: open ( symbols_path) ?) ;
134+ io:: copy ( & mut input, & mut writer) ?;
135+ }
136+ writer. finish ( ) ?;
137+ Ok ( ( ) )
138+ }
139+
104140struct Target {
105141 name : String ,
106142 server_path : PathBuf ,
0 commit comments