ssa: record NeedRuntime, NeedPyInit in Package to compatible multi-packages building

This commit is contained in:
Li Jie
2025-02-18 09:50:14 +08:00
parent 0e4ca910d6
commit 00406e08fb
4 changed files with 9 additions and 10 deletions

View File

@@ -275,7 +275,6 @@ type context struct {
}
func buildAllPkgs(ctx *context, initial []*packages.Package, verbose bool) (pkgs []*aPackage, err error) {
prog := ctx.prog
pkgs, errPkgs := allPkgs(ctx, initial, verbose)
for _, errPkg := range errPkgs {
for _, err := range errPkg.Errors {
@@ -364,7 +363,7 @@ func buildAllPkgs(ctx *context, initial []*packages.Package, verbose bool) (pkgs
if aPkg.AltPkg != nil {
aPkg.LinkArgs = append(aPkg.LinkArgs, concatPkgLinkFiles(ctx, aPkg.AltPkg.Package, verbose)...)
}
setNeedRuntimeOrPyInit(ctx, pkg, prog.NeedRuntime, prog.NeedPyInit)
setNeedRuntimeOrPyInit(ctx, pkg, aPkg.LPkg.NeedRuntime, aPkg.LPkg.NeedPyInit)
}
}
return

View File

@@ -204,8 +204,6 @@ type aProgram struct {
ptrSize int
NeedRuntime bool
NeedPyInit bool
is32Bits bool
}
@@ -281,7 +279,6 @@ func (p Program) runtime() *types.Package {
if p.rt == nil {
p.rt = p.rtget()
}
p.NeedRuntime = true
return p.rt
}
@@ -393,7 +390,6 @@ func (p Program) NewPackage(name, pkgPath string) Package {
goStrs := make(map[string]llvm.Value)
chkabi := make(map[types.Type]bool)
glbDbgVars := make(map[Expr]bool)
p.NeedRuntime = false
// Don't need reset p.needPyInit here
// p.needPyInit = false
ret := &aPackage{
@@ -656,11 +652,15 @@ type aPackage struct {
fnlink func(string) string
iRoutine int
NeedRuntime bool
NeedPyInit bool
}
type Package = *aPackage
func (p Package) rtFunc(fnName string) Expr {
p.NeedRuntime = true
fn := p.Prog.runtime().Scope().Lookup(fnName).(*types.Func)
name := FullName(fn.Pkg(), fnName)
sig := fn.Type().(*types.Signature)

View File

@@ -71,7 +71,7 @@ func (p Program) SetPython(py any) {
// -----------------------------------------------------------------------------
func (p Package) pyFunc(fullName string, sig *types.Signature) Expr {
p.Prog.NeedPyInit = true
p.NeedPyInit = true
return p.NewFunc(fullName, sig, InC).Expr
}
@@ -420,7 +420,7 @@ func (p Package) PyNewFunc(name string, sig *types.Signature, doInit bool) PyObj
prog := p.Prog
obj := p.NewVar(name, prog.PyObjectPtrPtr().RawType(), InC)
if doInit {
prog.NeedPyInit = true
p.NeedPyInit = true
obj.InitNil()
obj.impl.SetLinkage(llvm.LinkOnceAnyLinkage)
}

View File

@@ -234,7 +234,7 @@ source_filename = "foo/bar"
@a = external global {}, align 1
`)
if prog.NeedRuntime {
if pkg.NeedRuntime {
t.Fatal("NeedRuntime?")
}
}