Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/compile_commands.json
/.cache/
/_codeql_detected_source_root
bazel/external/__pycache__/
7 changes: 7 additions & 0 deletions bazel/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ load("@bazel_lib//lib:repositories.bzl", "bazel_lib_dependencies", "bazel_lib_re
load("@com_google_googletest//:googletest_deps.bzl", "googletest_deps")
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@envoy_toolshed//sysroot:sysroot.bzl", "setup_sysroots")
load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")
load("@proxy_wasm_cpp_host//bazel/cargo/wasmsign/remote:crates.bzl", wasmsign_crate_repositories = "crate_repositories")
load("@proxy_wasm_cpp_host//bazel/cargo/wasmtime/remote:crates.bzl", wasmtime_crate_repositories = "crate_repositories")
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
Expand Down Expand Up @@ -107,6 +108,12 @@ def proxy_wasm_cpp_host_dependencies():

protobuf_deps()

# LLVM with native Bazel build (for WAMR JIT).
# Configure LLVM using its native Bazel overlay from utils/bazel.
# Only build X86 and AArch64 targets to minimize build size.
# Note: LLVM external dependencies (llvm_zlib, llvm_zstd) are defined in repositories.bzl
llvm_configure(name = "llvm-project", targets = ["X86", "AArch64"])

# Wasmtime dependencies.

wasmtime_crate_repositories()
Expand Down
47 changes: 42 additions & 5 deletions bazel/external/wamr.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

licenses(["notice"]) # Apache 2
Expand All @@ -24,7 +25,35 @@ filegroup(
)

cmake(
name = "wamr_lib",
name = "wamr_lib_cmake",
cache_entries = select({
"@proxy_wasm_cpp_host//bazel:engine_wamr_jit": {
"BAZEL_BUILD": "ON",
# Set LLVM_INCLUDE_DIR for the patch to use
"LLVM_INCLUDE_DIR": "$$EXT_BUILD_ROOT/external/llvm_toolchain_llvm/include",
},
"//conditions:default": {},
}),
# LLVM dependencies for JIT are provided via Bazel, not CMake
# The patch skips LLVM CMake detection when BAZEL_BUILD is set
# LLVM headers from hermetic toolchain (bzlmod-compatible via data attribute)
# LLVM libraries are linked via cc_library deps (see wamr_lib below)
data = select({
"@proxy_wasm_cpp_host//bazel:engine_wamr_jit": [
"@llvm_toolchain_llvm//:all_includes",
],
"//conditions:default": [],
}),
env = select({
"@proxy_wasm_cpp_host//bazel:engine_wamr_jit": {
# Reference LLVM headers in sandbox via EXT_BUILD_ROOT
# The data attribute ensures llvm_toolchain_llvm is mounted in sandbox
# This path works with both WORKSPACE and bzlmod
"CFLAGS": "-isystem $$EXT_BUILD_ROOT/external/llvm_toolchain_llvm/include",
"CXXFLAGS": "-isystem $$EXT_BUILD_ROOT/external/llvm_toolchain_llvm/include",
},
"//conditions:default": {},
}),
generate_args = [
# disable WASI
"-DWAMR_BUILD_LIBC_WASI=0",
Expand All @@ -47,7 +76,8 @@ cmake(
"-GNinja",
] + select({
"@proxy_wasm_cpp_host//bazel:engine_wamr_jit": [
"-DLLVM_DIR=$EXT_BUILD_DEPS/copy_llvm-19_1_0/llvm/lib/cmake/llvm",
# WAMR's CMake will find LLVM via CMAKE_PREFIX_PATH
# No need to set LLVM_DIR explicitly
"-DWAMR_BUILD_AOT=1",
"-DWAMR_BUILD_FAST_INTERP=0",
"-DWAMR_BUILD_INTERP=0",
Expand All @@ -65,13 +95,20 @@ cmake(
],
}),
lib_source = ":srcs",
out_static_libs = ["libiwasm.a"],
)

# Wrapper library that adds LLVM dependencies for linking
cc_library(
name = "wamr_lib",
linkopts = select({
"@proxy_wasm_cpp_host//bazel:engine_wamr_jit": ["-ldl"],
"//conditions:default": [],
}),
out_static_libs = ["libiwasm.a"],
deps = select({
"@proxy_wasm_cpp_host//bazel:engine_wamr_jit": ["@llvm-19_1_0//:llvm_wamr_lib"],
deps = [":wamr_lib_cmake"] + select({
"@proxy_wasm_cpp_host//bazel:engine_wamr_jit": [
"@llvm-raw//:llvm_wamr_lib",
],
"//conditions:default": [],
}),
)
30 changes: 28 additions & 2 deletions bazel/external/wamr.patch
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,36 @@ index c33b211e..d04d0cc8 100644
EXPORT iwasmTargets
LIBRARY DESTINATION lib
diff --git a/build-scripts/config_common.cmake b/build-scripts/config_common.cmake
index cb15b8b0..b71cf077 100644
index cb15b8b0..41c32f79 100644
--- a/build-scripts/config_common.cmake
+++ b/build-scripts/config_common.cmake
@@ -140,7 +140,7 @@ else ()
@@ -103,14 +103,20 @@ if (WAMR_BUILD_JIT EQUAL 1)
if (NOT DEFINED LLVM_DIR)
set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm")
set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/build")
- if (NOT EXISTS "${LLVM_BUILD_ROOT}")
- message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_BUILD_ROOT}")
- endif ()
set (CMAKE_PREFIX_PATH "${LLVM_BUILD_ROOT};${CMAKE_PREFIX_PATH}")
set (LLVM_DIR ${LLVM_BUILD_ROOT}/lib/cmake/llvm)
endif ()
- find_package(LLVM REQUIRED CONFIG)
- include_directories(${LLVM_INCLUDE_DIRS})
+ # Skip LLVM CMake detection when BAZEL_BUILD is set (Bazel provides LLVM)
+ if (NOT DEFINED BAZEL_BUILD)
+ find_package(LLVM REQUIRED CONFIG)
+ include_directories(${LLVM_INCLUDE_DIRS})
+ message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
+ message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
+ else()
+ # Bazel build: LLVM headers from hermetic toolchain, libs via cc_library
+ message(STATUS "Bazel build: Skipping LLVM find_package")
+ include_directories(${LLVM_INCLUDE_DIR})
+ endif()
add_definitions(${LLVM_DEFINITIONS})
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
@@ -140,7 +146,7 @@ else ()
endif ()

# Version
Expand Down
Loading
Loading