4
4
5
5
extern crate bindgen;
6
6
extern crate cc;
7
+ #[ cfg( windows) ]
7
8
extern crate ruzstd;
9
+ #[ cfg( windows) ]
8
10
extern crate tar;
9
11
extern crate walkdir;
10
12
11
- use ruzstd:: StreamingDecoder ;
12
13
use std:: env;
13
14
use std:: ffi:: { OsStr , OsString } ;
14
15
use std:: fs;
@@ -17,7 +18,6 @@ use std::io::Read;
17
18
use std:: path:: { Path , PathBuf } ;
18
19
use std:: process:: Command ;
19
20
use std:: str;
20
- use tar:: Archive ;
21
21
use walkdir:: WalkDir ;
22
22
23
23
const ENV_VARS : & ' static [ & ' static str ] = & [
@@ -100,6 +100,7 @@ fn find_make() -> OsString {
100
100
}
101
101
}
102
102
103
+ #[ cfg( windows) ]
103
104
fn install_mozmake ( mozbuild_dir : & Path ) {
104
105
let mozbuild_dir = Path :: new ( mozbuild_dir) ;
105
106
let mozmake_tar_zst_path = mozbuild_dir. join ( "mozmake.tar.zst" ) ;
@@ -115,13 +116,13 @@ fn install_mozmake(mozbuild_dir: &Path) {
115
116
let mozmake_tar_zst =
116
117
File :: open ( & mozmake_tar_zst_path) . expect ( "Failed to open mozmake.tar.zst" ) ;
117
118
let mut mozmake_compressed =
118
- StreamingDecoder :: new ( mozmake_tar_zst) . expect ( "Failed to decode mozmake.tar.zst" ) ;
119
+ ruzstd :: StreamingDecoder :: new ( mozmake_tar_zst) . expect ( "Failed to decode mozmake.tar.zst" ) ;
119
120
let mut mozmake_uncompressed = Vec :: new ( ) ;
120
121
121
122
mozmake_compressed
122
123
. read_to_end ( & mut mozmake_uncompressed)
123
124
. expect ( "Failed to decode mozmake.tar.zst" ) ;
124
- let mut archive = Archive :: new ( & * mozmake_uncompressed) ;
125
+ let mut archive = tar :: Archive :: new ( & * mozmake_uncompressed) ;
125
126
archive
126
127
. unpack ( mozbuild_dir. join ( "bin" ) )
127
128
. expect ( "Failed to unpack mozmake.tar" ) ;
@@ -193,22 +194,25 @@ fn build_jsapi(build_dir: &Path) {
193
194
PathBuf :: from ( & mozbuild_env)
194
195
}
195
196
} ) ;
197
+
198
+ #[ cfg( windows) ]
199
+ {
200
+ if let Some ( mozbuild_dir) = & mozbuild {
201
+ // Add mozmake to PATH
202
+ let path = env:: var_os ( "PATH" ) . unwrap ( ) ;
203
+ let mut paths = Vec :: new ( ) ;
204
+ paths. push ( mozbuild_dir. join ( "bin" ) . join ( "mozmake" ) . into ( ) ) ;
205
+ paths. extend ( env:: split_paths ( & path) ) ;
206
+ let new_path = env:: join_paths ( paths) . unwrap ( ) ;
207
+ env:: set_var ( "PATH" , & new_path) ;
208
+
209
+ // Install mozmake if not installed
210
+ if !mozbuild_dir. join ( "MOZMAKE_LOCK" ) . exists ( ) {
211
+ install_mozmake ( & mozbuild_dir) ;
212
+ }
196
213
197
- if let Some ( mozbuild_dir) = & mozbuild {
198
- // Add mozmake to PATH
199
- let path = env:: var_os ( "PATH" ) . unwrap ( ) ;
200
- let mut paths = Vec :: new ( ) ;
201
- paths. push ( mozbuild_dir. join ( "bin" ) . join ( "mozmake" ) . into ( ) ) ;
202
- paths. extend ( env:: split_paths ( & path) ) ;
203
- let new_path = env:: join_paths ( paths) . unwrap ( ) ;
204
- env:: set_var ( "PATH" , & new_path) ;
205
-
206
- // Install mozmake if not installed
207
- if !mozbuild_dir. join ( "MOZMAKE_LOCK" ) . exists ( ) {
208
- install_mozmake ( & mozbuild_dir) ;
214
+ make = OsString :: from ( "mozmake" ) ;
209
215
}
210
-
211
- make = OsString :: from ( "mozmake" ) ;
212
216
}
213
217
214
218
let mut cmd = Command :: new ( make) ;
@@ -238,36 +242,46 @@ fn build_jsapi(build_dir: &Path) {
238
242
. env ( "SRC_DIR" , & cargo_manifest_dir. join ( "mozjs" ) )
239
243
. env ( "NO_RUST_PANIC_HOOK" , "1" ) ;
240
244
241
- if let Some ( mozbuild_dir) = mozbuild {
242
- // Create script that runs mozmake
243
- let script_path = build_dir. join ( "mozbuild.sh" ) ;
244
- let script = cmd_to_string ( & cmd) ;
245
- fs:: write ( & script_path, script) . expect ( "Failed to write to mozbuild.sh" ) ;
246
-
247
- let start_shell = mozbuild_dir. join ( "start-shell.bat" ) ;
248
- let mut shell = Command :: new ( start_shell. as_os_str ( ) ) ;
249
- shell
250
- . arg ( "-here" )
251
- . arg ( "-use-full-path" )
252
- . arg ( script_path. display ( ) . to_string ( ) ) ;
253
-
254
- for ( key, value) in cmd. get_envs ( ) {
255
- if let Some ( value) = value {
256
- shell. env ( key, value) ;
245
+ #[ cfg( not( windows) ) ]
246
+ {
247
+ let result = cmd. status ( ) . expect ( "Failed to run `make`" ) ;
248
+ assert ! ( result. success( ) ) ;
249
+ }
250
+
251
+ #[ cfg( windows) ]
252
+ {
253
+ if let Some ( mozbuild_dir) = mozbuild {
254
+ // Create script that runs mozmake
255
+ let script_path = build_dir. join ( "mozbuild.sh" ) ;
256
+ let script = cmd_to_string ( & cmd) ;
257
+ fs:: write ( & script_path, script) . expect ( "Failed to write to mozbuild.sh" ) ;
258
+
259
+ let start_shell = mozbuild_dir. join ( "start-shell.bat" ) ;
260
+ let mut shell = Command :: new ( start_shell. as_os_str ( ) ) ;
261
+ shell
262
+ . arg ( "-here" )
263
+ . arg ( "-use-full-path" )
264
+ . arg ( script_path. display ( ) . to_string ( ) ) ;
265
+
266
+ for ( key, value) in cmd. get_envs ( ) {
267
+ if let Some ( value) = value {
268
+ shell. env ( key, value) ;
269
+ }
257
270
}
258
- }
259
271
260
- if let Some ( current_dir) = cmd. get_current_dir ( ) {
261
- shell. current_dir ( current_dir) ;
262
- }
272
+ if let Some ( current_dir) = cmd. get_current_dir ( ) {
273
+ shell. current_dir ( current_dir) ;
274
+ }
263
275
264
- let result = shell. status ( ) . expect ( "Failed to run `make`" ) ;
265
- assert ! ( result. success( ) ) ;
266
- } else {
267
- let result = cmd. status ( ) . expect ( "Failed to run `make`" ) ;
268
- assert ! ( result. success( ) ) ;
276
+ let result = shell. status ( ) . expect ( "Failed to run `make`" ) ;
277
+ assert ! ( result. success( ) ) ;
278
+ } else {
279
+ let result = cmd. status ( ) . expect ( "Failed to run `make`" ) ;
280
+ assert ! ( result. success( ) ) ;
281
+ }
269
282
}
270
283
284
+
271
285
println ! (
272
286
"cargo:rustc-link-search=native={}/js/src/build" ,
273
287
build_dir. display( )
0 commit comments