Skip to content

Commit

Permalink
Add MacOS platform
Browse files Browse the repository at this point in the history
  • Loading branch information
Biswa96 authored and anatol committed Nov 12, 2022
1 parent b9146e8 commit a1ab35b
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 16 deletions.
32 changes: 30 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ jobs:
with:
name: package_source
path: ${{ github.workspace }}/build/android-tools-*.tar.xz
build:
runs-on: ubuntu-latest

linux:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -136,3 +136,31 @@ jobs:
echo -e "\n### make install ###\n"
ninja install
echo -e "\n### all done ###\n"
macos:
runs-on: macos-latest
steps:
- name: prep macos
run: |
brew install brotli cmake googletest libusb lz4 \
ninja pcre2 protobuf zstd
# required for patches
- name: git config
run: |
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
- name: checkout
uses: actions/checkout@v3
with:
submodules: true

- name: build & install
run: |
mkdir build && cd build
cmake -DCMAKE_C_FLAGS="$CFLAGS" -DCMAKE_CXX_FLAGS="$CXXFLAGS" -DCMAKE_BUILD_TYPE=Release -GNinja ..
ninja --verbose
echo -e "\n### make install ###\n"
ninja install
echo -e "\n### all done ###\n"
30 changes: 22 additions & 8 deletions vendor/CMakeLists.adb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ protobuf_generate_cpp(ADB_PAIRING_PROTO_SRCS ADB_PAIRING_PROTO_HDRS
adb/proto/pairing.proto)

