mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 21:13:39 +00:00
all: pretend to be linux/arm in baremetal targets
So far, we've pretended to be js/wasm in baremetal targets to make the
stdlib happy. Unfortunately, this has various problems because
syscall/js (a dependency of many stdlib packages) thinks it can do JS
calls, and emulating them gets quite hard with all changes to the
syscall/js packages in Go 1.12.
This commit does a few things:
* It lets baremetal targets pretend to be linux/arm instead of
js/wasm.
* It lets the loader only select particular packages from the src
overlay, instead of inserting them just before GOROOT. This makes it
possible to pick which packages to overlay for a given target.
* It adds a baremetal-only syscall package that stubs out almost all
syscalls.
This commit is contained in:
committed by
Ron Evans
parent
792274e86f
commit
a2d0f79be3
+33
-6
@@ -162,11 +162,11 @@ func (c *Compiler) selectGC() string {
|
||||
func (c *Compiler) Compile(mainPath string) error {
|
||||
// Prefix the GOPATH with the system GOROOT, as GOROOT is already set to
|
||||
// the TinyGo root.
|
||||
gopath := c.GOPATH
|
||||
if gopath == "" {
|
||||
gopath = runtime.GOROOT()
|
||||
overlayGopath := c.GOPATH
|
||||
if overlayGopath == "" {
|
||||
overlayGopath = runtime.GOROOT()
|
||||
} else {
|
||||
gopath = runtime.GOROOT() + string(filepath.ListSeparator) + gopath
|
||||
overlayGopath = runtime.GOROOT() + string(filepath.ListSeparator) + overlayGopath
|
||||
}
|
||||
|
||||
wd, err := os.Getwd()
|
||||
@@ -177,13 +177,40 @@ func (c *Compiler) Compile(mainPath string) error {
|
||||
Build: &build.Context{
|
||||
GOARCH: c.GOARCH,
|
||||
GOOS: c.GOOS,
|
||||
GOROOT: c.RootDir,
|
||||
GOPATH: gopath,
|
||||
GOROOT: runtime.GOROOT(),
|
||||
GOPATH: c.GOPATH,
|
||||
CgoEnabled: true,
|
||||
UseAllFiles: false,
|
||||
Compiler: "gc", // must be one of the recognized compilers
|
||||
BuildTags: append([]string{"tinygo", "gc." + c.selectGC()}, c.BuildTags...),
|
||||
},
|
||||
OverlayBuild: &build.Context{
|
||||
GOARCH: c.GOARCH,
|
||||
GOOS: c.GOOS,
|
||||
GOROOT: c.RootDir,
|
||||
GOPATH: overlayGopath,
|
||||
CgoEnabled: true,
|
||||
UseAllFiles: false,
|
||||
Compiler: "gc", // must be one of the recognized compilers
|
||||
BuildTags: append([]string{"tinygo", "gc." + c.selectGC()}, c.BuildTags...),
|
||||
},
|
||||
ShouldOverlay: func(path string) bool {
|
||||
switch path {
|
||||
case "machine", "os", "reflect", "runtime", "sync":
|
||||
return true
|
||||
default:
|
||||
if strings.HasPrefix(path, "device/") || strings.HasPrefix(path, "examples/") {
|
||||
return true
|
||||
} else if path == "syscall" {
|
||||
for _, tag := range c.BuildTags {
|
||||
if tag == "avr" || tag == "cortexm" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
},
|
||||
TypeChecker: types.Config{
|
||||
Sizes: &StdSizes{
|
||||
IntSize: int64(c.targetData.TypeAllocSize(c.intType)),
|
||||
|
||||
Reference in New Issue
Block a user