1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ load("@rules_cc//cc:defs.bzl", "cc_library")
1516load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
1617
1718licenses(["notice"]) # Apache 2
@@ -24,19 +25,46 @@ filegroup(
2425)
2526
2627cmake(
27- name = "wasmedge_lib ",
28+ name = "wasmedge_lib_cmake ",
2829 cache_entries = {
29- "WASMEDGE_USE_LLVM": "Off",
3030 "WASMEDGE_BUILD_SHARED_LIB": "Off",
3131 "WASMEDGE_BUILD_STATIC_LIB": "On",
3232 "WASMEDGE_BUILD_TOOLS": "Off",
3333 "WASMEDGE_FORCE_DISABLE_LTO": "On",
3434 # Provide spdlog and fmt as external dependencies via Bazel (not CMake FetchContent)
3535 "CMAKE_PREFIX_PATH": "$$EXT_BUILD_DEPS$$/spdlog;$$EXT_BUILD_DEPS$$/fmt",
36- },
37- env = {
38- "CXXFLAGS": "-Wno-error=dangling-reference -Wno-error=maybe-uninitialized -Wno-error=array-bounds= -Wno-error=deprecated-declarations -std=c++20",
39- },
36+ } | select({
37+ "@proxy_wasm_cpp_host//bazel:engine_wasmedge_aot": {
38+ "WASMEDGE_USE_LLVM": "On",
39+ "BAZEL_BUILD": "ON",
40+ # Set LLVM_INCLUDE_DIR for the build to use
41+ "LLVM_INCLUDE_DIR": "$$EXT_BUILD_ROOT/external/llvm_toolchain_llvm/include",
42+ },
43+ "//conditions:default": {
44+ "WASMEDGE_USE_LLVM": "Off",
45+ },
46+ }),
47+ # LLVM dependencies for AOT are provided via Bazel, not CMake
48+ # LLVM headers from hermetic toolchain (bzlmod-compatible via data attribute)
49+ # LLVM libraries are linked via cc_library deps (see wasmedge_lib below)
50+ data = select({
51+ "@proxy_wasm_cpp_host//bazel:engine_wasmedge_aot": [
52+ "@llvm_toolchain_llvm//:all_includes",
53+ ],
54+ "//conditions:default": [],
55+ }),
56+ env = select({
57+ "@proxy_wasm_cpp_host//bazel:engine_wasmedge_aot": {
58+ # Reference LLVM headers in sandbox via EXT_BUILD_ROOT
59+ # The data attribute ensures llvm_toolchain_llvm is mounted in sandbox
60+ # This path works with both WORKSPACE and bzlmod
61+ "CFLAGS": "-isystem $$EXT_BUILD_ROOT/external/llvm_toolchain_llvm/include",
62+ "CXXFLAGS": "-isystem $$EXT_BUILD_ROOT/external/llvm_toolchain_llvm/include -Wno-error=dangling-reference -Wno-error=maybe-uninitialized -Wno-error=array-bounds= -Wno-error=deprecated-declarations -std=c++20",
63+ },
64+ "//conditions:default": {
65+ "CXXFLAGS": "-Wno-error=dangling-reference -Wno-error=maybe-uninitialized -Wno-error=array-bounds= -Wno-error=deprecated-declarations -std=c++20",
66+ },
67+ }),
4068 generate_args = ["-GNinja"],
4169 lib_source = ":srcs",
4270 out_static_libs = ["libwasmedge.a"],
@@ -45,3 +73,18 @@ cmake(
4573 "@com_github_gabime_spdlog//:spdlog",
4674 ],
4775)
76+
77+ # Wrapper library that adds LLVM dependencies for linking
78+ cc_library(
79+ name = "wasmedge_lib",
80+ linkopts = select({
81+ "@proxy_wasm_cpp_host//bazel:engine_wasmedge_aot": ["-ldl"],
82+ "//conditions:default": [],
83+ }),
84+ deps = [":wasmedge_lib_cmake"] + select({
85+ "@proxy_wasm_cpp_host//bazel:engine_wasmedge_aot": [
86+ "@llvm-raw//:llvm_lib",
87+ ],
88+ "//conditions:default": [],
89+ }),
90+ )
0 commit comments