# No fastdeploy because it requires deployagent.inc
add_library(libadb STATIC
set(libadb_SOURCES
adb/client/adb_client.cpp
adb/client/adb_install.cpp
adb/client/adb_wifi.cpp
Expand All @@ -24,7 +24,6 @@ add_library(libadb STATIC
adb/client/main.cpp
adb/client/pairing/pairing_client.cpp
adb/client/usb_libusb.cpp
adb/client/usb_linux.cpp
adb/pairing_auth/aes_128_gcm.cpp
adb/pairing_auth/pairing_auth.cpp
adb/pairing_connection/pairing_connection.cpp
Expand All @@ -38,6 +37,15 @@ add_library(libadb STATIC
${ADB_KEY_TYPE_PROTO_SRCS} ${ADB_KEY_TYPE_PROTO_HDRS}
${ADB_PAIRING_PROTO_SRCS} ${ADB_PAIRING_PROTO_HDRS})

if(APPLE)
list(APPEND libadb_SOURCES
adb/client/usb_osx.cpp)
else()
list(APPEND libadb_SOURCES
adb/client/usb_linux.cpp)
endif()

add_library(libadb STATIC ${libadb_SOURCES})
target_compile_definitions(libadb PRIVATE -D_GNU_SOURCE)
target_compile_definitions(libadb PUBLIC -DADB_HOST=1)
target_include_directories(libadb PUBLIC
Expand Down Expand Up @@ -187,11 +195,17 @@ target_link_libraries(adb
crypto
ssl
${PROTOBUF_LIBRARIES}
brotlicommon
brotlidec
brotlienc
lz4
PkgConfig::libbrotlicommon
PkgConfig::libbrotlidec
PkgConfig::libbrotlienc
PkgConfig::liblz4
Threads::Threads
usb-1.0
PkgConfig::libusb-1.0
z
zstd)
PkgConfig::libzstd)

if(APPLE)
target_link_libraries(adb
"-framework CoreFoundation"
"-framework IOKit")
endif()
34 changes: 29 additions & 5 deletions vendor/CMakeLists.fastboot.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ add_library(libext4 STATIC
extras/ext4_utils/ext4_sb.cpp)

target_include_directories(libext4 PUBLIC
core/libsparse/include core/include selinux/libselinux/include
core/libsparse/include core/include
extras/ext4_utils/include libbase/include)

if(NOT APPLE)
target_include_directories(libext4 PUBLIC
selinux/libselinux/include)
endif(NOT APPLE)

add_library(libfsmgr STATIC
core/fs_mgr/liblp/images.cpp
core/fs_mgr/liblp/partition_opener.cpp
Expand All @@ -48,6 +53,7 @@ target_include_directories(libfsmgr PRIVATE
boringssl/include)
target_link_libraries(libfsmgr PUBLIC fmt::fmt)

if(NOT APPLE)
add_library(libselinux STATIC
selinux/libselinux/src/booleans.c
selinux/libselinux/src/callbacks.c
Expand Down Expand Up @@ -109,8 +115,9 @@ add_library(libsepol

target_include_directories(libsepol PUBLIC
selinux/libsepol/include)
endif(NOT APPLE)

add_executable(fastboot
set(fastboot_SOURCES
core/fastboot/bootimg_utils.cpp
core/fastboot/fastboot.cpp
core/fastboot/fastboot_driver.cpp
Expand All @@ -119,10 +126,18 @@ add_executable(fastboot
core/fastboot/socket.cpp
core/fastboot/tcp.cpp
core/fastboot/udp.cpp
core/fastboot/usb_linux.cpp
core/fastboot/vendor_boot_img_utils.cpp
core/fastboot/util.cpp)

if(APPLE)
list(APPEND fastboot_SOURCES
core/fastboot/usb_osx.cpp)
else()
list(APPEND fastboot_SOURCES
core/fastboot/usb_linux.cpp)
endif()

add_executable(fastboot ${fastboot_SOURCES})
target_include_directories(fastboot PRIVATE
libbase/include core/include core/adb core/libsparse/include
extras/ext4_utils/include extras/f2fs_utils
Expand All @@ -135,5 +150,14 @@ target_compile_definitions(fastboot PRIVATE
-DANDROID_MKE2FS_NAME="${ANDROID_MKE2FS_NAME}")
target_link_libraries(fastboot
libsparse libzip libcutils liblog libfsmgr libutil
libbase libext4 libselinux libsepol libdiagnoseusb crypto
z pcre2-8 Threads::Threads dl)
libbase libext4 libdiagnoseusb crypto
z PkgConfig::libpcre2-8 Threads::Threads dl)

if(APPLE)
target_link_libraries(fastboot
"-framework CoreFoundation"
"-framework IOKit")
else()
target_link_libraries(fastboot
libselinux libsepol)
endif()
2 changes: 2 additions & 0 deletions vendor/CMakeLists.mke2fs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ target_link_libraries("${ANDROID_MKE2FS_NAME}"
target_include_directories("${ANDROID_MKE2FS_NAME}" PRIVATE
e2fsprogs/lib)

if(NOT APPLE)
add_executable(e2fsdroid
e2fsprogs/contrib/android/e2fsdroid.c
e2fsprogs/contrib/android/basefs_allocator.c
Expand All @@ -137,6 +138,7 @@ target_link_libraries(e2fsdroid
libext2fs libsparse libzip libcutils liblog libutil libbase libselinux libsepol z pcre2-8 pthread)
target_include_directories(e2fsdroid PRIVATE
e2fsprogs/lib e2fsprogs/lib/ext2fs selinux/libselinux/include core/libcutils/include e2fsprogs/misc)
endif(NOT APPLE)

add_executable(ext2simg
e2fsprogs/contrib/android/ext2simg.c)
Expand Down
21 changes: 20 additions & 1 deletion vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DARWIN_C_SOURCE -D__DARWIN_C_LEVEL=__DARWIN_C_FULL")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_DARWIN_C_SOURCE -D__DARWIN_C_LEVEL=__DARWIN_C_FULL")
endif()

# Android seems to use various attributes supported by clang but not by
# GCC which causes it to emit lots of warnings. Since these attributes
# don't seem to effect runtime behaviour simply disable the warnings.
Expand Down Expand Up @@ -58,6 +63,15 @@ endif()
add_subdirectory(boringssl EXCLUDE_FROM_ALL)
add_subdirectory(fmtlib EXCLUDE_FROM_ALL)

find_package(PkgConfig REQUIRED)
pkg_check_modules(libbrotlicommon REQUIRED IMPORTED_TARGET libbrotlicommon)
pkg_check_modules(libbrotlidec REQUIRED IMPORTED_TARGET libbrotlidec)
pkg_check_modules(libbrotlienc REQUIRED IMPORTED_TARGET libbrotlienc)
pkg_check_modules(liblz4 REQUIRED IMPORTED_TARGET liblz4)
pkg_check_modules(libpcre2-8 REQUIRED IMPORTED_TARGET libpcre2-8)
pkg_check_modules(libusb-1.0 REQUIRED IMPORTED_TARGET libusb-1.0)
pkg_check_modules(libzstd REQUIRED IMPORTED_TARGET libzstd)

find_package(Protobuf REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
Expand Down Expand Up @@ -89,10 +103,15 @@ install(TARGETS
lpmake
lpunpack
simg2img
e2fsdroid
ext2simg
DESTINATION bin)

if(NOT APPLE)
install(TARGETS
e2fsdroid
DESTINATION bin)
endif()

# Install common completion files.
install(FILES adb/adb.bash RENAME adb DESTINATION "${COMPLETION_COMMON_DIR}")
install(FILES core/fastboot/fastboot.bash RENAME fastboot DESTINATION "${COMPLETION_COMMON_DIR}")
Expand Down

0 comments on commit a1ab35b

Please sign in to comment.