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,7 +25,35 @@ filegroup(
2425)
2526
2627cmake(
27- name = "wamr_lib",
28+ name = "wamr_lib_cmake",
29+ cache_entries = select({
30+ "@proxy_wasm_cpp_host//bazel:engine_wamr_jit": {
31+ "BAZEL_BUILD": "ON",
32+ # Set LLVM_INCLUDE_DIR for the patch to use
33+ "LLVM_INCLUDE_DIR": "$$EXT_BUILD_ROOT/external/llvm_toolchain_llvm/include",
34+ },
35+ "//conditions:default": {},
36+ }),
37+ # LLVM dependencies for JIT are provided via Bazel, not CMake
38+ # The patch skips LLVM CMake detection when BAZEL_BUILD is set
39+ # LLVM headers from hermetic toolchain (bzlmod-compatible via data attribute)
40+ # LLVM libraries are linked via cc_library deps (see wamr_lib below)
41+ data = select({
42+ "@proxy_wasm_cpp_host//bazel:engine_wamr_jit": [
43+ "@llvm_toolchain_llvm//:all_includes",
44+ ],
45+ "//conditions:default": [],
46+ }),
47+ env = select({
48+ "@proxy_wasm_cpp_host//bazel:engine_wamr_jit": {
49+ # Reference LLVM headers in sandbox via EXT_BUILD_ROOT
50+ # The data attribute ensures llvm_toolchain_llvm is mounted in sandbox
51+ # This path works with both WORKSPACE and bzlmod
52+ "CFLAGS": "-isystem $$EXT_BUILD_ROOT/external/llvm_toolchain_llvm/include",
53+ "CXXFLAGS": "-isystem $$EXT_BUILD_ROOT/external/llvm_toolchain_llvm/include",
54+ },
55+ "//conditions:default": {},
56+ }),
2857 generate_args = [
2958 # disable WASI
3059 "-DWAMR_BUILD_LIBC_WASI=0",
4776 "-GNinja",
4877 ] + select({
4978 "@proxy_wasm_cpp_host//bazel:engine_wamr_jit": [
50- "-DLLVM_DIR=$EXT_BUILD_DEPS/copy_llvm-19_1_0/llvm/lib/cmake/llvm",
79+ # WAMR's CMake will find LLVM via CMAKE_PREFIX_PATH
80+ # No need to set LLVM_DIR explicitly
5181 "-DWAMR_BUILD_AOT=1",
5282 "-DWAMR_BUILD_FAST_INTERP=0",
5383 "-DWAMR_BUILD_INTERP=0",
@@ -65,13 +95,20 @@ cmake(
6595 ],
6696 }),
6797 lib_source = ":srcs",
98+ out_static_libs = ["libiwasm.a"],
99+ )
100+
101+ # Wrapper library that adds LLVM dependencies for linking
102+ cc_library(
103+ name = "wamr_lib",
68104 linkopts = select({
69105 "@proxy_wasm_cpp_host//bazel:engine_wamr_jit": ["-ldl"],
70106 "//conditions:default": [],
71107 }),
72- out_static_libs = ["libiwasm.a"],
73- deps = select({
74- "@proxy_wasm_cpp_host//bazel:engine_wamr_jit": ["@llvm-19_1_0//:llvm_wamr_lib"],
108+ deps = [":wamr_lib_cmake"] + select({
109+ "@proxy_wasm_cpp_host//bazel:engine_wamr_jit": [
110+ "@llvm-raw//:llvm_wamr_lib",
111+ ],
75112 "//conditions:default": [],
76113 }),
77114)
0 commit comments