I tried to compile TVM with bazel, but block in src/target/llvm. Here is my TVM bazel BUILD file
cc_library(
name = "llvm_compiler",
srcs = glob([
"src/target/llvm/*.cc",
]),
hdrs = glob([
"src/target/llvm/*.h",
"src/target/*.h",
]),
deps = [
"//3rdparty/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-16.04:llvm",
":compiler_hdrs",
":runtime_hdrs",
":arith_hdrs",
":implicit_hdrs",
":tir_hdrs",
],
copts = [
"-DTVM_LLVM_VERSION=90",
"-O0",
],
# alwayslink = True,
linkstatic = True,
visibility = ["//visibility:public"])
And I add this file into clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.gz which download from web
cc_library(
name = "llvm",
srcs = glob([
"lib/libLLVMXRay.a",
"lib/libLLVMWindowsManifest.a",
"lib/libLLVMTextAPI.a",
"lib/libLLVMTableGen.a",
"lib/libLLVMSymbolize.a",
"lib/libLLVMDebugInfoPDB.a",
"lib/libLLVMOrcJIT.a",
"lib/libLLVMJITLink.a",
"lib/libLLVMObjectYAML.a",
"lib/libLLVMMCA.a",
"lib/libLLVMLTO.a",
"lib/libLLVMPasses.a",
"lib/libLLVMObjCARCOpts.a",
"lib/libLLVMLineEditor.a",
"lib/libLLVMLibDriver.a",
"lib/libLLVMInterpreter.a",
"lib/libLLVMFuzzMutate.a",
"lib/libLLVMMCJIT.a",
"lib/libLLVMExecutionEngine.a",
"lib/libLLVMRuntimeDyld.a",
"lib/libLLVMDlltoolDriver.a",
"lib/libLLVMOption.a",
"lib/libLLVMDebugInfoGSYM.a",
"lib/libLLVMCoverage.a",
"lib/libLLVMCoroutines.a",
"lib/libLLVMXCoreDisassembler.a",
"lib/libLLVMXCoreCodeGen.a",
"lib/libLLVMXCoreDesc.a",
"lib/libLLVMXCoreInfo.a",
"lib/libLLVMX86Disassembler.a",
"lib/libLLVMX86AsmParser.a",
"lib/libLLVMX86CodeGen.a",
"lib/libLLVMX86Desc.a",
"lib/libLLVMX86Utils.a",
"lib/libLLVMX86Info.a",
"lib/libLLVMWebAssemblyDisassembler.a",
"lib/libLLVMWebAssemblyCodeGen.a",
"lib/libLLVMWebAssemblyDesc.a",
"lib/libLLVMWebAssemblyAsmParser.a",
"lib/libLLVMWebAssemblyInfo.a",
"lib/libLLVMSystemZDisassembler.a",
"lib/libLLVMSystemZCodeGen.a",
"lib/libLLVMSystemZAsmParser.a",
"lib/libLLVMSystemZDesc.a",
"lib/libLLVMSystemZInfo.a",
"lib/libLLVMSparcDisassembler.a",
"lib/libLLVMSparcCodeGen.a",
"lib/libLLVMSparcAsmParser.a",
"lib/libLLVMSparcDesc.a",
"lib/libLLVMSparcInfo.a",
"lib/libLLVMRISCVDisassembler.a",
"lib/libLLVMRISCVCodeGen.a",
"lib/libLLVMRISCVAsmParser.a",
"lib/libLLVMRISCVDesc.a",
"lib/libLLVMRISCVUtils.a",
"lib/libLLVMRISCVInfo.a",
"lib/libLLVMPowerPCDisassembler.a",
"lib/libLLVMPowerPCCodeGen.a",
"lib/libLLVMPowerPCAsmParser.a",
"lib/libLLVMPowerPCDesc.a",
"lib/libLLVMPowerPCInfo.a",
"lib/libLLVMNVPTXCodeGen.a",
"lib/libLLVMNVPTXDesc.a",
"lib/libLLVMNVPTXInfo.a",
"lib/libLLVMMSP430Disassembler.a",
"lib/libLLVMMSP430CodeGen.a",
"lib/libLLVMMSP430AsmParser.a",
"lib/libLLVMMSP430Desc.a",
"lib/libLLVMMSP430Info.a",
"lib/libLLVMMipsDisassembler.a",
"lib/libLLVMMipsCodeGen.a",
"lib/libLLVMMipsAsmParser.a",
"lib/libLLVMMipsDesc.a",
"lib/libLLVMMipsInfo.a",
"lib/libLLVMLanaiDisassembler.a",
"lib/libLLVMLanaiCodeGen.a",
"lib/libLLVMLanaiAsmParser.a",
"lib/libLLVMLanaiDesc.a",
"lib/libLLVMLanaiInfo.a",
"lib/libLLVMHexagonDisassembler.a",
"lib/libLLVMHexagonCodeGen.a",
"lib/libLLVMHexagonAsmParser.a",
"lib/libLLVMHexagonDesc.a",
"lib/libLLVMHexagonInfo.a",
"lib/libLLVMBPFDisassembler.a",
"lib/libLLVMBPFCodeGen.a",
"lib/libLLVMBPFAsmParser.a",
"lib/libLLVMBPFDesc.a",
"lib/libLLVMBPFInfo.a",
"lib/libLLVMARMDisassembler.a",
"lib/libLLVMARMCodeGen.a",
"lib/libLLVMARMAsmParser.a",
"lib/libLLVMARMDesc.a",
"lib/libLLVMARMUtils.a",
"lib/libLLVMARMInfo.a",
"lib/libLLVMAMDGPUDisassembler.a",
"lib/libLLVMAMDGPUCodeGen.a",
"lib/libLLVMMIRParser.a",
"lib/libLLVMipo.a",
"lib/libLLVMInstrumentation.a",
"lib/libLLVMVectorize.a",
"lib/libLLVMLinker.a",
"lib/libLLVMIRReader.a",
"lib/libLLVMAsmParser.a",
"lib/libLLVMAMDGPUAsmParser.a",
"lib/libLLVMAMDGPUDesc.a",
"lib/libLLVMAMDGPUUtils.a",
"lib/libLLVMAMDGPUInfo.a",
"lib/libLLVMAArch64Disassembler.a",
"lib/libLLVMMCDisassembler.a",
"lib/libLLVMAArch64CodeGen.a",
"lib/libLLVMGlobalISel.a",
"lib/libLLVMSelectionDAG.a",
"lib/libLLVMAsmPrinter.a",
"lib/libLLVMDebugInfoDWARF.a",
"lib/libLLVMCodeGen.a",
"lib/libLLVMTarget.a",
"lib/libLLVMScalarOpts.a",
"lib/libLLVMInstCombine.a",
"lib/libLLVMAggressiveInstCombine.a",
"lib/libLLVMTransformUtils.a",
"lib/libLLVMBitWriter.a",
"lib/libLLVMAnalysis.a",
"lib/libLLVMProfileData.a",
"lib/libLLVMObject.a",
"lib/libLLVMBitReader.a",
"lib/libLLVMBitstreamReader.a",
"lib/libLLVMCore.a",
"lib/libLLVMRemarks.a",
"lib/libLLVMAArch64AsmParser.a",
"lib/libLLVMMCParser.a",
"lib/libLLVMAArch64Desc.a",
"lib/libLLVMMC.a",
"lib/libLLVMDebugInfoCodeView.a",
"lib/libLLVMDebugInfoMSF.a",
"lib/libLLVMBinaryFormat.a",
"lib/libLLVMAArch64Utils.a",
"lib/libLLVMAArch64Info.a",
"lib/libLLVMSupport.a",
"lib/libLLVMDemangle.a",
]),
hdrs = glob([
"include/**/*.h",
"include/**/*.def",
"include/**/*.inc",
]),
strip_include_prefix = "include",
includes = ["include"], # 添加包含目录,这样在源文件中就可以直接引用头文件
copts = [
"-lz",
"-lrt",
"-ldl",
"-ltinfo",
"-lpthread",
"-lm",
"-lxml2",
"-D_GNU_SOURCE",
"-D__STDC_CONSTANT_MACROS",
"-D__STDC_FORMAT_MACROS",
"-D__STDC_LIMIT_MACROS",
"-DDMLC_USE_FOPEN64=0",
],
visibility = ["//visibility:public"],
)
When I run this libtvm.so, it complain that:
TVMError: Check failed: bf != nullptr: target.build.llvm is not enabled
So I change llvm_compiler as alwayslink=true, but it complain
OSError: lib/libtvm.so: undefined symbol: _ZTIN4llvm6legacy11PassManagerE
And I tried this thread: Building LLVM with Bazel, with code : https://github.com/dgp1130/llvm-bazel-foolang, but the error reported is same.
Everything works fine on CMake, I don't know what's different with Bazel. And actually, I only hope "TVM_REGISTER_GLOBAL("target.build.llvm")" not delelte by gcc.
Thanks!