Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
MuggleWei committed Dec 7, 2023
2 parents 2646204 + fe2282e commit 6f10470
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 686 deletions.
23 changes: 19 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ message("-- use c++ compiler ${CMAKE_CXX_COMPILER}")

# set compile parameter
if (${CMAKE_C_COMPILER_ID} STREQUAL GNU)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
elseif (${CMAKE_C_COMPILER_ID} MATCHES Clang)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-missing-field-initializers")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-missing-field-initializers")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
elseif (${CMAKE_C_COMPILER_ID} STREQUAL MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1 -D_UNICODE -DUNICODE)
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
endif()

# set standard and print features
Expand Down Expand Up @@ -65,6 +67,19 @@ foreach(path ${CMAKE_PREFIX_PATH})
message("# CMake Prefix Path: ${path}")
endforeach()

# patch: find_package failed when use android toolchain
if (ANDROID)
message("# ANDROID PLATFORM: ${ANDROID_PLATFORM}")
message("# CMAKE_FIND_ROOT_PATH: ${CMAKE_FIND_ROOT_PATH}")
message("# append CMAKE_PREFIX_PATH into CMAKE_FIND_ROOT_PATH")
foreach(path ${CMAKE_PREFIX_PATH})
list(APPEND CMAKE_FIND_ROOT_PATH "${path}")
endforeach()

# Or use NO_CMAKE_FIND_ROOT_PATH, but openssl still failed
#find_package(mugglec REQUIRED NO_CMAKE_FIND_ROOT_PATH)
endif()

find_package(mugglec REQUIRED)
if (mugglec_FOUND)
message("deps mugglec version: ${mugglec_VERSION}")
Expand Down
47 changes: 21 additions & 26 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ build_openssl=1

# directories
build_dir=$origin_dir/build
install_dir=$build_dir/usr
deps_dir=$origin_dir/_deps
dist_dir=$build_dir/usr
pkg_dir=$origin_dir/dist
dep_dir=$origin_dir/_deps

