
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.
34 строки
676 Б
Go
34 строки
676 Б
Go
// +build avr cortexm wasm
|
|
|
|
package os
|
|
|
|
import (
|
|
_ "unsafe"
|
|
)
|
|
|
|
// Read is unsupported on this system.
|
|
func (f *File) Read(b []byte) (n int, err error) {
|
|
return 0, ErrUnsupported
|
|
}
|
|
|
|
// Write writes len(b) bytes to the output. It returns the number of bytes
|
|
// written or an error if this file is not stdout or stderr.
|
|
func (f *File) Write(b []byte) (n int, err error) {
|
|
switch f.fd {
|
|
case Stdout.fd, Stderr.fd:
|
|
for _, c := range b {
|
|
putchar(c)
|
|
}
|
|
return len(b), nil
|
|
default:
|
|
return 0, ErrUnsupported
|
|
}
|
|
}
|
|
|
|
// Close is unsupported on this system.
|
|
func (f *File) Close() error {
|
|
return ErrUnsupported
|
|
}
|
|
|
|
//go:linkname putchar runtime.putchar
|
|
func putchar(c byte)
|