all: add static and release Makefile targets
Этот коммит содержится в:
родитель
e7ad366f20
коммит
05d2c14600
5 изменённых файлов: 152 добавлений и 12 удалений
105
BUILDING.md
Обычный файл
105
BUILDING.md
Обычный файл
|
@ -0,0 +1,105 @@
|
||||||
|
# Building TinyGo
|
||||||
|
|
||||||
|
TinyGo depends on LLVM and libclang, which are both big C++ libraries. There are
|
||||||
|
two ways these can be linked: dynamically and statically. The default is dynamic
|
||||||
|
linking because it is fast and works almost out of the box on Debian-based
|
||||||
|
systems with the right libraries installed.
|
||||||
|
|
||||||
|
This guide describes how to statically link TinyGo against LLVM and libclang so
|
||||||
|
that the binary can be easily moved between systems.
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
LLVM and Clang are both quite light on dependencies, requiring only standard
|
||||||
|
build tools to be built. Go is of course necessary to build TinyGo itself.
|
||||||
|
|
||||||
|
* Go (1.11+)
|
||||||
|
* [dep](https://golang.github.io/dep/)
|
||||||
|
* Standard build tools (gcc/clang)
|
||||||
|
* git or subversion
|
||||||
|
* CMake
|
||||||
|
* [Ninja](https://ninja-build.org/) or make (preferably Ninja)
|
||||||
|
|
||||||
|
The rest of this guide assumes you're running Linux, but it should be equivalent
|
||||||
|
on a different system like Mac.
|
||||||
|
|
||||||
|
## Download the source
|
||||||
|
|
||||||
|
The first step is to get the source code. Place it in some directory, assuming
|
||||||
|
`$HOME/src` here, but you can pick a different one of course:
|
||||||
|
|
||||||
|
git clone -b release_70 https://github.com/llvm-mirror/llvm.git $HOME/src/llvm
|
||||||
|
git clone -b release_70 https://github.com/llvm-mirror/clang.git $HOME/src/llvm/tools/clang
|
||||||
|
go get -d github.com/tinygo-org/tinygo
|
||||||
|
cd $HOME/go/src/github.com/tinygo-org/tinygo
|
||||||
|
dep ensure -vendor-only # download dependencies
|
||||||
|
|
||||||
|
Note that Clang must be placed inside the tools subdirectory of LLVM to be
|
||||||
|
automatically built with the rest of the system.
|
||||||
|
|
||||||
|
## Build LLVM and Clang
|
||||||
|
|
||||||
|
Building LLVM is quite easy compared to some other software packages. However,
|
||||||
|
the default configuration is _not_ optimized for distribution. It is optimized
|
||||||
|
for development, meaning that binaries produce accurate error messages at the
|
||||||
|
cost of huge binaries and slow compiles.
|
||||||
|
|
||||||
|
Before configuring, you may want to set the following environment variables to
|
||||||
|
speed up the build. Most Linux distributions ship with GCC as the default
|
||||||
|
compiler, but Clang is significantly faster and uses much less memory while
|
||||||
|
producing binaries that are about as fast.
|
||||||
|
|
||||||
|
export CC=clang
|
||||||
|
export CXX=clang++
|
||||||
|
|
||||||
|
Make a build directory. LLVM requires out-of-tree builds:
|
||||||
|
|
||||||
|
mkdir $HOME/src/llvm-build
|
||||||
|
cd $HOME/src/llvm-build
|
||||||
|
|
||||||
|
Configure LLVM with CMake:
|
||||||
|
|
||||||
|
cmake -G Ninja ../llvm "-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64" "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR;WebAssembly" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=OFF -DLIBCLANG_BUILD_STATIC=ON
|
||||||
|
|
||||||
|
You can also choose a different build system than Ninja, but Ninja is fast.
|
||||||
|
|
||||||
|
There are various options you can tune here, but the options given above are
|
||||||
|
preferable for releases. Here is what they do:
|
||||||
|
|
||||||
|
* `LLVM_TARGETS_TO_BUILD` and `LLVM_EXPERIMENTAL_TARGETS_TO_BUILD`: the
|
||||||
|
targets that are natively supported by the LLVM code generators. The targets
|
||||||
|
listed here are the ones supported by TinyGo. Note that LLVM is a cross
|
||||||
|
compiler by default, unlike some other compilers.
|
||||||
|
* `CMAKE_BUILD_TYPE`: the default is Debug, which produces large inefficient
|
||||||
|
binaries that are easy to debug. We want small and fast binaries.
|
||||||
|
* `LLVM_ENABLE_ASSERTIONS`: the default is ON, which greatly slows down LLVM
|
||||||
|
and is only really useful during development. Disable them here.
|
||||||
|
* `LIBCLANG_BUILD_STATIC`: unlike LLVM, libclang is built as a shared library
|
||||||
|
by default. We want a static library for easy distribution.
|
||||||
|
|
||||||
|
Now build it:
|
||||||
|
|
||||||
|
ninja # or make, if you choose make in the previous step
|
||||||
|
|
||||||
|
This can take over an hour depending on the speed of your system.
|
||||||
|
|
||||||
|
## Build TinyGo
|
||||||
|
|
||||||
|
Now that you have a working version of LLVM, build TinyGo using it. You need to
|
||||||
|
specify the directories to the LLVM build directory and to the Clang source.
|
||||||
|
|
||||||
|
cd $HOME/go/src/github.com/tinygo-org/tinygo
|
||||||
|
make static LLVM_BUILDDIR=$HOME/src/llvm-build CLANG_SRC=$HOME/src/llvm/tools/clang
|
||||||
|
|
||||||
|
## Verify TinyGo
|
||||||
|
|
||||||
|
Try running TinyGo:
|
||||||
|
|
||||||
|
./build/tinygo help
|
||||||
|
|
||||||
|
Also, make sure the `tinygo` binary really is statically linked. Check this
|
||||||
|
using `ldd`:
|
||||||
|
|
||||||
|
ldd ./build/tinygo
|
||||||
|
|
||||||
|
The result should not contain libclang or libLLVM.
|
18
Gopkg.lock
сгенерированный
18
Gopkg.lock
сгенерированный
|
@ -1,14 +1,6 @@
|
||||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||||
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
digest = "1:747e7010f73dc26e5cb298444f6f1b4442ae155ab87e44080686b94a5f9d6c90"
|
|
||||||
name = "tinygo.org/x/go-llvm"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "UT"
|
|
||||||
revision = "8a0a627130a54562f55b1c2a9d7b8019ff14d9f1"
|
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
digest = "1:84316faef4ea12d34dde3b3e6dab682715a23b1c2bb8ab82cec9ab619766e214"
|
digest = "1:84316faef4ea12d34dde3b3e6dab682715a23b1c2bb8ab82cec9ab619766e214"
|
||||||
|
@ -21,12 +13,20 @@
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "3e7aa9e59977626dc60433e9aeadf1bb63d28295"
|
revision = "3e7aa9e59977626dc60433e9aeadf1bb63d28295"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
digest = "1:3611159788efdd4e0cfae18b6ebcccbad25a2815968b0e4323b42647d201031a"
|
||||||
|
name = "tinygo.org/x/go-llvm"
|
||||||
|
packages = ["."]
|
||||||
|
pruneopts = "UT"
|
||||||
|
revision = "f420620d1a0f54417a5712260153fe861780d030"
|
||||||
|
|
||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
input-imports = [
|
input-imports = [
|
||||||
"tinygo.org/x/go-llvm",
|
|
||||||
"golang.org/x/tools/go/ssa",
|
"golang.org/x/tools/go/ssa",
|
||||||
|
"tinygo.org/x/go-llvm",
|
||||||
]
|
]
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
|
30
Makefile
30
Makefile
|
@ -3,7 +3,7 @@
|
||||||
all: tinygo
|
all: tinygo
|
||||||
tinygo: build/tinygo
|
tinygo: build/tinygo
|
||||||
|
|
||||||
.PHONY: all tinygo run-test run-blinky run-blinky2 clean fmt gen-device gen-device-nrf gen-device-avr
|
.PHONY: all tinygo static run-test run-blinky run-blinky2 clean fmt gen-device gen-device-nrf gen-device-avr
|
||||||
|
|
||||||
TARGET ?= unix
|
TARGET ?= unix
|
||||||
|
|
||||||
|
@ -40,6 +40,15 @@ $(error Unknown target)
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines debuginfodwarf executionengine instrumentation interpreter ipo irreader linker mc mcjit objcarcopts option profiledata scalaropts support target
|
||||||
|
|
||||||
|
CLANG_LIBS = -Wl,--start-group $(abspath $(LLVM_BUILDDIR))/lib/libclang.a -lclangAnalysis -lclangARCMigrate -lclangAST -lclangASTMatchers -lclangBasic -lclangCodeGen -lclangCrossTU -lclangDriver -lclangDynamicASTMatchers -lclangEdit -lclangFormat -lclangFrontend -lclangFrontendTool -lclangHandleCXX -lclangHandleLLVM -lclangIndex -lclangLex -lclangParse -lclangRewrite -lclangRewriteFrontend -lclangSema -lclangSerialization -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangStaticAnalyzerFrontend -lclangTooling -lclangToolingASTDiff -lclangToolingCore -lclangToolingInclusions -lclangToolingRefactor -Wl,--end-group -lstdc++
|
||||||
|
|
||||||
|
# For static linking.
|
||||||
|
CGO_CPPFLAGS=$(shell $(LLVM_BUILDDIR)/bin/llvm-config --cppflags) -I$(abspath $(CLANG_SRC))/include
|
||||||
|
CGO_CXXFLAGS=-std=c++11
|
||||||
|
CGO_LDFLAGS=-L$(LLVM_BUILDDIR)/lib $(CLANG_LIBS) $(shell $(LLVM_BUILDDIR)/bin/llvm-config --ldflags --libs --system-libs $(LLVM_COMPONENTS))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
run-test: build/test
|
run-test: build/test
|
||||||
|
@ -100,6 +109,25 @@ tinygo:
|
||||||
@mkdir -p build
|
@mkdir -p build
|
||||||
go build -o build/tinygo .
|
go build -o build/tinygo .
|
||||||
|
|
||||||
|
static:
|
||||||
|
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go build -o build/tinygo -tags byollvm .
|
||||||
|
|
||||||
|
release: static gen-device
|
||||||
|
@mkdir -p build/release/tinygo/bin
|
||||||
|
@mkdir -p build/release/tinygo/lib/CMSIS/CMSIS
|
||||||
|
@mkdir -p build/release/tinygo/lib/compiler-rt/lib
|
||||||
|
@mkdir -p build/release/tinygo/lib/nrfx
|
||||||
|
@cp -p build/tinygo build/release/tinygo/bin
|
||||||
|
@cp -rp lib/CMSIS/CMSIS/Include build/release/tinygo/lib/CMSIS/CMSIS
|
||||||
|
@cp -rp lib/CMSIS/README.md build/release/tinygo/lib/CMSIS
|
||||||
|
@cp -rp lib/compiler-rt/lib/builtins build/release/tinygo/lib/compiler-rt/lib
|
||||||
|
@cp -rp lib/compiler-rt/LICENSE.TXT build/release/tinygo/lib/compiler-rt
|
||||||
|
@cp -rp lib/compiler-rt/README.txt build/release/tinygo/lib/compiler-rt
|
||||||
|
@cp -rp lib/nrfx/* build/release/tinygo/lib/nrfx
|
||||||
|
@cp -rp src build/release/tinygo/src
|
||||||
|
@cp -rp targets build/release/tinygo/targets
|
||||||
|
tar -czf build/release.tar.gz -C build/release tinygo
|
||||||
|
|
||||||
# Binary that can run on the host.
|
# Binary that can run on the host.
|
||||||
build/%: src/examples/% src/examples/%/*.go build/tinygo src/runtime/*.go
|
build/%: src/examples/% src/examples/%/*.go build/tinygo src/runtime/*.go
|
||||||
./build/tinygo build $(TGOFLAGS) -size=short -o $@ $(subst src/,,$<)
|
./build/tinygo build $(TGOFLAGS) -size=short -o $@ $(subst src/,,$<)
|
||||||
|
|
|
@ -9,8 +9,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo CFLAGS: -I/usr/lib/llvm-7/include
|
|
||||||
#cgo LDFLAGS: -L/usr/lib/llvm-7/lib -lclang
|
|
||||||
#include <clang-c/Index.h> // if this fails, install libclang-7-dev
|
#include <clang-c/Index.h> // if this fails, install libclang-7-dev
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
9
loader/libclang_config.go
Обычный файл
9
loader/libclang_config.go
Обычный файл
|
@ -0,0 +1,9 @@
|
||||||
|
// +build !byollvm
|
||||||
|
|
||||||
|
package loader
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo CFLAGS: -I/usr/lib/llvm-7/include
|
||||||
|
#cgo LDFLAGS: -L/usr/lib/llvm-7/lib -lclang
|
||||||
|
*/
|
||||||
|
import "C"
|
Загрузка…
Создание таблицы
Сослаться в новой задаче