build: PkgLinkExtern

This commit is contained in:
xushiwei
2024-05-09 14:51:01 +08:00
parent 093af00bbe
commit b133f70b6b
4 changed files with 40 additions and 23 deletions

View File

@@ -167,12 +167,12 @@ func buildAllPkgs(prog llssa.Program, initial []*packages.Package, mode Mode, ve
}
for _, aPkg := range pkgs {
pkg := aPkg.Package
switch kind := cl.PkgKindOf(pkg.Types); kind {
switch kind, param := cl.PkgKindOf(pkg.Types); kind {
case cl.PkgDeclOnly:
// skip packages that only contain declarations
// and set no export file
pkg.ExportFile = ""
case cl.PkgLinkIR: // cl.PkgLinkBitCode:
case cl.PkgLinkIR:
// skip packages that don't need to be compiled but need to be linked
pkgPath := pkg.PkgPath
if isPkgInLLGo(pkgPath) {
@@ -180,6 +180,15 @@ func buildAllPkgs(prog llssa.Program, initial []*packages.Package, mode Mode, ve
} else {
panic("todo")
}
case cl.PkgLinkExtern:
// skip packages that don't need to be compiled but need to be linked with external library
linkFile := os.ExpandEnv(strings.TrimSpace(param))
dir, lib := filepath.Split(linkFile)
command := " -l " + lib
if dir != "" {
command += " -L " + dir
}
pkg.ExportFile = command
default:
buildPkg(prog, aPkg, mode, verbose)
if prog.NeedRuntime() {