1- use std:: collections:: HashMap ;
21use std:: env;
32use std:: env:: consts;
4- use std:: ffi:: { OsStr , OsString } ;
3+ use std:: ffi:: OsString ;
54use std:: path:: { Path , PathBuf } ;
65use std:: process:: Command ;
76use which:: which;
@@ -18,16 +17,6 @@ macro_rules! system {
1817 . success( ) ) ;
1918 } ;
2019}
21- macro_rules! s {
22- ( $expr: expr) => {
23- $expr. to_string( )
24- } ;
25- }
26- macro_rules! q {
27- ( $expr: expr) => {
28- format!( "\" {}\" " , $expr)
29- } ;
30- }
3120
3221fn main ( ) {
3322 set_cargo_rerun ( ) ;
@@ -58,11 +47,7 @@ fn main() {
5847 return ;
5948 }
6049
61- build_v8 (
62- crate_dir,
63- out_dir,
64- gn_out_dir. as_os_str ( ) . try_into ( ) . unwrap ( ) ,
65- ) ;
50+ build_v8 ( crate_dir, out_dir, gn_out_dir) ;
6651}
6752
6853fn gn_os < ' a > ( os : & ' a str ) -> & ' a str {
@@ -84,7 +69,7 @@ fn gn_arch<'a>(arch: &'a str) -> &'a str {
8469 }
8570}
8671
87- fn build_v8 ( crate_dir : PathBuf , out_dir : PathBuf , gn_out_dir : & str ) {
72+ fn build_v8 ( crate_dir : PathBuf , out_dir : PathBuf , gn_out_dir : PathBuf ) {
8873 env:: set_var ( "DEPOT_TOOLS_WIN_TOOLCHAIN" , "0" ) ; // google uses internal visual studio by default
8974 env:: set_var ( "PYTHONDONTWRITEBYTECODE" , "1" ) ; // disable __pycache__
9075
@@ -95,52 +80,7 @@ fn build_v8(crate_dir: PathBuf, out_dir: PathBuf, gn_out_dir: &str) {
9580 let gn_target_os = gn_os ( & target_os) ;
9681 let gn_target_arch = gn_arch ( & target_arch) ;
9782
98- let mut gn_args = HashMap :: < & str , String > :: from ( [
99- ( "clang_use_chrome_plugins" , s ! ( false ) ) ,
100- ( "is_component_build" , s ! ( false ) ) ,
101- ( "linux_use_bundled_binutils" , s ! ( false ) ) ,
102- ( "use_dummy_lastchange" , s ! ( true ) ) ,
103- ( "use_sysroot" , s ! ( false ) ) ,
104- ( "win_crt_flavor_agnostic" , s ! ( true ) ) ,
105- // Minimize size of debuginfo in distributed static library.
106- ( "line_tables_only" , s ! ( true ) ) ,
107- ( "no_inline_line_tables" , s ! ( true ) ) ,
108- ( "symbol_level" , s ! ( 1 ) ) ,
109- ( "use_debug_fission" , s ! ( false ) ) ,
110- ( "v8_enable_sandbox" , s ! ( false ) ) ,
111- ( "v8_enable_snapshot_compression" , s ! ( false ) ) ,
112- ( "v8_enable_javascript_promise_hooks" , s ! ( true ) ) ,
113- ( "v8_promise_internal_field_count" , s ! ( 1 ) ) ,
114- ( "v8_use_external_startup_data" , s ! ( false ) ) ,
115- ( "v8_use_snapshot" , s ! ( true ) ) ,
116- // Disable handle zapping for performance
117- ( "v8_enable_handle_zapping" , s ! ( false ) ) ,
118- // Ensure allocation of typed arrays and arraybuffers always goes through
119- // the embedder's ArrayBufferAllocator, otherwise small buffers get moved
120- // around by the garbage collector but embedders normally want them to have
121- // fixed addresses.
122- ( "v8_typed_array_max_size_in_heap" , s ! ( 0 ) ) ,
123- // Enabling the shared read-only heap comes with a restriction that all
124- // isolates running at the same time must be created from the same snapshot.
125- // This is problematic for Deno, which has separate "runtime" and "typescript
126- // compiler" snapshots, and sometimes uses them both at the same time.
127- ( "v8_enable_shared_ro_heap" , s ! ( false ) ) ,
128- // V8 11.6 hardcoded an assumption in `mksnapshot` that shared RO heap
129- // is enabled. In our case it's disabled so without this flag we can't
130- // compile.
131- ( "v8_enable_verify_heap" , s ! ( false ) ) ,
132- // V8 introduced a bug in 11.1 that causes the External Pointer Table to never
133- // be cleaned which causes resource exhaustion. Disabling pointer compression
134- // makes sure that the EPT is not used.
135- // https://bugs.chromium.org/p/v8/issues/detail?id=13640&q=garbage%20collection&can=2
136- ( "v8_enable_pointer_compression" , s ! ( false ) ) ,
137- // Maglev *should* be supported when pointer compression is disabled as per
138- // https://chromium-review.googlesource.com/c/v8/v8/+/4753150, but it still
139- // fails to compile.
140- ( "v8_enable_maglev" , s ! ( false ) ) ,
141- ] ) ;
142-
143- let is_debug = if target_os == "windows" {
83+ let is_debug = if cfg ! ( target_os = "windows" ) {
14484 false
14585 } else {
14686 match env:: var ( "PROFILE" ) . unwrap ( ) . as_str ( ) {
@@ -149,90 +89,36 @@ fn build_v8(crate_dir: PathBuf, out_dir: PathBuf, gn_out_dir: &str) {
14989 }
15090 } ;
15191
152- #[ cfg( not( feature = "use_custom_libcxx" ) ) ]
153- gn_args. insert ( "use_custom_libcxx" , s ! ( false ) ) ;
154-
155- gn_args. insert ( "is_debug" , s ! ( is_debug) ) ;
156- gn_args. insert ( "target_cpu" , q ! ( gn_target_arch) ) ;
157- gn_args. insert ( "v8_target_cpu" , q ! ( gn_target_arch) ) ;
158-
159- if let Some ( cc_wrapper) = find_cc_wrapper ( ) {
160- gn_args. insert ( "cc_wrapper" , q ! ( cc_wrapper. to_string_lossy( ) ) ) ;
161- }
162-
163- if target_os != consts:: OS {
164- gn_args. insert ( "target_os" , q ! ( gn_target_os) ) ;
165- }
166-
167- let use_sysroot = target_arch != consts:: ARCH ;
168- gn_args. insert ( "use_sysroot" , s ! ( use_sysroot) ) ;
169-
170- if env:: var_os ( "DISABLE_CLANG" ) . is_some ( ) {
171- gn_args. insert ( "is_clang" , s ! ( false ) ) ;
172- gn_args. insert ( "line_tables_only" , s ! ( false ) ) ;
173- } else if let Ok ( clang_base_path) = env:: var ( "CLANG_BASE_PATH" ) {
174- gn_args. insert ( "clang_base_path" , q ! ( clang_base_path) ) ;
175- gn_args. insert ( "treat_warnings_as_errors" , s ! ( false ) ) ;
176- }
177-
178- let extra_gn_args = env:: var ( "GN_ARGS" ) . unwrap_or_default ( ) ;
179-
180- for pair in extra_gn_args
181- . split_whitespace ( )
182- . map ( |pair| pair. split_once ( "=" ) )
183- {
184- if let Some ( ( k, v) ) = pair {
185- gn_args. insert ( k, v. to_string ( ) ) ;
186- }
187- }
188-
189- let gn_args = gn_args
190- . iter ( )
191- . map ( |( key, value) | format ! ( "{key}={value}" ) )
192- . collect :: < Vec < String > > ( )
193- . join ( " " ) ;
194-
195- env:: set_var ( "GN_ARGS" , & gn_args) ;
196-
197- println ! ( "[*] crate_dir : {}" , crate_dir. display( ) ) ;
198- println ! ( "[*] out_dir : {}" , out_dir. display( ) ) ;
199- println ! ( "[*] gn_out_dir : {}" , gn_out_dir) ;
200- println ! ( "[*] gn_args : {}" , gn_args) ;
201-
202- env:: set_current_dir ( & out_dir) . unwrap ( ) ;
92+ let use_custom_libcxx = cfg ! ( feature = "use_custom_libcxx" ) ;
20393
20494 let python = find_python ( ) . expect ( "Can't find python" ) ;
20595 system ! (
20696 & python,
20797 [
208- crate_dir. join( "scripts/download_v8.py" ) . as_os_str( ) ,
209- crate_dir. as_os_str( ) ,
210- out_dir. as_os_str( ) ,
211- OsStr :: new( gn_host_os) ,
212- OsStr :: new( gn_host_arch) ,
213- OsStr :: new( gn_target_os) ,
214- OsStr :: new( gn_target_arch) ,
215- OsStr :: new( & format!( "--host-os={gn_host_os}" ) ) ,
216- OsStr :: new( & format!( "--host-cpu={gn_host_arch}" ) ) ,
98+ crate_dir
99+ . join( "scripts/build_v8.py" )
100+ . to_string_lossy( )
101+ . as_ref( ) ,
102+ "--crate-root" ,
103+ crate_dir. to_string_lossy( ) . as_ref( ) ,
104+ "--root" ,
105+ out_dir. to_string_lossy( ) . as_ref( ) ,
106+ "--gn-root" ,
107+ gn_out_dir. to_string_lossy( ) . as_ref( ) ,
108+ "--host-os" ,
109+ gn_host_os,
110+ "--host-cpu" ,
111+ gn_host_arch,
112+ "--target-os" ,
113+ gn_target_os,
114+ "--target-cpu" ,
115+ gn_target_arch,
116+ "--is-debug" ,
117+ is_debug. to_string( ) . as_ref( ) ,
118+ "--use-custom-libcxx" ,
119+ use_custom_libcxx. to_string( ) . as_ref( ) ,
217120 ]
218121 ) ;
219-
220- let gn = find_gn ( & out_dir) . expect ( "Can't find gn" ) ;
221- let gn_se = format ! ( "--script-executable={}" , python. to_string_lossy( ) ) ;
222-
223- system ! (
224- & gn,
225- [ & gn_se, "gen" , gn_out_dir, & format!( "--args={gn_args}" ) ]
226- ) ;
227-
228- if env:: var_os ( "PRINT_GN_ARGS" ) . is_some ( ) {
229- system ! ( & gn, [ & gn_se, "args" , gn_out_dir, "--list" ] ) ;
230- }
231-
232- system ! (
233- find_ninja( & out_dir) . expect( "Can't find ninja" ) ,
234- [ "-C" , gn_out_dir, "rusty_v8" ]
235- ) ;
236122}
237123
238124fn set_cargo_rerun ( ) {
@@ -332,51 +218,3 @@ fn find_python() -> Option<OsString> {
332218 return None ;
333219 } )
334220}
335-
336- fn find_ninja ( out_dir : & Path ) -> Option < OsString > {
337- let mut ninja_path = out_dir. join ( "third_party" ) . join ( "ninja" ) . join ( "ninja" ) ;
338- ninja_path. set_extension ( consts:: EXE_EXTENSION ) ;
339-
340- Some ( if let Some ( path) = env:: var_os ( "NINJA" ) {
341- path
342- } else if ninja_path. exists ( ) {
343- ninja_path. into ( )
344- } else if let Ok ( path) = which ( "ninja" ) {
345- path. into ( )
346- } else {
347- return None ;
348- } )
349- }
350-
351- fn find_gn ( out_dir : & Path ) -> Option < OsString > {
352- let platform = match consts:: OS {
353- "linux" => "linux64" ,
354- "windows" => "win" ,
355- "macos" => "mac" ,
356- _ => "unsupported" ,
357- } ;
358- let mut gn_path = out_dir. join ( "buildtools" ) . join ( platform) . join ( "gn" ) ;
359- gn_path. set_extension ( consts:: EXE_EXTENSION ) ;
360-
361- Some ( if let Some ( path) = env:: var_os ( "GN" ) {
362- path
363- } else if gn_path. exists ( ) {
364- gn_path. into ( )
365- } else {
366- return None ;
367- } )
368- }
369-
370- fn find_cc_wrapper ( ) -> Option < OsString > {
371- Some ( if let Some ( path) = env:: var_os ( "SCCACHE" ) {
372- path
373- } else if let Ok ( path) = which ( "sccache" ) {
374- path. into ( )
375- } else if let Some ( path) = env:: var_os ( "CCACHE" ) {
376- path
377- } else if let Ok ( path) = which ( "ccache" ) {
378- path. into ( )
379- } else {
380- return None ;
381- } )
382- }
0 commit comments