From 8031c68038d68d446248e71d653ba1eb306a39e9 Mon Sep 17 00:00:00 2001 From: arm64v8a <48624112+arm64v8a@users.noreply.github.com> Date: Mon, 8 Aug 2022 11:07:29 +0800 Subject: [PATCH] update build script --- .github/workflows/build-qv2ray-cmake.yml | 79 +++++++++++++------ CMakeLists.txt | 13 ++- cmake/fuck_windows/fuck.cmake | 2 +- cmake/myproto.cmake | 2 +- libs/.gitignore | 2 +- libs/build_asset.sh | 14 ++++ libs/build_go.sh | 43 ++++++++++ libs/deploy_common.sh | 45 +---------- libs/deploy_linux64.sh | 16 +--- libs/deploy_windows64.sh | 18 ++--- libs/get_source.sh | 23 ++++++ matsuri_commit.txt | 2 +- .../components/proxy/QvProxyConfigurator.cpp | 8 +- 13 files changed, 163 insertions(+), 104 deletions(-) create mode 100755 libs/build_asset.sh create mode 100755 libs/build_go.sh create mode 100755 libs/get_source.sh diff --git a/.github/workflows/build-qv2ray-cmake.yml b/.github/workflows/build-qv2ray-cmake.yml index cc8f37c..36b5e94 100644 --- a/.github/workflows/build-qv2ray-cmake.yml +++ b/.github/workflows/build-qv2ray-cmake.yml @@ -10,12 +10,35 @@ on: description: 'Publish: If want ignore' required: false jobs: - build: + build-go: + runs-on: ubuntu-latest + steps: + - name: Checking out sources + uses: actions/checkout@v2 + - name: Install Golang + uses: actions/setup-go@v2 + with: + stable: false + go-version: 1.18.5 + - name: Build golang and common parts + shell: bash + run: | + ./libs/get_source.sh + GOOS=linux GOARCH=amd64 ./libs/build_go.sh + GOOS=windows GOARCH=amd64 ./libs/build_go.sh + ./libs/build_asset.sh + - name: Tar files + run: tar czvf artifacts.tgz ./deployment + - name: Uploading Artifact + uses: actions/upload-artifact@master + with: + name: NekoRay-${{ github.sha }}-Common + path: artifacts.tgz + build-cpp: strategy: matrix: platform: [ windows-2022, ubuntu-18.04 ] arch: [ x64 ] - build_type: [ Release ] qt_version: [ 5.15.2 ] include: - platform: windows-2022 @@ -66,11 +89,6 @@ jobs: run: | sudo apt-get update sudo apt-get install -y ninja-build - - name: Install Golang - uses: actions/setup-go@v2 - with: - stable: false - go-version: 1.18.5 # ========================================================================================================= 编译与 Qt 无关的依赖 - name: Cache Download id: cache-deps @@ -93,9 +111,7 @@ jobs: run: | mkdir build cd build - cmake .. -GNinja \ - -DCMAKE_PREFIX_PATH=./libs/deps/built \ - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + cmake -GNinja -DCMAKE_BUILD_TYPE=Release .. cmake --build . --parallel $(nproc) cd .. ./libs/deploy_windows64.sh @@ -105,26 +121,34 @@ jobs: run: | mkdir build cd build - cmake .. -GNinja \ - -DCMAKE_PREFIX_PATH=./libs/deps/built \ - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + cmake -GNinja -DCMAKE_BUILD_TYPE=Release .. cmake --build . --parallel $(nproc) cd .. ./libs/deploy_linux64.sh # ========================================================================================================= Deployments + - name: Tar files + shell: bash + run: tar czvf artifacts.tgz ./deployment - name: Uploading Artifact uses: actions/upload-artifact@master with: name: NekoRay-${{ github.sha }}-${{ matrix.platform }}-${{ matrix.arch }} - path: ./deployment/ + path: artifacts.tgz publish: name: Publish Release if: github.event.inputs.publish != 'y' runs-on: ubuntu-latest - needs: build + needs: + - build-cpp + - build-go steps: - - name: Checkout + - name: Checking out sources uses: actions/checkout@v2 + - name: Donwload Artifacts + uses: actions/download-artifact@v2 + with: + name: NekoRay-${{ github.sha }}-Common + path: artifacts-common - name: Donwload Artifacts uses: actions/download-artifact@v2 with: @@ -137,10 +161,21 @@ jobs: path: artifacts-windows - name: Release run: | - wget -O ghr.tar.gz https://github.com/tcnksm/ghr/releases/download/v0.13.0/ghr_v0.13.0_linux_amd64.tar.gz - tar -xvf ghr.tar.gz + source libs/deploy_common.sh + curl -Lo - https://github.com/tcnksm/ghr/releases/download/v0.13.0/ghr_v0.13.0_linux_amd64.tar.gz | tar xzv mv ghr*linux_amd64/ghr . - mkdir apks - find artifacts-linux -name "*.tar.gz" -exec cp {} apks \; - find artifacts-windows -name "*.zip" -exec cp {} apks \; - ./ghr -delete -t "${{ github.token }}" -n "${{ github.event.inputs.tag }}" "${{ github.event.inputs.tag }}" apks + tar xzvf artifacts-linux/artifacts.tgz + tar xzvf artifacts-windows/artifacts.tgz + tar xzvf artifacts-common/artifacts.tgz + cd deployment + cp -r assets/* linux64 + cp -r assets/* windows64 + rm -rf assets + mv linux64 nekoray + zip -r $version_standalone-linux64.zip nekoray + rm -rf nekoray + mv windows64 nekoray + zip -r $version_standalone-windows64.zip nekoray + rm -rf nekoray + cd .. + ./ghr -delete -t "${{ github.token }}" -n "${{ github.event.inputs.tag }}" "${{ github.event.inputs.tag }}" deployment diff --git a/CMakeLists.txt b/CMakeLists.txt index 0099a1f..765a83d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,12 +33,16 @@ endif () # Windows include("cmake/fuck_windows/fuck.cmake") -# My dependencies -include("cmake/print.cmake") -set(MY_DEPS_DIR "${CMAKE_SOURCE_DIR}/libs/deps/built") -list(APPEND CMAKE_PREFIX_PATH ${MY_DEPS_DIR}) +# default prefix path +list(APPEND CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/libs/deps/built) +message("[CMAKE_PREFIX_PATH] ${CMAKE_PREFIX_PATH}") + +# for some cross toolchain +list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_PREFIX_PATH}) +message("[CMAKE_FIND_ROOT_PATH] ${CMAKE_FIND_ROOT_PATH}") # NKR +include("cmake/print.cmake") include("cmake/nkr.cmake") find_package(Threads) @@ -64,6 +68,7 @@ else () # QHotkey (static submodule) set(QHOTKEY_INSTALL OFF) + set(BUILD_SHARED_LIBS OFF) add_subdirectory(3rdparty/QHotkey) list(APPEND NKR_EXTERNAL_TARGETS qhotkey) endif () diff --git a/cmake/fuck_windows/fuck.cmake b/cmake/fuck_windows/fuck.cmake index e9b455d..ed82fcd 100644 --- a/cmake/fuck_windows/fuck.cmake +++ b/cmake/fuck_windows/fuck.cmake @@ -1,5 +1,6 @@ if (WIN32) set(PLATFORM_FUCKING_SOURCES 3rdparty/WinCommander.cpp) + set(PLATFORM_FUCKING_LIBRARIES wininet wsock32 ws2_32 user32 rasapi32 iphlpapi) include(cmake/fuck_windows/generate_product_version.cmake) generate_product_version( @@ -21,7 +22,6 @@ if (WIN32) add_compile_options("/utf-8") add_compile_options("/std:c++17") add_definitions(-D_WIN32_WINNT=0x600 -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS) - set(PLATFORM_FUCKING_LIBRARIES wininet wsock32 ws2_32 user32 Rasapi32 Iphlpapi) list(APPEND PLATFORM_FUCKING_SOURCES sys/windows/MiniDump.cpp) endif () endif () diff --git a/cmake/myproto.cmake b/cmake/myproto.cmake index 89ddb70..0533fea 100644 --- a/cmake/myproto.cmake +++ b/cmake/myproto.cmake @@ -4,7 +4,7 @@ set(PROTO_FILES go/gen/libcore.proto ) -add_library(myproto ${PROTO_FILES}) +add_library(myproto STATIC ${PROTO_FILES}) target_link_libraries(myproto PUBLIC protobuf::libprotobuf diff --git a/libs/.gitignore b/libs/.gitignore index f428a32..ecbf89d 100644 --- a/libs/.gitignore +++ b/libs/.gitignore @@ -1,2 +1,2 @@ -deps +/deps* downloaded \ No newline at end of file diff --git a/libs/build_asset.sh b/libs/build_asset.sh new file mode 100755 index 0000000..e76a6d5 --- /dev/null +++ b/libs/build_asset.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -e + +source libs/deploy_common.sh +DEST=$DEPLOYMENT/assets +rm -rf $DEST +mkdir -p $DEST + +#### Download: geoip #### +curl -Lso $DEST/geoip.dat "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/download/202206042210/geoip.dat" +curl -Lso $DEST/geosite.dat "https://github.com/v2fly/domain-list-community/releases/download/20220604062951/dlc.dat" + +#### copy assets #### +cp assets/* $DEST diff --git a/libs/build_go.sh b/libs/build_go.sh new file mode 100755 index 0000000..767e0ff --- /dev/null +++ b/libs/build_go.sh @@ -0,0 +1,43 @@ +#!/bin/bash +set -e + +source libs/deploy_common.sh +[ "$GOOS" == "windows" ] && [ "$GOARCH" == "amd64" ] && DEST=$DEPLOYMENT/windows64 || true +[ "$GOOS" == "linux" ] && [ "$GOARCH" == "amd64" ] && DEST=$DEPLOYMENT/linux64 || true +if [ -z $DEST ]; then + echo "Please set GOOS GOARCH" + exit +fi +rm -rf $DEST +mkdir -p $DEST + +export CGO_ENABLED=0 + +#### Go: updater #### +pushd updater +go build -o $DEST -trimpath -ldflags "-w -s" +[ "$GOOS" == "linux" ] && mv $DEST/updater $DEST/launcher +popd + +#### Go: nekoray_core #### +pushd ../v2ray-core +version_v2ray=$(git log --pretty=format:'%h' -n 1) +popd +pushd go +go build -v -o $DEST -trimpath -ldflags "-w -s -X main.version_v2ray=$version_v2ray -X main.version_standalone=$version_standalone" +popd + +#### Windows only #### +if [ "$GOOS" != "windows" ]; then + exit +fi + +#### Go: sing-box #### +pushd $DEST +curl -Lso sing-box.zip https://github.com/SagerNet/sing-box/archive/64dbac813837bbadfaeec1a6e0d064875a123e5e.zip +unzip sing-box.zip +pushd sing-box-*/cmd/sing-box +go build -o $DEST -trimpath -ldflags "-w -s" +popd +rm -rf sing-box.zip sing-box-* +popd diff --git a/libs/deploy_common.sh b/libs/deploy_common.sh index 34d8825..68368a6 100644 --- a/libs/deploy_common.sh +++ b/libs/deploy_common.sh @@ -1,46 +1,5 @@ +#### env #### SRC_ROOT="$PWD" -DEST="$PWD/deployment/nekoray" +DEPLOYMENT="$SRC_ROOT/deployment" BUILD="$SRC_ROOT/build" - -mkdir -p $DEST -mkdir -p $BUILD - -export CGO_ENABLED=0 - -#### Go: updater #### -pushd updater -go build -o $DEST -trimpath -ldflags "-w -s" -popd - -#### libcore #### -COMMIT_M=$(cat matsuri_commit.txt) -COMMIT_V=$(cat core_commit.txt) version_standalone="nekoray-"$(cat nekoray_version.txt) - -pushd .. - -git clone --no-checkout https://github.com/MatsuriDayo/Matsuri.git -git clone --no-checkout https://github.com/MatsuriDayo/v2ray-core.git - -pushd Matsuri -git checkout $COMMIT_M -popd - -pushd v2ray-core -git checkout $COMMIT_V -version_v2ray=$(git log --pretty=format:'%h' -n 1) -popd - -popd - -#### Go: nekoray_core #### -pushd go -go build -o $DEST -trimpath -ldflags "-w -s -X main.version_v2ray=$version_v2ray -X main.version_standalone=$version_standalone" -popd - -#### Download: geoip #### -curl -Lso $DEST/geoip.dat "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/download/202206042210/geoip.dat" -curl -Lso $DEST/geosite.dat "https://github.com/v2fly/domain-list-community/releases/download/20220604062951/dlc.dat" - -#### copy assets #### -cp assets/* $DEST diff --git a/libs/deploy_linux64.sh b/libs/deploy_linux64.sh index 1859645..4196649 100755 --- a/libs/deploy_linux64.sh +++ b/libs/deploy_linux64.sh @@ -2,9 +2,9 @@ set -e source libs/deploy_common.sh - -#### updater to launcher #### -mv $DEST/updater $DEST/launcher +DEST=$DEPLOYMENT/linux64 +rm -rf $DEST +mkdir -p $DEST #### copy binary #### cp $BUILD/nekoray $DEST @@ -12,13 +12,5 @@ cp $BUILD/nekoray $DEST #### Download: prebuilt runtime #### curl -Lso usr.zip https://github.com/MatsuriDayo/nekoray_qt_runtime/releases/download/20220503/20220705-5.15.2-linux64.zip unzip usr.zip +rm usr.zip mv usr $DEST - -#### copy runtime #### -LIB=$SRC_ROOT/libs/deps/built/lib -#cp $LIB/libZXing.so.1 $DEST/usr/lib - -#### pack tar #### -chmod +x $DEST/nekoray $DEST/nekoray_core $DEST/launcher -tar cvzf $SRC_ROOT/deployment/$version_standalone-linux64.tar.gz -C $SRC_ROOT/deployment nekoray -rm -rf $DEST $BUILD diff --git a/libs/deploy_windows64.sh b/libs/deploy_windows64.sh index 898223a..3ee8415 100755 --- a/libs/deploy_windows64.sh +++ b/libs/deploy_windows64.sh @@ -2,15 +2,9 @@ set -e source libs/deploy_common.sh - -#### Go: sing-box #### -pushd $BUILD -curl -Lso sing-box.zip https://github.com/SagerNet/sing-box/archive/64dbac813837bbadfaeec1a6e0d064875a123e5e.zip -unzip sing-box.zip -pushd sing-box-*/cmd/sing-box -go build -o $DEST -trimpath -ldflags "-w -s" -popd -popd +DEST=$DEPLOYMENT/windows64 +rm -rf $DEST +mkdir -p $DEST #### copy exe #### cp $BUILD/nekoray.exe $DEST @@ -23,7 +17,5 @@ curl -LSsO https://github.com/MatsuriDayo/nekoray_qt_runtime/releases/download/2 rm -rf translations popd -#### pack zip #### -7z a $SRC_ROOT/deployment/$version_standalone-windows64.zip $DEST -cp $BUILD/*.pdb $SRC_ROOT/deployment/ -rm -rf $DEST $BUILD +#### prepare deployment #### +cp $BUILD/*.pdb $DEPLOYMENT diff --git a/libs/get_source.sh b/libs/get_source.sh new file mode 100755 index 0000000..8050624 --- /dev/null +++ b/libs/get_source.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -e + +source libs/deploy_common.sh + +#### get source #### +COMMIT_M=$(cat matsuri_commit.txt) +COMMIT_V=$(cat core_commit.txt) + +pushd .. + +git clone --no-checkout https://github.com/MatsuriDayo/Matsuri.git +git clone --no-checkout https://github.com/MatsuriDayo/v2ray-core.git + +pushd Matsuri +git checkout $COMMIT_M +popd + +pushd v2ray-core +git checkout $COMMIT_V +popd + +popd diff --git a/matsuri_commit.txt b/matsuri_commit.txt index 5fa36e5..d9e0d41 100644 --- a/matsuri_commit.txt +++ b/matsuri_commit.txt @@ -1 +1 @@ -3dd90ce8b7dcb7001f3de42f6bcc8edf0093353a +4fdd5842f61b467f1de777aea4d0b1c23f5feb2a diff --git a/qv2ray/v2/components/proxy/QvProxyConfigurator.cpp b/qv2ray/v2/components/proxy/QvProxyConfigurator.cpp index b41aa55..93a6c96 100644 --- a/qv2ray/v2/components/proxy/QvProxyConfigurator.cpp +++ b/qv2ray/v2/components/proxy/QvProxyConfigurator.cpp @@ -1,12 +1,10 @@ -#ifndef __MINGW32__ - #include "QvProxyConfigurator.hpp" #ifdef Q_OS_WIN // -#include +#include // -#include +#include #include #include #include @@ -480,5 +478,3 @@ namespace Qv2ray::components::proxy { #endif } } // namespace Qv2ray::components::proxy - -#endif