From 6653efe2c9c2a01173779844c714fbc97f481d27 Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Sat, 1 Aug 2026 20:01:59 +0200 Subject: [PATCH] Add option to enable new Rust based mDNS backend Fixes: https://github.com/nmeum/android-tools/issues/181 --- .github/workflows/build.yml | 54 ++++++++--- .gitmodules | 4 + CMakeLists.txt | 18 ++++ ...2-adb-disable-mdns-transport-support.patch | 23 ++--- .../0003-adb-include-missing-headers.patch | 19 +++- patches/adb/0016-adb-disable-mDNS.patch | 81 ++++++----------- patches/adb/0017-adb_wifi-remove-mDNS.patch | 42 ++++----- ...crate-type-dependencies-and-lib-name.patch | 41 +++++++++ ...19-adbmdns-Downgrade-edition-to-2021.patch | 53 +++++++++++ .../adb/0021-Rip-out-openscreen-support.patch | 91 +++++++++++++++++++ patches/adb/0028-Migrate-to-fmt-format.patch | 85 ++++++++++++++--- vendor/CMakeLists.adb.txt | 25 +++++ vendor/corrosion | 1 + 13 files changed, 421 insertions(+), 116 deletions(-) create mode 100644 patches/adb/0018-adbmdns-Fix-crate-type-dependencies-and-lib-name.patch create mode 100644 patches/adb/0019-adbmdns-Downgrade-edition-to-2021.patch create mode 100644 patches/adb/0021-Rip-out-openscreen-support.patch create mode 160000 vendor/corrosion diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 044f2695..90467474 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,12 +6,14 @@ jobs: upload-src: name: Upload the source runs-on: ubuntu-latest + outputs: + version: ${{ steps.build_and_install.outputs.version }} steps: - name: prep ubuntu run: | sudo apt-get update DEBIAN_FRONTEND=noninteractive sudo apt-get install -yq \ - ${{ matrix.pkgs }} cmake git libbrotli-dev \ + ${{ matrix.pkgs }} cargo cmake git libbrotli-dev \ libgtest-dev liblz4-dev libpcre2-dev libprotobuf-dev libunwind-dev \ libzstd-dev make pandoc pkg-config protobuf-compiler xz-utils - name: checkout @@ -22,26 +24,48 @@ jobs: run: | git config --global user.email "you@example.com" git config --global user.name "Your Name" + - name: get vendor modules + run: | + cd vendor/adb/client/adbmdns + cargo vendor + mkdir -p .cargo + cat > .cargo/config.toml << 'EOF' + [source.crates-io] + replace-with = "vendored-sources" + + [source.vendored-sources] + directory = "vendor" + EOF - name: generate man page run: | cd vendor/adb/docs/user pandoc -s -t man adb.1.md -o adb.1 - - name: build & install + - id: build_and_install + name: build & install run: | export SOURCE_DATE_EPOCH=$(date +%s) echo "SOURCE_DATE_EPOCH: ${SOURCE_DATE_EPOCH}" cmake \ + -DANDROID_TOOLS_USE_BUNDLED_CORROSION=ON \ -DANDROID_TOOLS_USE_BUNDLED_FMT=ON \ -DANDROID_TOOLS_USE_BUNDLED_LIBUSB=ON \ + -DANDROID_TOOLS_ADB_ENABLE_MDNS=ON \ -B build - cmake --build build --target package_source + cmake --build build --target package_source vendor_source for x in sha1sum sha256sum sha512sum b2sum; do - printf "$x " && $x ${{ github.workspace }}/build/android-tools-*.tar.xz | cut -d " " -f 1 + printf "$x " && $x ${{ github.workspace }}/build/android-tools-*.tar.xz done + VERSION=$(grep PLATFORM_TOOLS_VERSION ${{ github.workspace }}/build/vendor/platform_tools_version.h | awk '{print substr($3, 2, length($3) - 2)}') + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" - name: upload package_source uses: actions/upload-artifact@v7 with: - path: ${{ github.workspace }}/build/android-tools-*.tar.xz + path: ${{ github.workspace }}/build/android-tools-${{ steps.build_and_install.outputs.version }}.tar.xz + archive: false + - name: upload vendor_source + uses: actions/upload-artifact@v7 + with: + path: ${{ github.workspace }}/build/android-tools-${{ steps.build_and_install.outputs.version }}-vendor.tar.xz archive: false linux: @@ -93,7 +117,7 @@ jobs: if: startsWith(matrix.os, 'opensuse') run: | zypper -n ref - zypper -n in ${{ matrix.pkgs }} cmake gtest pcre2-devel pkgconfig \ + zypper -n in ${{ matrix.pkgs }} cargo cmake gtest pcre2-devel pkgconfig \ 'pkgconfig(libbrotlicommon)' 'pkgconfig(liblz4)' \ 'pkgconfig(libunwind-generic)' \ 'pkgconfig(libzstd)' 'pkgconfig(protobuf)' ninja tar xz zlib-devel @@ -102,7 +126,7 @@ jobs: if: startsWith(matrix.os, 'archlinux') run: | pacman -Syu --needed --noconfirm \ - ${{ matrix.pkgs }} brotli cmake gtest libunwind \ + ${{ matrix.pkgs }} brotli cargo cmake gtest libunwind \ lz4 pcre2 pkgconfig protobuf zstd ninja - name: prep ubuntu @@ -110,7 +134,7 @@ jobs: run: | apt-get update DEBIAN_FRONTEND=noninteractive apt-get install -yq \ - ${{ matrix.pkgs }} cmake libbrotli-dev \ + ${{ matrix.pkgs }} cargo cmake libbrotli-dev \ libgtest-dev liblz4-dev libpcre2-dev libprotobuf-dev libunwind-dev \ libzstd-dev pkg-config protobuf-compiler ninja-build xz-utils @@ -118,19 +142,19 @@ jobs: if: startsWith(matrix.os, 'alpine') run: | apk add build-base pcre2-dev linux-headers gtest-dev samurai \ - cmake protobuf-dev brotli-dev zstd-dev lz4-dev + cargo cmake protobuf-dev brotli-dev zstd-dev lz4-dev - name: prep fedora if: startsWith(matrix.os, 'fedora') run: | - dnf install -y ${{ matrix.pkgs }} cmake ninja-build \ + dnf install -y ${{ matrix.pkgs }} cargo cmake ninja-build \ brotli-devel gtest-devel lz4-devel pcre2-devel protobuf-devel \ libzstd-devel tar xz - name: download source uses: actions/download-artifact@v8 with: - pattern: android-tools-*.tar.xz + pattern: android-tools-${{ needs.upload-src.outputs.version }}.tar.xz - name: build & install run: | @@ -143,8 +167,10 @@ jobs: -DCMAKE_C_FLAGS="$CFLAGS" \ -DCMAKE_CXX_FLAGS="$CXXFLAGS" \ -DCMAKE_BUILD_TYPE=Release \ + -DANDROID_TOOLS_USE_BUNDLED_CORROSION=ON \ -DANDROID_TOOLS_USE_BUNDLED_FMT=ON \ -DANDROID_TOOLS_USE_BUNDLED_LIBUSB=ON \ + -DANDROID_TOOLS_ADB_ENABLE_MDNS=ON \ -GNinja \ .. ninja --verbose @@ -178,12 +204,12 @@ jobs: run: | rm -rf /opt/homebrew/include/openssl /usr/local/opt/openssl /usr/local/include/openssl brew install --overwrite --quiet brotli cmake googletest lz4 \ - ninja pcre2 protobuf zstd + ninja pcre2 protobuf rust zstd - name: download source uses: actions/download-artifact@v8 with: - pattern: android-tools-*.tar.xz + pattern: android-tools-${{ needs.upload-src.outputs.version }}.tar.xz - name: build & install run: | @@ -195,8 +221,10 @@ jobs: -DCMAKE_CXX_FLAGS="$CXXFLAGS" \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=$HOME/android-tools \ + -DANDROID_TOOLS_USE_BUNDLED_CORROSION=ON \ -DANDROID_TOOLS_USE_BUNDLED_FMT=ON \ -DANDROID_TOOLS_USE_BUNDLED_LIBUSB=ON \ + -DANDROID_TOOLS_ADB_ENABLE_MDNS=ON \ -GNinja \ .. ninja --verbose diff --git a/.gitmodules b/.gitmodules index d840901a..2ec06a2d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -62,3 +62,7 @@ shallow = true path = vendor/fs_mgr url = https://android.googlesource.com/platform/system/fs/fs_mgr.git +[submodule "vendor/corrosion"] + shallow = true + path = vendor/corrosion + url = https://github.com/corrosion-rs/corrosion.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 27664cca..5c5bec0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,8 +9,10 @@ include(GNUInstallDirs) # This helps to build vendor projects with or without any patching. Also if any # files are changed in vendor projects those can be retained with this option. option(ANDROID_TOOLS_PATCH_VENDOR "Patch vendor projects using patches directory" ON) +option(ANDROID_TOOLS_USE_BUNDLED_CORROSION "Use bundled corrosion instead of system provided one" OFF) option(ANDROID_TOOLS_USE_BUNDLED_FMT "Use bundled fmt library instead of system provided one" OFF) option(ANDROID_TOOLS_USE_BUNDLED_LIBUSB "Use bundled libusb library instead of system provided one" OFF) +option(ANDROID_TOOLS_ADB_ENABLE_MDNS "Enable ADB mDNS support" OFF) option(ANDROID_TOOLS_LIBUSB_ENABLE_UDEV "Enable udev for device enumeration and hotplug support" OFF) # Install bash/zsh completion files. @@ -47,6 +49,7 @@ set(CPACK_SOURCE_GENERATOR "TXZ") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${ANDROID_VERSION}") set(CPACK_SOURCE_IGNORE_FILES "/patches/" "/build/" "/.git/" "/.github/" "/tests/" "/test/" "/testdata/" "/extras/simpleperf/scripts/" "/extras/simpleperf/demo/" + "/adb/client/adbmdns/.cargo" "/adb/client/adbmdns/vendor" "aes_128_gcm.txt" "aes_256_gcm.txt" "/fuzz/" "/wycheproof_testvectors/" @@ -56,6 +59,7 @@ set(CPACK_SOURCE_IGNORE_FILES "/patches/" "/build/" "/.git/" "/.github/" "/tests "\\\\.data$" "\\\\.git$" "\\\\.html$" + "\\\\.lock$" "\\\\.orig$" "\\\\.pdf$" "\\\\.pem$" @@ -68,3 +72,17 @@ set(CPACK_SOURCE_IGNORE_FILES "/patches/" "/build/" "/.git/" "/.github/" "/tests "\\\\.zip$" ) include(CPack) + +# Create a custom target to for vendor source tarball. +add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/${ANDROID_VENDOR}-${ANDROID_VERSION}-vendor.tar.xz + COMMAND ${CMAKE_COMMAND} -E tar + cJf ${CMAKE_BINARY_DIR}/${ANDROID_VENDOR}-${ANDROID_VERSION}-vendor.tar.xz + vendor/adb/client/adbmdns/.cargo + vendor/adb/client/adbmdns/vendor + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} +) + +add_custom_target(vendor_source + DEPENDS ${CMAKE_BINARY_DIR}/${ANDROID_VENDOR}-${ANDROID_VERSION}-vendor.tar.xz +) diff --git a/patches/adb/0002-adb-disable-mdns-transport-support.patch b/patches/adb/0002-adb-disable-mdns-transport-support.patch index 7ea107b2..e992c602 100644 --- a/patches/adb/0002-adb-disable-mdns-transport-support.patch +++ b/patches/adb/0002-adb-disable-mdns-transport-support.patch @@ -1,28 +1,29 @@ -From 419a5885e90871647e4bca76f528e6bd3c0d7ada Mon Sep 17 00:00:00 2001 +From 704721ad0f2b9730f49e985c318576f90903b048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Sun, 1 Sep 2019 15:04:18 +0000 Subject: [PATCH] adb: disable mdns transport support Would require patching the MDNS code as well. --- - client/main.cpp | 4 ---- - 1 file changed, 4 deletions(-) + client/main.cpp | 2 ++ + 1 file changed, 2 insertions(+) diff --git a/client/main.cpp b/client/main.cpp -index d8186c3..50a53b0 100644 +index d8186c3..efde06c 100644 --- a/client/main.cpp +++ b/client/main.cpp -@@ -133,10 +133,6 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, const char* o +@@ -133,9 +133,11 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, const char* o init_reconnect_handler(); -- if (mdns::is_enabled()) { -- init_mdns_transport_discovery(); -- } -- ++#if ADB_MDNS + if (mdns::is_enabled()) { + init_mdns_transport_discovery(); + } ++#endif + if (is_usb_enabled()) { if (is_libusb_enabled()) { - libusb::usb_init(); -- -2.54.0 +2.55.0 diff --git a/patches/adb/0003-adb-include-missing-headers.patch b/patches/adb/0003-adb-include-missing-headers.patch index 148fac34..c0a7e9df 100644 --- a/patches/adb/0003-adb-include-missing-headers.patch +++ b/patches/adb/0003-adb-include-missing-headers.patch @@ -1,12 +1,25 @@ -From c37bd188a394b36ecb5aa5eeac9469fc5ef4473a Mon Sep 17 00:00:00 2001 +From edcfea31a3381decc13f4550e412e5d84b8e968b Mon Sep 17 00:00:00 2001 From: Biswapriyo Nath Date: Thu, 1 Feb 2024 19:39:48 +0530 Subject: [PATCH] adb include missing headers --- + adb_mdns.cpp | 1 + sysdeps/uio.h | 1 + - 1 file changed, 1 insertion(+) + 2 files changed, 2 insertions(+) +diff --git a/adb_mdns.cpp b/adb_mdns.cpp +index dde08d7..312ea3c 100644 +--- a/adb_mdns.cpp ++++ b/adb_mdns.cpp +@@ -19,6 +19,7 @@ + #include "adb_mdns.h" + + #include ++#include + #include + + #include diff --git a/sysdeps/uio.h b/sysdeps/uio.h index f3ace64..266a20b 100644 --- a/sysdeps/uio.h @@ -20,5 +33,5 @@ index f3ace64..266a20b 100644 using adb_iovec = struct iovec; inline ssize_t adb_writev(borrowed_fd fd, const adb_iovec* iov, int iovcnt) { -- -2.43.0 +2.55.0 diff --git a/patches/adb/0016-adb-disable-mDNS.patch b/patches/adb/0016-adb-disable-mDNS.patch index 6821ebd1..301d3dff 100644 --- a/patches/adb/0016-adb-disable-mDNS.patch +++ b/patches/adb/0016-adb-disable-mDNS.patch @@ -1,90 +1,65 @@ -From b54cab3861198ffcb8c6330cae0e14070fab3467 Mon Sep 17 00:00:00 2001 +From fc5b0a99f01b0d0577382caa02ade8b1b24f0499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= Date: Sun, 1 Nov 2020 15:51:35 +0700 Subject: [PATCH] adb: disable mDNS --- - adb.cpp | 15 --------------- - client/commandline.cpp | 2 ++ - socket_spec.cpp | 25 +------------------------ - 3 files changed, 3 insertions(+), 39 deletions(-) + adb.cpp | 2 ++ + client/commandline.cpp | 4 ++++ + socket_spec.cpp | 4 +++- + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/adb.cpp b/adb.cpp -index a4794e9..30e668d 100644 +index a4794e9..e23d4a3 100644 --- a/adb.cpp +++ b/adb.cpp -@@ -1257,21 +1257,6 @@ bool is_usb_enabled() { +@@ -1257,6 +1257,7 @@ bool is_usb_enabled() { } static bool handle_mdns_request(std::string_view service, int reply_fd) { -- if (!android::base::ConsumePrefix(&service, "mdns:")) { -- return false; -- } -- -- if (service == "check") { -- std::string check = mdns_check(); -- SendOkay(reply_fd, check); -- return true; -- } -- if (service == "services") { -- std::string services_list = mdns_list_discovered_services(); -- SendOkay(reply_fd, services_list); -- return true; -- } -- ++#if ADB_MDNS + if (!android::base::ConsumePrefix(&service, "mdns:")) { + return false; + } +@@ -1271,6 +1272,7 @@ static bool handle_mdns_request(std::string_view service, int reply_fd) { + SendOkay(reply_fd, services_list); + return true; + } ++#endif + return false; } - diff --git a/client/commandline.cpp b/client/commandline.cpp -index 4f43fb9..abe38dc 100644 +index 4f43fb9..0e77793 100644 --- a/client/commandline.cpp +++ b/client/commandline.cpp -@@ -1950,6 +1950,8 @@ int adb_commandline(int argc, const char** argv) { +@@ -1950,6 +1950,10 @@ int adb_commandline(int argc, const char** argv) { ReadOrderlyShutdown(fd); return 0; } else if (!strcmp(argv[0], "mdns")) { ++#if !ADB_MDNS + error_exit("mdns is not supported by this version of adb."); ++#endif + --argc; if (argc < 1) error_exit("mdns requires an argument"); ++argv; diff --git a/socket_spec.cpp b/socket_spec.cpp -index 391bfdb..3c0e2d0 100644 +index 391bfdb..da9f100 100644 --- a/socket_spec.cpp +++ b/socket_spec.cpp -@@ -228,30 +228,7 @@ bool socket_spec_connect(unique_fd* fd, std::string_view address, int* port, +@@ -228,7 +228,9 @@ bool socket_spec_connect(unique_fd* fd, std::string_view address, int* port, if (tcp_host_is_local(hostname)) { fd->reset(network_loopback_client(port_value, SOCK_STREAM, error)); } else { -#if ADB_HOST -- // Check if the address is an mdns service we can connect to. -- if (auto mdns_info = mdns_get_connect_service_info(std::string(address.substr(4))); -- mdns_info != std::nullopt) { -- fd->reset(network_connect(mdns_info->v4_address_string(), mdns_info->port, -- SOCK_STREAM, 0, error)); -- if (fd->get() != -1) { -- // TODO(joshuaduong): We still show the ip address for the serial. Change it to -- // use the mdns instance name, so we can adjust to address changes on -- // reconnects. -- port_value = mdns_info->port; -- if (transport_name) { -- *transport_name = -- std::format("{}.{}", mdns_info->instance, mdns_info->service); -- } -- } -- } else { -- fd->reset(network_connect(hostname, port_value, SOCK_STREAM, 0, error)); -- } --#else -- // Disallow arbitrary connections in adbd. -- *error = "adbd does not support arbitrary tcp connections"; -- return false; --#endif ++#if !ADB_MDNS + fd->reset(network_connect(hostname, port_value, SOCK_STREAM, 0, error)); - } - - if (fd->get() > 0) { ++#elif ADB_HOST + // Check if the address is an mdns service we can connect to. + if (auto mdns_info = mdns_get_connect_service_info(std::string(address.substr(4))); + mdns_info != std::nullopt) { -- 2.55.0 diff --git a/patches/adb/0017-adb_wifi-remove-mDNS.patch b/patches/adb/0017-adb_wifi-remove-mDNS.patch index 34cfa90f..63af041b 100644 --- a/patches/adb/0017-adb_wifi-remove-mDNS.patch +++ b/patches/adb/0017-adb_wifi-remove-mDNS.patch @@ -1,45 +1,37 @@ -From 4271ff1e73588021c26dbf7292abd0650e6e6e62 Mon Sep 17 00:00:00 2001 +From afd19d466933dda5d316110cd945117c9b34f442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= Date: Sun, 1 Nov 2020 19:44:01 +0700 Subject: [PATCH] adb_wifi: remove mDNS --- - client/adb_wifi.cpp | 9 ++------- - 1 file changed, 2 insertions(+), 7 deletions(-) + client/adb_wifi.cpp | 6 ++++++ + 1 file changed, 6 insertions(+) diff --git a/client/adb_wifi.cpp b/client/adb_wifi.cpp -index 0f4231f..33762f3 100644 +index 0f4231f..0141d9c 100644 --- a/client/adb_wifi.cpp +++ b/client/adb_wifi.cpp -@@ -177,9 +177,7 @@ bool KnownWifiHostsFile::IsKnownHost(const std::string& host) { +@@ -177,7 +177,11 @@ bool KnownWifiHostsFile::IsKnownHost(const std::string& host) { void adb_wifi_pair_device(const std::string& host, const std::string& password, std::string& response) { -- auto mdns_info = mdns_get_pairing_service_info(host); -- -- if (!mdns_info.has_value()) { -+ if (true) { - // Check the address for a valid address and port. - std::string parsed_host; - std::string err; -@@ -223,9 +221,7 @@ void adb_wifi_pair_device(const std::string& host, const std::string& password, ++#if ADB_MDNS + auto mdns_info = mdns_get_pairing_service_info(host); ++#else ++ auto mdns_info = std::optional{}; ++#endif - PairingResultWaiter waiter; - std::unique_lock lock(waiter.mutex_); -- if (!client->Start(mdns_info.has_value() ? std::format("{}:{}", mdns_info->v4_address_string(), -- mdns_info->port) -- : host, -+ if (!client->Start(host, - waiter.OnResult, &waiter)) { - response = "Failed: Unable to start pairing client."; - return; -@@ -249,5 +245,4 @@ void adb_wifi_pair_device(const std::string& host, const std::string& password, + if (!mdns_info.has_value()) { + // Check the address for a valid address and port. +@@ -249,5 +253,7 @@ void adb_wifi_pair_device(const std::string& host, const std::string& password, known_wifi_hosts_file.AddKnownHost(device_guid); // Try to auto-connect. -- adb_secure_connect_by_service_name(device_guid); ++#if ADB_MDNS + adb_secure_connect_by_service_name(device_guid); ++#endif } -- -2.53.0 +2.55.0 diff --git a/patches/adb/0018-adbmdns-Fix-crate-type-dependencies-and-lib-name.patch b/patches/adb/0018-adbmdns-Fix-crate-type-dependencies-and-lib-name.patch new file mode 100644 index 00000000..02157eec --- /dev/null +++ b/patches/adb/0018-adbmdns-Fix-crate-type-dependencies-and-lib-name.patch @@ -0,0 +1,41 @@ +From 5f83bc5634b857b4503167ce46e1772d03e573ee Mon Sep 17 00:00:00 2001 +From: LuK1337 +Date: Sat, 1 Aug 2026 20:11:03 +0200 +Subject: [PATCH] adbmdns: Fix crate type, dependencies and lib name + +--- + client/adbmdns/Cargo.toml | 7 ++++--- + 1 file changed, 4 insertions(+), 3 deletions(-) + +diff --git a/client/adbmdns/Cargo.toml b/client/adbmdns/Cargo.toml +index 63e08e6..1446935 100644 +--- a/client/adbmdns/Cargo.toml ++++ b/client/adbmdns/Cargo.toml +@@ -4,8 +4,9 @@ version = "0.1.0" + edition = "2024" + + [lib] +-name = "zeroconf" ++name = "adbmdns_bridge" + path = "adbmdns_bridge.rs" ++crate-type = ["staticlib"] + + [dependencies] + socket2 = { version = "0.4.0", features = ["all"] } +@@ -14,11 +15,11 @@ simple-dns = "0.11.0" + zerocopy = { version = "0.8.26", features = ["derive"] } + libc = "0.2.174" + anyhow = "1.0.99" +-nix = { version = "0.29.0", features = ["socket", "uio"] } ++nix = { version = "0.29.0", features = ["net", "socket", "uio"] } + if-addrs = "0.14.0" + mio = { version = "1.1.0", features = ["net", "os-poll"] } + +-[dependencies.windows-sys] ++[target.'cfg(windows)'.dependencies.windows-sys] + version = "0.61.1" + features = [ + "Win32_Foundation", +-- +2.55.0 + diff --git a/patches/adb/0019-adbmdns-Downgrade-edition-to-2021.patch b/patches/adb/0019-adbmdns-Downgrade-edition-to-2021.patch new file mode 100644 index 00000000..05e42cf6 --- /dev/null +++ b/patches/adb/0019-adbmdns-Downgrade-edition-to-2021.patch @@ -0,0 +1,53 @@ +From 6ae3fecc7f1c09a6d17aeab1b3a2855e9172e8ed Mon Sep 17 00:00:00 2001 +From: LuK1337 +Date: Sat, 1 Aug 2026 23:23:25 +0200 +Subject: [PATCH] adbmdns: Downgrade edition to 2021 + +Required for Ubuntu 24.04. +--- + client/adbmdns/Cargo.toml | 2 +- + client/adbmdns/adbmdns_bridge.rs | 2 +- + client/adbmdns/netwatch/netwatch_linux.rs | 1 + + 3 files changed, 3 insertions(+), 2 deletions(-) + +diff --git a/client/adbmdns/Cargo.toml b/client/adbmdns/Cargo.toml +index 3238484..18fbacd 100644 +--- a/client/adbmdns/Cargo.toml ++++ b/client/adbmdns/Cargo.toml +@@ -3,7 +3,7 @@ cargo-features = ["edition2024"] + [package] + name = "adb_mdns" + version = "0.1.0" +-edition = "2024" ++edition = "2021" + + [lib] + name = "adbmdns_bridge" +diff --git a/client/adbmdns/adbmdns_bridge.rs b/client/adbmdns/adbmdns_bridge.rs +index 507b94a..52514fb 100644 +--- a/client/adbmdns/adbmdns_bridge.rs ++++ b/client/adbmdns/adbmdns_bridge.rs +@@ -297,7 +297,7 @@ impl log::Log for AdbLogger { + /// 3. Accept NUL-terminated strings for all const char* parameters + /// 4. Accept a buffer of `num_ipv4s` 32-bit values in `ipv4s` (expected to be network order octets) + /// 5. Accept a buffer of bytes in `ipv6s` which is the size of `num_ipv6s` * 16 (expected to be a sequence of sequences of octets, flattened). +-#[unsafe(no_mangle)] ++#[no_mangle] + pub unsafe extern "C" fn adbmdns_start( + log_callback: AdbLoggerCallback, + event_callback: EventCallback, +diff --git a/client/adbmdns/netwatch/netwatch_linux.rs b/client/adbmdns/netwatch/netwatch_linux.rs +index 18e1bdb..05ab96c 100644 +--- a/client/adbmdns/netwatch/netwatch_linux.rs ++++ b/client/adbmdns/netwatch/netwatch_linux.rs +@@ -37,6 +37,7 @@ use nix::sys::socket::SockProtocol; + use nix::sys::socket::SockType; + use std::collections::HashMap; + use std::fmt; ++use std::mem::size_of; + use std::os::fd::AsRawFd; + use std::path::PathBuf; + use std::thread; +-- +2.55.0 + diff --git a/patches/adb/0021-Rip-out-openscreen-support.patch b/patches/adb/0021-Rip-out-openscreen-support.patch new file mode 100644 index 00000000..7c0ed79d --- /dev/null +++ b/patches/adb/0021-Rip-out-openscreen-support.patch @@ -0,0 +1,91 @@ +From 12c17993d461d0b6514815f69d14dff0d1fcf5f9 Mon Sep 17 00:00:00 2001 +From: LuK1337 +Date: Sat, 1 Aug 2026 20:21:01 +0200 +Subject: [PATCH] Rip out openscreen support + +Will be gone in the next ADB release anyway. +--- + adb.cpp | 6 +----- + client/mdns_utils.cpp | 10 ---------- + client/mdns_utils.h | 2 -- + client/transport_mdns.cpp | 10 +--------- + 4 files changed, 2 insertions(+), 26 deletions(-) + +diff --git a/adb.cpp b/adb.cpp +index 0d8be53..1197bdd 100644 +--- a/adb.cpp ++++ b/adb.cpp +@@ -1371,11 +1371,7 @@ HostRequestResult handle_host_request(std::string_view service, TransportType ty + status.set_usb_backend_forced(getenv("ADB_LIBUSB") != nullptr); + + if (mdns::is_enabled()) { +- if (mdns::should_use_openscreen()) { +- status.set_mdns_backend(adb::proto::AdbServerStatus::OPENSCREEN); +- } else { +- status.set_mdns_backend(adb::proto::AdbServerStatus::LIBADBMDNS); +- } ++ status.set_mdns_backend(adb::proto::AdbServerStatus::LIBADBMDNS); + } else { + status.set_mdns_backend(adb::proto::AdbServerStatus::MDNS_DISABLED); + } +diff --git a/client/mdns_utils.cpp b/client/mdns_utils.cpp +index e578c1a..74a9036 100644 +--- a/client/mdns_utils.cpp ++++ b/client/mdns_utils.cpp +@@ -78,14 +78,4 @@ bool is_enabled() { + return !getenv("ADB_MDNS") || strcmp(getenv("ADB_MDNS"), "0") != 0; + } + +-// Historically, this env variable was a boolean used to disable openscreen. +-// It has evolved into an enum to select the mdns backend +-// 0 = Bonjour (deprecated) +-// 1 = Openscreen +-// 2 = Adbmdns +-bool should_use_openscreen() { +- const char* mdns_osp = getenv("ADB_MDNS_OPENSCREEN"); +- return mdns_osp != nullptr && strcmp(mdns_osp, "1") == 0; +-} +- + } // namespace mdns +diff --git a/client/mdns_utils.h b/client/mdns_utils.h +index d106133..86b8fe9 100644 +--- a/client/mdns_utils.h ++++ b/client/mdns_utils.h +@@ -53,6 +53,4 @@ std::optional mdns_parse_instance_name(std::string_view name); + + // Return true if mdns backend is enabled + bool is_enabled(); +- +-bool should_use_openscreen(); + } // namespace mdns +diff --git a/client/transport_mdns.cpp b/client/transport_mdns.cpp +index 930c695..809f156 100644 +--- a/client/transport_mdns.cpp ++++ b/client/transport_mdns.cpp +@@ -132,11 +132,7 @@ void OnServiceReceiverResult(const ServiceInfo& info, ServiceInfoState state) { + ///////////////////////////////////////////////////////////////////////////////// + + void init_mdns_transport_discovery() { +- if (mdns::should_use_openscreen()) { +- StartOpenScreenDiscovery(); +- } else { +- StartAdbMdnsDiscovery(); +- } ++ StartAdbMdnsDiscovery(); + } + + bool adb_secure_connect_by_service_name(const std::string& instance_name) { +@@ -152,10 +148,6 @@ std::string mdns_check() { + return "ERROR: mdns discovery disabled"; + } + +- if (mdns::should_use_openscreen()) { +- return "mdns daemon version [Openscreen discovery 0.0.0]"; +- } +- + return "mdns daemon version [adb discovery 0.0.0]"; + } + +-- +2.55.0 + diff --git a/patches/adb/0028-Migrate-to-fmt-format.patch b/patches/adb/0028-Migrate-to-fmt-format.patch index 14287b30..79bf7cdf 100644 --- a/patches/adb/0028-Migrate-to-fmt-format.patch +++ b/patches/adb/0028-Migrate-to-fmt-format.patch @@ -1,4 +1,4 @@ -From b9c8b7ddc67a70a3f0f48fb92976662f630cb600 Mon Sep 17 00:00:00 2001 +From 73c5f3d3753ccdd40a43fe1981150df8c71dbf23 Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Fri, 13 Mar 2026 00:15:41 +0100 Subject: [PATCH] Migrate to fmt::format() @@ -6,6 +6,8 @@ Subject: [PATCH] Migrate to fmt::format() Restores support for older toolchains. --- adb.cpp | 2 +- + client/adb_wifi.cpp | 2 +- + client/adbmdns/adbmdns.cpp | 8 +++++--- client/discovered_services.cpp | 4 ++-- client/discovered_services.h | 6 +++--- client/incremental.cpp | 22 +++++++++++----------- @@ -14,11 +16,12 @@ Restores support for older toolchains. client/usb_libusb_device.cpp | 10 +++++----- client/usb_libusb_hotplug.cpp | 4 +++- client/usb_osx.cpp | 3 ++- + socket_spec.cpp | 2 +- transport.cpp | 3 ++- - 10 files changed, 40 insertions(+), 36 deletions(-) + 13 files changed, 47 insertions(+), 41 deletions(-) diff --git a/adb.cpp b/adb.cpp -index 6321981..438243b 100644 +index 8f01d95..1197bdd 100644 --- a/adb.cpp +++ b/adb.cpp @@ -433,7 +433,7 @@ static void handle_new_connection(atransport* t, apacket* p) { @@ -30,6 +33,53 @@ index 6321981..438243b 100644 ((char*)(&(p->msg.command)))[1], ((char*)(&(p->msg.command)))[2], ((char*)(&(p->msg.command)))[3]); +diff --git a/client/adb_wifi.cpp b/client/adb_wifi.cpp +index 0141d9c..8a00f8d 100644 +--- a/client/adb_wifi.cpp ++++ b/client/adb_wifi.cpp +@@ -227,7 +227,7 @@ void adb_wifi_pair_device(const std::string& host, const std::string& password, + + PairingResultWaiter waiter; + std::unique_lock lock(waiter.mutex_); +- if (!client->Start(mdns_info.has_value() ? std::format("{}:{}", mdns_info->v4_address_string(), ++ if (!client->Start(mdns_info.has_value() ? fmt::format("{}:{}", mdns_info->v4_address_string(), + mdns_info->port) + : host, + waiter.OnResult, &waiter)) { +diff --git a/client/adbmdns/adbmdns.cpp b/client/adbmdns/adbmdns.cpp +index dd88283..ee0005e 100644 +--- a/client/adbmdns/adbmdns.cpp ++++ b/client/adbmdns/adbmdns.cpp +@@ -17,6 +17,8 @@ + #include "adbmdns.h" + #include "adbmdns_bridge.h" + ++#include ++ + #include + + #include "adb_trace.h" +@@ -25,9 +27,9 @@ + + template + requires std::is_enum_v +-struct std::formatter : std::formatter { ++struct fmt::formatter : fmt::formatter { + constexpr auto format(const E& e, auto& ctx) const { +- using Base = std::formatter; ++ using Base = fmt::formatter; + return Base::format("Enum(" + std::to_string(e) + ")", ctx); + } + }; +@@ -78,7 +80,7 @@ static std::vector> parseTxt(const uint32_t num_txt_kv, + for (uint32_t kv_index = 0; kv_index < num_txt_kv; kv_index++) { + std::string key(txt_kvs[kv_index].key, txt_kvs[kv_index].key_size); + std::string value(txt_kvs[kv_index].value, txt_kvs[kv_index].value_size); +- std::string entry = std::format("{}={}", key, value); ++ std::string entry = fmt::format("{}={}", key, value); + + // Convert string into vector + std::vector u8_vec; diff --git a/client/discovered_services.cpp b/client/discovered_services.cpp index a5fd0d5..7e7ceb0 100644 --- a/client/discovered_services.cpp @@ -53,7 +103,7 @@ index a5fd0d5..7e7ceb0 100644 return {}; } diff --git a/client/discovered_services.h b/client/discovered_services.h -index be8bffa..36731b9 100644 +index 73fefd4..7bd2413 100644 --- a/client/discovered_services.h +++ b/client/discovered_services.h @@ -17,10 +17,10 @@ @@ -77,7 +127,7 @@ index be8bffa..36731b9 100644 if (i < 14) { result += ":"; -@@ -102,7 +102,7 @@ struct ServiceInfo { +@@ -104,7 +104,7 @@ struct ServiceInfo { if (!v4_address.has_value()) { return ""; } @@ -268,10 +318,10 @@ index fae5f83..1eb7961 100644 } return std::make_pair(offset, tree_size); diff --git a/client/transport_mdns.cpp b/client/transport_mdns.cpp -index e3aa9d7..03e481d 100644 +index b643fce..809f156 100644 --- a/client/transport_mdns.cpp +++ b/client/transport_mdns.cpp -@@ -53,8 +53,8 @@ static void RequestConnectToDevice(const ServiceInfo& info) { +@@ -55,8 +55,8 @@ static void RequestConnectToDevice(const ServiceInfo& info) { std::thread([=] { VLOG(MDNS) << "Attempting to secure connect to instance '" << info << "'"; std::string response; @@ -282,7 +332,7 @@ index e3aa9d7..03e481d 100644 info.service, info.v4_address_string(), info.port, response); }).detach(); } -@@ -152,7 +152,7 @@ std::string mdns_check() { +@@ -154,7 +154,7 @@ std::string mdns_check() { std::string mdns_list_discovered_services() { std::string result; auto cb = [&](const ServiceInfo& si) { @@ -291,7 +341,7 @@ index e3aa9d7..03e481d 100644 si.port); }; mdns::discovered_services.ForAllServices(cb); -@@ -169,7 +169,7 @@ std::optional mdns_get_connect_service_info(const std::string& name +@@ -171,7 +171,7 @@ std::optional mdns_get_connect_service_info(const std::string& name } std::string fq_service = @@ -385,8 +435,21 @@ index 0e5af48..730150b 100644 } } +diff --git a/socket_spec.cpp b/socket_spec.cpp +index da9f100..e298dc3 100644 +--- a/socket_spec.cpp ++++ b/socket_spec.cpp +@@ -243,7 +243,7 @@ bool socket_spec_connect(unique_fd* fd, std::string_view address, int* port, + port_value = mdns_info->port; + if (transport_name) { + *transport_name = +- std::format("{}.{}", mdns_info->instance, mdns_info->service); ++ fmt::format("{}.{}", mdns_info->instance, mdns_info->service); + } + } + } else { diff --git a/transport.cpp b/transport.cpp -index c5fe0aa..cf8561f 100644 +index 09d7d20..4659717 100644 --- a/transport.cpp +++ b/transport.cpp @@ -46,6 +46,7 @@ @@ -407,5 +470,5 @@ index c5fe0aa..cf8561f 100644 ((char*)(&(p->msg.command)))[3]); -- -2.54.0 +2.55.0 diff --git a/vendor/CMakeLists.adb.txt b/vendor/CMakeLists.adb.txt index b2afabac..8f766fc3 100644 --- a/vendor/CMakeLists.adb.txt +++ b/vendor/CMakeLists.adb.txt @@ -9,6 +9,20 @@ protobuf_generate_cpp(ADB_KNOWN_HOSTS_PROTO_SRCS ADB_KNOWN_HOSTS_PROTO_HDRS protobuf_generate_cpp(ADB_PAIRING_PROTO_SRCS ADB_PAIRING_PROTO_HDRS adb/proto/pairing.proto) +if(ANDROID_TOOLS_ADB_ENABLE_MDNS) + if(ANDROID_TOOLS_USE_BUNDLED_CORROSION) + add_subdirectory(corrosion) + else() + find_package(Corrosion CONFIG REQUIRED) + message(STATUS "Found Corrosion: ${Corrosion_DIR} (version ${Corrosion_VERSION})") + endif() + + corrosion_import_crate( + MANIFEST_PATH adb/client/adbmdns/Cargo.toml + PROFILE release + ) +endif() + # No fastdeploy because it requires deployagent.inc set(libadb_SOURCES adb/client/adb_client.cpp @@ -60,6 +74,12 @@ else() adb/client/usb_linux_netlink.cpp) endif() +if(ANDROID_TOOLS_ADB_ENABLE_MDNS) + list(APPEND libadb_SOURCES + adb/client/adbmdns/adbmdns.cpp + adb/adb_mdns.cpp) +endif() + add_library(libadb STATIC ${libadb_SOURCES}) target_compile_definitions(libadb PRIVATE -D_GNU_SOURCE) target_compile_definitions(libadb PUBLIC -DADB_HOST=1) @@ -81,6 +101,11 @@ if(ANDROID_TOOLS_USE_BUNDLED_LIBUSB) target_include_directories(libadb PUBLIC libusb) endif() +if(ANDROID_TOOLS_ADB_ENABLE_MDNS) + target_compile_definitions(libadb PUBLIC -DADB_MDNS=1) + target_link_libraries(libadb PUBLIC adbmdns_bridge) +endif() + target_link_libraries(libadb PUBLIC fmt::fmt) add_library(libadb_crypto_defaults STATIC diff --git a/vendor/corrosion b/vendor/corrosion new file mode 160000 index 00000000..c4786e7a --- /dev/null +++ b/vendor/corrosion @@ -0,0 +1 @@ +Subproject commit c4786e7ae2d5ade784aca29448df362c874ed04e