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
39 changes: 39 additions & 0 deletions bazel/external/fmt.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Based on Bazel Central Registry fmt module BUILD file
# https://github.com/bazelbuild/bazel-central-registry/tree/main/modules/fmt/11.0.2

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

package(default_visibility = ["//visibility:public"])

licenses(["notice"]) # MIT

cc_library(
name = "fmt",
srcs = [
"src/format.cc",
"src/os.cc",
],
hdrs = glob([
"include/fmt/*.h",
]),
copts = select({
"@platforms//os:windows": ["-utf-8"],
"//conditions:default": [],
}),
includes = ["include"],
strip_include_prefix = "include",
)
32 changes: 32 additions & 0 deletions bazel/external/spdlog.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Based on Bazel Central Registry spdlog module BUILD file
# https://github.com/bazelbuild/bazel-central-registry/tree/main/modules/spdlog/1.13.0

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

package(default_visibility = ["//visibility:public"])

licenses(["notice"]) # MIT

cc_library(
name = "spdlog",
hdrs = glob([
"include/**/*.h",
]),
defines = ["SPDLOG_FMT_EXTERNAL"],
includes = ["include"],
deps = ["@com_github_fmtlib_fmt//:fmt"],
)
8 changes: 7 additions & 1 deletion bazel/external/wasmedge.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@ filegroup(
cmake(
name = "wasmedge_lib",
cache_entries = {
"WASMEDGE_BUILD_AOT_RUNTIME": "Off",
"WASMEDGE_USE_LLVM": "Off",
"WASMEDGE_BUILD_SHARED_LIB": "Off",
"WASMEDGE_BUILD_STATIC_LIB": "On",
"WASMEDGE_BUILD_TOOLS": "Off",
"WASMEDGE_FORCE_DISABLE_LTO": "On",
# Provide spdlog and fmt as external dependencies via Bazel (not CMake FetchContent)
"CMAKE_PREFIX_PATH": "$$EXT_BUILD_DEPS$$/spdlog;$$EXT_BUILD_DEPS$$/fmt",
},
env = {
"CXXFLAGS": "-Wno-error=dangling-reference -Wno-error=maybe-uninitialized -Wno-error=array-bounds= -Wno-error=deprecated-declarations -std=c++20",
},
generate_args = ["-GNinja"],
lib_source = ":srcs",
out_static_libs = ["libwasmedge.a"],
deps = [
"@com_github_fmtlib_fmt//:fmt",
"@com_github_gabime_spdlog//:spdlog",
],
)
99 changes: 99 additions & 0 deletions bazel/external/wasmedge.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1111111..2222222 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -186,6 +186,59 @@ endif()
include(Helper)
include(GNUInstallDirs)

+# When building under Bazel with rules_foreign_cc, dependencies are provided via EXT_BUILD_DEPS
+# EXT_BUILD_DEPS environment variable contains the path to the merged dependency directory
+# created by rules_foreign_cc, with headers in include/ and libraries in lib/
+# All dependencies listed in the cmake() rule's deps attribute are merged into a single directory structure
+# Create IMPORTED targets for fmt and spdlog to prevent CMake FetchContent from trying to download them
+if(DEFINED ENV{EXT_BUILD_DEPS})
+ set(BAZEL_EXT_BUILD_DEPS "$ENV{EXT_BUILD_DEPS}")
+ message(STATUS "Bazel build detected, using dependencies from: ${BAZEL_EXT_BUILD_DEPS}")
+
+ # Create fmt::fmt IMPORTED target
+ # fmt is a library with compiled sources (not header-only)
+ if(NOT TARGET fmt::fmt AND EXISTS "${BAZEL_EXT_BUILD_DEPS}/include/fmt")
+ # Look for the fmt library file
+ find_library(FMT_LIBRARY
+ NAMES fmt libfmt
+ PATHS "${BAZEL_EXT_BUILD_DEPS}/lib"
+ NO_DEFAULT_PATH
+ )
+
+ if(FMT_LIBRARY)
+ # Create STATIC IMPORTED library
+ add_library(fmt::fmt STATIC IMPORTED)
+ set_target_properties(fmt::fmt PROPERTIES
+ IMPORTED_LOCATION "${FMT_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${BAZEL_EXT_BUILD_DEPS}/include"
+ )
+ message(STATUS "Created fmt::fmt IMPORTED target from Bazel deps: ${FMT_LIBRARY}")
+ else()
+ message(WARNING "fmt headers found at ${BAZEL_EXT_BUILD_DEPS}/include/fmt but compiled library not found in ${BAZEL_EXT_BUILD_DEPS}/lib. Check that fmt dependency is properly configured in Bazel BUILD file.")
+ endif()
+
+ # Create non-namespaced alias for backward compatibility with code that references fmt without the namespace
+ if(TARGET fmt::fmt)
+ add_library(fmt ALIAS fmt::fmt)
+ endif()
+ endif()
+
+ # Create spdlog::spdlog IMPORTED target
+ # spdlog is header-only when using external fmt
+ if(NOT TARGET spdlog::spdlog AND EXISTS "${BAZEL_EXT_BUILD_DEPS}/include/spdlog")
+ add_library(spdlog::spdlog INTERFACE IMPORTED)
+ set_target_properties(spdlog::spdlog PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${BAZEL_EXT_BUILD_DEPS}/include"
+ INTERFACE_COMPILE_DEFINITIONS "SPDLOG_FMT_EXTERNAL"
+ )
+ # spdlog depends on fmt
+ if(TARGET fmt::fmt)
+ set_property(TARGET spdlog::spdlog APPEND PROPERTY INTERFACE_LINK_LIBRARIES fmt::fmt)
+ endif()
+ message(STATUS "Created spdlog::spdlog IMPORTED target from Bazel deps")
+ endif()
+endif()
+
set(CPACK_PACKAGE_VENDOR Second State LLC)
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_NAME}")
set(CPACK_STRIP_FILES ON)
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index 1111111..2222222 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -39,6 +39,8 @@ configure_file(common/enum_configure.h api/wasmedge/enum_configure.h COPYONLY)
configure_file(common/enum_errcode.h api/wasmedge/enum_errcode.h COPYONLY)
configure_file(common/enum_types.h api/wasmedge/enum_types.h COPYONLY)
configure_file(common/version.h.in common/version.h)
+install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/api/wasmedge
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
unset(WASMEDGE_VERSION_STRING)
unset(WASMEDGE_VERSION_LIST)
unset(WASMEDGE_VERSION_MAJOR)
diff --git a/lib/api/CMakeLists.txt b/lib/api/CMakeLists.txt
index 1111111..2222222 100644
--- a/lib/api/CMakeLists.txt
+++ b/lib/api/CMakeLists.txt
@@ -151,8 +151,15 @@ if(WASMEDGE_BUILD_SHARED_LIB)
endif()

