diff --git a/.github/workflows/reusable-wasi.yml b/.github/workflows/reusable-wasi.yml index 85af793c342c51..3f96c888e2dd30 100644 --- a/.github/workflows/reusable-wasi.yml +++ b/.github/workflows/reusable-wasi.yml @@ -17,7 +17,7 @@ jobs: WASI_SDK_VERSION: 24 WASI_SDK_PATH: /opt/wasi-sdk CROSS_BUILD_PYTHON: cross-build/build - CROSS_BUILD_WASI: cross-build/wasm32-wasi + CROSS_BUILD_WASI: cross-build/wasm32-wasip1 steps: - uses: actions/checkout@v4 # No problem resolver registered as one doesn't currently exist for Clang. @@ -31,7 +31,7 @@ jobs: with: path: ${{ env.WASI_SDK_PATH }} key: ${{ runner.os }}-wasi-sdk-${{ env.WASI_SDK_VERSION }} - - name: "Install WASI SDK" + - name: "Install WASI SDK" # Hard-coded to x64. if: steps.cache-wasi-sdk.outputs.cache-hit != 'true' run: | mkdir ${{ env.WASI_SDK_PATH }} && \ diff --git a/Misc/NEWS.d/next/Build/2024-11-07-11-09-31.gh-issue-123877.CVdd0b.rst b/Misc/NEWS.d/next/Build/2024-11-07-11-09-31.gh-issue-123877.CVdd0b.rst new file mode 100644 index 00000000000000..080d2f2ab12af9 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2024-11-07-11-09-31.gh-issue-123877.CVdd0b.rst @@ -0,0 +1,3 @@ +Use ``wasm32-wasip1`` as the target triple for WASI instead of +``wasm32-wasi``. The latter will eventually be reclaimed for WASI 1.0 while +CPython currently only supports WASI preview1. diff --git a/Python/codegen.c b/Python/codegen.c index d6ba85887e3860..624d4f7ce14f21 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -51,16 +51,19 @@ #define ERROR -1 #define RETURN_IF_ERROR(X) \ - if ((X) == -1) { \ - return ERROR; \ - } - -#define RETURN_IF_ERROR_IN_SCOPE(C, CALL) { \ - if ((CALL) < 0) { \ - _PyCompile_ExitScope((C)); \ - return ERROR; \ - } \ -} + do { \ + if ((X) == -1) { \ + return ERROR; \ + } \ + } while (0) + +#define RETURN_IF_ERROR_IN_SCOPE(C, CALL) \ + do { \ + if ((CALL) < 0) { \ + _PyCompile_ExitScope((C)); \ + return ERROR; \ + } \ + } while (0) struct _PyCompiler; typedef struct _PyCompiler compiler; @@ -261,7 +264,7 @@ codegen_addop_i(instr_sequence *seq, int opcode, Py_ssize_t oparg, location loc) RETURN_IF_ERROR(codegen_addop_i(INSTR_SEQUENCE(C), (OP), (O), (LOC))) #define ADDOP_I_IN_SCOPE(C, LOC, OP, O) \ - RETURN_IF_ERROR_IN_SCOPE(C, codegen_addop_i(INSTR_SEQUENCE(C), (OP), (O), (LOC))); + RETURN_IF_ERROR_IN_SCOPE(C, codegen_addop_i(INSTR_SEQUENCE(C), (OP), (O), (LOC))) static int codegen_addop_noarg(instr_sequence *seq, int opcode, location loc) @@ -303,17 +306,18 @@ codegen_addop_load_const(compiler *c, location loc, PyObject *o) RETURN_IF_ERROR_IN_SCOPE((C), codegen_addop_load_const((C), (LOC), (O))) /* Same as ADDOP_LOAD_CONST, but steals a reference. */ -#define ADDOP_LOAD_CONST_NEW(C, LOC, O) { \ - PyObject *__new_const = (O); \ - if (__new_const == NULL) { \ - return ERROR; \ - } \ - if (codegen_addop_load_const((C), (LOC), __new_const) < 0) { \ - Py_DECREF(__new_const); \ - return ERROR; \ - } \ - Py_DECREF(__new_const); \ -} +#define ADDOP_LOAD_CONST_NEW(C, LOC, O) \ + do { \ + PyObject *__new_const = (O); \ + if (__new_const == NULL) { \ + return ERROR; \ + } \ + if (codegen_addop_load_const((C), (LOC), __new_const) < 0) { \ + Py_DECREF(__new_const); \ + return ERROR; \ + } \ + Py_DECREF(__new_const); \ + } while (0) static int codegen_addop_o(compiler *c, location loc, @@ -325,19 +329,23 @@ codegen_addop_o(compiler *c, location loc, return SUCCESS; } -#define ADDOP_N(C, LOC, OP, O, TYPE) { \ - assert(!OPCODE_HAS_CONST(OP)); /* use ADDOP_LOAD_CONST_NEW */ \ - int ret = codegen_addop_o((C), (LOC), (OP), METADATA(C)->u_ ## TYPE, (O)); \ - Py_DECREF((O)); \ - RETURN_IF_ERROR(ret); \ -} - -#define ADDOP_N_IN_SCOPE(C, LOC, OP, O, TYPE) { \ - assert(!OPCODE_HAS_CONST(OP)); /* use ADDOP_LOAD_CONST_NEW */ \ - int ret = codegen_addop_o((C), (LOC), (OP), METADATA(C)->u_ ## TYPE, (O)); \ - Py_DECREF((O)); \ - RETURN_IF_ERROR_IN_SCOPE((C), ret); \ -} +#define ADDOP_N(C, LOC, OP, O, TYPE) \ + do { \ + assert(!OPCODE_HAS_CONST(OP)); /* use ADDOP_LOAD_CONST_NEW */ \ + int ret = codegen_addop_o((C), (LOC), (OP), \ + METADATA(C)->u_ ## TYPE, (O)); \ + Py_DECREF((O)); \ + RETURN_IF_ERROR(ret); \ + } while (0) + +#define ADDOP_N_IN_SCOPE(C, LOC, OP, O, TYPE) \ + do { \ + assert(!OPCODE_HAS_CONST(OP)); /* use ADDOP_LOAD_CONST_NEW */ \ + int ret = codegen_addop_o((C), (LOC), (OP), \ + METADATA(C)->u_ ## TYPE, (O)); \ + Py_DECREF((O)); \ + RETURN_IF_ERROR_IN_SCOPE((C), ret); \ + } while (0) #define LOAD_METHOD -1 #define LOAD_SUPER_METHOD -2 @@ -426,31 +434,31 @@ codegen_addop_j(instr_sequence *seq, location loc, */ #define VISIT(C, TYPE, V) \ - RETURN_IF_ERROR(codegen_visit_ ## TYPE((C), (V))); + RETURN_IF_ERROR(codegen_visit_ ## TYPE((C), (V))) #define VISIT_IN_SCOPE(C, TYPE, V) \ RETURN_IF_ERROR_IN_SCOPE((C), codegen_visit_ ## TYPE((C), (V))) -#define VISIT_SEQ(C, TYPE, SEQ) { \ - int _i; \ - asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \ - for (_i = 0; _i < asdl_seq_LEN(seq); _i++) { \ - TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, _i); \ - RETURN_IF_ERROR(codegen_visit_ ## TYPE((C), elt)); \ - } \ -} - -#define VISIT_SEQ_IN_SCOPE(C, TYPE, SEQ) { \ - int _i; \ - asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \ - for (_i = 0; _i < asdl_seq_LEN(seq); _i++) { \ - TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, _i); \ - if (codegen_visit_ ## TYPE((C), elt) < 0) { \ - _PyCompile_ExitScope(C); \ - return ERROR; \ - } \ - } \ -} +#define VISIT_SEQ(C, TYPE, SEQ) \ + do { \ + asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \ + for (int _i = 0; _i < asdl_seq_LEN(seq); _i++) { \ + TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, _i); \ + RETURN_IF_ERROR(codegen_visit_ ## TYPE((C), elt)); \ + } \ + } while (0) + +#define VISIT_SEQ_IN_SCOPE(C, TYPE, SEQ) \ + do { \ + asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \ + for (int _i = 0; _i < asdl_seq_LEN(seq); _i++) { \ + TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, _i); \ + if (codegen_visit_ ## TYPE((C), elt) < 0) { \ + _PyCompile_ExitScope(C); \ + return ERROR; \ + } \ + } \ + } while (0) static int codegen_call_exit_with_nones(compiler *c, location loc) @@ -2866,7 +2874,7 @@ codegen_visit_stmt(compiler *c, stmt_ty s) case Return_kind: return codegen_return(c, s); case Delete_kind: - VISIT_SEQ(c, expr, s->v.Delete.targets) + VISIT_SEQ(c, expr, s->v.Delete.targets); break; case Assign_kind: { @@ -4759,7 +4767,7 @@ codegen_async_with(compiler *c, stmt_ty s, int pos) pos++; if (pos == asdl_seq_LEN(s->v.AsyncWith.items)) { /* BLOCK code */ - VISIT_SEQ(c, stmt, s->v.AsyncWith.body) + VISIT_SEQ(c, stmt, s->v.AsyncWith.body); } else { RETURN_IF_ERROR(codegen_async_with(c, s, pos)); @@ -4858,7 +4866,7 @@ codegen_with(compiler *c, stmt_ty s, int pos) pos++; if (pos == asdl_seq_LEN(s->v.With.items)) { /* BLOCK code */ - VISIT_SEQ(c, stmt, s->v.With.body) + VISIT_SEQ(c, stmt, s->v.With.body); } else { RETURN_IF_ERROR(codegen_with(c, s, pos)); diff --git a/Python/compile.c b/Python/compile.c index ecca9b0b06ecf7..cbfba7f493e07d 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -31,9 +31,11 @@ #define ERROR -1 #define RETURN_IF_ERROR(X) \ - if ((X) == -1) { \ - return ERROR; \ - } + do { \ + if ((X) == -1) { \ + return ERROR; \ + } \ + } while (0) typedef _Py_SourceLocation location; typedef _PyJumpTargetLabel jump_target_label; diff --git a/Tools/wasm/wasi.py b/Tools/wasm/wasi.py index 050e3723feb247..ac36d55587a38f 100644 --- a/Tools/wasm/wasi.py +++ b/Tools/wasm/wasi.py @@ -346,7 +346,7 @@ def main(): "(default designed for wasmtime 14 or newer: " f"`{default_host_runner}`)") for subcommand in build, configure_host, make_host: - subcommand.add_argument("--host-triple", action="store", default="wasm32-wasi", + subcommand.add_argument("--host-triple", action="store", default="wasm32-wasip1", help="The target triple for the WASI host build") context = parser.parse_args() diff --git a/configure b/configure index 1d5c0941247c30..71ffe9ca1c841e 100755 --- a/configure +++ b/configure @@ -4062,7 +4062,7 @@ then *-*-emscripten) ac_sys_system=Emscripten ;; - *-*-wasi) + *-*-wasi*) ac_sys_system=WASI ;; *) @@ -7086,7 +7086,7 @@ case $host/$ac_cv_cc_name in #( PY_SUPPORT_TIER=2 ;; #( powerpc64le-*-linux-gnu/gcc) : PY_SUPPORT_TIER=2 ;; #( - wasm32-unknown-wasi/clang) : + wasm32-unknown-wasip1/clang) : PY_SUPPORT_TIER=2 ;; #( x86_64-*-linux-gnu/clang) : PY_SUPPORT_TIER=2 ;; #( @@ -7792,7 +7792,7 @@ then : fi ;; #( WASI/*) : - HOSTRUNNER='wasmtime run --wasm max-wasm-stack=16777216 --wasi preview2 --env PYTHONPATH=/$(shell realpath --relative-to $(abs_srcdir) $(abs_builddir))/$(shell cat pybuilddir.txt):/Lib --dir $(srcdir)::/' ;; #( + HOSTRUNNER='wasmtime run --wasm max-wasm-stack=16777216 --wasi preview2=n --env PYTHONPATH=/$(shell realpath --relative-to $(abs_srcdir) $(abs_builddir))/$(shell cat pybuilddir.txt):/Lib --dir $(srcdir)::/' ;; #( *) : HOSTRUNNER='' ;; diff --git a/configure.ac b/configure.ac index ce5a5eb9c2891f..36199b36d27ba2 100644 --- a/configure.ac +++ b/configure.ac @@ -336,7 +336,7 @@ then *-*-emscripten) ac_sys_system=Emscripten ;; - *-*-wasi) + *-*-wasi*) ac_sys_system=WASI ;; *) @@ -1201,7 +1201,7 @@ AS_CASE([$host/$ac_cv_cc_name], [aarch64-*-linux-gnu/gcc], [PY_SUPPORT_TIER=2], dnl Linux ARM64, glibc, gcc+clang [aarch64-*-linux-gnu/clang], [PY_SUPPORT_TIER=2], [powerpc64le-*-linux-gnu/gcc], [PY_SUPPORT_TIER=2], dnl Linux on PPC64 little endian, glibc, gcc - [wasm32-unknown-wasi/clang], [PY_SUPPORT_TIER=2], dnl WebAssembly System Interface, clang + [wasm32-unknown-wasip1/clang], [PY_SUPPORT_TIER=2], dnl WebAssembly System Interface preview1, clang [x86_64-*-linux-gnu/clang], [PY_SUPPORT_TIER=2], dnl Linux on AMD64, any vendor, glibc, clang [aarch64-pc-windows-msvc/msvc], [PY_SUPPORT_TIER=3], dnl Windows ARM64, MSVC @@ -1647,7 +1647,7 @@ then dnl TODO: support other WASI runtimes dnl wasmtime starts the process with "/" as CWD. For OOT builds add the dnl directory containing _sysconfigdata to PYTHONPATH. - [WASI/*], [HOSTRUNNER='wasmtime run --wasm max-wasm-stack=16777216 --wasi preview2 --env PYTHONPATH=/$(shell realpath --relative-to $(abs_srcdir) $(abs_builddir))/$(shell cat pybuilddir.txt):/Lib --dir $(srcdir)::/'], + [WASI/*], [HOSTRUNNER='wasmtime run --wasm max-wasm-stack=16777216 --wasi preview2=n --env PYTHONPATH=/$(shell realpath --relative-to $(abs_srcdir) $(abs_builddir))/$(shell cat pybuilddir.txt):/Lib --dir $(srcdir)::/'], [HOSTRUNNER=''] ) fi