2020
2121CROSS_BUILD_DIR  =  CHECKOUT  /  "cross-build" 
2222BUILD_DIR  =  CROSS_BUILD_DIR  /  "build" 
23- HOST_TRIPLE  =  "wasm32-wasi" 
24- HOST_DIR  =  CROSS_BUILD_DIR  /  HOST_TRIPLE 
2523
2624LOCAL_SETUP  =  CHECKOUT  /  "Modules"  /  "Setup.local" 
2725LOCAL_SETUP_MARKER  =  "# Generated by Tools/wasm/wasi.py\n " .encode ("utf-8" )
@@ -63,12 +61,17 @@ def subdir(working_dir, *, clean_ok=False):
6361    def  decorator (func ):
6462        @functools .wraps (func ) 
6563        def  wrapper (context ):
64+             nonlocal  working_dir 
65+ 
66+             if  callable (working_dir ):
67+                 working_dir  =  working_dir (context )
6668            try :
6769                tput_output  =  subprocess .check_output (["tput" , "cols" ],
6870                                                      encoding = "utf-8" )
69-                 terminal_width  =  int (tput_output .strip ())
7071            except  subprocess .CalledProcessError :
7172                terminal_width  =  80 
73+             else :
74+                 terminal_width  =  int (tput_output .strip ())
7275            print ("⎯"  *  terminal_width )
7376            print ("📁" , working_dir )
7477            if  (clean_ok  and  getattr (context , "clean" , False ) and 
@@ -193,7 +196,7 @@ def wasi_sdk_env(context):
193196    return  env 
194197
195198
196- @subdir (HOST_DIR , clean_ok = True ) 
199+ @subdir (lambda   context :  CROSS_BUILD_DIR   /   context . host_triple , clean_ok = True ) 
197200def  configure_wasi_python (context , working_dir ):
198201    """Configure the WASI/host build.""" 
199202    if  not  context .wasi_sdk_path  or  not  context .wasi_sdk_path .exists ():
@@ -238,7 +241,7 @@ def configure_wasi_python(context, working_dir):
238241    # to find the stdlib due to Python not recognizing that it's being 
239242    # executed from within a checkout. 
240243    configure  =  [os .path .relpath (CHECKOUT  /  'configure' , working_dir ),
241-                     f"--host={ HOST_TRIPLE }  " ,
244+                     f"--host={ context . host_triple }  " ,
242245                    f"--build={ build_platform ()}  " ,
243246                    f"--with-build-python={ build_python }  " ]
244247    if  pydebug :
@@ -258,7 +261,7 @@ def configure_wasi_python(context, working_dir):
258261    sys .stdout .flush ()
259262
260263
261- @subdir (HOST_DIR ) 
264+ @subdir (lambda   context :  CROSS_BUILD_DIR   /   context . host_triple ) 
262265def  make_wasi_python (context , working_dir ):
263266    """Run `make` for the WASI/host build.""" 
264267    call (["make" , "--jobs" , str (cpu_count ()), "all" ],
@@ -343,6 +346,9 @@ def main():
343346                        help = "Command template for running the WASI host " 
344347                             "(default designed for wasmtime 14 or newer: " 
345348                                f"`{ default_host_runner }  `)" )
349+     for  subcommand  in  build , configure_host , make_host :
350+         subcommand .add_argument ("--host-triple" , action = "store" , default = "wasm32-wasi" ,
351+                         help = "The target triple for the WASI host build" )
346352
347353    context  =  parser .parse_args ()
348354
0 commit comments