From f0696bff800f8c810441d21ee603887162893a6b Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 11 May 2021 16:44:22 +0900 Subject: [PATCH] build: enable WAMR and LLVM builds. Signed-off-by: Takeshi Yoneda --- .github/workflows/cpp.yml | 2 +- BUILD | 7 +- bazel/external/llvm.BUILD | 115 ++++++++++++++++++++++++++++++++ bazel/external/llvm.patch | 25 +++++++ bazel/external/wamr.BUILD | 14 ++-- bazel/external/wasm-c-api.BUILD | 2 + bazel/external/wasmtime.BUILD | 1 + bazel/repositories.bzl | 10 +++ 8 files changed, 167 insertions(+), 9 deletions(-) create mode 100644 bazel/external/llvm.BUILD create mode 100644 bazel/external/llvm.patch diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index ab27b2797..20227bebb 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -60,7 +60,7 @@ jobs: strategy: matrix: # TODO(mathetake): Add other runtimes. - runtime: [ "wasmtime" ] + runtime: [ "wamr", "wasmtime" ] steps: - uses: actions/checkout@v2 diff --git a/BUILD b/BUILD index 2f760f841..bdb57d2f1 100644 --- a/BUILD +++ b/BUILD @@ -54,13 +54,12 @@ cc_library( cc_library( name = "wamr_lib", srcs = glob([ - # TODO(@mathetake): Add WAMR lib. - # "src/wamr/*.h", - # "src/wamr/*.cc", + "src/wamr/*.h", + "src/wamr/*.cc", ]), deps = [ ":common_lib", - # TODO(@mathetake): Add WAMR lib. + "@wamr//:wamr_lib", ], ) diff --git a/bazel/external/llvm.BUILD b/bazel/external/llvm.BUILD new file mode 100644 index 000000000..49de4c7f4 --- /dev/null +++ b/bazel/external/llvm.BUILD @@ -0,0 +1,115 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") + +licenses(["notice"]) # Apache 2 + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "srcs", + srcs = glob(["**"]), + visibility = ["//visibility:public"], +) + +cmake( + name = "llvm_lib", + cache_entries = { + # Disable both: BUILD and INCLUDE, since some of the INCLUDE + # targets build code instead of only generating build files. + "LLVM_BUILD_DOCS": "off", + "LLVM_INCLUDE_DOCS": "off", + "LLVM_BUILD_EXAMPLES": "off", + "LLVM_INCLUDE_EXAMPLES": "off", + "LLVM_BUILD_RUNTIME": "off", + "LLVM_BUILD_RUNTIMES": "off", + "LLVM_INCLUDE_RUNTIMES": "off", + "LLVM_BUILD_TESTS": "off", + "LLVM_INCLUDE_TESTS": "off", + "LLVM_BUILD_TOOLS": "off", + "LLVM_INCLUDE_TOOLS": "off", + "LLVM_BUILD_UTILS": "off", + "LLVM_INCLUDE_UTILS": "off", + "LLVM_ENABLE_LIBEDIT": "off", + "LLVM_ENABLE_LIBXML2": "off", + "LLVM_ENABLE_TERMINFO": "off", + "LLVM_ENABLE_ZLIB": "off", + "LLVM_TARGETS_TO_BUILD": "X86", + "CMAKE_CXX_COMPILER_FORCED": "on", + # Workaround for the issue with statically linked libstdc++ + # using -l:libstdc++.a. + "CMAKE_CXX_FLAGS": "-lstdc++", + }, + env_vars = { + # Workaround for the -DDEBUG flag added in fastbuild on macOS, + # which conflicts with DEBUG macro used in LLVM. + "CFLAGS": "-UDEBUG", + "CXXFLAGS": "-UDEBUG", + "ASMFLAGS": "-UDEBUG", + }, + lib_source = ":srcs", + static_libraries = [ + # Order from llvm-config --libnames. + "libLLVMInterpreter.a", + "libLLVMWindowsManifest.a", + "libLLVMLibDriver.a", + "libLLVMObjectYAML.a", + "libLLVMCoverage.a", + "libLLVMLineEditor.a", + "libLLVMDlltoolDriver.a", + "libLLVMOption.a", + "libLLVMTableGen.a", + "libLLVMFuzzMutate.a", + "libLLVMSymbolize.a", + "libLLVMCoroutines.a", + "libLLVMDebugInfoPDB.a", + "libLLVMLTO.a", + "libLLVMObjCARCOpts.a", + "libLLVMMIRParser.a", + "libLLVMOrcJIT.a", + "libLLVMOrcError.a", + "libLLVMJITLink.a", + "libLLVMPasses.a", + "libLLVMipo.a", + "libLLVMInstrumentation.a", + "libLLVMVectorize.a", + "libLLVMLinker.a", + "libLLVMIRReader.a", + "libLLVMAsmParser.a", + "libLLVMX86Disassembler.a", + "libLLVMX86AsmParser.a", + "libLLVMX86CodeGen.a", + "libLLVMCFGuard.a", + "libLLVMGlobalISel.a", + "libLLVMSelectionDAG.a", + "libLLVMAsmPrinter.a", + "libLLVMDebugInfoDWARF.a", + "libLLVMCodeGen.a", + "libLLVMScalarOpts.a", + "libLLVMInstCombine.a", + "libLLVMAggressiveInstCombine.a", + "libLLVMTransformUtils.a", + "libLLVMBitWriter.a", + "libLLVMX86Desc.a", + "libLLVMMCDisassembler.a", + "libLLVMX86Utils.a", + "libLLVMX86Info.a", + "libLLVMMCJIT.a", + "libLLVMExecutionEngine.a", + "libLLVMTarget.a", + "libLLVMAnalysis.a", + "libLLVMProfileData.a", + "libLLVMRuntimeDyld.a", + "libLLVMObject.a", + "libLLVMTextAPI.a", + "libLLVMMCParser.a", + "libLLVMBitReader.a", + "libLLVMMC.a", + "libLLVMDebugInfoCodeView.a", + "libLLVMDebugInfoMSF.a", + "libLLVMCore.a", + "libLLVMRemarks.a", + "libLLVMBitstreamReader.a", + "libLLVMBinaryFormat.a", + "libLLVMSupport.a", + "libLLVMDemangle.a", + ], +) diff --git a/bazel/external/llvm.patch b/bazel/external/llvm.patch new file mode 100644 index 000000000..cd02f2842 --- /dev/null +++ b/bazel/external/llvm.patch @@ -0,0 +1,25 @@ +# Workaround for Envoy's CMAKE_BUILD_TYPE=Bazel. +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -247,7 +247,7 @@ + string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) + + if (CMAKE_BUILD_TYPE AND +- NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$") ++ NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL|BAZEL)$") + message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") + endif() + +# Workaround for a missing -fuse-ld flag in CXXFLAGS, which results in +# different linkers being used during configure and compilation phases. +--- a/cmake/modules/HandleLLVMOptions.cmake ++++ b/cmake/modules/HandleLLVMOptions.cmake +@@ -718,8 +718,6 @@ endif() + if (UNIX AND CMAKE_GENERATOR STREQUAL "Ninja") + include(CheckLinkerFlag) + check_linker_flag("-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS) +- append_if(LINKER_SUPPORTS_COLOR_DIAGNOSTICS "-Wl,--color-diagnostics" +- CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) + endif() + + # Add flags for add_dead_strip(). diff --git a/bazel/external/wamr.BUILD b/bazel/external/wamr.BUILD index f1d82a061..0f03bc84d 100644 --- a/bazel/external/wamr.BUILD +++ b/bazel/external/wamr.BUILD @@ -1,7 +1,7 @@ -licenses(["notice"]) # Apache 2 - load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") +licenses(["notice"]) # Apache 2 + package(default_visibility = ["//visibility:public"]) filegroup( @@ -11,15 +11,21 @@ filegroup( ) cmake( - name = "libiwasm", + name = "wamr_lib", cache_entries = { + "LLVM_DIR": "$EXT_BUILD_DEPS/copy_llvm/llvm/lib/cmake/llvm", "WAMR_BUILD_INTERP": "1", "WAMR_BUILD_JIT": "0", "WAMR_BUILD_AOT": "0", "WAMR_BUILD_SIMD": "0", "WAMR_BUILD_MULTI_MODULE": "1", "WAMR_BUILD_LIBC_WASI": "0", + "WAMR_BUILD_TAIL_CALL": "1", }, + defines = ["WASM_WAMR"], lib_source = ":srcs", - out_shared_libs = ["libiwasm.so"], + static_libraries = ["libvmlib.a"], + deps = [ + "@llvm//:llvm_lib", + ], ) diff --git a/bazel/external/wasm-c-api.BUILD b/bazel/external/wasm-c-api.BUILD index 22cd50dac..06a7fa2f8 100644 --- a/bazel/external/wasm-c-api.BUILD +++ b/bazel/external/wasm-c-api.BUILD @@ -1,3 +1,5 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + licenses(["notice"]) # Apache 2 package(default_visibility = ["//visibility:public"]) diff --git a/bazel/external/wasmtime.BUILD b/bazel/external/wasmtime.BUILD index f6feed7e8..d8afdff3a 100644 --- a/bazel/external/wasmtime.BUILD +++ b/bazel/external/wasmtime.BUILD @@ -1,3 +1,4 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_rust//rust:rust.bzl", "rust_library") licenses(["notice"]) # Apache 2 diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index d87c8fbbd..05188e92f 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -80,3 +80,13 @@ def proxy_wasm_cpp_host_repositories(): strip_prefix = "rules_foreign_cc-0.2.0", url = "https://github.com/bazelbuild/rules_foreign_cc/archive/0.2.0.tar.gz", ) + + http_archive( + name = "llvm", + build_file = "@proxy_wasm_cpp_host//bazel/external:llvm.BUILD", + sha256 = "df83a44b3a9a71029049ec101fb0077ecbbdf5fe41e395215025779099a98fdf", + strip_prefix = "llvm-10.0.0.src", + url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/llvm-10.0.0.src.tar.xz", + patch_args = ["-p1"], + patches = ["@proxy_wasm_cpp_host//bazel/external:llvm.patch"], + )