forked from OSchip/llvm-project
parent
bf6952c87a
commit
a4f0bd7857
|
@ -603,6 +603,31 @@ function(add_unittest test_suite test_name)
|
|||
endif ()
|
||||
endfunction()
|
||||
|
||||
function(llvm_add_go_executable binary pkgpath)
|
||||
cmake_parse_arguments(ARG "ALL" "" "DEPENDS;GOFLAGS" ${ARGN})
|
||||
|
||||
if(LLVM_BINDINGS MATCHES "go")
|
||||
# FIXME: This should depend only on the libraries Go needs.
|
||||
get_property(llvmlibs GLOBAL PROPERTY LLVM_LIBS)
|
||||
set(binpath ${CMAKE_BINARY_DIR}/bin/${binary}${CMAKE_EXECUTABLE_SUFFIX})
|
||||
set(cc "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
|
||||
set(cxx "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
|
||||
set(ldflags "${CMAKE_EXE_LINKER_FLAGS}")
|
||||
add_custom_command(OUTPUT ${binpath}
|
||||
COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "cc=${cc}" "cxx=${cxx}" "ldflags=${ldflags}"
|
||||
${ARG_GOFLAGS} build -o ${binpath} ${pkgpath}
|
||||
DEPENDS llvm-config ${CMAKE_BINARY_DIR}/bin/llvm-go${CMAKE_EXECUTABLE_SUFFIX}
|
||||
${llvmlibs} ${ARG_DEPENDS}
|
||||
COMMENT "Building Go executable ${binary}"
|
||||
VERBATIM)
|
||||
if (ARG_ALL)
|
||||
add_custom_target(${binary} ALL DEPENDS ${binpath})
|
||||
else()
|
||||
add_custom_target(${binary} DEPENDS ${binpath})
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# This function provides an automatic way to 'configure'-like generate a file
|
||||
# based on a set of common and custom variables, specifically targeting the
|
||||
# variables needed for the 'lit.site.cfg' files. This function bundles the
|
||||
|
|
|
@ -81,6 +81,7 @@ else()
|
|||
endif()
|
||||
|
||||
add_llvm_external_project(clang)
|
||||
add_llvm_external_project(llgo)
|
||||
|
||||
if( NOT LLVM_INCLUDE_TOOLS STREQUAL "bootstrap-only" )
|
||||
add_llvm_external_project(lld)
|
||||
|
|
|
@ -30,6 +30,7 @@ type pkg struct {
|
|||
|
||||
var packages = []pkg{
|
||||
{"bindings/go/llvm", "llvm.org/llvm/bindings/go/llvm"},
|
||||
{"tools/llgo", "llvm.org/llgo"},
|
||||
}
|
||||
|
||||
type compilerFlags struct {
|
||||
|
@ -136,7 +137,7 @@ type (run_build_sh int)
|
|||
`, flags.cpp, flags.cxx, flags.ld)
|
||||
}
|
||||
|
||||
func runGoWithLLVMEnv(args []string, cc, cxx, cppflags, cxxflags, ldflags string) {
|
||||
func runGoWithLLVMEnv(args []string, cc, cxx, llgo, cppflags, cxxflags, ldflags string) {
|
||||
args = addTag(args, "byollvm")
|
||||
|
||||
srcdir := llvmConfig("--src-root")
|
||||
|
@ -159,6 +160,28 @@ func runGoWithLLVMEnv(args []string, cc, cxx, cppflags, cxxflags, ldflags string
|
|||
}
|
||||
}
|
||||
|
||||
newpath := os.Getenv("PATH")
|
||||
|
||||
if llgo != "" {
|
||||
bindir := filepath.Join(tmpgopath, "bin")
|
||||
|
||||
err = os.MkdirAll(bindir, os.ModePerm)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
err = os.Symlink(llgo, filepath.Join(bindir, "gccgo"))
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
newpathlist := []string{bindir}
|
||||
newpathlist = append(newpathlist, filepath.SplitList(newpath)...)
|
||||
newpath = strings.Join(newpathlist, string(filepath.ListSeparator))
|
||||
|
||||
args = append([]string{args[0], "-compiler", "gccgo"}, args[1:]...)
|
||||
}
|
||||
|
||||
newgopathlist := []string{tmpgopath}
|
||||
newgopathlist = append(newgopathlist, filepath.SplitList(os.Getenv("GOPATH"))...)
|
||||
newgopath := strings.Join(newgopathlist, string(filepath.ListSeparator))
|
||||
|
@ -172,6 +195,7 @@ func runGoWithLLVMEnv(args []string, cc, cxx, cppflags, cxxflags, ldflags string
|
|||
"CGO_CXXFLAGS=" + flags.cxx + " " + cxxflags,
|
||||
"CGO_LDFLAGS=" + flags.ld + " " + ldflags,
|
||||
"GOPATH=" + newgopath,
|
||||
"PATH=" + newpath,
|
||||
}
|
||||
for _, v := range os.Environ() {
|
||||
if !strings.HasPrefix(v, "CC=") &&
|
||||
|
@ -179,7 +203,8 @@ func runGoWithLLVMEnv(args []string, cc, cxx, cppflags, cxxflags, ldflags string
|
|||
!strings.HasPrefix(v, "CGO_CPPFLAGS=") &&
|
||||
!strings.HasPrefix(v, "CGO_CXXFLAGS=") &&
|
||||
!strings.HasPrefix(v, "CGO_LDFLAGS=") &&
|
||||
!strings.HasPrefix(v, "GOPATH=") {
|
||||
!strings.HasPrefix(v, "GOPATH=") &&
|
||||
!strings.HasPrefix(v, "PATH=") {
|
||||
newenv = append(newenv, v)
|
||||
}
|
||||
}
|
||||
|
@ -222,6 +247,7 @@ func main() {
|
|||
cppflags := os.Getenv("CGO_CPPFLAGS")
|
||||
cxxflags := os.Getenv("CGO_CXXFLAGS")
|
||||
ldflags := os.Getenv("CGO_LDFLAGS")
|
||||
llgo := ""
|
||||
|
||||
args := os.Args[1:]
|
||||
DONE: for {
|
||||
|
@ -234,6 +260,9 @@ func main() {
|
|||
case strings.HasPrefix(args[0], "cxx="):
|
||||
cxx = args[0][4:]
|
||||
args = args[1:]
|
||||
case strings.HasPrefix(args[0], "llgo="):
|
||||
llgo = args[0][5:]
|
||||
args = args[1:]
|
||||
case strings.HasPrefix(args[0], "cppflags="):
|
||||
cppflags = args[0][9:]
|
||||
args = args[1:]
|
||||
|
@ -250,7 +279,7 @@ func main() {
|
|||
|
||||
switch args[0] {
|
||||
case "build", "get", "install", "run", "test":
|
||||
runGoWithLLVMEnv(args, cc, cxx, cppflags, cxxflags, ldflags)
|
||||
runGoWithLLVMEnv(args, cc, cxx, llgo, cppflags, cxxflags, ldflags)
|
||||
case "print-components":
|
||||
printComponents()
|
||||
case "print-config":
|
||||
|
|
Loading…
Reference in New Issue