baremetal,wasm: support command line params and environment variables

This is mainly useful to be able to run `tinygo test`, for example:

    tinygo test -target=cortex-m-qemu -v math

This is not currently supported, but will be in the future.
This commit is contained in:
Ayke van Laethem
2021-08-10 21:35:52 +02:00
committed by Ron Evans
parent c25a7cc747
commit f57e9622fd
6 changed files with 126 additions and 37 deletions
@@ -1,4 +1,4 @@
// +build baremetal
// +build baremetal js
package syscall
@@ -47,8 +47,24 @@ const (
O_CLOEXEC = 0
)
func runtime_envs() []string
func Getenv(key string) (value string, found bool) {
return "", false // stub
env := runtime_envs()
for _, keyval := range env {
// Split at '=' character.
var k, v string
for i := 0; i < len(keyval); i++ {
if keyval[i] == '=' {
k = keyval[:i]
v = keyval[i+1:]
}
}
if k == key {
return v, true
}
}
return "", false
}
func Open(path string, mode int, perm uint32) (fd int, err error) {
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build baremetal nintendoswitch
// +build baremetal nintendoswitch js
package syscall