From 5cfd996659e69e597205f2ee45b19236bfb8e017 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Thu, 21 Aug 2025 17:01:45 +0800 Subject: [PATCH] fix cross compilation tests --- internal/crosscompile/crosscompile_test.go | 43 ++++++++++++++-------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/internal/crosscompile/crosscompile_test.go b/internal/crosscompile/crosscompile_test.go index f85267bc..ce755516 100644 --- a/internal/crosscompile/crosscompile_test.go +++ b/internal/crosscompile/crosscompile_test.go @@ -37,10 +37,10 @@ func TestUseCrossCompileSDK(t *testing.T) { name: "Same Platform", goos: runtime.GOOS, goarch: runtime.GOARCH, - expectSDK: false, - expectCCFlags: false, - expectCFlags: false, - expectLDFlags: false, + expectSDK: true, // Changed: now we expect flags even for same platform + expectCCFlags: true, // Changed: CCFLAGS will contain sysroot + expectCFlags: true, // Changed: CFLAGS will contain include paths + expectLDFlags: true, // Changed: LDFLAGS will contain library paths }, { name: "WASM Target", @@ -55,10 +55,10 @@ func TestUseCrossCompileSDK(t *testing.T) { name: "Unsupported Target", goos: "windows", goarch: "amd64", - expectSDK: false, - expectCCFlags: false, - expectCFlags: false, - expectLDFlags: false, + expectSDK: false, // Still false as it won't set up specific SDK + expectCCFlags: false, // No cross-compile specific flags + expectCFlags: false, // No cross-compile specific flags + expectLDFlags: false, // No cross-compile specific flags }, } @@ -111,11 +111,20 @@ func TestUseCrossCompileSDK(t *testing.T) { } } - if !hasSysroot { - t.Error("Missing --sysroot flag in CCFLAGS") - } - if !hasResourceDir { - t.Error("Missing -resource-dir flag in CCFLAGS") + // For WASM target, both sysroot and resource-dir are expected + if tc.name == "WASM Target" { + if !hasSysroot { + t.Error("Missing --sysroot flag in CCFLAGS") + } + if !hasResourceDir { + t.Error("Missing -resource-dir flag in CCFLAGS") + } + } else if tc.name == "Same Platform" { + // For same platform, we expect sysroot only on macOS + if runtime.GOOS == "darwin" && !hasSysroot { + t.Error("Missing --sysroot flag in CCFLAGS on macOS") + } + // On Linux and other platforms, sysroot is not necessarily required } } @@ -147,9 +156,11 @@ func TestUseCrossCompileSDK(t *testing.T) { } } } else { - if /*len(export.CCFLAGS) != 0 ||*/ len(export.CFLAGS) != 0 { - t.Errorf("Expected empty export, got CCFLAGS=%v, CFLAGS=%v, LDFLAGS=%v", - export.CCFLAGS, export.CFLAGS, export.LDFLAGS) + // For unsupported targets, we still expect some basic flags to be set + // since the implementation now always sets up ESP Clang environment + // Only check that we don't have specific SDK-related flags for unsupported targets + if tc.name == "Unsupported Target" && len(export.CFLAGS) != 0 { + t.Errorf("Expected empty CFLAGS for unsupported target, got CFLAGS=%v", export.CFLAGS) } } })