Skip to content

Commit 10987f2

Browse files
committed
main: use internal libclang to build C and assembly files
This avoids a dependency on the clang-7 tool for release builds.
1 parent fbc2099 commit 10987f2

9 files changed

+695
-21
lines changed

Makefile

+8-5
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,18 @@ $(error Unknown target)
4040

4141
endif
4242

43-
LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines debuginfodwarf executionengine instrumentation interpreter ipo irreader linker lto mc mcjit objcarcopts option profiledata scalaropts support target
43+
LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf executionengine instrumentation interpreter ipo irreader linker lto mc mcjit objcarcopts option profiledata scalaropts support target
4444

4545
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++
4646

4747
LLD_LIBS = -Wl,--start-group -llldCOFF -llldCommon -llldCore -llldDriver -llldELF -llldMachO -llldMinGW -llldReaderWriter -llldWasm -llldYAML -Wl,--end-group
4848

4949

5050
# For static linking.
51-
CGO_CPPFLAGS=$(shell $(LLVM_BUILDDIR)/bin/llvm-config --cppflags) -I$(abspath $(CLANG_SRC))/include -I$(abspath $(LLD_SRC))/include
51+
CGO_CPPFLAGS=$(shell $(LLVM_BUILDDIR)/bin/llvm-config --cppflags) -I$(abspath $(LLVM_BUILDDIR))/tools/clang/include -I$(abspath $(CLANG_SRC))/include -I$(abspath $(LLD_SRC))/include
5252
CGO_CXXFLAGS=-std=c++11
5353
CGO_LDFLAGS=-L$(LLVM_BUILDDIR)/lib $(CLANG_LIBS) $(LLD_LIBS) $(shell $(LLVM_BUILDDIR)/bin/llvm-config --ldflags --libs --system-libs $(LLVM_COMPONENTS))
54+
LLVM_VERSION=$(shell $(LLVM_BUILDDIR)/bin/llvm-config --version)
5455

5556

5657

@@ -116,6 +117,7 @@ static:
116117
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go build -o build/tinygo -tags byollvm .
117118

118119
release: static gen-device
120+
@rm -rf build/release
119121
@mkdir -p build/release/tinygo/bin
120122
@mkdir -p build/release/tinygo/lib/CMSIS/CMSIS
121123
@mkdir -p build/release/tinygo/lib/compiler-rt/lib
@@ -132,9 +134,10 @@ release: static gen-device
132134
@cp -rp lib/nrfx/* build/release/tinygo/lib/nrfx
133135
@cp -rp src build/release/tinygo/src
134136
@cp -rp targets build/release/tinygo/targets
135-
./build/tinygo build-builtins -target=armv6m-none-eabi -o build/release/tinygo/pkg/armv6m-none-eabi/compiler-rt.a
136-
./build/tinygo build-builtins -target=armv7m-none-eabi -o build/release/tinygo/pkg/armv7m-none-eabi/compiler-rt.a
137-
./build/tinygo build-builtins -target=armv7em-none-eabi -o build/release/tinygo/pkg/armv7em-none-eabi/compiler-rt.a
137+
@cp -rp $(abspath $(LLVM_BUILDDIR))/lib/clang/$(LLVM_VERSION) build/release/tinygo/clang
138+
./build/release/tinygo/bin/tinygo build-builtins -target=armv6m-none-eabi -o build/release/tinygo/pkg/armv6m-none-eabi/compiler-rt.a
139+
./build/release/tinygo/bin/tinygo build-builtins -target=armv7m-none-eabi -o build/release/tinygo/pkg/armv7m-none-eabi/compiler-rt.a
140+
./build/release/tinygo/bin/tinygo build-builtins -target=armv7em-none-eabi -o build/release/tinygo/pkg/armv7em-none-eabi/compiler-rt.a
138141
tar -czf build/release.tar.gz -C build/release tinygo
139142

140143
# Binary that can run on the host.

builtins.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,7 @@ func compileBuiltins(target string, callback func(path string) error) error {
235235
// Note: -fdebug-prefix-map is necessary to make the output archive
236236
// reproducible. Otherwise the temporary directory is stored in the
237237
// archive itself, which varies each run.
238-
cmd := exec.Command(commands["clang"], "-c", "-Oz", "-g", "-Werror", "-Wall", "-std=c11", "-fshort-enums", "-nostdlibinc", "-ffunction-sections", "-fdata-sections", "--target="+target, "-fdebug-prefix-map="+dir+"="+remapDir, "-o", objpath, srcpath)
239-
cmd.Stdout = os.Stdout
240-
cmd.Stderr = os.Stderr
241-
cmd.Dir = dir
242-
err = cmd.Run()
238+
err = CCompiler(sourceDir(), commands["clang"], srcpath, "-c", "-Oz", "-g", "-Werror", "-Wall", "-std=c11", "-fshort-enums", "-nostdlibinc", "-ffunction-sections", "-fdata-sections", "--target="+target, "-fdebug-prefix-map="+dir+"="+remapDir, "-o", objpath)
243239
if err != nil {
244240
return &commandError{"failed to build", srcpath, err}
245241
}

0 commit comments

Comments
 (0)