Skip to content

Commit 1923782

Browse files
committed
update windows
1 parent 3d5e44c commit 1923782

16 files changed

Lines changed: 188 additions & 38 deletions

CMakeLists.txt

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ find_package(fmt REQUIRED)
66
find_package(spdlog REQUIRED)
77
find_package(cxxopts REQUIRED)
88
find_package(jsoncpp REQUIRED)
9-
find_package(LLVM REQUIRED)
9+
find_package(LLVM REQUIRED CONFIG)
1010
include(CTest)
1111
if (WIN32)
1212
set(WASI_SDK_DIR D:/wasi-sdk/)
@@ -53,7 +53,7 @@ else ()
5353
set(WAMR_BUILD_LIBC_UVWASI 1)
5454
set(CMAKE_MSVC_RUNTIME_LIBRARY "")
5555
set(CMAKE_GENERATOR_PLATFORM "")
56-
set(CMAKE_CXX_FLAGS "/MD /EHsc")
56+
set(CMAKE_CXX_FLAGS "/MD /EHsc /DNOMINMAX")
5757
find_library(DETOURS_LIBRARY detours REQUIRED)
5858
find_path(DETOURS_INCLUDE_DIRS "detours/detours.h")
5959
find_library(DETOURS_LIBRARY detours REQUIRED)
@@ -101,8 +101,14 @@ set(WAMR_BUILD_JIT 0)
101101
set(WAMR_BUILD_DEBUG_INTERP 0)
102102
set(WAMR_BUILD_DEBUG_AOT 0)
103103
set(WAMR_BUILD_FAST_JIT 0)
104-
set(WAMR_BUILD_WASI_NN 1)
105-
set(WAMR_BUILD_WASI_NN_ENABLE_GPU 1)
104+
if(WIN32)
105+
# Disable WASI-NN on Windows due to TensorFlow Lite header compatibility issues
106+
set(WAMR_BUILD_WASI_NN 0)
107+
set(WAMR_BUILD_WASI_NN_ENABLE_GPU 0)
108+
else()
109+
set(WAMR_BUILD_WASI_NN 1)
110+
set(WAMR_BUILD_WASI_NN_ENABLE_GPU 1)
111+
endif()
106112
set(WAMR_BUILD_LIBC_BUILTIN 1)
107113
set(WAMR_BUILD_LIBC_WASI 1)
108114
set(WAMR_BUILD_DUMP_CALL_STACK 1)
@@ -123,13 +129,16 @@ set(CMAKE_MACOSX_RPATH True)
123129
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/wasm-micro-runtime)
124130

