From edd75229a1b6a831e6e46176771e27e47120f85e Mon Sep 17 00:00:00 2001 From: Pierre Augier Date: Thu, 15 Oct 2026 16:16:39 +0200 Subject: [PATCH 1/3] test_init: test_i64_mul_multi_object_build --- spy/tests/compiler/test_int.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spy/tests/compiler/test_int.py b/spy/tests/compiler/test_int.py index afe0ed562..258903cae 100644 --- a/spy/tests/compiler/test_int.py +++ b/spy/tests/compiler/test_int.py @@ -455,3 +455,14 @@ def foo() -> i64: ("integer literal out of range", "2147483648"), ) self.compile_raises(src, "foo", errors) + + def test_i64_mul_multi_object_build(self): + # A tuple return type pulls in more modules, so the C backend builds + # several .o files and links them in a separate step. + src = """ + def mul(a: i64, b: i64) -> tuple[i64, i64]: + return a * b, a + """ + mod = self.compile(src) + assert mod.mul(6, 7) == (42, 6) + assert mod.mul(-6, 7) == (-42, -6) From 41190cda92783c279ae15751d02a61d725fd21fd Mon Sep 17 00:00:00 2001 From: Pierre Augier Date: Thu, 15 Oct 2026 16:17:52 +0200 Subject: [PATCH 2/3] wasi: same ABI for compile and link steps --- spy/build/flags.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spy/build/flags.py b/spy/build/flags.py index 6775c1420..69e47fc0f 100644 --- a/spy/build/flags.py +++ b/spy/build/flags.py @@ -62,6 +62,8 @@ _TARGET_LDFLAGS: dict[str, list[str]] = { "wasi": [ "--target=wasm32-wasi-musl", + # The link step must use the same ABI as the compile step. + *_WASM_CFLAGS, ], "emscripten": [], "native": [], From b394ce526caadbb5a31e63a1ea226c3b0c25f60a Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Tue, 17 Nov 2026 23:23:25 +0100 Subject: [PATCH 3/3] rename WASM_CFLAGS into WASM_ABI_FLAGS, which is more understandable IMHO --- spy/build/flags.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/spy/build/flags.py b/spy/build/flags.py index 69e47fc0f..a85fcfc93 100644 --- a/spy/build/flags.py +++ b/spy/build/flags.py @@ -30,8 +30,9 @@ "-DSPY_GC_NONE", ] -# WASM-specific CFLAGS shared by wasi and emscripten -_WASM_CFLAGS: list[str] = [ +# WASM ABI/codegen flags shared by wasi and emscripten. They must be passed BOTH when +# compiling and when linking. +_WASM_ABI_FLAGS: list[str] = [ "-mmultivalue", "-Xclang", "-target-abi", @@ -44,11 +45,11 @@ "wasi": [ "-DSPY_TARGET_WASI", "--target=wasm32-wasi-musl", - *_WASM_CFLAGS, + *_WASM_ABI_FLAGS, ], "emscripten": [ "-DSPY_TARGET_EMSCRIPTEN", - *_WASM_CFLAGS, + *_WASM_ABI_FLAGS, ], "native": [ "-DSPY_TARGET_NATIVE", @@ -62,10 +63,11 @@ _TARGET_LDFLAGS: dict[str, list[str]] = { "wasi": [ "--target=wasm32-wasi-musl", - # The link step must use the same ABI as the compile step. - *_WASM_CFLAGS, + *_WASM_ABI_FLAGS, + ], + "emscripten": [ + *_WASM_ABI_FLAGS, ], - "emscripten": [], "native": [], "native-static": [ "--target=native-native-musl",