if(WASMEDGE_BUILD_STATIC_LIB)
- wasmedge_add_static_lib_component_command(fmt::fmt)
- wasmedge_add_static_lib_component_command(spdlog::spdlog)
+ # When using Bazel, skip packaging fmt/spdlog into libwasmedge.a
+ # Bazel will handle linking these dependencies directly from the deps attribute
+ # This allows fmt to be either static or shared, and avoids the need to extract
+ # object files from libraries (which fails for shared libraries)
+ if(NOT DEFINED ENV{EXT_BUILD_DEPS})
+ # In non-Bazel builds, package fmt and spdlog into the static library
+ wasmedge_add_static_lib_component_command(fmt::fmt)
+ wasmedge_add_static_lib_component_command(spdlog::spdlog)
+ endif()
wasmedge_add_static_lib_component_command(wasmedgeSystem)
wasmedge_add_static_lib_component_command(wasmedgeCommon)
wasmedge_add_static_lib_component_command(wasmedgePO)
32 changes: 29 additions & 3 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,40 @@ def proxy_wasm_cpp_host_repositories():
)

# WasmEdge with dependencies.
# Using native Bazel cc_library rules based on Bazel Central Registry (BCR) definitions
# to avoid CMake FetchContent network access during build.

# fmt dependency for spdlog (version 11.0.2, based on BCR)
# https://github.com/bazelbuild/bazel-central-registry/tree/main/modules/fmt/11.0.2
maybe(
http_archive,
name = "com_github_fmtlib_fmt",
sha256 = "6cb1e6d37bdcb756dbbe59be438790db409cdb4868c66e888d5df9f13f7c027f",
strip_prefix = "fmt-11.0.2",
urls = ["https://github.com/fmtlib/fmt/archive/refs/tags/11.0.2.tar.gz"],
build_file = "@proxy_wasm_cpp_host//bazel/external:fmt.BUILD",
)

# spdlog dependency for WasmEdge (version 1.13.0, based on BCR)
# https://github.com/bazelbuild/bazel-central-registry/tree/main/modules/spdlog/1.13.0
maybe(
http_archive,
name = "com_github_gabime_spdlog",
sha256 = "534f2ee1a4dcbeb22249856edfb2be76a1cf4f708a20b0ac2ed090ee24cfdbc9",
strip_prefix = "spdlog-1.13.0",
urls = ["https://github.com/gabime/spdlog/archive/refs/tags/v1.13.0.tar.gz"],
build_file = "@proxy_wasm_cpp_host//bazel/external:spdlog.BUILD",
)

maybe(
http_archive,
name = "com_github_wasmedge_wasmedge",
build_file = "@proxy_wasm_cpp_host//bazel/external:wasmedge.BUILD",
sha256 = "7ab8a0df37c8d282ecff72d0f0bff8db63fd92df1645d5a014a9dbed4b7f9025",
strip_prefix = "WasmEdge-proxy-wasm-0.13.1",
url = "https://github.com/WasmEdge/WasmEdge/archive/refs/tags/proxy-wasm/0.13.1.tar.gz",
sha256 = "2354d90a67e3eb396179663bdc0b457abbbc70dca967ec4528f211599a49f62a",
strip_prefix = "WasmEdge-0.16.1",
url = "https://github.com/WasmEdge/WasmEdge/archive/refs/tags/0.16.1.tar.gz",
patches = ["@proxy_wasm_cpp_host//bazel/external:wasmedge.patch"],
patch_args = ["-p1"],
)

# Wasmtime with dependencies.
Expand Down
Loading
Loading