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 GitHub
parent 9083334f69
commit 294a625fe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 14 deletions

View File

@ -131,7 +131,7 @@ include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
# STATIC LIBRARY # STATIC LIBRARY
add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE}) add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE})
if (WAMR_BUILD_WASM_CACHE EQUAL 1) if (WAMR_BUILD_WASM_CACHE EQUAL 1)
target_link_libraries(iwasm_static OpenSSL::SSL) target_link_libraries(iwasm_static PUBLIC boringssl_crypto)
endif () endif ()
set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib) set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib)
@ -142,7 +142,7 @@ add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE})
set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm) set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm)
target_link_libraries (iwasm_shared ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread) target_link_libraries (iwasm_shared ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
if (WAMR_BUILD_WASM_CACHE EQUAL 1) if (WAMR_BUILD_WASM_CACHE EQUAL 1)
target_link_libraries(iwasm_shared OpenSSL::SSL) target_link_libraries(iwasm_shared boringssl_crypto)
endif () endif ()
if (MINGW) 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 () 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 default options
# Set WAMR_BUILD_TARGET, currently values supported: # Set WAMR_BUILD_TARGET, currently values supported:
@ -147,6 +139,10 @@ if (WAMR_BUILD_LIB_RATS EQUAL 1)
include (${IWASM_DIR}/libraries/lib-rats/lib_rats.cmake) include (${IWASM_DIR}/libraries/lib-rats/lib_rats.cmake)
endif () endif ()
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
include (${WAMR_ROOT_DIR}/build-scripts/involve_boringssl.cmake)
endif ()
####################### Common sources ####################### ####################### Common sources #######################
if (NOT MSVC) if (NOT MSVC)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections \ 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 WASM_ENABLE_WASM_CACHE != 0
/* if cached */ /* 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); module_ex = try_reuse_loaded_module(store, binary_hash);
if (module_ex) if (module_ex)
return module_ext_to_module(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) target_link_libraries (vmlib ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
if (WAMR_BUILD_WASM_CACHE EQUAL 1) if (WAMR_BUILD_WASM_CACHE EQUAL 1)
target_link_libraries(vmlib OpenSSL::SSL) target_link_libraries(vmlib boringssl_crypto)
endif () endif ()
################################################ ################################################
@ -165,7 +165,7 @@ foreach(EX ${EXAMPLES})
add_executable(${EX} ${SRC} ${UNCOMMON_SHARED_SOURCE} ${MM_UTIL}) add_executable(${EX} ${SRC} ${UNCOMMON_SHARED_SOURCE} ${MM_UTIL})
set_target_properties (${EX} PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties (${EX} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(${EX} PRIVATE ${UNCOMMON_SHARED_DIR}) target_include_directories(${EX} PRIVATE ${UNCOMMON_SHARED_DIR})
target_link_libraries(${EX} vmlib -lpthread -lm) target_link_libraries(${EX} vmlib)
if (MSVC) if (MSVC)
target_compile_definitions(${EX} PRIVATE WASM_API_EXTERN=) target_compile_definitions(${EX} PRIVATE WASM_API_EXTERN=)
endif() endif()
@ -206,7 +206,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_custom_command( add_custom_command(
OUTPUT ${EX}_leak_check.report OUTPUT ${EX}_leak_check.report
DEPENDS ${EX} ${EX}_WASM 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} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
) )
add_custom_target(${EX}_LEAK_TEST ALL add_custom_target(${EX}_LEAK_TEST ALL

View File

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