mirror of https://github.com/python/cpython
GH-121634: have `wasi.py` accept the host target triple as an argument (GH-123030)
This commit is contained in:
parent
e001027188
commit
b15b81ed4f
|
@ -0,0 +1 @@
|
||||||
|
Allow for specifying the target compile triple for WASI.
|
|
@ -20,8 +20,6 @@ CHECKOUT = pathlib.Path(__file__).parent.parent.parent
|
||||||
|
|
||||||
CROSS_BUILD_DIR = CHECKOUT / "cross-build"
|
CROSS_BUILD_DIR = CHECKOUT / "cross-build"
|
||||||
BUILD_DIR = CROSS_BUILD_DIR / "build"
|
BUILD_DIR = CROSS_BUILD_DIR / "build"
|
||||||
HOST_TRIPLE = "wasm32-wasi"
|
|
||||||
HOST_DIR = CROSS_BUILD_DIR / HOST_TRIPLE
|
|
||||||
|
|
||||||
LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local"
|
LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local"
|
||||||
LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/wasi.py\n".encode("utf-8")
|
LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/wasi.py\n".encode("utf-8")
|
||||||
|
@ -63,12 +61,17 @@ def subdir(working_dir, *, clean_ok=False):
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def wrapper(context):
|
def wrapper(context):
|
||||||
|
nonlocal working_dir
|
||||||
|
|
||||||
|
if callable(working_dir):
|
||||||
|
working_dir = working_dir(context)
|
||||||
try:
|
try:
|
||||||
tput_output = subprocess.check_output(["tput", "cols"],
|
tput_output = subprocess.check_output(["tput", "cols"],
|
||||||
encoding="utf-8")
|
encoding="utf-8")
|
||||||
terminal_width = int(tput_output.strip())
|
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
terminal_width = 80
|
terminal_width = 80
|
||||||
|
else:
|
||||||
|
terminal_width = int(tput_output.strip())
|
||||||
print("⎯" * terminal_width)
|
print("⎯" * terminal_width)
|
||||||
print("📁", working_dir)
|
print("📁", working_dir)
|
||||||
if (clean_ok and getattr(context, "clean", False) and
|
if (clean_ok and getattr(context, "clean", False) and
|
||||||
|
@ -193,7 +196,7 @@ def wasi_sdk_env(context):
|
||||||
return env
|
return env
|
||||||
|
|
||||||
|
|
||||||
@subdir(HOST_DIR, clean_ok=True)
|
@subdir(lambda context: CROSS_BUILD_DIR / context.host_triple, clean_ok=True)
|
||||||
def configure_wasi_python(context, working_dir):
|
def configure_wasi_python(context, working_dir):
|
||||||
"""Configure the WASI/host build."""
|
"""Configure the WASI/host build."""
|
||||||
if not context.wasi_sdk_path or not context.wasi_sdk_path.exists():
|
if not context.wasi_sdk_path or not context.wasi_sdk_path.exists():
|
||||||
|
@ -238,7 +241,7 @@ def configure_wasi_python(context, working_dir):
|
||||||
# to find the stdlib due to Python not recognizing that it's being
|
# to find the stdlib due to Python not recognizing that it's being
|
||||||
# executed from within a checkout.
|
# executed from within a checkout.
|
||||||
configure = [os.path.relpath(CHECKOUT / 'configure', working_dir),
|
configure = [os.path.relpath(CHECKOUT / 'configure', working_dir),
|
||||||
f"--host={HOST_TRIPLE}",
|
f"--host={context.host_triple}",
|
||||||
f"--build={build_platform()}",
|
f"--build={build_platform()}",
|
||||||
f"--with-build-python={build_python}"]
|
f"--with-build-python={build_python}"]
|
||||||
if pydebug:
|
if pydebug:
|
||||||
|
@ -258,7 +261,7 @@ def configure_wasi_python(context, working_dir):
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
@subdir(HOST_DIR)
|
@subdir(lambda context: CROSS_BUILD_DIR / context.host_triple)
|
||||||
def make_wasi_python(context, working_dir):
|
def make_wasi_python(context, working_dir):
|
||||||
"""Run `make` for the WASI/host build."""
|
"""Run `make` for the WASI/host build."""
|
||||||
call(["make", "--jobs", str(cpu_count()), "all"],
|
call(["make", "--jobs", str(cpu_count()), "all"],
|
||||||
|
@ -342,6 +345,9 @@ def main():
|
||||||
help="Command template for running the WASI host "
|
help="Command template for running the WASI host "
|
||||||
"(default designed for wasmtime 14 or newer: "
|
"(default designed for wasmtime 14 or newer: "
|
||||||
f"`{default_host_runner}`)")
|
f"`{default_host_runner}`)")
|
||||||
|
for subcommand in build, configure_host, make_host:
|
||||||
|
subcommand.add_argument("--host-triple", action="store", default="wasm32-wasi",
|
||||||
|
help="The target triple for the WASI host build")
|
||||||
|
|
||||||
context = parser.parse_args()
|
context = parser.parse_args()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue