aboutsummaryrefslogtreecommitdiffhomepage
path: root/builder/tools-builtin.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-11-10 17:58:38 +0100
committerRon Evans <[email protected]>2022-02-12 15:33:06 +0100
commitcdd267fa10370e294480fa203af1fc1cd91b47fa (patch)
tree4cad9d00bc605486537762249a1ec7cdbd262881 /builder/tools-builtin.go
parent850a5fdbfb00f1bdfe930bd41013d0404f75e248 (diff)
downloadtinygo-cdd267fa10370e294480fa203af1fc1cd91b47fa.tar.gz
tinygo-cdd267fa10370e294480fa203af1fc1cd91b47fa.zip
builder: add support for cross compiling to Darwin
This means that it will be possible to generate a Darwin binary on any platform (Windows, Linux, and MacOS of course), including CGo. Of course, the resulting binaries can only run on MacOS itself. The binary links against libSystem.dylib, which is a shared library. The macos-minimal-sdk repository contains open source header files and generated symbol stubs so we can generate a stub libSystem.dylib without copying any closed source code.
Diffstat (limited to 'builder/tools-builtin.go')
-rw-r--r--builder/tools-builtin.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/builder/tools-builtin.go b/builder/tools-builtin.go
index e5ecd424c..5474e3e5e 100644
--- a/builder/tools-builtin.go
+++ b/builder/tools-builtin.go
@@ -14,6 +14,7 @@ import (
#include <stdlib.h>
bool tinygo_clang_driver(int argc, char **argv);
bool tinygo_link_elf(int argc, char **argv);
+bool tinygo_link_macho(int argc, char **argv);
bool tinygo_link_mingw(int argc, char **argv);
bool tinygo_link_wasm(int argc, char **argv);
*/
@@ -27,8 +28,13 @@ const hasBuiltinTools = true
// linking statically with LLVM (with the byollvm build tag).
func RunTool(tool string, args ...string) error {
linker := "elf"
- if tool == "ld.lld" && len(args) >= 2 && args[0] == "-m" && args[1] == "i386pep" {
- linker = "mingw"
+ if tool == "ld.lld" && len(args) >= 2 {
+ if args[0] == "-m" && args[1] == "i386pep" {
+ linker = "mingw"
+ } else if args[0] == "-flavor" {
+ linker = args[1]
+ args = args[2:]
+ }
}
args = append([]string{"tinygo:" + tool}, args...)
@@ -48,6 +54,8 @@ func RunTool(tool string, args ...string) error {
ok = C.tinygo_clang_driver(C.int(len(args)), (**C.char)(buf))
case "ld.lld":
switch linker {
+ case "darwinnew":
+ ok = C.tinygo_link_macho(C.int(len(args)), (**C.char)(buf))
case "elf":
ok = C.tinygo_link_elf(C.int(len(args)), (**C.char)(buf))
case "mingw":