Make wasi-nn backends as separated shared libraries (#3509)
- All files under *core/iwasm/libraries/wasi-nn* are compiled as shared libraries - *wasi-nn.c* is shared between backends - Every backend has a separated shared library - If wasi-nn feature is enabled, iwasm will depend on shared library libiwasm.so instead of linking static library libvmlib.a
This commit is contained in:
@ -123,6 +123,18 @@ if (WAMR_BUILD_DEBUG_INTERP EQUAL 1)
|
||||
set (WAMR_BUILD_SIMD 0)
|
||||
endif ()
|
||||
|
||||
# if enable wasi-nn, both wasi-nn-backends and iwasm
|
||||
# need to use same WAMR (dynamic) libraries
|
||||
if (WAMR_BUILD_WASI_NN EQUAL 1)
|
||||
set (WAMR_BUILD_SHARED 1)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_SHARED)
|
||||
set (WAMR_BUILD_SHARED 0)
|
||||
elseif (WAMR_BUILD_SHARED EQUAL 1)
|
||||
message ("build WAMR as shared libraries")
|
||||
endif ()
|
||||
|
||||
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
|
||||
|
||||
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
||||
@ -160,9 +172,16 @@ add_executable (iwasm main.c ${UNCOMMON_SHARED_SOURCE})
|
||||
|
||||
set_target_properties (iwasm PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
install (TARGETS iwasm DESTINATION bin)
|
||||
target_link_libraries(iwasm
|
||||
$<$<BOOL:${WAMR_BUILD_SHARED}>:libiwasm> $<$<NOT:$<BOOL:${WAMR_BUILD_SHARED}>>:vmlib>
|
||||
${LLVM_AVAILABLE_LIBS}
|
||||
${UV_A_LIBS}
|
||||
-lm
|
||||
-ldl
|
||||
-lpthread
|
||||
)
|
||||
|
||||
target_link_libraries (iwasm vmlib ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} ${WASI_NN_LIBS} -lm -ldl -lpthread)
|
||||
install (TARGETS iwasm DESTINATION bin)
|
||||
|
||||
add_library (libiwasm SHARED ${WAMR_RUNTIME_LIB_SOURCE})
|
||||
|
||||
@ -170,4 +189,4 @@ install (TARGETS libiwasm DESTINATION lib)
|
||||
|
||||
set_target_properties (libiwasm PROPERTIES OUTPUT_NAME iwasm)
|
||||
|
||||
target_link_libraries (libiwasm ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} ${WASI_NN_LIBS} -lm -ldl -lpthread)
|
||||
target_link_libraries (libiwasm ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
|
||||
|
||||
@ -295,7 +295,8 @@ load_native_lib(const char *name)
|
||||
/* open the native library */
|
||||
if (!(lib->handle = dlopen(name, RTLD_NOW | RTLD_GLOBAL))
|
||||
&& !(lib->handle = dlopen(name, RTLD_LAZY))) {
|
||||
LOG_WARNING("warning: failed to load native library %s", name);
|
||||
LOG_WARNING("warning: failed to load native library %s. %s", name,
|
||||
dlerror());
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user