From 255d95ef98f9c27870a5fb21992471a5183db0f2 Mon Sep 17 00:00:00 2001 From: arm64v8a <48624112+arm64v8a@users.noreply.github.com> Date: Sun, 25 Dec 2022 09:26:44 +0900 Subject: [PATCH] update build --- .github/workflows/build-qv2ray-cmake.yml | 24 +++++---- cmake/fuck_windows/fuck.cmake | 10 ++-- docs/Build_Linux.md | 52 +++++++++++-------- docs/Build_Windows.md | 26 ++++++++-- examples/.gitignore | 1 - examples/build-alpine.md | 5 -- examples/netns-root.sh | 30 ----------- examples/netns.sh | 13 ----- examples/readme.txt | 9 ---- examples/set-cap.sh | 14 ----- libs/build_deps_all.sh | 18 +++++-- libs/{build_asset.sh => build_public_res.sh} | 8 +-- libs/deploy_macos.sh | 4 +- main/main.cpp | 2 +- res/neko.qrc | 8 +-- {assets => res/public}/nekobox.png | Bin {assets => res/public}/nekoray.png | Bin {assets => res/public}/qtbase_zh_CN.qm | Bin {examples => res/vpn}/sing-box-vpn.json | 0 {examples => res/vpn}/vpn-run-root.sh | 0 ui/mainwindow.cpp | 4 +- ui/mainwindow.h | 6 +-- ui/mainwindow_grpc.cpp | 5 +- 23 files changed, 101 insertions(+), 138 deletions(-) delete mode 100644 examples/.gitignore delete mode 100644 examples/build-alpine.md delete mode 100755 examples/netns-root.sh delete mode 100755 examples/netns.sh delete mode 100644 examples/readme.txt delete mode 100755 examples/set-cap.sh rename libs/{build_asset.sh => build_public_res.sh} (83%) rename {assets => res/public}/nekobox.png (100%) rename {assets => res/public}/nekoray.png (100%) rename {assets => res/public}/qtbase_zh_CN.qm (100%) rename {examples => res/vpn}/sing-box-vpn.json (100%) rename {examples => res/vpn}/vpn-run-root.sh (100%) diff --git a/.github/workflows/build-qv2ray-cmake.yml b/.github/workflows/build-qv2ray-cmake.yml index de5737d13..bef7ecd7a 100644 --- a/.github/workflows/build-qv2ray-cmake.yml +++ b/.github/workflows/build-qv2ray-cmake.yml @@ -9,6 +9,9 @@ on: publish: description: 'Publish: If want ignore' required: false + artifact-pack: + description: 'artifact-pack: If want ignore' + required: false jobs: build-go: strategy: @@ -16,8 +19,8 @@ jobs: cross_os: [ windows, linux, darwin ] cross_arch: [ amd64 ] include: - - cross_os: asset - cross_arch: asset + - cross_os: public_res + cross_arch: public_res fail-fast: false runs-on: ubuntu-latest steps: @@ -40,10 +43,10 @@ jobs: if: steps.cache-common.outputs.cache-hit != 'true' shell: bash run: | - [ ${{ matrix.cross_os }} == asset ] || ./libs/get_source.sh - [ ${{ matrix.cross_os }} == asset ] || GOOS=${{ matrix.cross_os }} GOARCH=${{ matrix.cross_arch }} ./libs/build_go.sh - [ ${{ matrix.cross_os }} == asset ] || exit 0 - ./libs/build_asset.sh + [ ${{ matrix.cross_os }} == public_res ] || ./libs/get_source.sh + [ ${{ matrix.cross_os }} == public_res ] || GOOS=${{ matrix.cross_os }} GOARCH=${{ matrix.cross_arch }} ./libs/build_go.sh + [ ${{ matrix.cross_os }} == public_res ] || exit 0 + ./libs/build_public_res.sh - name: Tar files if: steps.cache-common.outputs.cache-hit != 'true' run: tar czvf artifacts.tgz ./deployment @@ -166,7 +169,8 @@ jobs: name: NekoRay-${{ github.sha }}-${{ matrix.platform }}-${{ matrix.arch }} path: artifacts.tgz publish: - name: Publish Release + name: Pack & Publish Release + if: github.event.inputs.artifact-pack != 'y' runs-on: ubuntu-latest needs: - build-cpp @@ -185,9 +189,9 @@ jobs: mv ghr*linux_amd64/ghr . find . -name artifacts.tgz | xargs -n1 tar xvzf cd deployment - cp -r assets/* linux64 - cp -r assets/* windows64 - rm -rf assets *.pdb + cp -r public_res/* linux64 + cp -r public_res/* windows64 + rm -rf public_res *.pdb #### mv linux64 nekoray zip -r $version_standalone-linux64.zip nekoray diff --git a/cmake/fuck_windows/fuck.cmake b/cmake/fuck_windows/fuck.cmake index c91e82a58..a224ef66d 100644 --- a/cmake/fuck_windows/fuck.cmake +++ b/cmake/fuck_windows/fuck.cmake @@ -5,12 +5,12 @@ if (WIN32) include(cmake/fuck_windows/generate_product_version.cmake) generate_product_version( QV2RAY_RC - NAME "Nekoray" - BUNDLE "Nekoray Project Family" ICON "${CMAKE_SOURCE_DIR}/res/nekoray.ico" - COMPANY_NAME "Nekoray Workgroup" - COMPANY_COPYRIGHT "Nekoray Workgroup" - FILE_DESCRIPTION "Nekoray Main Application" + NAME "nekoray" + BUNDLE "nekoray" + COMPANY_NAME "nekoray" + COMPANY_COPYRIGHT "nekoray" + FILE_DESCRIPTION "nekoray" ) add_definitions(-DUNICODE -D_UNICODE -DNOMINMAX) set(GUI_TYPE WIN32) diff --git a/docs/Build_Linux.md b/docs/Build_Linux.md index 8af1a20bb..0d80a0ce2 100644 --- a/docs/Build_Linux.md +++ b/docs/Build_Linux.md @@ -1,18 +1,18 @@ 在 Linux 下编译 Nekoray -### git clone 源码 +## git clone 源码 ``` git clone https://github.com/MatsuriDayo/nekoray.git --recursive ``` -### 简单编译法 +## 简单编译法 条件: -1. C++ 依赖:`protobuf yaml-cpp zxing-cpp` 已用包管理器安装,并符合版本要求 +1. C++ 依赖:`protobuf yaml-cpp zxing-cpp` 已用包管理器安装,并符合版本要求。 2. 已安装 `qtbase` `qtsvg` `qttools` `qtx11extras` -3. Qt 版本必须大于等于 5.15 +3. 已安装 Qt `5.12.x` 或 `5.15.x` 4. 系统为 `x86-64-linux-gnu` ```shell @@ -26,37 +26,43 @@ ninja 解压 Release 的压缩包,替换其中的 `nekoray`,删除 `launcher` 即可使用。 -### 复杂编译法 +## 复杂编译法 -#### CMake 参数 +### CMake 参数 -| CMake 参数 | 默认值 | 含义 | -|------------------|-----|-------------------------| -| QT_VERSION_MAJOR | 5 | QT版本 | -| NKR_NO_EXTERNAL | | 不包含外部C++依赖(以下所有) | -| NKR_NO_YAML | | 不包含yaml-cpp | -| NKR_NO_QHOTKEY | | 不包含qhotkey | -| NKR_NO_ZXING | | 不包含zxing | -| NKR_NO_GRPC | | 不包含gRPC | -| NKR_NO_QUICKJS | | 不包含quickjs | +| CMake 参数 | 默认值 | 含义 | +|-------------------|-------------------|-----------------------| +| QT_VERSION_MAJOR | 5 | QT版本 | +| NKR_NO_EXTERNAL | | 不包含外部 C/C++ 依赖 (以下所有) | +| NKR_NO_YAML | | 不包含 yaml-cpp | +| NKR_NO_QHOTKEY | | 不包含 qhotkey | +| NKR_NO_ZXING | | 不包含 zxing | +| NKR_NO_GRPC | | 不包含 gRPC | +| NKR_NO_QUICKJS | | 不包含 quickjs | +| NKR_PACKAGE | | 编译 package 版本 (aur) | +| NKR_PACKAGE_MACOS | | 编译 macos 版本 | +| NKR_LIBS | ./libs/deps/built | 依赖搜索目录 | +| NKR_DISABLE_LIBS | | 禁用 NKR_LIBS | -#### C++ 部分 +1. `NKR_LIBS` 的值会被追加到 `CMAKE_PREFIX_PATH` +2. `NKR_PACKAGE` 打开后,`NKR_LIBS` 的默认值为 `./libs/deps/package` ,具体依赖请看 `build_deps_all.sh` +3. `NKR_PACKAGE_MACOS` 或 `NKR_PACKAGE` 打开后,应用将使用 appdata 目录存放配置,自动更新等功能将被禁用。 -当您的发行版没有上面几个 C++ 依赖包,或者版本不符合要求时,可以参考 libs 文件夹内的默认编译脚本自行编译。 +### C++ 部分 -依赖搜寻 prefix 为 `libs/deps/bulit` +当您的发行版没有上面几个 C++ 依赖包,或者版本不符合要求时,可以参考 `build_deps_all.sh` 编译脚本自行编译。 -条件: +条件: 已安装 Qt `5.12.x` 或 `5.15.x` -1. Qt 版本必须大于等于 5.15 +#### 编译安装 C/C++ 依赖 -首先编译安装C++依赖(这一步可能要挂梯) +(这一步可能要挂梯) ```shell ./libs/build_deps_all.sh ``` -然后编译本体 +#### 编译本体 ```shell mkdir build @@ -67,7 +73,7 @@ ninja 编译完成后得到 `nekoray` -#### Go 部分 +### Go 部分 1. 把 `Matsuridayo/Matsuri` `Matsuridayo/v2ray-core` 置于 `../` 2. 进入 `go/cmd/nekoray_core` 文件夹 `go build` 得到 `nekoray_core`。 diff --git a/docs/Build_Windows.md b/docs/Build_Windows.md index 22ae6bf6d..4c412cfb6 100644 --- a/docs/Build_Windows.md +++ b/docs/Build_Windows.md @@ -16,23 +16,39 @@ git clone https://github.com/MatsuriDayo/nekoray.git --recursive ### 下载 Qt SDK -目前使用的版本是 Qt 5.15.7 其他版本未测试 +目前使用的版本是 Qt 5.15.x + +暂时不建议使用 Qt 6.x + +下载解压后,将 bin 目录添加到环境变量。 + +#### Qt 5.15.7 MSVC2019 x86_64 + +https://github.com/MatsuriDayo/nekoray_qt_runtime/releases/download/20220503/Qt5.15.7-Windows-x86_64-VS2019-16.11.20-20221103.7z + +#### 官方签名版 Qt 5.15.2 (可选,已知有内存泄漏的BUG) 在此下载 `qtbase` `qtsvg` `qttools` 的包并解压到同一个目录。 https://download.qt.io/online/qtsdkrepository/windows_x86/desktop/qt5_5152/qt.qt5.5152.win64_msvc2019_64/ -将 bin 目录添加到环境变量。 - ### C++ 部分编译 -首先编译安装C++依赖(这一步可能要挂梯) +#### 编译安装 C/C++ 依赖 + +(这一步可能要挂梯) ```shell bash ./libs/build_deps_all.sh ``` -然后编译本体(根据你的 QT Sdk 的位置替换命令) +目前只有 bash 脚本,没有批处理或 powershell,如果 Windows 没有带 bash 建议自行安装。 + +CMake 参数等细节与 Linux 大同小异,有问题可以参照 Build_Linux 文档。 + +#### 编译本体 + +请根据你的 QT Sdk 的位置替换命令 ```shell mkdir build diff --git a/examples/.gitignore b/examples/.gitignore deleted file mode 100644 index 02f9235c8..000000000 --- a/examples/.gitignore +++ /dev/null @@ -1 +0,0 @@ -tun2socks diff --git a/examples/build-alpine.md b/examples/build-alpine.md deleted file mode 100644 index 0856d66cb..000000000 --- a/examples/build-alpine.md +++ /dev/null @@ -1,5 +0,0 @@ -alpine 3.16 - -all use package - -apk add git cmake g++ ninja zxing-cpp-dev yaml-cpp-dev grpc-dev protobuf-dev qt5-qtbase-dev qt5-qtsvg-dev qt5-qttools-dev qt5-qtx11extras-dev c-ares-dev re2-dev diff --git a/examples/netns-root.sh b/examples/netns-root.sh deleted file mode 100755 index 2c78086cb..000000000 --- a/examples/netns-root.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh -set -e -set -x - -if [ "$EUID" -ne 0 ]; then - echo "Please run as root" - exit -fi - -# add netns -ip netns add nekoray -# ip netns exec nekoray readlink /proc/self/ns/net - -# add lo: lo is not shared -ip -n nekoray addr add 127.0.0.1/8 dev lo -ip -n nekoray link set dev lo up - -# add tun -ip -n nekoray tuntap add tun0 user $USERID mode tun -ip -n nekoray addr add 26.0.0.1/30 dev tun0 -ip -n nekoray link set dev tun0 up -ip -n nekoray route add default dev tun0 - -# set veth to use the socks port -ip link add dev nekoray-ve1 type veth peer name nekoray-ve2 -ip addr add 26.1.0.1/30 dev nekoray-ve1 -ip link set nekoray-ve1 up -ip link set nekoray-ve2 netns nekoray -ip -n nekoray addr add 26.1.0.2/30 dev nekoray-ve2 -ip -n nekoray link set nekoray-ve2 up diff --git a/examples/netns.sh b/examples/netns.sh deleted file mode 100755 index 8ae51afb3..000000000 --- a/examples/netns.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh -set -e -set -x - -BASEDIR=$(dirname "$0") - -# netns -[ -f /var/run/netns/nekoray ] || pkexec env USERID=`id -u` sh -c "cd $PWD && $BASEDIR/netns-root.sh" || true - -# run xjasonlyu/tun2socks to provide vpn -firejail --noprofile --netns=nekoray ./tun2socks -device tun0 -proxy socks5://26.1.0.1:2080 -interface nekoray-ve2 -drop-multicast - -# use "firejail --noprofile --netns=nekoray ..." to run your program in VPN diff --git a/examples/readme.txt b/examples/readme.txt deleted file mode 100644 index 0af92270a..000000000 --- a/examples/readme.txt +++ /dev/null @@ -1,9 +0,0 @@ -Linux Only - -此处为配置 VPN 的脚本,仅供参考,使用时要按实际情况替换某些参数(如 socks 端口) - -vpn.sh 配置全局 VPN -ctrl-c 退出后自动删除 VPN - -vpn-netns.sh 配置 netns -分应用代理,用法参考脚本内容 diff --git a/examples/set-cap.sh b/examples/set-cap.sh deleted file mode 100755 index 195f26efd..000000000 --- a/examples/set-cap.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -set -e -set -x - -if [ "$EUID" -ne 0 ] - then echo "Please run as root" - exit -fi - -killall nekoray_core || true -cp nekoray_core /opt/nekoray_core -cp geo* /opt/ -setcap cap_net_admin+ep /opt/nekoray_core -ln -sf /opt/nekoray_core nekoray_core_cap diff --git a/libs/build_deps_all.sh b/libs/build_deps_all.sh index bc48b25b1..61e2bdf65 100755 --- a/libs/build_deps_all.sh +++ b/libs/build_deps_all.sh @@ -3,9 +3,17 @@ set -e cd libs +# 参数 +if [ -z $cmake ]; then + cmake="cmake" +fi +if [ -z $deps ]; then + deps="deps" +fi + # libs/deps/... -mkdir -p deps -cd deps +mkdir -p $deps +cd $deps if [ -z $NKR_PACKAGE ]; then INSTALL_PREFIX=$PWD/built else @@ -27,7 +35,7 @@ cd zxing-* mkdir -p build cd build -cmake .. -GNinja -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=OFF -DBUILD_BLACKBOX_TESTS=OFF -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX +$cmake .. -GNinja -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=OFF -DBUILD_BLACKBOX_TESTS=OFF -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX ninja && ninja install cd ../.. @@ -46,7 +54,7 @@ cd yaml-* mkdir -p build cd build -cmake .. -GNinja -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX +$cmake .. -GNinja -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX ninja && ninja install cd ../.. @@ -59,7 +67,7 @@ git clone --recurse-submodules -b v21.4 --depth 1 --shallow-submodules https://g mkdir -p protobuf/build cd protobuf/build -cmake .. -GNinja \ +$cmake .. -GNinja \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_SHARED_LIBS=OFF \ -Dprotobuf_MSVC_STATIC_RUNTIME=OFF \ diff --git a/libs/build_asset.sh b/libs/build_public_res.sh similarity index 83% rename from libs/build_asset.sh rename to libs/build_public_res.sh index 32c3e2225..49943fb9c 100755 --- a/libs/build_asset.sh +++ b/libs/build_public_res.sh @@ -2,15 +2,15 @@ set -e source libs/deploy_common.sh -DEST=$DEPLOYMENT/assets +DEST=$DEPLOYMENT/public_res rm -rf $DEST mkdir -p $DEST -#### Download: geoip #### +#### Download geodata #### curl -Lso $DEST/geoip.dat "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat" curl -Lso $DEST/geosite.dat "https://github.com/v2fly/domain-list-community/releases/latest/download/dlc.dat" curl -Lso $DEST/geoip.db "https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db" curl -Lso $DEST/geosite.db "https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db" -#### copy assets #### -cp assets/* $DEST +#### copy res/public #### +cp res/public/* $DEST diff --git a/libs/deploy_macos.sh b/libs/deploy_macos.sh index c661d111f..7a45f3df2 100755 --- a/libs/deploy_macos.sh +++ b/libs/deploy_macos.sh @@ -12,10 +12,10 @@ DEST=$DEPLOYMENT/macos-$ARCH rm -rf $DEST mkdir -p $DEST -#### copy golang & asset => .app #### +#### copy golang & public_res => .app #### pushd download-artifact find . -name artifacts.tgz | xargs -n1 tar xvzf -mv deployment/assets/* deployment/macos-$ARCH +mv deployment/public_res/* deployment/macos-$ARCH mv deployment/macos-$ARCH/* $BUILD/nekoray.app/Contents/MacOS popd diff --git a/main/main.cpp b/main/main.cpp index 822adb629..020cf8aad 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) { if (args.contains("-tray")) NekoRay::dataStore->flag_tray = true; if (args.contains("-debug")) NekoRay::dataStore->flag_debug = true; #ifdef NKR_CPP_USE_APPDATA - NekoRay::dataStore->flag_use_appdata = true; + NekoRay::dataStore->flag_use_appdata = true; // Example: Package & MacOS #endif #ifdef NKR_CPP_DEBUG NekoRay::dataStore->flag_debug = true; diff --git a/res/neko.qrc b/res/neko.qrc index 6d546a9d6..64d3cae95 100644 --- a/res/neko.qrc +++ b/res/neko.qrc @@ -8,10 +8,10 @@ icon/system-software-update.svg - ../assets/nekobox.png - ../assets/nekoray.png + public/nekobox.png + public/nekoray.png neko.css - ../examples/vpn-run-root.sh - ../examples/sing-box-vpn.json + vpn/vpn-run-root.sh + vpn/sing-box-vpn.json diff --git a/assets/nekobox.png b/res/public/nekobox.png similarity index 100% rename from assets/nekobox.png rename to res/public/nekobox.png diff --git a/assets/nekoray.png b/res/public/nekoray.png similarity index 100% rename from assets/nekoray.png rename to res/public/nekoray.png diff --git a/assets/qtbase_zh_CN.qm b/res/public/qtbase_zh_CN.qm similarity index 100% rename from assets/qtbase_zh_CN.qm rename to res/public/qtbase_zh_CN.qm diff --git a/examples/sing-box-vpn.json b/res/vpn/sing-box-vpn.json similarity index 100% rename from examples/sing-box-vpn.json rename to res/vpn/sing-box-vpn.json diff --git a/examples/vpn-run-root.sh b/res/vpn/vpn-run-root.sh similarity index 100% rename from examples/vpn-run-root.sh rename to res/vpn/vpn-run-root.sh diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 29c0f983c..b5060ace9 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -550,7 +550,7 @@ void MainWindow::on_menu_exit_triggered() { // NekoRay::dataStore->core_prepare_exit = true; hide(); - ExitNekorayCore(); + stop_core_daemon(); // MF_release_runguard(); if (exit_reason == 1) { @@ -1394,7 +1394,7 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event) { auto mouseEvent = dynamic_cast(event); if (obj == ui->label_running && mouseEvent->button() == Qt::LeftButton && running != nullptr) { - test_current(); + speedtest_current(); return true; } else if (obj == ui->label_inbound && mouseEvent->button() == Qt::LeftButton) { on_menu_basic_settings_triggered(); diff --git a/ui/mainwindow.h b/ui/mainwindow.h index ceffda8e7..219abf5ba 100644 --- a/ui/mainwindow.h +++ b/ui/mainwindow.h @@ -173,13 +173,13 @@ private slots: // grpc and ... - static void ExitNekorayCore(); + void setup_grpc(); void speedtest_current_group(int mode); - void test_current(); + void speedtest_current(); - void setup_grpc(); + static void stop_core_daemon(); void CheckUpdate(); diff --git a/ui/mainwindow_grpc.cpp b/ui/mainwindow_grpc.cpp index 36df6d0b7..a22d94d3d 100644 --- a/ui/mainwindow_grpc.cpp +++ b/ui/mainwindow_grpc.cpp @@ -157,7 +157,7 @@ void MainWindow::speedtest_current_group(int mode) { #endif } -void MainWindow::test_current() { +void MainWindow::speedtest_current() { #ifndef NKR_NO_GRPC last_test_time = QTime::currentTime(); ui->label_running->setText(tr("Testing")); @@ -186,7 +186,7 @@ void MainWindow::test_current() { #endif } -void MainWindow::ExitNekorayCore() { +void MainWindow::stop_core_daemon() { #ifndef NKR_NO_GRPC NekoRay::rpc::defaultClient->Exit(); #endif @@ -287,6 +287,7 @@ void MainWindow::neko_stop(bool crash) { } void MainWindow::CheckUpdate() { + // on new thread... #ifndef NKR_NO_GRPC bool ok; libcore::UpdateReq request;