@@ -317,16 +317,23 @@ def configure_wasi_python(context, working_dir):
317317
318318 wasi_build_dir = working_dir .relative_to (CHECKOUT )
319319
320- python_build_dir = BUILD_DIR / "build"
321- lib_dirs = list (python_build_dir .glob ("lib.*" ))
322- assert len (lib_dirs ) == 1 , (
323- f"Expected a single lib.* directory in { python_build_dir } "
324- )
325- lib_dir = os .fsdecode (lib_dirs [0 ])
326- python_version = lib_dir .rpartition ("-" )[- 1 ]
327- sysconfig_data_dir = (
328- f"{ wasi_build_dir } /build/lib.wasi-wasm32-{ python_version } "
329- )
320+ pybuilddir = working_dir / "pybuilddir.txt"
321+ if pybuilddir .is_file ():
322+ with pybuilddir .open ("r" , encoding = "utf-8" ) as f :
323+ sysconfig_data_dir = f"{ wasi_build_dir } /{ f .read ().strip ()} "
324+ else :
325+ # Fallback if the build hasn't generated the file yet.
326+ python_build_dir = BUILD_DIR / "build"
327+ lib_dirs = list (python_build_dir .glob ("lib.*" ))
328+ assert len (lib_dirs ) == 1 , (
329+ f"Expected a single lib.* directory in { python_build_dir } "
330+ )
331+ lib_dir = os .fsdecode (lib_dirs [0 ])
332+ python_version = lib_dir .rpartition ("-" )[- 1 ]
333+
334+ sysconfig_data_dir = (
335+ f"{ wasi_build_dir } /build/lib.wasi-wasm32-{ python_version } "
336+ )
330337
331338 # Use PYTHONPATH to include sysconfig data which must be anchored to the
332339 # WASI guest's `/` directory.
0 commit comments