mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-31 17:59:03 +00:00
a213d9ae46
* GNUmakefile: split into topic files in make/ The GNUmakefile had 1295 lines and mixed build configuration, LLVM bootstrapping, device generation, four test suites, the smoke tests, release packaging, and lint tools. The smoke tests alone were 500 lines. Move each part into its own file in make/ and include them from GNUmakefile. config.mk must be included first because the other files use its variables in immediate assignments and conditionals. There is no change in behavior. The parsed make database is identical for the default build and for ASSERT=1, STATIC=1, XTENSA=0, STM32=0, WASM=0, and CROSS=aarch64-linux-gnu, except for MAKEFILE_LIST and the .PHONY list, which now also includes targets that were phony but not declared. The Dockerfile copies GNUmakefile alone before it builds LLVM, to keep that layer independent of the source tree. It must copy make/ too. * make/smoketest.mk: split into groups and add smoketest-quick The smoke test was one recipe of about 500 lines with 236 builds that always ran in sequence. Split it at the group boundaries that were already there, so that: - `make -j smoketest` builds the groups in parallel. A full run goes from 325 to 91 seconds on a 32 core machine. - CI can shard the groups across runners. Each group writes to its own name in build/smoke/, because all builds wrote to test.hex before and would overwrite each other in a parallel build. The output extension selects the format, so it stays per line. Add smoketest-quick, which builds one board for each processor architecture. The full smoke test answers "can TinyGo build for every board", which does not depend on the host OS, so it only needs to run on one OS. The other jobs use smoketest-quick. The comment above the esp32c3 group had 4 spaces of indentation instead of a tab. That was harmless in the middle of a recipe, but it is now the first line of a group, where it would stop the recipe from starting. The set of build commands is unchanged for the default flags and for XTENSA=0, STM32=0, and WASM=0. All 226 checksums are the same as before, for a sequential build and for `make -j16`. * ci: run the full smoke test once, on Linux only The smoke test ran six times for each push: twice on Linux, twice on macOS, once on Windows, and once in the compatibility test. Together that was about 97 minutes of the CI time. The smoke test checks that TinyGo can build a binary for each board. That does not depend on the host OS. The only part that does is one build behind a Windows check. Add a smoketest-linux job that runs the full set, split across four runners that use the tarball from the build-linux job. The groups are balanced with the measured build time of each group. Remove the full smoke test from test-linux-build, which the new job replaces, and use smoketest-quick for the other four jobs. Expected result: about 55 to 39 minutes for the slowest workflow, and about 97 to 35 minutes of total smoke test time. * make/smoketest.mk: build nintendoswitch in smoketest-quick It is the only target that uses the aarch64 LLVM triple. With it, smoketest-quick covers all 13 triples that the full smoke test uses.
99 lines
5.1 KiB
Makefile
99 lines
5.1 KiB
Makefile
# LLVM and Binaryen: component lists, link flags, source checkout, and build.
|
|
|
|
.PHONY: llvm-source $(LLVM_BUILDDIR)
|
|
|
|
LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf debuginfopdb dtlto executionengine frontenddriver frontendhlsl frontendopenmp instrumentation interpreter ipo irreader libdriver linker lto mc mcjit objcarcopts option profiledata scalaropts support target windowsdriver windowsmanifest
|
|
|
|
ifeq ($(OS),Windows_NT)
|
|
EXE = .exe
|
|
START_GROUP = -Wl,--start-group
|
|
END_GROUP = -Wl,--end-group
|
|
|
|
# PIC needs to be disabled for libclang to work.
|
|
LLVM_OPTION += -DLLVM_ENABLE_PIC=OFF
|
|
# Statically link the C++ and GCC runtime into LLVM tools so they don't
|
|
# depend on MinGW DLLs that may not be on PATH when executed during the build.
|
|
LLVM_OPTION += '-DCMAKE_EXE_LINKER_FLAGS=-static-libgcc -static-libstdc++'
|
|
|
|
CGO_CPPFLAGS += -DCINDEX_NO_EXPORTS
|
|
CGO_LDFLAGS += -static -static-libgcc -static-libstdc++
|
|
CGO_LDFLAGS_EXTRA += -lversion
|
|
|
|
USE_SYSTEM_BINARYEN ?= 1
|
|
|
|
else ifeq ($(uname),Darwin)
|
|
MD5SUM ?= md5
|
|
|
|
CGO_LDFLAGS += -lxar
|
|
|
|
USE_SYSTEM_BINARYEN ?= 1
|
|
|
|
else ifeq ($(uname),FreeBSD)
|
|
MD5SUM ?= md5
|
|
START_GROUP = -Wl,--start-group
|
|
END_GROUP = -Wl,--end-group
|
|
else
|
|
START_GROUP = -Wl,--start-group
|
|
END_GROUP = -Wl,--end-group
|
|
endif
|
|
|
|
# md5sum binary default, can be overridden by an environment variable
|
|
MD5SUM ?= md5sum
|
|
|
|
# Libraries that should be linked in for the statically linked Clang.
|
|
CLANG_LIB_NAMES = clangAnalysis clangAnalysisLifetimeSafety clangAPINotes clangAST clangASTMatchers clangBasic clangCodeGen clangCrossTU clangDriver clangDynamicASTMatchers clangEdit clangExtractAPI clangFormat clangFrontend clangFrontendTool clangHandleCXX clangHandleLLVM clangIndex clangInstallAPI clangLex clangOptions clangParse clangRewrite clangRewriteFrontend clangSema clangSerialization clangSupport clangTooling clangToolingASTDiff clangToolingCore clangToolingInclusions
|
|
CLANG_LIBS = $(START_GROUP) $(addprefix -l,$(CLANG_LIB_NAMES)) $(END_GROUP) -lstdc++
|
|
|
|
# Libraries that should be linked in for the statically linked LLD.
|
|
LLD_LIB_NAMES = lldCOFF lldCommon lldELF lldMachO lldMinGW lldWasm
|
|
LLD_LIBS = $(START_GROUP) $(addprefix -l,$(LLD_LIB_NAMES)) $(END_GROUP)
|
|
|
|
# Other libraries that are needed to link TinyGo.
|
|
EXTRA_LIB_NAMES = LLVMDTLTO LLVMInterpreter LLVMMCA LLVMRISCVTargetMCA LLVMX86TargetMCA
|
|
|
|
# All libraries to be built and linked with the tinygo binary (lib/lib*.a).
|
|
LIB_NAMES = clang $(CLANG_LIB_NAMES) $(LLD_LIB_NAMES) $(EXTRA_LIB_NAMES)
|
|
|
|
# These build targets appear to be the only ones necessary to build all TinyGo
|
|
# dependencies. Only building a subset significantly speeds up rebuilding LLVM.
|
|
# The Makefile rules convert a name like lldELF to lib/liblldELF.a to match the
|
|
# library path (for ninja).
|
|
# This list also includes a few tools that are necessary as part of the full
|
|
# TinyGo build.
|
|
NINJA_BUILD_TARGETS = clang llvm-config llvm-ar llvm-nm lld $(addprefix lib/lib,$(addsuffix .a,$(LIB_NAMES)))
|
|
|
|
# For static linking.
|
|
ifneq ("$(wildcard $(LLVM_BUILDDIR)/bin/llvm-config*)","")
|
|
CGO_CPPFLAGS+=$(shell $(LLVM_CONFIG_PREFIX) $(LLVM_BUILDDIR)/bin/llvm-config --cppflags) -I$(abspath $(LLVM_BUILDDIR))/tools/clang/include -I$(abspath $(CLANG_SRC))/include -I$(abspath $(LLD_SRC))/include
|
|
CGO_CXXFLAGS=-std=c++17
|
|
ifneq ($(uname),Windows_NT)
|
|
# Disable GCC DWARF compression: lld built without zlib cannot link
|
|
# object files with ELFCOMPRESS_ZLIB debug sections.
|
|
CGO_CFLAGS+=-gz=none
|
|
CGO_CXXFLAGS+=-gz=none
|
|
endif
|
|
CGO_LDFLAGS+=-L$(abspath $(LLVM_BUILDDIR)/lib) -lclang $(CLANG_LIBS) $(LLD_LIBS) $(shell $(LLVM_CONFIG_PREFIX) $(LLVM_BUILDDIR)/bin/llvm-config --ldflags --libs --system-libs $(LLVM_COMPONENTS)) -lstdc++ $(CGO_LDFLAGS_EXTRA)
|
|
endif
|
|
|
|
$(LLVM_PROJECTDIR)/llvm:
|
|
git clone -b tinygo_22.x --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR)
|
|
llvm-source: $(LLVM_PROJECTDIR)/llvm ## Get LLVM sources
|
|
|
|
# Configure LLVM.
|
|
TINYGO_SOURCE_DIR=$(shell pwd)
|
|
$(LLVM_BUILDDIR)/build.ninja:
|
|
mkdir -p $(LLVM_BUILDDIR) && cd $(LLVM_BUILDDIR) && cmake -G Ninja $(TINYGO_SOURCE_DIR)/$(LLVM_PROJECTDIR)/llvm "-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64;AVR;Mips;RISCV;WebAssembly" "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=Xtensa" -DCMAKE_BUILD_TYPE=Release -DLIBCLANG_BUILD_STATIC=ON -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_ZSTD=OFF -DLLVM_ENABLE_LIBEDIT=OFF -DLLVM_ENABLE_Z3_SOLVER=OFF -DLLVM_ENABLE_OCAMLDOC=OFF -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=OFF -DCLANG_ENABLE_STATIC_ANALYZER=OFF -DCLANG_ENABLE_ARCMT=OFF $(LLVM_OPTION)
|
|
|
|
$(LLVM_BUILDDIR): $(LLVM_BUILDDIR)/build.ninja ## Build LLVM
|
|
cd $(LLVM_BUILDDIR) && ninja $(NINJA_BUILD_TARGETS)
|
|
|
|
ifneq ($(USE_SYSTEM_BINARYEN),1)
|
|
# Build Binaryen
|
|
.PHONY: binaryen
|
|
binaryen: build/wasm-opt$(EXE)
|
|
build/wasm-opt$(EXE):
|
|
mkdir -p build
|
|
cd lib/binaryen && cmake -G Ninja . -DBUILD_STATIC_LIB=ON -DBUILD_TESTS=OFF -DENABLE_WERROR=OFF $(BINARYEN_OPTION) && ninja bin/wasm-opt$(EXE)
|
|
cp lib/binaryen/bin/wasm-opt$(EXE) build/wasm-opt$(EXE)
|
|
endif
|