diff --git a/internal/build/build.go b/internal/build/build.go index 010aab8f..ec741f60 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -663,6 +663,18 @@ func isWasmTarget(goos string) bool { return slices.Contains([]string{"wasi", "js", "wasip1"}, goos) } +func needStart(conf *Config) bool { + if conf.Target == "" { + return !isWasmTarget(conf.Goos) + } + switch conf.Target { + case "wasip2": + return false + default: + return true + } +} + func genMainModuleFile(ctx *context, rtPkgPath string, pkg *packages.Package, needRuntime, needPyInit bool) (path string, err error) { var ( pyInitDecl string @@ -717,8 +729,10 @@ define weak void @_start() { } ` mainDefine := "define i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr" - if isWasmTarget(ctx.buildConf.Goos) { + if !needStart(ctx.buildConf) && isWasmTarget(ctx.buildConf.Goos) { mainDefine = "define hidden noundef i32 @__main_argc_argv(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr" + } + if !needStart(ctx.buildConf) { startDefine = "" } mainCode := fmt.Sprintf(`; ModuleID = 'main'