diff options
author | Ayke van Laethem <[email protected]> | 2020-04-01 23:13:16 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2021-11-04 17:15:38 +0100 |
commit | 403d93560b78a7eb6cc3bc2853d80cb7dfadc239 (patch) | |
tree | acc51a31099783f35b3ea7dbaa82a19c635de025 /builder/picolibc.go | |
parent | b344d657819827d54936c88df6c66c56331ef0b6 (diff) | |
download | tinygo-403d93560b78a7eb6cc3bc2853d80cb7dfadc239.tar.gz tinygo-403d93560b78a7eb6cc3bc2853d80cb7dfadc239.zip |
builder: build static binaries using musl on Linux
This commit adds support for musl-libc and uses it by default on Linux.
The main benefit of it is that binaries are always statically linked
instead of depending on the host libc, even when using CGo.
Advantages:
- The resulting binaries are always statically linked.
- No need for any tools on the host OS, like a compiler, linker, or
libc in a release build of TinyGo.
- This also simplifies cross compilation as no cross compiler is
needed (it's all built into the TinyGo release build).
Disadvantages:
- Binary size increases by 5-6 kilobytes if -no-debug is used. Binary
size increases by a much larger margin when debugging symbols are
included (the default behavior) because musl is built with debugging
symbols enabled.
- Musl does things a bit differently than glibc, and some CGo code
might rely on the glibc behavior.
- The first build takes a bit longer because musl needs to be built.
As an additional bonus, time is now obtained from the system in a way
that fixes the Y2038 problem because musl has been a bit more agressive
in switching to 64-bit time_t.
Diffstat (limited to 'builder/picolibc.go')
-rw-r--r-- | builder/picolibc.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/builder/picolibc.go b/builder/picolibc.go index 273c13609..75c93e91c 100644 --- a/builder/picolibc.go +++ b/builder/picolibc.go @@ -11,14 +11,14 @@ import ( // based on newlib. var Picolibc = Library{ name: "picolibc", - makeHeaders: func(includeDir string) error { + makeHeaders: func(target, includeDir string) error { f, err := os.Create(filepath.Join(includeDir, "picolibc.h")) if err != nil { return err } return f.Close() }, - cflags: func(headerPath string) []string { + cflags: func(target, headerPath string) []string { picolibcDir := filepath.Join(goenv.Get("TINYGOROOT"), "lib/picolibc/newlib/libc") return []string{ "-Werror", @@ -34,7 +34,7 @@ var Picolibc = Library{ } }, sourceDir: "lib/picolibc/newlib/libc", - sources: func(target string) []string { + librarySources: func(target string) []string { return picolibcSources }, } |