Skip to content

Commit

Permalink
[libusbmuxd] Add tools feature (microsoft#33838)
Browse files Browse the repository at this point in the history
* [libusbmuxd] Add tools feature

* Update version database

* Remove tools from default-features

* Update version database
  • Loading branch information
xiaozhuai authored Sep 19, 2023
1 parent d55379b commit 7c06f2b
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 7 deletions.
42 changes: 42 additions & 0 deletions ports/libusbmuxd/005_fix_tools_msvc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
diff --git a/tools/inetcat.c b/tools/inetcat.c
index f70215b..748db15 100644
--- a/tools/inetcat.c
+++ b/tools/inetcat.c
@@ -33,7 +33,9 @@
#include <string.h>
#include <fcntl.h>
#include <stddef.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#include <errno.h>
#include <getopt.h>
#ifdef WIN32
@@ -50,6 +52,13 @@
#include "usbmuxd.h"
#include <libimobiledevice-glue/socket.h>

+#ifdef _MSC_VER
+#include <BaseTsd.h>
+typedef SSIZE_T ssize_t;
+#define STDIN_FILENO _fileno(stdin)
+#define STDOUT_FILENO _fileno(stdout)
+#endif
+
static int debug_level = 0;

static size_t read_data_socket(int fd, uint8_t* buf, size_t bufsize)
diff --git a/tools/iproxy.c b/tools/iproxy.c
index d5f66b6..6510cb8 100644
--- a/tools/iproxy.c
+++ b/tools/iproxy.c
@@ -34,7 +34,9 @@
#include <string.h>
#include <fcntl.h>
#include <stddef.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#include <errno.h>
#include <getopt.h>
#ifdef WIN32
43 changes: 38 additions & 5 deletions ports/libusbmuxd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(libusbmuxd C)

option(BUILD_TOOLS "Build tools." OFF)

include(GNUInstallDirs)

file(GLOB_RECURSE LIBUSBMUXD_HEADER include/*.h)
Expand All @@ -25,18 +27,17 @@ endif()

if(WIN32)
list(APPEND DEFINITIONS -D_CRT_SECURE_NO_WARNINGS)
list(APPEND DEFINITIONS -DWIN32_LEAN_AND_MEAN)
list(APPEND DEFINITIONS -DWIN32)
endif()

find_package(unofficial-libplist CONFIG REQUIRED)
find_package(unofficial-libimobiledevice-glue CONFIG REQUIRED)

add_library(libusbmuxd ${LIBUSBMUXD_SOURCE})
target_include_directories(libusbmuxd
PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
PUBLIC
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
target_include_directories(libusbmuxd PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
target_compile_definitions(libusbmuxd PRIVATE ${DEFINITIONS})
target_link_libraries(libusbmuxd
Expand Down Expand Up @@ -82,3 +83,35 @@ install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/libusbmuxd-2.0.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)

if(BUILD_TOOLS)
if(WIN32)
find_package(unofficial-getopt-win32 REQUIRED)
endif()

function(add_tool name source)
add_executable("${name}" "${source}")
target_compile_definitions("${name}" PRIVATE
-DPACKAGE_VERSION="2.0.2"
-DPACKAGE_URL="https://github.com/libimobiledevice/libusbmuxd"
-DPACKAGE_BUGREPORT="https://github.com/libimobiledevice/libusbmuxd/issues"
)
target_link_libraries("${name}" PRIVATE libusbmuxd unofficial::libimobiledevice-glue::libimobiledevice-glue)
if(WIN32)
target_compile_definitions("${name}" PRIVATE
-D_CRT_SECURE_NO_WARNINGS
-DWIN32_LEAN_AND_MEAN
-DWIN32
)
target_link_libraries("${name}" PRIVATE unofficial::getopt-win32::getopt Ws2_32)
endif()
endfunction(add_tool)

add_tool(inetcat "tools/inetcat.c")
add_tool(iproxy "tools/iproxy.c")

install(
TARGETS inetcat iproxy
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
endif()
11 changes: 11 additions & 0 deletions ports/libusbmuxd/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,29 @@ vcpkg_from_github(
002_fix_struct_pack.patch
003_fix_msvc.patch
004_fix_api.patch
005_fix_tools_msvc.patch
)

file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")
file(COPY "${CMAKE_CURRENT_LIST_DIR}/exports.def" DESTINATION "${SOURCE_PATH}")

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
tools BUILD_TOOLS
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
${FEATURE_OPTIONS}
)

vcpkg_cmake_install()
vcpkg_cmake_config_fixup(PACKAGE_NAME unofficial-${PORT})
vcpkg_fixup_pkgconfig()
if("tools" IN_LIST FEATURES)
vcpkg_copy_tools(TOOL_NAMES inetcat iproxy AUTO_CLEAN)
endif()

file(READ "${CURRENT_PACKAGES_DIR}/share/unofficial-${PORT}/unofficial-${PORT}-config.cmake" cmake_config)
file(WRITE "${CURRENT_PACKAGES_DIR}/share/unofficial-${PORT}/unofficial-${PORT}-config.cmake"
Expand Down
12 changes: 11 additions & 1 deletion ports/libusbmuxd/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "libusbmuxd",
"version-date": "2023-06-21",
"port-version": 1,
"description": "A client library to multiplex connections from and to iOS devices",
"homepage": "https://libimobiledevice.org/",
"license": "LGPL-2.1-or-later",
Expand All @@ -16,5 +17,14 @@
"name": "vcpkg-cmake-config",
"host": true
}
]
],
"features": {
"tools": {
"description": "build command line tool",
"supports": "!android & !ios & !xbox",
"dependencies": [
"getopt"
]
}
}
}
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -4790,7 +4790,7 @@
},
"libusbmuxd": {
"baseline": "2023-06-21",
"port-version": 0
"port-version": 1
},
"libuuid": {
"baseline": "1.0.3",
Expand Down
5 changes: 5 additions & 0 deletions versions/l-/libusbmuxd.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "ba5bfe9a2e679d22d3b3b520e432c493df3919e9",
"version-date": "2023-06-21",
"port-version": 1
},
{
"git-tree": "7a9145917e1df41e8820d26c2e167f3839d7a947",
"version-date": "2023-06-21",
Expand Down

0 comments on commit 7c06f2b

Please sign in to comment.