Skip to content

Commit 75c6032

Browse files
yamtlum1n0us
authored andcommitted
wamr-wasi-extensions: add lib-socket things (bytecodealliance#4360)
1 parent 90f9902 commit 75c6032

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

wamr-wasi-extensions/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ cmake_minimum_required (VERSION 3.14)
66
project(wamr-wasi-extensions LANGUAGES C)
77

88
add_subdirectory(nn)
9+
add_subdirectory(socket)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
3+
set(CMAKE_C_STANDARD 99)
4+
set(CMAKE_C_STANDARD_REQUIRED YES)
5+
set(CMAKE_C_EXTENSIONS NO)
6+
7+
project(socket-nslookup LANGUAGES C)
8+
add_executable(socket-nslookup ${CMAKE_CURRENT_SOURCE_DIR}/../../../core/iwasm/libraries/lib-socket/test/nslookup.c)
9+
find_package(wamr-wasi-socket REQUIRED)
10+
target_link_libraries(socket-nslookup wamr-wasi-socket)
11+
target_link_options(socket-nslookup PRIVATE -Wl,--max-memory=262144)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
3+
set(CMAKE_C_STANDARD 99)
4+
set(CMAKE_C_STANDARD_REQUIRED YES)
5+
6+
project(socket-tcp-udp LANGUAGES C)
7+
add_executable(socket-tcp-udp ${CMAKE_CURRENT_SOURCE_DIR}/../../../core/iwasm/libraries/lib-socket/test/tcp_udp.c)
8+
find_package(wamr-wasi-socket REQUIRED)
9+
target_link_libraries(socket-tcp-udp wamr-wasi-socket)
10+
target_link_options(socket-tcp-udp PRIVATE -Wl,--max-memory=262144)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
set(wasi_socket_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../core/iwasm/libraries/lib-socket)
2+
set(wasi_socket_header_dir ${wasi_socket_dir}/inc)
3+
4+
set(srcs ${wasi_socket_dir}/src/wasi/wasi_socket_ext.c)
5+
set(headers
6+
${wasi_socket_header_dir}/wasi_socket_ext.h
7+
)
8+
9+
add_library(wamr-wasi-socket STATIC ${srcs})
10+
set_property(TARGET wamr-wasi-socket PROPERTY PUBLIC_HEADER ${headers})
11+
target_include_directories(wamr-wasi-socket
12+
PUBLIC
13+
$<BUILD_INTERFACE:${wasi_socket_header_dir}>
14+
$<INSTALL_INTERFACE:include>)
15+
16+
install(TARGETS wamr-wasi-socket
17+
EXPORT wamr-wasi-socket-config
18+
PUBLIC_HEADER DESTINATION include)
19+
install(EXPORT wamr-wasi-socket-config
20+
DESTINATION lib/cmake/wamr-wasi-socket)

wamr-wasi-extensions/test.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Copyright (C) 2025 Midokura Japan KK. All rights reserved.
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

6+
set -e
7+
68
PREFIX=/tmp/wamr
79
WASI_SDK=${WASI_SDK:-/opt/wasi-sdk}
810

@@ -17,3 +19,15 @@ cmake -B build-app-nn \
1719
-DCMAKE_PREFIX_PATH=${PREFIX} \
1820
samples/nn
1921
cmake --build build-app-nn
22+
23+
cmake -B build-app-socket-nslookup \
24+
-DCMAKE_TOOLCHAIN_FILE=${WASI_SDK}/share/cmake/wasi-sdk-pthread.cmake \
25+
-DCMAKE_PREFIX_PATH=${PREFIX} \
26+
samples/socket-nslookup
27+
cmake --build build-app-socket-nslookup
28+
29+
cmake -B build-app-socket-tcp-udp \
30+
-DCMAKE_TOOLCHAIN_FILE=${WASI_SDK}/share/cmake/wasi-sdk-pthread.cmake \
31+
-DCMAKE_PREFIX_PATH=${PREFIX} \
32+
samples/socket-tcp-udp
33+
cmake --build build-app-socket-tcp-udp

0 commit comments

Comments
 (0)