# function
download_src() {
Expand Down Expand Up @@ -49,31 +49,31 @@ if [ ! -d $build_dir ]; then
mkdir -p $build_dir
fi

if [ ! -d $install_dir ]; then
if [ ! -d $deps_dir ]; then
echo "create dependency directory"
mkdir -p $deps_dir
fi

if [ ! -d $dist_dir ]; then
echo "create install directory"
mkdir -p $install_dir
mkdir -p $dist_dir
fi

if [ ! -d $pkg_dir ]; then
echo "create package directory"
mkdir -p $pkg_dir
fi

if [ ! -d $dep_dir ]; then
echo "create dependency directory"
mkdir -p $dep_dir
fi

# mugglec
echo "------------------------"
if [ $build_mugglec -eq 1 ]; then
echo "build mugglec"
cd $dep_dir
cd $deps_dir

mugglec_git=https://github.com/MuggleWei/mugglec.git
mugglec_tag=v1.3.2
mugglec_tag=v1.4.3
mugglec_name=mugglec-$mugglec_tag
mugglec_src_dir=$dep_dir/$mugglec_name
mugglec_src_dir=$deps_dir/$mugglec_name
mugglec_build_dir=$build_dir/_deps/mugglec

if [ ! -d $mugglec_src_dir ]; then
Expand All @@ -86,11 +86,6 @@ if [ $build_mugglec -eq 1 ]; then
fi
cd $mugglec_build_dir

# patch for mac
if [[ "$OSTYPE" == "darwin"* ]]; then
cp $origin_dir/patch_scripts/mugglec_cmakelist.txt $mugglec_src_dir/CMakeLists.txt
fi

cmake \
-S $mugglec_src_dir -B $mugglec_build_dir \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
Expand All @@ -101,7 +96,7 @@ if [ $build_mugglec -eq 1 ]; then
-DBUILD_TESTING=OFF \
-DMUGGLE_BUILD_EXAMPLE=OFF \
-DMUGGLE_BUILD_BENCHMARK=OFF \
-DCMAKE_INSTALL_PREFIX=$install_dir
-DCMAKE_INSTALL_PREFIX=$dist_dir

cmake --build $mugglec_build_dir
cmake --build $mugglec_build_dir --target install
Expand All @@ -115,12 +110,12 @@ cd $origin_dir
echo "------------------------"
if [ $build_openssl -eq 1 ]; then
echo "build openssl"
cd $dep_dir
cd $deps_dir

openssl_git=https://github.com/openssl/openssl.git
openssl_tag=openssl-3.1.4
openssl_name=openssl-$openssl_tag
openssl_src_dir=$dep_dir/$openssl_name
openssl_src_dir=$deps_dir/$openssl_name
openssl_build_dir=$build_dir/_deps/openssl

if [ ! -d $openssl_src_dir ]; then
Expand All @@ -134,8 +129,8 @@ if [ $build_openssl -eq 1 ]; then
cd $openssl_build_dir

$openssl_src_dir/Configure \
--prefix=$install_dir \
--openssldir=$install_dir \
--prefix=$dist_dir \
--openssldir=$dist_dir \
--libdir=lib \
threads \
no-comp \
Expand All @@ -157,18 +152,18 @@ cd $origin_dir
cmake \
-S $origin_dir -B $build_dir \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_PREFIX_PATH=$install_dir \
-DCMAKE_INSTALL_PREFIX=$install_dir
-DCMAKE_PREFIX_PATH=$dist_dir \
-DCMAKE_INSTALL_PREFIX=$dist_dir
#ln -sf $build_dir/compile_commands.json $origin_dir/
cmake --build $build_dir
cmake --build $build_dir --target install

# package
cd $install_dir
cd $dist_dir
if [[ "$OSTYPE" == "darwin"* ]]; then
# force change rpath to openssl in yoauth
if [ $build_openssl -eq 1 ]; then
install_name_tool -change "$install_dir/lib/libcrypto.3.dylib" @rpath/libcrypto.3.dylib bin/yoauth
install_name_tool -change "$dist_dir/lib/libcrypto.3.dylib" @rpath/libcrypto.3.dylib bin/yoauth
fi
tar -czvf yoauth.tar.gz bin/yoauth* lib/*.dylib*
else
Expand Down
2 changes: 1 addition & 1 deletion build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: yoauth
variables:
- build_type: release
- yoauth_tag: v1.0.0
- yoauth_tag: v1.0.17
- mugglec_tag: v1.3.5
- openssl_tag: openssl-3.1.4
- unity_tag: v2.5.2
Expand Down
178 changes: 178 additions & 0 deletions build_android.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
#!/bin/bash

# handle argv
if [ "$#" -lt 1 ]; then
echo "[WARNING] Usage: bootstrap.sh <Debug|Release|RelWithDebInfo>"
echo "[WARNING] bootstrap without build type, use release by default"
BUILD_TYPE=release
else
# to lowercase
BUILD_TYPE=$(echo $1 | tr '[:upper:]' '[:lower:]')
fi

# project root directory
origin_dir="$(dirname "$(readlink -f "$0")")"

# build option
build_mugglec=1
build_openssl=1

# directories
build_dir=$origin_dir/build
deps_dir=$origin_dir/_deps
dist_dir=$build_dir/dist
pkg_dir=$origin_dir/dist

abi=arm64-v8a
min_sdk=29

# function
download_src() {
local name=$1
local git_repo=$2
local tag=$3
local src_dir=$4

if [ -d $src_dir ]; then
echo "$name source directory already exists"
else
echo "$name source directory not exists, clone"
echo "name=$name"
echo "git_repo=$git_repo"
echo "tag=$tag"
echo "src_dir=$src_dir"

git clone --branch $tag --depth 1 $git_repo $src_dir
fi
}

# check ndk
if [ -z "$ANDROID_NDK_ROOT" ]; then
echo "run without ANDROID_NDK_ROOT"
exit 1
else
echo "ndk: $ANDROID_NDK_ROOT"
fi

# clean
if [ ! -d $build_dir ]; then
echo "create build directory"
mkdir -p $build_dir
fi

if [ ! -d $deps_dir ]; then
echo "create dependency directory"
mkdir -p $deps_dir
fi

if [ ! -d $dist_dir ]; then
echo "create install directory"
mkdir -p $dist_dir
fi

if [ ! -d $pkg_dir ]; then
echo "create package directory"
mkdir -p $pkg_dir
fi

# mugglec
echo "------------------------"
if [ $build_mugglec -eq 1 ]; then
echo "build mugglec"
cd $deps_dir

mugglec_git=https://github.com/MuggleWei/mugglec.git
mugglec_tag=v1.4.3
mugglec_name=mugglec-$mugglec_tag
mugglec_src_dir=$deps_dir/$mugglec_name
mugglec_build_dir=$build_dir/_deps/mugglec

if [ ! -d $mugglec_src_dir ]; then
download_src $mugglec_name $mugglec_git $mugglec_tag ${mugglec_src_dir}_tmp
mv ${mugglec_src_dir}_tmp $mugglec_src_dir
fi

if [ ! -d $mugglec_build_dir ]; then
mkdir -p $mugglec_build_dir
fi
cd $mugglec_build_dir

cmake \
-S $mugglec_src_dir -B $mugglec_build_dir \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX=$dist_dir \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=$abi \
-DANDROID_PLATFORM=android-$min_sdk
cmake --build $mugglec_build_dir
cmake --build $mugglec_build_dir --target install
else
echo "option build mugglec off, ignore build mugglec"
fi
cd $origin_dir

# openssl
echo "------------------------"
if [ $build_openssl -eq 1 ]; then
echo "build openssl"
cd $deps_dir

openssl_git=https://github.com/openssl/openssl.git
openssl_tag=openssl-3.1.4
openssl_name=openssl-$openssl_tag
openssl_src_dir=$deps_dir/$openssl_name
openssl_build_dir=$build_dir/_deps/openssl

if [ ! -d $openssl_src_dir ]; then
download_src $openssl_name $openssl_git $openssl_tag ${openssl_src_dir}_tmp
mv ${openssl_src_dir}_tmp $openssl_src_dir
fi

if [ ! -d $openssl_build_dir ]; then
mkdir -p $openssl_build_dir
fi
cd $openssl_build_dir

PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
$openssl_src_dir/Configure \
android-arm64 \
-U__ANDROID_API__ \
-D__ANDROID_API__=$min_sdk \
--prefix=$dist_dir \
--openssldir=$dist_dir \
--libdir=lib \
threads \
no-shared \
no-comp \
-Wl,-rpath,\\\$\$ORIGIN/../lib \
no-tests \
--$BUILD_TYPE

#bear -- make
make
make install_sw
#ln -sf $openssl_build_dir/compile_commands.json $openssl_src_dir
else
echo "option build openssl off, ignore build openssl"
fi
cd $origin_dir

# build
cd $origin_dir
cmake \
-S $origin_dir -B $build_dir \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_PREFIX_PATH=$dist_dir \
-DCMAKE_INSTALL_PREFIX=$dist_dir \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=$abi \
-DANDROID_PLATFORM=android-$min_sdk
cmake --build $build_dir
cmake --build $build_dir --target install

# package
cd $dist_dir
tar -czvf yoauth.tar.gz bin/yoauth*
mv yoauth.tar.gz $pkg_dir
2 changes: 1 addition & 1 deletion dep_modules/mugglec.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: mugglec
variables:
- build_type: release
- mugglec_tag: v1.3.5
- mugglec_tag: v1.4.3
- mugglec_url: https://github.com/MuggleWei/mugglec.git
source:
maintainer: mugglewei
Expand Down
Loading

0 comments on commit 6f10470

Please sign in to comment.