build: build runtime local
This commit is contained in:
Binary file not shown.
@@ -149,7 +149,13 @@ func Do(args []string, conf *Config) {
|
||||
|
||||
var runtimeFiles []string
|
||||
if needRt {
|
||||
runtimeFiles = allLinkFiles(rt)
|
||||
dpkg := buildAllPkgs(prog, rt[:1], mode, verbose)
|
||||
for _, pkg := range dpkg {
|
||||
if !strings.HasSuffix(pkg.ExportFile, ".ll") {
|
||||
continue
|
||||
}
|
||||
runtimeFiles = append(runtimeFiles, pkg.ExportFile)
|
||||
}
|
||||
}
|
||||
if mode != ModeBuild {
|
||||
nErr := 0
|
||||
@@ -266,7 +272,7 @@ func linkMainPkg(pkg *packages.Package, pkgs []*aPackage, runtimeFiles []string,
|
||||
needRuntime := false
|
||||
needPyInit := false
|
||||
packages.Visit([]*packages.Package{pkg}, nil, func(p *packages.Package) {
|
||||
if p.ExportFile != "" && !isRuntimePkg(p.PkgPath) { // skip packages that only contain declarations
|
||||
if p.ExportFile != "" { // skip packages that only contain declarations
|
||||
args = appendLinkFiles(args, p.ExportFile)
|
||||
need1, need2 := isNeedRuntimeOrPyInit(p)
|
||||
if !needRuntime {
|
||||
@@ -445,38 +451,6 @@ func checkFlag(arg string, i *int, verbose *bool, swflags map[string]bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func allLinkFiles(rt []*packages.Package) (outFiles []string) {
|
||||
outFiles = make([]string, 0, len(rt))
|
||||
packages.Visit(rt, nil, func(p *packages.Package) {
|
||||
pkgPath := p.PkgPath
|
||||
kind, param := cl.PkgKindOf(p.Types)
|
||||
if isRuntimePkg(pkgPath) {
|
||||
exptFile := ""
|
||||
if kind == cl.PkgLinkIR || kind == cl.PkgDeclOnly {
|
||||
exptFile = strings.TrimSpace(param)
|
||||
}
|
||||
llgoPkgLinkFiles(pkgPath, exptFile, func(linkFile string) {
|
||||
outFiles = append(outFiles, linkFile)
|
||||
})
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const (
|
||||
pkgAbi = llgoModPath + "/internal/abi"
|
||||
pkgRuntime = llgoModPath + "/internal/runtime"
|
||||
pkgRuntimeC = llgoModPath + "/internal/runtime/c"
|
||||
)
|
||||
|
||||
func isRuntimePkg(pkgPath string) bool {
|
||||
switch pkgPath {
|
||||
case pkgRuntime, pkgAbi, pkgRuntimeC:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
rootDir string
|
||||
)
|
||||
|
||||
@@ -19,6 +19,10 @@ package c
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl"
|
||||
)
|
||||
|
||||
type (
|
||||
Char = int8
|
||||
Int = C.int
|
||||
@@ -26,15 +30,6 @@ type (
|
||||
FilePtr = unsafe.Pointer
|
||||
)
|
||||
|
||||
//go:linkname Stdin stdin
|
||||
var Stdin FilePtr
|
||||
|
||||
//go:linkname Stdout stdout
|
||||
var Stdout FilePtr
|
||||
|
||||
//go:linkname Stderr stderr
|
||||
var Stderr FilePtr
|
||||
|
||||
//go:linkname Str llgo.cstr
|
||||
func Str(string) *Char
|
||||
|
||||
|
||||
@@ -3,6 +3,13 @@
|
||||
|
||||
package c
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl: c_default.ll"
|
||||
)
|
||||
import _ "unsafe"
|
||||
|
||||
//go:linkname Stdin __stdinp
|
||||
var Stdin FilePtr
|
||||
|
||||
//go:linkname Stdout __stdoutp
|
||||
var Stdout FilePtr
|
||||
|
||||
//go:linkname Stderr __stderrp
|
||||
var Stderr FilePtr
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
; ModuleID = 'github.com/goplus/llgo/internal/runtime/c'
|
||||
source_filename = "github.com/goplus/llgo/internal/runtime/c"
|
||||
|
||||
@__stderrp = external global ptr
|
||||
@__stdinp = external global ptr
|
||||
@__stdoutp = external global ptr
|
||||
@stdin = alias i8*, i8** @__stdinp
|
||||
@stdout = alias i8*, i8** @__stdoutp
|
||||
@stderr = alias i8*, i8** @__stderrp
|
||||
@@ -3,6 +3,13 @@
|
||||
|
||||
package c
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl: c_linux.ll"
|
||||
)
|
||||
import _ "unsafe"
|
||||
|
||||
//go:linkname Stdin stdin
|
||||
var Stdin FilePtr
|
||||
|
||||
//go:linkname Stdout stdout
|
||||
var Stdout FilePtr
|
||||
|
||||
//go:linkname Stderr stderr
|
||||
var Stderr FilePtr
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
; ModuleID = 'github.com/goplus/llgo/internal/runtime/c'
|
||||
source_filename = "github.com/goplus/llgo/internal/runtime/c"
|
||||
Binary file not shown.
Reference in New Issue
Block a user