diff --git a/BUILD.gn b/BUILD.gn index 72c722ea97e64cbd0fbb7872d66db0f270136b7d..1ed32764c20ef746e4d508e20fac3804df06675f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -15,6 +15,11 @@ import("//build/ohos.gni") platform = "${current_os}_${current_cpu}" +if (target_os == "ios") { + libwebsockets_path = rebase_path("//third_party/libwebsockets") + exec_script("for_ios.sh", [ "$libwebsockets_path" ]) +} + ohos_static_library("websockets") { sources = [ "//third_party/libwebsockets/lib/core-net/adopt.c", @@ -30,11 +35,9 @@ ohos_static_library("websockets") { "//third_party/libwebsockets/lib/core-net/network.c", "//third_party/libwebsockets/lib/core-net/output.c", "//third_party/libwebsockets/lib/core-net/pollfd.c", - "//third_party/libwebsockets/lib/core-net/route.c", "//third_party/libwebsockets/lib/core-net/service.c", "//third_party/libwebsockets/lib/core-net/sorted-usec-list.c", "//third_party/libwebsockets/lib/core-net/state.c", - "//third_party/libwebsockets/lib/core-net/vhost.c", "//third_party/libwebsockets/lib/core-net/wsi-timeout.c", "//third_party/libwebsockets/lib/core-net/wsi.c", "//third_party/libwebsockets/lib/core/alloc.c", @@ -78,7 +81,6 @@ ohos_static_library("websockets") { "//third_party/libwebsockets/lib/roles/http/server/lws-spa.c", "//third_party/libwebsockets/lib/roles/http/server/server.c", "//third_party/libwebsockets/lib/roles/listen/ops-listen.c", - "//third_party/libwebsockets/lib/roles/netlink/ops-netlink.c", "//third_party/libwebsockets/lib/roles/pipe/ops-pipe.c", "//third_party/libwebsockets/lib/roles/raw-file/ops-raw-file.c", "//third_party/libwebsockets/lib/roles/raw-skt/ops-raw-skt.c", @@ -101,6 +103,13 @@ ohos_static_library("websockets") { "//third_party/libwebsockets/lib/tls/tls.c", ] + if (target_os != "ios") { + sources += [ + "//third_party/libwebsockets/lib/core-net/route.c", + "//third_party/libwebsockets/lib/roles/netlink/ops-netlink.c", + ] + } + include_dirs = [ "//third_party/libwebsockets/include", "//third_party/libwebsockets/include/libwebsockets", @@ -205,10 +214,20 @@ ohos_static_library("websockets") { "//third_party/glib", ] + if (target_os == "ios") { + sources += [ "//third_party/libwebsockets/lib/core-net/vhost_ios.c" ] + } else { + sources += [ "//third_party/libwebsockets/lib/core-net/vhost.c" ] + } + defines = [ "OHOS_LIBWEBSOCKETS=1", "OPENSSL_SUPPRESS_DEPRECATED", ] + if (target_os == "ios") { + defines += [ "LWS_DETECTED_PLAT_IOS=1" ] + defines += [ "CROSS_PLATFORM_IOS_LIBWEBSOCKETS=1" ] + } cflags = [ "-fPIC", diff --git a/for_ios.patch b/for_ios.patch new file mode 100755 index 0000000000000000000000000000000000000000..c3c398aedf6b5d0c5719303f40d0246b4f393cbd --- /dev/null +++ b/for_ios.patch @@ -0,0 +1,13 @@ +diff --git a/lib/core-net/vhost_ios.c b/lib/core-net/vhost_ios.c +index 298bf01e..e8dc468e 100644 +--- a/lib/core-net/vhost_ios.c ++++ b/lib/core-net/vhost_ios.c +@@ -48,6 +48,8 @@ const struct lws_role_ops *available_roles[] = { + #endif + #if defined(LWS_WITH_NETLINK) + &role_ops_netlink, ++#else ++ NULL, + #endif + NULL + }; diff --git a/for_ios.sh b/for_ios.sh new file mode 100755 index 0000000000000000000000000000000000000000..fbc3cdbe42c68dc797f63435153bc4caf4bba48c --- /dev/null +++ b/for_ios.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +cd $1 +rm -f lib/core-net/vhost_ios.c +cp lib/core-net/vhost.c lib/core-net/vhost_ios.c +git apply for_ios.patch diff --git a/include/lws_config.h b/include/lws_config.h index 18254f2bc1ce9daf23eaae6c7a369533d450b949..5153f360335bceef50be277cfd3784cf072bf045 100644 --- a/include/lws_config.h +++ b/include/lws_config.h @@ -89,7 +89,9 @@ #define LWS_HAVE_HMAC_CTX_new #define LWS_HAVE_MALLOC_H #define LWS_HAVE_MALLOC_TRIM +#if !defined (CROSS_PLATFORM_IOS_LIBWEBSOCKETS) #define LWS_HAVE_MALLOC_USABLE_SIZE +#endif /* #undef LWS_HAVE_mbedtls_md_setup */ /* #undef LWS_HAVE_mbedtls_net_init */ /* #undef LWS_HAVE_mbedtls_rsa_complete */ @@ -107,8 +109,10 @@ /* #undef LWS_HAVE_NEW_UV_VERSION_H */ #define LWS_HAVE_OPENSSL_ECDH_H #define LWS_HAVE_OPENSSL_STACK +#if !defined (CROSS_PLATFORM_IOS_LIBWEBSOCKETS) #define LWS_HAVE_PIPE2 #define LWS_HAVE_EVENTFD +#endif #define LWS_HAVE_PTHREAD_H #define LWS_HAVE_RSA_SET0_KEY /* #undef LWS_HAVE_RSA_verify_pss_mgf1 */ @@ -207,7 +211,9 @@ #define LWS_LOGS_TIMESTAMP /* #undef LWS_WITH_MBEDTLS */ /* #undef LWS_WITH_MINIZ */ +#if !defined (CROSS_PLATFORM_IOS_LIBWEBSOCKETS) #define LWS_WITH_NETLINK +#endif #define LWS_WITH_NETWORK /* #undef LWS_WITH_NO_LOGS */ #define LWS_WITH_CACHE_NSCOOKIEJAR diff --git a/include/lws_config_private.h b/include/lws_config_private.h index 1005421b18859e3a429edb22540449a5fdf2715a..248979444815dcea356bd64b23f029d1ecb903e8 100644 --- a/include/lws_config_private.h +++ b/include/lws_config_private.h @@ -71,8 +71,10 @@ /* Define to 1 if you have the header file. */ #define LWS_HAVE_STRING_H +#if !defined (CROSS_PLATFORM_IOS_LIBWEBSOCKETS) /* Define to 1 if you have the header file. */ #define LWS_HAVE_SYS_PRCTL_H +#endif /* Define to 1 if you have the header file. */ #define LWS_HAVE_SYS_RESOURCE_H