Skip to content

Commit 294a625

Browse files
authored
Use boringssl instead of openssl to implement wasm cache loading (#1804)
1 parent 9083334 commit 294a625

File tree

6 files changed

+52
-14
lines changed

6 files changed

+52
-14
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
131131
# STATIC LIBRARY
132132
add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE})
133133
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
134-
target_link_libraries(iwasm_static OpenSSL::SSL)
134+
target_link_libraries(iwasm_static PUBLIC boringssl_crypto)
135135
endif ()
136136
set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib)
137137

@@ -142,7 +142,7 @@ add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE})
142142
set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm)
143143
target_link_libraries (iwasm_shared ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
144144
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
145-
target_link_libraries(iwasm_shared OpenSSL::SSL)
145+
target_link_libraries(iwasm_shared boringssl_crypto)
146146
endif ()
147147

148148
if (MINGW)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
message(STATUS "involving boringssl...")
5+
6+
include(ExternalProject)
7+
8+
ExternalProject_Add(boringssl
9+
PREFIX external/boringssl
10+
# follow envoy, which tracks BoringSSL, which tracks Chromium
11+
# https://github.com/envoyproxy/envoy/blob/main/bazel/repository_locations.bzl#L112
12+
# chromium-105.0.5195.37 (linux/beta)
13+
URL https://github.com/google/boringssl/archive/098695591f3a2665fccef83a3732ecfc99acdcdd.tar.gz
14+
URL_HASH SHA256=e141448cf6f686b6e9695f6b6459293fd602c8d51efe118a83106752cf7e1280
15+
DOWNLOAD_EXTRACT_TIMESTAMP NEW
16+
# SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../external/boringssl
17+
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/src/boringssl-build/libssl.a
18+
${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/
19+
&& ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/src/boringssl-build/libcrypto.a
20+
${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/
21+
&& ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/src/boringssl/src/include/openssl
22+
${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/openssl
23+
)
24+
25+
add_library(boringssl_ssl STATIC IMPORTED GLOBAL)
26+
set_target_properties(
27+
boringssl_ssl
28+
PROPERTIES
29+
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/libssl.a
30+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/
31+
)
32+
add_dependencies(boringssl_ssl boringssl)
33+
34+
add_library(boringssl_crypto STATIC IMPORTED GLOBAL)
35+
set_target_properties(
36+
boringssl_crypto
37+
PROPERTIES
38+
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/libcrypto.a
39+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/external/boringssl/
40+
)
41+
add_dependencies(boringssl_crypto boringssl)

build-scripts/runtime_lib.cmake

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ if (DEFINED EXTRA_SDK_INCLUDE_PATH)
2727
)
2828
endif ()
2929

30-
# Need exactly OpenSSL 1.1.1
31-
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
32-
# Set OPENSSL_ROOT_DIR to the root directory of an OpenSSL installation.
33-
# Like: cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl
34-
# Especially on MacOS
35-
find_package(OpenSSL 1.1.1 EXACT REQUIRED)
36-
endif ()
37-
3830
# Set default options
3931

4032
# Set WAMR_BUILD_TARGET, currently values supported:
@@ -147,6 +139,10 @@ if (WAMR_BUILD_LIB_RATS EQUAL 1)
147139
include (${IWASM_DIR}/libraries/lib-rats/lib_rats.cmake)
148140
endif ()
149141

142+
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
143+
include (${WAMR_ROOT_DIR}/build-scripts/involve_boringssl.cmake)
144+
endif ()
145+
150146
####################### Common sources #######################
151147
if (NOT MSVC)
152148
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections \

core/iwasm/common/wasm_c_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,7 @@ wasm_module_new(wasm_store_t *store, const wasm_byte_vec_t *binary)
21832183

21842184
#if WASM_ENABLE_WASM_CACHE != 0
21852185
/* if cached */
2186-
SHA256((void *)binary->data, binary->num_elems, binary_hash);
2186+
SHA256((void *)binary->data, binary->num_elems, (uint8_t *)binary_hash);
21872187
module_ex = try_reuse_loaded_module(store, binary_hash);
21882188
if (module_ex)
21892189
return module_ext_to_module(module_ex);

samples/wasm-c-api/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ endif()
9494
target_link_libraries (vmlib ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
9595

9696
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
97-
target_link_libraries(vmlib OpenSSL::SSL)
97+
target_link_libraries(vmlib boringssl_crypto)
9898
endif ()
9999
################################################
100100

@@ -165,7 +165,7 @@ foreach(EX ${EXAMPLES})
165165
add_executable(${EX} ${SRC} ${UNCOMMON_SHARED_SOURCE} ${MM_UTIL})
166166
set_target_properties (${EX} PROPERTIES POSITION_INDEPENDENT_CODE ON)
167167
target_include_directories(${EX} PRIVATE ${UNCOMMON_SHARED_DIR})
168-
target_link_libraries(${EX} vmlib -lpthread -lm)
168+
target_link_libraries(${EX} vmlib)
169169
if (MSVC)
170170
target_compile_definitions(${EX} PRIVATE WASM_API_EXTERN=)
171171
endif()
@@ -206,7 +206,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
206206
add_custom_command(
207207
OUTPUT ${EX}_leak_check.report
208208
DEPENDS ${EX} ${EX}_WASM
209-
COMMAND ${VALGRIND} --tool=memcheck --leak-check=summary -- ./${EX} > ${EX}_leak_check.report 2>&1
209+
COMMAND ${VALGRIND} --tool=memcheck --leak-check=full -- ./${EX} > ${EX}_leak_check.report 2>&1
210210
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
211211
)
212212
add_custom_target(${EX}_LEAK_TEST ALL

samples/wasm-c-api/src/clone.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ main()
522522
pthread_mutex_unlock(&ready_go_lock);
523523
pthread_cond_broadcast(&ready_go_cond);
524524

525+
sleep(3);
525526
for (size_t i = 0; i < sizeof(tids) / sizeof(tids[0]); i++) {
526527
if (tids[i] != 0)
527528
pthread_join(tids[i], NULL);

0 commit comments

Comments
 (0)