Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build support for Darwin #1

Closed
wants to merge 1 commit into from
Closed

Conversation

alitn
Copy link
Contributor

@alitn alitn commented Oct 22, 2018

This makes it possible to compile tinygo on macOS.

It assumes that llvm is installed via brew, instead of using the system provided llvm. This has the benefit of easily installing other llvm versions should tinygo requires a higher version of llvm in the future. Tinygo installation documentation should be updated for macOS to include this installation:

brew install llvm

While this PR leads to a successful build of tinygo, the compiler itself fails at runtime:

$ tinygo build -o /src/blinky.elf -target arduino /src/examples/blinky
error: No available targets are compatible with this triple.

@aykevl
Copy link
Member

aykevl commented Oct 22, 2018

What about other targets?

tinygo build -o /src/blinky.elf -target microbit /src/examples/blinky
tinygo build -o /src/wasm.wasm -target wasm /src/examples/wasm

It looks like the brew formula doesn't include the WebAssembly and AVR backends. You may want to lobby for the WebAssembly backend in Homebrew/homebrew-core#29068. An argument why it's fine to add this experimental backend: while it is experimental, that is only relevant when you actually use the backend (and experimental is better than nothing at all), and both Debian and apt.llvm.org have enabled this backend in their stable builds.

@aykevl
Copy link
Member

aykevl commented Oct 22, 2018

Also, can you show me the diff of llvm_config.go after running make config? It may be possible to share the same config for both Linux and Darwin, if it's only include directories (and perhaps libffi, I wonder why that must be specified manually?). That would avoid the need for the make config step on Darwin making installation easier.

@aykevl aykevl mentioned this pull request Oct 22, 2018
@alitn
Copy link
Contributor Author

alitn commented Oct 22, 2018

I get same error for wasm target, for microbit the error is different due to no code being present in device/nrf package after go get.

Looks like wasm backend will be out of experimental in llvm 8. Until then, one option is to provide a third party repo.

Here is the diff for llvm_config.go:

// Automatically generated by `make config BUILDDIR=`, do not edit.
 
-// #cgo CPPFLAGS: -I/usr/lib/llvm-7/include   -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
+// #cgo CPPFLAGS: -I/usr/local/Cellar/llvm/7.0.0/include   -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
 // #cgo CXXFLAGS: -std=c++11
-// #cgo LDFLAGS: -L/usr/lib/llvm-7/lib  -lLLVM-7
+// #cgo LDFLAGS: -L/usr/local/Cellar/llvm/7.0.0/lib -Wl,-search_paths_first -Wl,-headerpad_max_install_names -lLLVMOption -lLLVMObjCARCOpts -lLLVMMCJIT -lLLVMInterpreter -lLLVMExecutionEngine -lLLVMRuntimeDyld -lLLVMDebugInfoDWARF -lLLVMCoroutines -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreInfo -lLLVMXCoreAsmPrinter -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMSystemZDisassembler -lLLVMSystemZCodeGen -lLLVMSystemZAsmParser -lLLVMSystemZDesc -lLLVMSystemZInfo -lLLVMSystemZAsmPrinter -lLLVMSparcDisassembler -lLLVMSparcCodeGen -lLLVMSparcAsmParser -lLLVMSparcDesc -lLLVMSparcInfo -lLLVMSparcAsmPrinter -lLLVMPowerPCDisassembler -lLLVMPowerPCCodeGen -lLLVMPowerPCAsmParser -lLLVMPowerPCDesc -lLLVMPowerPCInfo -lLLVMPowerPCAsmPrinter -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMNVPTXAsmPrinter -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMMSP430AsmPrinter -lLLVMMipsDisassembler -lLLVMMipsCodeGen -lLLVMMipsAsmParser -lLLVMMipsDesc -lLLVMMipsInfo -lLLVMMipsAsmPrinter -lLLVMLanaiDisassembler -lLLVMLanaiCodeGen -lLLVMLanaiAsmParser -lLLVMLanaiDesc -lLLVMLanaiAsmPrinter -lLLVMLanaiInfo -lLLVMHexagonDisassembler -lLLVMHexagonCodeGen -lLLVMHexagonAsmParser -lLLVMHexagonDesc -lLLVMHexagonInfo -lLLVMBPFDisassembler -lLLVMBPFCodeGen -lLLVMBPFAsmParser -lLLVMBPFDesc -lLLVMBPFInfo -lLLVMBPFAsmPrinter -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMARMAsmParser -lLLVMARMDesc -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMARMUtils -lLLVMAMDGPUDisassembler -lLLVMAMDGPUCodeGen -lLLVMipo -lLLVMInstrumentation -lLLVMVectorize -lLLVMLinker -lLLVMIRReader -lLLVMAsmParser -lLLVMAMDGPUAsmParser -lLLVMAMDGPUDesc -lLLVMAMDGPUInfo -lLLVMAMDGPUAsmPrinter -lLLVMAMDGPUUtils -lLLVMAArch64Disassembler -lLLVMMCDisassembler -lLLVMAArch64CodeGen -lLLVMGlobalISel -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMCodeGen -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMAggressiveInstCombine -lLLVMTransformUtils -lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMBitReader -lLLVMCore -lLLVMAArch64AsmParser -lLLVMMCParser -lLLVMAArch64Desc -lLLVMAArch64Info -lLLVMAArch64AsmPrinter -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMDebugInfoMSF -lLLVMBinaryFormat -lLLVMAArch64Utils -lLLVMSupport -lLLVMDemangle -lz -lcurses -lm -lxml2 -L/usr/local/opt/libffi/lib -lffi
 import "C"
 
 type (run_build_sh int)

@aykevl
Copy link
Member

aykevl commented Oct 27, 2018

Merged in f861638. Thank you for the work! However, I made a small change to avoid a whitespace difference in the generated llvm_config.go on Linux.

Maybe it would be best to generate llvm_config_$GOOS.go files so that it would work transparently on both Linux/Debian and OS X. You can use go env GOOS for that, if you want to look into it.

@aykevl aykevl closed this Oct 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants