llvm.org GIT mirror llvm / a9ce038
Teach LLVM about llgo subproject. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222860 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 6 years ago
3 changed file(s) with 58 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
602602 endif ()
603603 endfunction()
604604
605 function(llvm_add_go_executable binary pkgpath)
606 cmake_parse_arguments(ARG "ALL" "" "DEPENDS;GOFLAGS" ${ARGN})
607
608 if(LLVM_BINDINGS MATCHES "go")
609 # FIXME: This should depend only on the libraries Go needs.
610 get_property(llvmlibs GLOBAL PROPERTY LLVM_LIBS)
611 set(binpath ${CMAKE_BINARY_DIR}/bin/${binary}${CMAKE_EXECUTABLE_SUFFIX})
612 set(cc "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
613 set(cxx "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
614 set(ldflags "${CMAKE_EXE_LINKER_FLAGS}")
615 add_custom_command(OUTPUT ${binpath}
616 COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "cc=${cc}" "cxx=${cxx}" "ldflags=${ldflags}"
617 ${ARG_GOFLAGS} build -o ${binpath} ${pkgpath}
618 DEPENDS llvm-config ${CMAKE_BINARY_DIR}/bin/llvm-go${CMAKE_EXECUTABLE_SUFFIX}
619 ${llvmlibs} ${ARG_DEPENDS}
620 COMMENT "Building Go executable ${binary}"
621 VERBATIM)
622 if (ARG_ALL)
623 add_custom_target(${binary} ALL DEPENDS ${binpath})
624 else()
625 add_custom_target(${binary} DEPENDS ${binpath})
626 endif()
627 endif()
628 endfunction()
629
605630 # This function provides an automatic way to 'configure'-like generate a file
606631 # based on a set of common and custom variables, specifically targeting the
607632 # variables needed for the 'lit.site.cfg' files. This function bundles the
8080 endif()
8181
8282 add_llvm_external_project(clang)
83 add_llvm_external_project(llgo)
8384
8485 if( NOT LLVM_INCLUDE_TOOLS STREQUAL "bootstrap-only" )
8586 add_llvm_external_project(lld)
2929
3030 var packages = []pkg{
3131 {"bindings/go/llvm", "llvm.org/llvm/bindings/go/llvm"},
32 {"tools/llgo", "llvm.org/llgo"},
3233 }
3334
3435 type compilerFlags struct {
135136 `, flags.cpp, flags.cxx, flags.ld)
136137 }
137138
138 func runGoWithLLVMEnv(args []string, cc, cxx, cppflags, cxxflags, ldflags string) {
139 func runGoWithLLVMEnv(args []string, cc, cxx, llgo, cppflags, cxxflags, ldflags string) {
139140 args = addTag(args, "byollvm")
140141
141142 srcdir := llvmConfig("--src-root")
156157 if err != nil {
157158 panic(err.Error())
158159 }
160 }
161
162 newpath := os.Getenv("PATH")
163
164 if llgo != "" {
165 bindir := filepath.Join(tmpgopath, "bin")
166
167 err = os.MkdirAll(bindir, os.ModePerm)
168 if err != nil {
169 panic(err.Error())
170 }
171
172 err = os.Symlink(llgo, filepath.Join(bindir, "gccgo"))
173 if err != nil {
174 panic(err.Error())
175 }
176
177 newpathlist := []string{bindir}
178 newpathlist = append(newpathlist, filepath.SplitList(newpath)...)
179 newpath = strings.Join(newpathlist, string(filepath.ListSeparator))
180
181 args = append([]string{args[0], "-compiler", "gccgo"}, args[1:]...)
159182 }
160183
161184 newgopathlist := []string{tmpgopath}
171194 "CGO_CXXFLAGS=" + flags.cxx + " " + cxxflags,
172195 "CGO_LDFLAGS=" + flags.ld + " " + ldflags,
173196 "GOPATH=" + newgopath,
197 "PATH=" + newpath,
174198 }
175199 for _, v := range os.Environ() {
176200 if !strings.HasPrefix(v, "CC=") &&
178202 !strings.HasPrefix(v, "CGO_CPPFLAGS=") &&
179203 !strings.HasPrefix(v, "CGO_CXXFLAGS=") &&
180204 !strings.HasPrefix(v, "CGO_LDFLAGS=") &&
181 !strings.HasPrefix(v, "GOPATH=") {
205 !strings.HasPrefix(v, "GOPATH=") &&
206 !strings.HasPrefix(v, "PATH=") {
182207 newenv = append(newenv, v)
183208 }
184209 }
221246 cppflags := os.Getenv("CGO_CPPFLAGS")
222247 cxxflags := os.Getenv("CGO_CXXFLAGS")
223248 ldflags := os.Getenv("CGO_LDFLAGS")
249 llgo := ""
224250
225251 args := os.Args[1:]
226252 DONE: for {
233259 case strings.HasPrefix(args[0], "cxx="):
234260 cxx = args[0][4:]
235261 args = args[1:]
262 case strings.HasPrefix(args[0], "llgo="):
263 llgo = args[0][5:]
264 args = args[1:]
236265 case strings.HasPrefix(args[0], "cppflags="):
237266 cppflags = args[0][9:]
238267 args = args[1:]
249278
250279 switch args[0] {
251280 case "build", "get", "install", "run", "test":
252 runGoWithLLVMEnv(args, cc, cxx, cppflags, cxxflags, ldflags)
281 runGoWithLLVMEnv(args, cc, cxx, llgo, cppflags, cxxflags, ldflags)
253282 case "print-components":
254283 printComponents()
255284 case "print-config":