aboutsummaryrefslogtreecommitdiffhomepage
path: root/loader
AgeCommit message (Collapse)Author
2024-02-19compileopts: always enable CGoAyke van Laethem
CGo is needed for the rp2040 and for macOS (GOOS=darwin), without it these targets just won't work. And there really isn't a benefit from disabling CGo: we don't need any external linkers for example. This avoids a somewhat common issue of people having CGO_ENABLED=0 somewhere in their environment and not understanding why things don't work. See for example: https://github.com/tinygo-org/tinygo/issues/3450
2024-01-19loader: make sure Go version is plumbed throughAyke van Laethem
This fixes the new loop variable behavior in Go 1.22. Specifically: * The compiler (actually, the x/tools/go/ssa package) now correctly picks up the Go version. * If a module doesn't specify the Go version, the current Go version (from the `go` tool and standard library) is used. This fixes `go run`. * The tests in testdata/ that use a separate directory are now actually run in that directory. This makes it possible to use a go.mod file there. * There is a test to make sure old Go modules still work with the old Go behavior, even on a newer Go version.
2024-01-19loader: enforce Go language version in the type checkerAyke van Laethem
This means for example that ranging over integers will only work when setting the Go version to go1.22 or later in the go.mod file.
2024-01-18cgo: add file AST for fake C file locationsAyke van Laethem
This is needed for the type checker, otherwise it doesn't know which Go version it should use for type checking.
2023-12-30os/user: add bare-bones implementation of the os/user packageElias Naur
Signed-off-by: Elias Naur <[email protected]>
2023-12-06Add network device driver model, netdevScott Feldman
This PR adds a network device driver model called netdev. There will be a companion PR for TinyGo drivers to update the netdev drivers and network examples. This PR covers the core "net" package. An RFC for the work is here: #tinygo-org/drivers#487. Some things have changed from the RFC, but nothing major. The "net" package is a partial port of Go's "net" package, version 1.19.3. The src/net/README file has details on what is modified from Go's "net" package. Most "net" features are working as they would in normal Go. TCP/UDP/TLS protocol support is there. As well as HTTP client and server support. Standard Go network packages such as golang.org/x/net/websockets and Paho MQTT client work as-is. Other packages are likely to work as-is. Testing results are here (https://docs.google.com/spreadsheets/d/e/2PACX-1vT0cCjBvwXf9HJf6aJV2Sw198F2ief02gmbMV0sQocKT4y4RpfKv3dh6Jyew8lQW64FouZ8GwA2yjxI/pubhtml?gid=1013173032&single=true).
2023-10-15refactor: rm io/ioutil funcsginglis13
io/ioutil has been deprecated since Go 1.16 https://pkg.go.dev/io/ioutil Signed-off-by: ginglis13 <[email protected]>
2023-10-14builder: refactor clang include headersAyke van Laethem
Set -resource-dir in a central place instead of passing the header path around everywhere and adding it using the `-I` flag. I believe this is closer to how Clang is intended to be used. This change was inspired by my attempt to add a Nix flake file to TinyGo.
2023-08-13loader: merge go.env file which is now required starting in Go 1.21 to ↵deadprogram
correctly get required packages Signed-off-by: deadprogram <[email protected]>
2023-03-10Added missing TCPAddr and UDPAddr implementations to the net packageJustin A. Wilson
2022-09-16cgo: implement support for static functionsAyke van Laethem
2022-09-01loader,crypto: fix link error for crypto/internal/boring/sig.StandardCryptoDamian Gryski
2022-08-30all: drop support for Go 1.16 and Go 1.17Ayke van Laethem
2022-08-07all: move from os.IsFoo to errors.Is(err, ErrFoo)Damian Gryski
2022-08-07all: remove calls to deprecated ioutil packageDamian Gryski
Fixes produced via semgrep and https://github.com/dgryski/semgrep-go/blob/master/ioutil.yml
2022-06-11compiler: add support for type parameters (aka generics)Ayke van Laethem
...that was surprisingly easy.
2022-06-11fix: fixes tinygo test ./... syntax.José Carlos Chávez
2022-05-30all: add support for the embed packageAyke van Laethem
2022-04-09Add a shim for internal/fuzzElliott Sales de Andrade
This simply shadows the real code temporarily to see what else is broken. It only defines a single type to fix testing/internal/testdeps.
2022-02-28Revert "all: move stm32 files to separate repository"sago35
This reverts commit 644356c220ed88f110d01300f671a170cd36eb04.
2022-02-18all: move stm32 files to separate repositoryAyke van Laethem
2022-02-12loader: only add Clang header path for CGoAyke van Laethem
It should only be added at the point that it is needed, for example when using libclang or using the built-in Clang. It isn't needed when running an external tool.
2022-01-23main (test): integrate test corpus runnerNia Waldvogel
This allows us to test a large corpus of external packages against the compiler.
2022-01-19loader: respect $GOROOT when running `go list`Ayke van Laethem
This makes it possible to select the Go version using GOROOT, and works even if the `go` binary is not in $PATH.
2022-01-15pass more --dirs to wasmtime so it can read the entire module treeDamian Gryski
This allows compress/flate to pass on -target=wasi out of the box Fixes #2367
2022-01-09all: switch to LLVM 13Ayke van Laethem
This adds support for building with `-tags=llvm13` and switches to LLVM 13 for tinygo binaries that are statically linked against LLVM. Some notes on this commit: * Added `-mfloat-abi=soft` to all Cortex-M targets because otherwise nrfx would complain that floating point was enabled on Cortex-M0. That's not the case, but with `-mfloat-abi=soft` the `__SOFTFP__` macro is defined which silences this warning. See: https://reviews.llvm.org/D100372 * Changed from `--sysroot=<root>` to `-nostdlib -isystem <root>` for musl because with Clang 13, even with `--sysroot` some system libraries are used which we don't want. * Changed all `-Xclang -internal-isystem -Xclang` to simply `-isystem`, for consistency with the above change. It appears to have the same effect. * Moved WebAssembly function declarations to the top of the file in task_asyncify_wasm.S because (apparently) the assembler has become more strict.
2021-12-28loader: elminate goroot cache inconsistencyNia Waldvogel
This change breaks the merged goroot creation process into 2 steps: 1. List all overrides 2. Construct a goroot with the specified overrides Now step 2 is cached using a hash of the results from step 1. This eliminates cache inconsistency, but means that step 1 needs to be run on every build. This is relatively acceptable, as step 1 only takes about 3 ms (assuming the directory tree is in the OS filesystem cache).
2021-11-16net/ip, syscall/errno: Reduce code duplication by switching to internal/itoa.Dan Kegel
internal/itoa wasn't around back in go 1.12 days when tinygo's syscall/errno.go was written. It was only added as of go 1.17 ( https://github.com/golang/go/commit/061a6903a232cb868780b ) so we have to have an internal copy for now. The internal copy should be deleted when tinygo drops support for go 1.16. FWIW, the new version seems nicer. It uses no allocations when converting 0, and although the optimizer might make this moot, uses a multiplication x 10 instead of a mod operation.
2021-11-03builder: improve accuracy of the -size=full flagAyke van Laethem
This commit improves accuracy of the -size=full flag in a big way. Instead of relying on symbol names to figure out by which package symbols belong, it will instead mostly use DWARF debug information (specifically, debug line tables and debug information for global variables) relying on symbols only for some specific things. This is much more accurate: it also accounts for inlined functions. For example, here is how it looked previously when compiling a personal project: code rodata data bss | flash ram | package 1902 333 0 0 | 2235 0 | (bootstrap) 46 256 0 0 | 302 0 | github 0 454 0 0 | 454 0 | handleHardFault$string 154 24 4 4 | 182 8 | internal/task 2498 83 5 2054 | 2586 2059 | machine 0 16 24 130 | 40 154 | machine$alloc 1664 32 12 8 | 1708 20 | main 0 0 0 200 | 0 200 | main$alloc 2476 79 0 36 | 2555 36 | runtime 576 0 0 0 | 576 0 | tinygo 9316 1277 45 2432 | 10638 2477 | (sum) 11208 - 48 6548 | 11256 6596 | (all) And here is how it looks now: code rodata data bss | flash ram | package ------------------------------- | --------------- | ------- 1509 0 12 23 | 1521 35 | (unknown) 660 0 0 0 | 660 0 | C compiler-rt 58 0 0 0 | 58 0 | C picolibc 0 0 0 4096 | 0 4096 | C stack 174 0 0 0 | 174 0 | device/arm 6 0 0 0 | 6 0 | device/sam 598 256 0 0 | 854 0 | github.com/aykevl/ledsgo 320 24 0 4 | 344 4 | internal/task 1414 99 24 2181 | 1537 2205 | machine 726 352 12 208 | 1090 220 | main 3002 542 0 36 | 3544 36 | runtime 848 0 0 0 | 848 0 | runtime/volatile 70 0 0 0 | 70 0 | time 550 0 0 0 | 550 0 | tinygo.org/x/drivers/ws2812 ------------------------------- | --------------- | ------- 9935 1273 48 6548 | 11256 6596 | total There are some notable differences: * Odd packages like main$alloc and handleHardFault$string are gone, instead their code is put in the correct package. * C libraries and the stack are now included in the list, they were previously part of the (bootstrap) pseudo-package. * Unknown bytes are slightly reduced. It should be possible to reduce it significantly more in the future: most of it is now caused by interface invoke wrappers. * Inlined functions are now correctly attributed. For example, the runtime/volatile package is normally entirely inlined. * There is no difference between (sum) and (all) anymore. A better code size algorithm now counts the code/data sizes correctly. * And last (but not least) there is a stylistic change: the table now looks more like a table. Especially the summary should be clearer now. Future goals: * Improve debug information so that the (unknown) pseudo-package is reduced in size or even eliminated altogether. * Add support for other file formats, most importantly WebAssembly. * Perhaps provide a way to expand this report per file, or in a machine-readable format like JSON or CSV.
2021-10-31loader: fix true path detection on WindowsAyke van Laethem
This is necessary to display error messages on Windows. For example, this command invocation is not correct (esp32 doesn't define machine.LED, you need esp32-coreboard-v2 for example): tinygo run -target=esp32 examples/blinky1 It results in the following hard-to-read error message: # examples/blinky1 ..\..\..\..\..\AppData\Local\tinygo\goroot-go1.16-24cb853b66a5367bf6d65bc08b2cb665c75bd9971f0be8f8b73f69d1a33e04a1-syscall\src\examples\blinky1\blinky1.go:11:17: LED not declared by package machine With this commit, this error message becomes much easier to read: # examples/blinky1 C:\Users\Ayke\go\src\github.com\tinygo-org\tinygo\src\examples\blinky1\blinky1.go:11:17: LED not declared by package machine
2021-09-28builder, cgo: support function definitions in CGo headersAyke van Laethem
For example, the following did not work before but does work with this change: // int add(int a, int b) { // return a + b; // } import "C" func main() { println("add:", C.add(3, 5)) } Even better, the functions in the header are compiled together with the rest of the Go code and so they can be optimized together! Currently, inlining is not yet allowed but const-propagation across functions works. This should be improved in the future.
2021-09-15loader: fix panic in CGo files with syntax errorsAyke van Laethem
If all of the Go files presented to the compiler have syntax errors, cgo.Process gets an empty files slice and will panic: panic: runtime error: index out of range [0] with length 0 goroutine 1 [running]: github.com/tinygo-org/tinygo/cgo.Process({0x0, 0x4e8e36, 0x0}, {0xc000024104, 0x18}, 0xc000090fc0, {0xc000899780, 0x7, 0xc00018ce68}) /home/ayke/src/github.com/tinygo-org/tinygo/cgo/cgo.go:186 +0x22ee github.com/tinygo-org/tinygo/loader.(*Package).parseFiles(0xc0001ccf00) /home/ayke/src/github.com/tinygo-org/tinygo/loader/loader.go:400 +0x51e This is simple to work around: just don't try to run CGo when there are no files to process. It just means there are bugs to fix before CGo can properly run. (This is perhaps not the nicest solution but certainly the simplest).
2021-08-12baremetal,wasm: support command line params and environment variablesAyke van Laethem
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.
2021-06-21crypto/rand: replace this package with a TinyGo versionAyke van Laethem
This package provides access to an operating system resource (cryptographic numbers) and so needs to be replaced with a TinyGo version that does this in a different way. I've made the following choices while adding this feature: - I'm using the getentropy call whenever possible (most POSIX like systems), because it is easier to use and more reliable. Linux is the exception: it only added getentropy relatively recently. - I've left bare-metal implementations to a future patch. This because it's hard to reliably get cryptographically secure random numbers on embedded devices: most devices do not have a hardware PRNG for this purpose.
2021-06-02loader: fix testing a main packageAyke van Laethem
This was broken because multiple packages in the program were named 'main', even one that was imported (by the generated main package). This fixes tests for main packages.
2021-05-20Add support for net.IPFederico G. Schwindt
2021-05-06main: match `go test` outputAyke van Laethem
This commit makes the output of `tinygo test` similar to that of `go test`. It changes the following things in the process: * Running multiple tests in a single command is now possible. They aren't paralellized yet. * Packages with no test files won't crash TinyGo, instead it logs it in the same way the Go toolchain does.
2021-04-06cgo: add support for CFLAGS in .c filesAyke van Laethem
This patch adds support for passing CFLAGS added in #cgo lines of the CGo preprocessing phase to the compiler when compiling C files inside packages. This is expected and convenient but didn't work before.
2021-03-21builder, compiler: compile and cache packages in parallelAyke van Laethem
This commit switches from the previous behavior of compiling the whole program at once, to compiling every package in parallel and linking the LLVM bitcode files together for further whole-program optimization. This is a small performance win, but it has several advantages in the future: - There are many more things that can be done per package in parallel, avoiding the bottleneck at the end of the compiler phase. This should speed up the compiler futher. - This change is a necessary step towards a non-LTO build mode for fast incremental builds that only rebuild the changed package, when compiler speed is more important than binary size. - This change refactors the compiler in such a way that it will be easier to inspect the IR for one package only. Inspecting this IR will be very helpful for compiler developers.
2021-03-09all: use ExitCode() call to get exit code of exited processAyke van Laethem
This is an addition that landed in Go 1.12 but we couldn't use before because we were supporting Go back until Go 1.11. It simplifies the code around processes a bit.
2021-01-21loader: support imports from vendor directoriesAyke van Laethem
This fixes https://github.com/tinygo-org/tinygo/issues/1518.
2021-01-15compiler: refactor and add testsAyke van Laethem
This commit finally introduces unit tests for the compiler, to check whether input Go code is converted to the expected output IR. To make this necessary, a few refactors were needed. Hopefully these refactors (to compile a program package by package instead of all at once) will eventually become standard, so that packages can all be compiled separate from each other and be cached between compiles.
2021-01-15loader: use name "main" for the main packageAyke van Laethem
This should make exported names a bit more consistent. I believe there was a bug report for this issue, but I can't easily find it. In any case, I think it's an important improvement to match the behavior of the Go toolchain.
2020-09-29support WASI target (#1373)Takeshi Yoneda
* initial commit for WASI support * merge "time" package with wasi build tag * override syscall package with wasi build tag * create runtime_wasm_{js,wasi}.go files * create syscall_wasi.go file * create time/zoneinfo_wasi.go file as the replacement of zoneinfo_js.go * add targets/wasi.json target * set visbility hidden for runtime extern variables Accodring to the WASI docs (https://github.com/WebAssembly/WASI/blob/master/design/application-abi.md#current-unstable-abi), none of exports of WASI executable(Command) should no be accessed. v0.19.0 of bytecodealliance/wasmetime, which is often refered to as the reference implementation of WASI, does not accept any exports except functions and the only limited variables like "table", "memory". * merge syscall_{baremetal,wasi}.go * fix js target build * mv wasi functions to syscall/wasi && implement sleepTicks * WASI: set visibility hidden for globals variables * mv back syscall/wasi/* to runtime package * WASI: add test * unexport wasi types * WASI test: fix wasmtime path * stop changing visibility of runtime.alloc * use GOOS=linux, GOARCH=arm for wasi target Signed-off-by: mathetake <[email protected]> * WASI: fix build tags for os/runtime packages Signed-off-by: mathetake <[email protected]> * run WASI test only on Linux Signed-off-by: mathetake <[email protected]> * set InternalLinkage instead of changing visibility Signed-off-by: mathetake <[email protected]>
2020-09-21loader: fix linkname in test binariesAyke van Laethem
This is an issue in particular in the math package, of which most functions are defined in the runtime package.
2020-09-03loader: rewrite/refactor much of the code to use go list directlyAyke van Laethem
There were a few problems with the go/packages package. While it is more or less designed for our purpose, it didn't work quite well as it didn't provide access to indirectly imported packages (most importantly the runtime package). This led to a workaround that sometimes broke `tinygo test`. This PR contains a number of related changes: * It uses `go list` directly to retrieve the list of packages/files to compile, instead of relying on the go/packages package. * It replaces our custom TestMain replace code with the standard code for running tests (generated by `go list`). * It adds a dummy runtime/pprof package and modifies the testing package, to get tests to run again with the code generated by `go list`.
2020-08-29loader: be more robust when creating the cached GOROOTAyke van Laethem
This commit fixes two issues: * Do not try to create the cached GOROOT multiple times in parallel. This may happen in tests and is a waste of resources (and thus speed). * Check for an "access denied" error when trying to rename a directory over an existing directory. On *nix systems, this results in the expected "file exists" error. Unfortunately, Windows gives an access denied. This commit fixes the Windows behavior.
2020-08-28loader: use ioutil.TempDir to create a temporary directoryAyke van Laethem
... instead of generating one with math/rand. The problem was that math/rand is deterministic across runs, resulting in a possible race when trying to create the same directory between two processes. Additionally, because I used `os.MkdirAll`, no error was reported when the directory already existed. The solution to this is to use the stdlib function designed for this: ioutil.TempDir.
2020-08-19loader: work around Windows symlink limitationAyke van Laethem
Currently there will be a problem if the TinyGo installation directory is not the same filesystem as the cache directory (usually the C drive) and Developer Mode is disabled. Therefore, let's add another fallback for when both conditions are true, falling back to copying the file instead of symlinking/hardlinking it.
2020-07-31nintendoswitch: Add experimental Nintendo Switch support without CRTLucas Teske
Bare minimal nintendo switch support using LLD