Use boringssl instead of openssl to implement wasm cache loading (#1804)

This commit is contained in:
liang.he 2022-12-13 14:23:37 +08:00 committed by Wenyong Huang
parent d267121c88
commit b826a84cd6
6 changed files with 52 additions and 14 deletions

View File

@ -136,7 +136,7 @@ include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
# STATIC LIBRARY
add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE})
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
target_link_libraries(iwasm_static OpenSSL::SSL)
target_link_libraries(iwasm_static PUBLIC boringssl_crypto)
endif ()
set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib)
@ -147,7 +147,7 @@ add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE})
set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm)
target_link_libraries (iwasm_shared ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
target_link_libraries(iwasm_shared OpenSSL::SSL)
target_link_libraries(iwasm_shared boringssl_crypto)
endif ()
if (MINGW)

View File

@ -0,0 +1,41 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
message(STATUS "involving boringssl...")
include(ExternalProject)
ExternalProject_Add(boringssl
PREFIX external/boringssl
# follow envoy, which tracks BoringSSL, which tracks Chromium
# https://github.com/envoyproxy/envoy/blob/main/bazel/repository_locations.bzl#L112
# chromium-105.0.5195.37 (linux/beta)
URL https://github.com/google/boringssl/archive/098695591f3a2665fccef83a3732ecfc99acdcdd.tar.gz
URL_HASH SHA256=e141448cf6f686b6e9695f6b6459293fd602c8d51efe118a83106752cf7e1280
DOWNLOAD_EXTRACT_TIMESTAMP NEW
# SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../external/boringssl
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/src/boringssl-build/libssl.a
${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/
&& ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/src/boringssl-build/libcrypto.a
${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/
&& ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/src/boringssl/src/include/openssl
${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/openssl
)
add_library(boringssl_ssl STATIC IMPORTED GLOBAL)
set_target_properties(
boringssl_ssl
PROPERTIES
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/libssl.a
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/
)
add_dependencies(boringssl_ssl boringssl)
add_library(boringssl_crypto STATIC IMPORTED GLOBAL)
set_target_properties(
boringssl_crypto
PROPERTIES
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/libcrypto.a
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/
)
add_dependencies(boringssl_crypto boringssl)

View File

@ -27,14 +27,6 @@ if (DEFINED EXTRA_SDK_INCLUDE_PATH)
)
endif ()
# Need exactly OpenSSL 1.1.1
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
# Set OPENSSL_ROOT_DIR to the root directory of an OpenSSL installation.
# Like: cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl
# Especially on MacOS
find_package(OpenSSL 1.1.1 EXACT REQUIRED)
endif ()
# Set default options
# Set WAMR_BUILD_TARGET, currently values supported:
@ -155,6 +147,10 @@ if (WAMR_BUILD_LIB_RATS EQUAL 1)
include (${IWASM_DIR}/libraries/lib-rats/lib_rats.cmake)
endif ()
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
include (${WAMR_ROOT_DIR}/build-scripts/involve_boringssl.cmake)
endif ()
####################### Common sources #######################
if (NOT MSVC)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections \

View File

@ -2183,7 +2183,7 @@ wasm_module_new(wasm_store_t *store, const wasm_byte_vec_t *binary)
#if WASM_ENABLE_WASM_CACHE != 0
/* if cached */
SHA256((void *)binary->data, binary->num_elems, binary_hash);
SHA256((void *)binary->data, binary->num_elems, (uint8_t *)binary_hash);
module_ex = try_reuse_loaded_module(store, binary_hash);
if (module_ex)
return module_ext_to_module(module_ex);

View File

@ -94,7 +94,7 @@ endif()
target_link_libraries (vmlib ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
target_link_libraries(vmlib OpenSSL::SSL)
target_link_libraries(vmlib boringssl_crypto)
endif ()
################################################
@ -165,7 +165,7 @@ foreach(EX ${EXAMPLES})
add_executable(${EX} ${SRC} ${UNCOMMON_SHARED_SOURCE} ${MM_UTIL})
set_target_properties (${EX} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(${EX} PRIVATE ${UNCOMMON_SHARED_DIR})
target_link_libraries(${EX} vmlib -lpthread -lm)
target_link_libraries(${EX} vmlib)
if (MSVC)
target_compile_definitions(${EX} PRIVATE WASM_API_EXTERN=)
endif()
@ -206,7 +206,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_custom_command(
OUTPUT ${EX}_leak_check.report
DEPENDS ${EX} ${EX}_WASM
COMMAND ${VALGRIND} --tool=memcheck --leak-check=summary -- ./${EX} > ${EX}_leak_check.report 2>&1
COMMAND ${VALGRIND} --tool=memcheck --leak-check=full -- ./${EX} > ${EX}_leak_check.report 2>&1
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_custom_target(${EX}_LEAK_TEST ALL

View File

@ -522,6 +522,7 @@ main()
pthread_mutex_unlock(&ready_go_lock);
pthread_cond_broadcast(&ready_go_cond);
sleep(3);
for (size_t i = 0; i < sizeof(tids) / sizeof(tids[0]); i++) {
if (tids[i] != 0)
pthread_join(tids[i], NULL);