1
1
use std:: {
2
2
env,
3
3
fs:: File ,
4
- io,
4
+ io:: { self , BufWriter } ,
5
5
path:: { Path , PathBuf } ,
6
6
} ;
7
7
8
8
use flate2:: { write:: GzEncoder , Compression } ;
9
9
use xshell:: { cmd, Shell } ;
10
+ use zip:: { write:: FileOptions , DateTime , ZipWriter } ;
10
11
11
12
use crate :: { date_iso, flags, project_root} ;
12
13
@@ -89,6 +90,9 @@ fn dist_server(sh: &Shell, release: &str, target: &Target) -> anyhow::Result<()>
89
90
90
91
let dst = Path :: new ( "dist" ) . join ( & target. artifact_name ) ;
91
92
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
+ }
92
96
93
97
Ok ( ( ) )
94
98
}
@@ -101,6 +105,38 @@ fn gzip(src_path: &Path, dest_path: &Path) -> anyhow::Result<()> {
101
105
Ok ( ( ) )
102
106
}
103
107
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
+
104
140
struct Target {
105
141
name : String ,
106
142
server_path : PathBuf ,
0 commit comments