125131
include(${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
126-
add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
132+
add_library(vmlib STATIC ${WAMR_RUNTIME_LIB_SOURCE})
127133

128134
include(${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
129135
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/lib/wasm-micro-runtime/core/iwasm/aot ${CMAKE_CURRENT_SOURCE_DIR}/lib/yalantinglibs/include ${BLAS_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/lib/libcrafter/libcrafter/ ${jsoncpp_INCLUDE_DIRS})
130136

131-
set(BUILD_TESTING OFF CACHE BOOL "Disable s2n-tls tests" FORCE)
132-
add_subdirectory(lib/s2n-tls)
137+
if(NOT WIN32)
138+
# s2n-tls is not compatible with Windows
139+
set(BUILD_TESTING OFF CACHE BOOL "Disable s2n-tls tests" FORCE)
140+
add_subdirectory(lib/s2n-tls)
141+
endif()
133142

134143
if (MVVM_BUILD_BENCH)
135144
add_subdirectory(bench)
@@ -150,14 +159,30 @@ set(GPU_CC_SOURCES
150159
src/wamr_gpu_cc_amd.cpp
151160
src/wamr_gpu_cc_intel.cpp
152161
)
153-
add_library(MVVM_export ${SOURCE_FILES} ${GPU_CC_SOURCES} ${UNCOMMON_SHARED_SOURCE})
162+
add_library(MVVM_export SHARED ${SOURCE_FILES} ${GPU_CC_SOURCES} ${UNCOMMON_SHARED_SOURCE})
163+
target_compile_definitions(MVVM_export PRIVATE MVVM_EXPORT_EXPORTS)
154164
add_executable(MVVM_restore src/restore.cpp ${UNCOMMON_SHARED_SOURCE})
155165
add_executable(MVVM_checkpoint src/checkpoint.cpp ${UNCOMMON_SHARED_SOURCE})
156-
add_executable(MVVM_profile src/profile.cpp ${UNCOMMON_SHARED_SOURCE})
166+
if(NOT WIN32)
167+
# Profile tool uses Unix-specific features
168+
add_executable(MVVM_profile src/profile.cpp ${UNCOMMON_SHARED_SOURCE})
169+
endif()
157170
include_directories(${LLVM_INCLUDE_DIRS} ${s2n_SOURCE_DIR}/api)
158171
add_definitions(${LLVM_DEFINITIONS})
159-
target_link_libraries(MVVM_export fmt::fmt spdlog::spdlog jsoncpp_lib ${BLAS_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY} ZLIB::ZLIB zstd dl)
160-
target_link_libraries(MVVM_restore ${LLVM_LIBRARIES} LLVM fmt::fmt spdlog::spdlog cxxopts::cxxopts ${BLAS_LIBRARIES} MVVM_export vmlib s2n tensorflow-lite)
161-
target_link_libraries(MVVM_checkpoint ${LLVM_LIBRARIES} LLVM fmt::fmt spdlog::spdlog cxxopts::cxxopts ${BLAS_LIBRARIES} MVVM_export vmlib s2n tensorflow-lite)
162-
target_link_libraries(MVVM_profile ${LLVM_LIBRARIES} LLVM fmt::fmt spdlog::spdlog cxxopts::cxxopts ${BLAS_LIBRARIES} MVVM_export vmlib s2n tensorflow-lite)
172+
173+
# Get LLVM components
174+
llvm_map_components_to_libnames(llvm_libs Support Core IRReader)
175+
176+
if(WIN32)
177+
# Windows specific libraries
178+
target_link_libraries(MVVM_export fmt::fmt spdlog::spdlog jsoncpp_lib ${BLAS_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY} ZLIB::ZLIB $<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>)
179+
target_link_libraries(MVVM_restore ${llvm_libs} fmt::fmt spdlog::spdlog cxxopts::cxxopts ${BLAS_LIBRARIES} MVVM_export vmlib ${WIN_EXTRA_LIBS})
180+
target_link_libraries(MVVM_checkpoint ${llvm_libs} fmt::fmt spdlog::spdlog cxxopts::cxxopts ${BLAS_LIBRARIES} MVVM_export vmlib ${WIN_EXTRA_LIBS})
181+
else()
182+
# Non-Windows platforms
183+
target_link_libraries(MVVM_export fmt::fmt spdlog::spdlog jsoncpp_lib ${BLAS_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY} ZLIB::ZLIB zstd dl)
184+
target_link_libraries(MVVM_restore ${LLVM_LIBRARIES} fmt::fmt spdlog::spdlog cxxopts::cxxopts ${BLAS_LIBRARIES} MVVM_export vmlib s2n tensorflow-lite)
185+
target_link_libraries(MVVM_checkpoint ${LLVM_LIBRARIES} fmt::fmt spdlog::spdlog cxxopts::cxxopts ${BLAS_LIBRARIES} MVVM_export vmlib s2n tensorflow-lite)
186+
target_link_libraries(MVVM_profile ${LLVM_LIBRARIES} fmt::fmt spdlog::spdlog cxxopts::cxxopts ${BLAS_LIBRARIES} MVVM_export vmlib s2n tensorflow-lite)
187+
endif()
163188
add_definitions(-DCXXOPTS_NO_RTTI=1)

include/mvvm_export.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* The WebAssembly Live Migration Project
3+
*
4+
* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
5+
* Copyright 2025 Regents of the University of California
6+
* UC Santa Cruz Sluglab.
7+
*/
8+
9+
#ifndef MVVM_EXPORT_H
10+
#define MVVM_EXPORT_H
11+
12+
#ifdef _WIN32
13+
#ifdef MVVM_EXPORT_EXPORTS
14+
#define MVVM_API __declspec(dllexport)
15+
#else
16+
#define MVVM_API __declspec(dllimport)
17+
#endif
18+
#else
19+
#define MVVM_API
20+
#endif
21+
22+
#endif // MVVM_EXPORT_H

include/wamr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ class WAMRInstance {
130130
std::vector<const char *> addr_{};
131131
std::vector<const char *> ns_pool_{};
132132
std::vector<WAMRExecEnv *> execEnv{};
133+
#if defined(WAMR_BUILD_WASI_NN) && WAMR_BUILD_WASI_NN != 0
133134
std::vector<WAMRWASINNModel> nn_context{};
134135
WAMRWASINNContext nn_context_mvvm;
136+
#endif
135137
std::map<int, std::tuple<std::string, std::vector<std::tuple<int, int, fd_op>>>> fd_map_{};
136138
// add offset to pair->tuple, 3rd param 'int'
137139
std::map<int, int> new_sock_map_{};

include/wamr_export.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313

1414
#include "platform_common.h"
1515
#include "wasm_runtime.h"
16+
#include "mvvm_export.h"
1617

1718
#ifdef __cplusplus
1819
extern "C" {
1920
#endif
2021

22+
// Forward declaration
23+
class WAMRInstance;
24+
extern MVVM_API WAMRInstance *wamr;
25+
2126
#if !defined(MVVM_WASI)
2227
#define MVVM_WASI
2328
#define SNAPSHOT_DEBUG_STEP 0

include/wamr_platform_windows.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Windows Platform Configuration for WAMR
3+
*/
4+
5+
#ifndef WAMR_PLATFORM_WINDOWS_H
6+
#define WAMR_PLATFORM_WINDOWS_H
7+
8+
#ifdef _WIN32
9+
10+
// Define Windows platform before including WAMR headers
11+
#ifndef BH_PLATFORM_WINDOWS
12+
#define BH_PLATFORM_WINDOWS
13+
#endif
14+
15+
// Prevent inclusion of winsock.h - we want winsock2.h
16+
#ifndef _WINSOCKAPI_
17+
#define _WINSOCKAPI_
18+
#endif
19+
20+
#ifndef WIN32_LEAN_AND_MEAN
21+
#define WIN32_LEAN_AND_MEAN
22+
#endif
23+
24+
// Include WAMR platform headers
25+
// Note: platform_internal.h will include windows.h and winsock2.h in the correct order
26+
#include "../lib/wasm-micro-runtime/core/shared/platform/windows/platform_internal.h"
27+
#else
28+
#include "platform_common.h"
29+
#include "platform_api_vmcore.h"
30+
#endif // _WIN32
31+
32+
#endif // WAMR_PLATFORM_WINDOWS_H

include/wamr_security_framework.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class SecureMigrationProtocol {
230230
~SecureMigrationProtocol();
231231

232232
// Protocol states
233-
enum class ProtocolState { INIT, HANDSHAKE, AUTHENTICATED, MIGRATING, COMPLETED, ERROR };
233+
enum class ProtocolState { STATE_INIT, STATE_HANDSHAKE, STATE_AUTHENTICATED, STATE_MIGRATING, STATE_COMPLETED, STATE_ERROR };
234234

235235
// Initialize protocol
236236
bool initializeProtocol(bool is_source);

include/wamr_wasi_nn_context.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@
1414
#ifndef MVVM_WAMR_WASI_NN_H
1515
#define MVVM_WAMR_WASI_NN_H
1616

17+
#include "wasm_export.h"
18+
19+
// Only include WASI-NN headers if it's enabled
20+
#if defined(WAMR_BUILD_WASI_NN) && WAMR_BUILD_WASI_NN != 0
1721
#include "wasi_nn.h"
1822
#include "wasi_nn_types.h"
19-
#include "wasm_export.h"
2023
#ifdef __cplusplus
2124
extern "C" {
2225
#endif
2326
#include "wasi_nn_app_native.h"
2427
#ifdef __cplusplus
2528
}
2629
#endif
30+
#endif // WAMR_BUILD_WASI_NN
2731
#include <memory>
2832
#include <string>
2933
#include <unordered_map>
@@ -39,10 +43,13 @@ extern "C" {
3943
// Forward declaration
4044
struct WAMRWASINNContext;
4145

46+
#if defined(WAMR_BUILD_WASI_NN) && WAMR_BUILD_WASI_NN != 0
4247
// We need to use the WAMR library's WASINNContext, but avoid conflicts
4348
// Include the required header that defines it
4449
#include "wasi_nn_private.h"
50+
#endif
4551

52+
#if defined(WAMR_BUILD_WASI_NN) && WAMR_BUILD_WASI_NN != 0
4653
// 操作类型枚举
4754
enum class WASINNOperationType { LOAD_MODEL, INIT_EXECUTION_CONTEXT, SET_INPUT, COMPUTE, GET_OUTPUT };
4855

@@ -168,10 +175,14 @@ struct WAMRWASINNContext {
168175
template <typename T> void dump(T *t, WASINNContext *env) { t->dump_impl(env); }
169176
template <typename T> void restore(T *t, WASINNContext *env) { t->restore_impl(env); }
170177

178+
#endif // WAMR_BUILD_WASI_NN
179+
171180
#ifdef __cplusplus
172181
extern "C" {
173182
#endif
174183

184+
#if defined(WAMR_BUILD_WASI_NN) && WAMR_BUILD_WASI_NN != 0
185+
175186
// Initialize the WASI-NN recorder for a module instance
176187
void wamr_wasi_nn_recorder_init(wasm_module_inst_t instance);
177188

@@ -203,6 +214,8 @@ size_t wamr_wasi_nn_get_recorder_memory_size(wasm_module_inst_t instance);
203214
size_t wamr_wasi_nn_get_recorder_peak_memory_size(wasm_module_inst_t instance);
204215
size_t wamr_wasi_nn_get_recorder_operation_count(wasm_module_inst_t instance);
205216

217+
#endif // WAMR_BUILD_WASI_NN
218+
206219
#ifdef __cplusplus
207220
}
208221
#endif

include/wamr_wasi_nn_tflite_gpu_cc.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88

99
#include "wamr_gpu_cc_framework.h"
1010
#include <memory>
11+
12+
#if defined(WAMR_BUILD_WASI_NN) && WAMR_BUILD_WASI_NN != 0
1113
#include <tensorflow/lite/delegates/gpu/delegate.h>
14+
#endif
15+
16+
#if defined(WAMR_BUILD_WASI_NN) && WAMR_BUILD_WASI_NN != 0
1217

1318
namespace mvvm {
1419
namespace wasi_nn {
@@ -97,4 +102,6 @@ int wasi_nn_tflite_gpu_cc_get_attestation(void *gpu_cc_ctx, uint8_t *report_buff
97102
} // namespace wasi_nn
98103
} // namespace mvvm
99104

105+
#endif // WAMR_BUILD_WASI_NN
106+
100107
#endif // WASI_NN_TFLITE_GPU_CC_H

src/restore.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ extern std::string target;
3131
extern ReadStream *reader;
3232
extern WriteStream *writer;
3333

34-
35-
void spdlog::logger::err_handler_(std::string const &) {}
36-
3734
int main(int argc, char **argv) {
3835
cxxopts::Options options("MVVM", "Migratable Velocity Virtual Machine, to ship the VM state to another machine");
3936
options.add_options()("t,target", "The webassembly file to execute",

src/wamr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
* UC Santa Cruz Sluglab.
1212
*/
1313

14+
#include "mvvm_export.h"
1415
#include "wamr.h"
15-
#include "platform_api_vmcore.h"
16-
#include "platform_common.h"
16+
#include "wamr_platform_windows.h"
1717
#include "wamr_export.h"
1818
#include "wamr_native.h"
1919
#include "wamr_read_write.h"
@@ -39,7 +39,7 @@
3939
#include <windows.h>
4040
#endif
4141

42-
WAMRInstance *wamr = nullptr;
42+
MVVM_API WAMRInstance *wamr = nullptr;
4343
std::ostringstream re{};
4444
WriteStream *writer;
4545
ReadStream *reader;

0 commit comments

Comments
 (0)