diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9a4fd15..a13c7c6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -157,7 +157,7 @@ jobs: - uses: msys2/setup-msys2@v2 with: update: true - install: base-devel git mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-pcre2 patch + install: base-devel git mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-pcre2 patch mingw-w64-x86_64-xmake msystem: MINGW64 path-type: inherit - name: Add commit id into version @@ -197,7 +197,7 @@ jobs: - uses: msys2/setup-msys2@v2 with: update: true - install: base-devel git mingw-w64-i686-gcc mingw-w64-i686-cmake mingw-w64-i686-pcre2 patch + install: base-devel git mingw-w64-i686-gcc mingw-w64-i686-cmake mingw-w64-i686-pcre2 patch mingw-w64-i686-xmake msystem: MINGW32 path-type: inherit - name: Add commit id into version diff --git a/.gitignore b/.gitignore index 567b776..e8cf7a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ subconverter.exe .vscode -cmake-build-debug +cmake-build-* .idea base/cache +build +.xmake diff --git a/scripts/Dockerfile b/scripts/Dockerfile index 37d1016..9232fca 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -4,45 +4,49 @@ ARG THREADS="4" ARG SHA="" # build minimized -WORKDIR / +WORKDIR /subconverter +COPY . /subconverter/ RUN set -xe && \ - apk add --no-cache --virtual .build-tools git g++ build-base linux-headers cmake python3 && \ - apk add --no-cache --virtual .build-deps curl-dev rapidjson-dev pcre2-dev yaml-cpp-dev && \ - git clone https://github.com/ftk/quickjspp --depth=1 && \ - cd quickjspp && \ - git submodule update --init && \ - cmake -DCMAKE_BUILD_TYPE=Release . && \ - make quickjs -j $THREADS && \ - install -d /usr/lib/quickjs/ && \ - install -m644 quickjs/libquickjs.a /usr/lib/quickjs/ && \ - install -d /usr/include/quickjs/ && \ - install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h /usr/include/quickjs/ && \ - install -m644 quickjspp.hpp /usr/include && \ - cd .. && \ - git clone https://github.com/PerMalmberg/libcron --depth=1 && \ - cd libcron && \ - git submodule update --init && \ - cmake -DCMAKE_BUILD_TYPE=Release . && \ - make libcron -j $THREADS && \ - install -m644 libcron/out/Release/liblibcron.a /usr/lib/ && \ - install -d /usr/include/libcron/ && \ - install -m644 libcron/include/libcron/* /usr/include/libcron/ && \ - install -d /usr/include/date/ && \ - install -m644 libcron/externals/date/include/date/* /usr/include/date/ && \ - cd .. && \ - git clone https://github.com/ToruNiina/toml11 --branch="v3.7.1" --depth=1 && \ - cd toml11 && \ - cmake -DCMAKE_CXX_STANDARD=11 . && \ - make install -j $THREADS && \ - cd .. && \ - git clone https://github.com/tindy2013/subconverter --depth=1 && \ - cd subconverter && \ - [ -n "$SHA" ] && sed -i 's/\(v[0-9]\.[0-9]\.[0-9]\)/\1-'"$SHA"'/' src/version.h;\ + apk add --no-cache --virtual .build-tools git g++ build-base linux-headers cmake python3 curl unzip p7zip && \ + apk add --no-cache --virtual .build-deps curl-dev rapidjson-dev pcre2-dev yaml-cpp-dev lua5.4-dev luajit-dev && \ + curl -fsSL https://xmake.io/shget.text | bash && \ +# git clone https://github.com/ftk/quickjspp --depth=1 && \ +# cd quickjspp && \ +# git submodule update --init && \ +# cmake -DCMAKE_BUILD_TYPE=Release . && \ +# make quickjs -j $THREADS && \ +# install -d /usr/lib/quickjs/ && \ +# install -m644 quickjs/libquickjs.a /usr/lib/quickjs/ && \ +# install -d /usr/include/quickjs/ && \ +# install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h /usr/include/quickjs/ && \ +# install -m644 quickjspp.hpp /usr/include && \ +# cd .. && \ +# git clone https://github.com/PerMalmberg/libcron --depth=1 && \ +# cd libcron && \ +# git submodule update --init && \ +# cmake -DCMAKE_BUILD_TYPE=Release . && \ +# make libcron -j $THREADS && \ +# install -m644 libcron/out/Release/liblibcron.a /usr/lib/ && \ +# install -d /usr/include/libcron/ && \ +# install -m644 libcron/include/libcron/* /usr/include/libcron/ && \ +# install -d /usr/include/date/ && \ +# install -m644 libcron/externals/date/include/date/* /usr/include/date/ && \ +# cd .. && \ +# git clone https://github.com/ToruNiina/toml11 --branch="v3.7.1" --depth=1 && \ +# cd toml11 && \ +# cmake -DCMAKE_CXX_STANDARD=11 . && \ +# make install -j $THREADS && \ +# cd .. && \ +# git clone https://github.com/tindy2013/subconverter --depth=1 && \ +# cd subconverter && \ +# [ -n "$SHA" ] && sed -i 's/\(v[0-9]\.[0-9]\.[0-9]\)/\1-'"$SHA"'/' src/version.h;\ +# cmake -DCMAKE_BUILD_TYPE=Release -DUSE_EXTERNAL_CURL=ON -DUSE_EXTERNAL_RAPIDJSON=ON -DUSE_EXTERNAL_YAML_CPP=ON . && \ +# make -j $THREADS && \ + xmake f --root --static=false -m release && \ + xmake --root subconverter --build release && \ python3 -m ensurepip && \ python3 -m pip install gitpython && \ - python3 scripts/update_rules.py -c scripts/rules_config.conf && \ - cmake -DCMAKE_BUILD_TYPE=Release . && \ - make -j $THREADS + python3 scripts/update_rules.py -c scripts/rules_config.conf # build final image FROM alpine:3.16 diff --git a/scripts/build.alpine.release.sh b/scripts/build.alpine.release.sh index c159737..1eec902 100644 --- a/scripts/build.alpine.release.sh +++ b/scripts/build.alpine.release.sh @@ -1,51 +1,60 @@ #!/bin/bash set -xe -apk add gcc g++ build-base linux-headers cmake make autoconf automake libtool python2 python3 -apk add mbedtls-dev mbedtls-static zlib-dev rapidjson-dev zlib-static pcre2-dev +#apk add gcc g++ build-base linux-headers cmake make autoconf automake libtool python2 python3 +#apk add mbedtls-dev mbedtls-static zlib-dev rapidjson-dev zlib-static pcre2-dev +# +#git clone https://github.com/curl/curl --depth=1 --branch curl-8_4_0 +#cd curl +#cmake -DCURL_USE_MBEDTLS=ON -DHTTP_ONLY=ON -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_USE_LIBSSH2=OFF -DBUILD_CURL_EXE=OFF . > /dev/null +#make install -j2 > /dev/null +#cd .. +# +#git clone https://github.com/jbeder/yaml-cpp --depth=1 +#cd yaml-cpp +#cmake -DCMAKE_BUILD_TYPE=Release -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF . > /dev/null +#make install -j3 > /dev/null +#cd .. +# +#git clone https://github.com/ftk/quickjspp --depth=1 +#cd quickjspp +#cmake -DCMAKE_BUILD_TYPE=Release . +#make quickjs -j3 > /dev/null +#install -d /usr/lib/quickjs/ +#install -m644 quickjs/libquickjs.a /usr/lib/quickjs/ +#install -d /usr/include/quickjs/ +#install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h /usr/include/quickjs/ +#install -m644 quickjspp.hpp /usr/include/ +#cd .. +# +#git clone https://github.com/PerMalmberg/libcron --depth=1 +#cd libcron +#git submodule update --init +#cmake -DCMAKE_BUILD_TYPE=Release . +#make libcron install -j3 +#cd .. +# +#git clone https://github.com/ToruNiina/toml11 --branch="v3.7.1" --depth=1 +#cd toml11 +#cmake -DCMAKE_CXX_STANDARD=11 . +#make install -j4 +#cd .. +# +#export PKG_CONFIG_PATH=/usr/lib64/pkgconfig +#cmake -DCMAKE_BUILD_TYPE=Release . +#make -j3 +#rm subconverter +## shellcheck disable=SC2046 +#g++ -o base/subconverter $(find CMakeFiles/subconverter.dir/src/ -name "*.o") -static -lpcre2-8 -lyaml-cpp -L/usr/lib64 -lcurl -lmbedtls -lmbedcrypto -lmbedx509 -lz -l:quickjs/libquickjs.a -llibcron -O3 -s -git clone https://github.com/curl/curl --depth=1 --branch curl-8_4_0 -cd curl -cmake -DCURL_USE_MBEDTLS=ON -DHTTP_ONLY=ON -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_USE_LIBSSH2=OFF -DBUILD_CURL_EXE=OFF . > /dev/null -make install -j2 > /dev/null -cd .. +apk add git g++ build-base linux-headers cmake python3 curl unzip p7zip +apk add lua5.4-dev luajit-dev mbedtls-dev mbedtls-static zlib-dev +curl -fsSL https://xmake.io/shget.text | bash +source "$HOME/.xmake/profile" -git clone https://github.com/jbeder/yaml-cpp --depth=1 -cd yaml-cpp -cmake -DCMAKE_BUILD_TYPE=Release -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF . > /dev/null -make install -j3 > /dev/null -cd .. - -git clone https://github.com/ftk/quickjspp --depth=1 -cd quickjspp -cmake -DCMAKE_BUILD_TYPE=Release . -make quickjs -j3 > /dev/null -install -d /usr/lib/quickjs/ -install -m644 quickjs/libquickjs.a /usr/lib/quickjs/ -install -d /usr/include/quickjs/ -install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h /usr/include/quickjs/ -install -m644 quickjspp.hpp /usr/include/ -cd .. - -git clone https://github.com/PerMalmberg/libcron --depth=1 -cd libcron -git submodule update --init -cmake -DCMAKE_BUILD_TYPE=Release . -make libcron install -j3 -cd .. - -git clone https://github.com/ToruNiina/toml11 --branch="v3.7.1" --depth=1 -cd toml11 -cmake -DCMAKE_CXX_STANDARD=11 . -make install -j4 -cd .. - -export PKG_CONFIG_PATH=/usr/lib64/pkgconfig -cmake -DCMAKE_BUILD_TYPE=Release . -make -j3 -rm subconverter -# shellcheck disable=SC2046 -g++ -o base/subconverter $(find CMakeFiles/subconverter.dir/src/ -name "*.o") -static -lpcre2-8 -lyaml-cpp -L/usr/lib64 -lcurl -lmbedtls -lmbedcrypto -lmbedx509 -lz -l:quickjs/libquickjs.a -llibcron -O3 -s +xmake f --root --static=true -m release +xmake --root subconverter +cp "$(find build -name subconverter -type f)" base/subconverter python3 -m ensurepip python3 -m pip install gitpython diff --git a/scripts/build.macos.release.sh b/scripts/build.macos.release.sh index 833418b..91c17a4 100644 --- a/scripts/build.macos.release.sh +++ b/scripts/build.macos.release.sh @@ -1,59 +1,65 @@ #!/bin/bash set -xe -brew reinstall rapidjson zlib pcre2 pkgconfig - -#git clone https://github.com/curl/curl --depth=1 --branch curl-7_88_1 -#cd curl -#./buildconf > /dev/null -#./configure --with-ssl=/usr/local/opt/openssl@1.1 --without-mbedtls --disable-ldap --disable-ldaps --disable-rtsp --without-libidn2 > /dev/null -#cmake -DCMAKE_USE_SECTRANSP=ON -DHTTP_ONLY=ON -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_USE_LIBSSH2=OFF . > /dev/null -#make -j8 > /dev/null +#brew reinstall rapidjson zlib pcre2 pkgconfig +# +##git clone https://github.com/curl/curl --depth=1 --branch curl-7_88_1 +##cd curl +##./buildconf > /dev/null +##./configure --with-ssl=/usr/local/opt/openssl@1.1 --without-mbedtls --disable-ldap --disable-ldaps --disable-rtsp --without-libidn2 > /dev/null +##cmake -DCMAKE_USE_SECTRANSP=ON -DHTTP_ONLY=ON -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_USE_LIBSSH2=OFF . > /dev/null +##make -j8 > /dev/null +##cd .. +# +#git clone https://github.com/jbeder/yaml-cpp --depth=1 +#cd yaml-cpp +#cmake -DCMAKE_BUILD_TYPE=Release -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF . > /dev/null +#make install -j8 > /dev/null #cd .. +# +#git clone https://github.com/ftk/quickjspp --depth=1 +#cd quickjspp +#cmake -DCMAKE_BUILD_TYPE=Release . +#make quickjs -j8 +#install -d /usr/local/lib/quickjs/ +#install -m644 quickjs/libquickjs.a /usr/local/lib/quickjs/ +#install -d /usr/local/include/quickjs/ +#install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h /usr/local/include/quickjs/ +#install -m644 quickjspp.hpp /usr/local/include/ +#cd .. +# +#git clone https://github.com/PerMalmberg/libcron --depth=1 +#cd libcron +#git submodule update --init +#cmake -DCMAKE_BUILD_TYPE=Release . +#make libcron install -j8 +#install -m644 libcron/out/Release/liblibcron.a /usr/local/lib/ +#install -d /usr/local/include/libcron/ +#install -m644 libcron/include/libcron/* /usr/local/include/libcron/ +#install -d /usr/local/include/date/ +#install -m644 libcron/externals/date/include/date/* /usr/local/include/date/ +#cd .. +# +#git clone https://github.com/ToruNiina/toml11 --depth=1 +#cd toml11 +#cmake -DCMAKE_CXX_STANDARD=11 . +#make install -j4 +#cd .. +# +#cp /usr/local/opt/zlib/lib/libz.a . +#cp /usr/local/lib/libpcre2-8.a . +# +#cmake -DCMAKE_BUILD_TYPE=Release . +#make -j8 +#rm subconverter +## shellcheck disable=SC2046 +#c++ -Xlinker -unexported_symbol -Xlinker "*" -o base/subconverter -framework CoreFoundation -framework Security $(find CMakeFiles/subconverter.dir/src/ -name "*.o") $(find . -name "*.a") -lcurl -O3 -git clone https://github.com/jbeder/yaml-cpp --depth=1 -cd yaml-cpp -cmake -DCMAKE_BUILD_TYPE=Release -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF . > /dev/null -make install -j8 > /dev/null -cd .. +brew reinstall xmake rapidjson pkgconfig -git clone https://github.com/ftk/quickjspp --depth=1 -cd quickjspp -cmake -DCMAKE_BUILD_TYPE=Release . -make quickjs -j8 -install -d /usr/local/lib/quickjs/ -install -m644 quickjs/libquickjs.a /usr/local/lib/quickjs/ -install -d /usr/local/include/quickjs/ -install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h /usr/local/include/quickjs/ -install -m644 quickjspp.hpp /usr/local/include/ -cd .. - -git clone https://github.com/PerMalmberg/libcron --depth=1 -cd libcron -git submodule update --init -cmake -DCMAKE_BUILD_TYPE=Release . -make libcron install -j8 -install -m644 libcron/out/Release/liblibcron.a /usr/local/lib/ -install -d /usr/local/include/libcron/ -install -m644 libcron/include/libcron/* /usr/local/include/libcron/ -install -d /usr/local/include/date/ -install -m644 libcron/externals/date/include/date/* /usr/local/include/date/ -cd .. - -git clone https://github.com/ToruNiina/toml11 --depth=1 -cd toml11 -cmake -DCMAKE_CXX_STANDARD=11 . -make install -j4 -cd .. - -cp /usr/local/opt/zlib/lib/libz.a . -cp /usr/local/lib/libpcre2-8.a . - -cmake -DCMAKE_BUILD_TYPE=Release . -make -j8 -rm subconverter -# shellcheck disable=SC2046 -c++ -Xlinker -unexported_symbol -Xlinker "*" -o base/subconverter -framework CoreFoundation -framework Security $(find CMakeFiles/subconverter.dir/src/ -name "*.o") $(find . -name "*.a") -lcurl -O3 +xmake f --root -m release +xmake --root subconverter +cp "$(find build -name subconverter -type f)" base/subconverter python -m ensurepip python -m pip install gitpython diff --git a/scripts/build.windows.release.sh b/scripts/build.windows.release.sh index 5de4c8d..bd66e12 100644 --- a/scripts/build.windows.release.sh +++ b/scripts/build.windows.release.sh @@ -1,57 +1,63 @@ #!/bin/bash set -xe +# +#git clone https://github.com/curl/curl --depth=1 --branch curl-8_4_0 +#cd curl +#cmake -DCMAKE_BUILD_TYPE=Release -DCURL_USE_LIBSSH2=OFF -DHTTP_ONLY=ON -DCURL_USE_SCHANNEL=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" -DHAVE_LIBIDN2=OFF -DCURL_USE_LIBPSL=OFF . +#make install -j4 +#cd .. +# +#git clone https://github.com/jbeder/yaml-cpp --depth=1 +#cd yaml-cpp +#cmake -DCMAKE_BUILD_TYPE=Release -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" . +#make install -j4 +#cd .. +# +#git clone https://github.com/ftk/quickjspp --depth=1 +#cd quickjspp +#patch quickjs/quickjs-libc.c -i ../scripts/patches/0001-quickjs-libc-add-realpath-for-Windows.patch +#cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release . +#make quickjs -j4 +#install -d "$MINGW_PREFIX/lib/quickjs/" +#install -m644 quickjs/libquickjs.a "$MINGW_PREFIX/lib/quickjs/" +#install -d "$MINGW_PREFIX/include/quickjs" +#install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h "$MINGW_PREFIX/include/quickjs/" +#install -m644 quickjspp.hpp "$MINGW_PREFIX/include/" +#cd .. +# +#git clone https://github.com/PerMalmberg/libcron --depth=1 +#cd libcron +#git submodule update --init +#cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" . +#make libcron install -j4 +#cd .. +# +#git clone https://github.com/Tencent/rapidjson --depth=1 +#cd rapidjson +#cmake -DRAPIDJSON_BUILD_DOC=OFF -DRAPIDJSON_BUILD_EXAMPLES=OFF -DRAPIDJSON_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" . +#make install -j4 +#cd .. +# +#git clone https://github.com/ToruNiina/toml11 --depth=1 +#cd toml11 +#cmake -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" -DCMAKE_CXX_STANDARD=11 . +#make install -j4 +#cd .. +# +#rm -f C:/Strawberry/perl/bin/pkg-config C:/Strawberry/perl/bin/pkg-config.bat +#cmake -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" . +#make -j4 +#rm subconverter.exe +## shellcheck disable=SC2046 +#g++ $(find CMakeFiles/subconverter.dir/src -name "*.obj") curl/lib/libcurl.a -o base/subconverter.exe -static -lbcrypt -lpcre2-8 -l:quickjs/libquickjs.a -llibcron -lyaml-cpp -liphlpapi -lcrypt32 -lws2_32 -lwsock32 -lz -s -git clone https://github.com/curl/curl --depth=1 --branch curl-8_4_0 -cd curl -cmake -DCMAKE_BUILD_TYPE=Release -DCURL_USE_LIBSSH2=OFF -DHTTP_ONLY=ON -DCURL_USE_SCHANNEL=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" -DHAVE_LIBIDN2=OFF -DCURL_USE_LIBPSL=OFF . -make install -j4 -cd .. - -git clone https://github.com/jbeder/yaml-cpp --depth=1 -cd yaml-cpp -cmake -DCMAKE_BUILD_TYPE=Release -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" . -make install -j4 -cd .. - -git clone https://github.com/ftk/quickjspp --depth=1 -cd quickjspp -patch quickjs/quickjs-libc.c -i ../scripts/patches/0001-quickjs-libc-add-realpath-for-Windows.patch -cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release . -make quickjs -j4 -install -d "$MINGW_PREFIX/lib/quickjs/" -install -m644 quickjs/libquickjs.a "$MINGW_PREFIX/lib/quickjs/" -install -d "$MINGW_PREFIX/include/quickjs" -install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h "$MINGW_PREFIX/include/quickjs/" -install -m644 quickjspp.hpp "$MINGW_PREFIX/include/" -cd .. - -git clone https://github.com/PerMalmberg/libcron --depth=1 -cd libcron -git submodule update --init -cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" . -make libcron install -j4 -cd .. - -git clone https://github.com/Tencent/rapidjson --depth=1 -cd rapidjson -cmake -DRAPIDJSON_BUILD_DOC=OFF -DRAPIDJSON_BUILD_EXAMPLES=OFF -DRAPIDJSON_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" . -make install -j4 -cd .. - -git clone https://github.com/ToruNiina/toml11 --depth=1 -cd toml11 -cmake -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" -DCMAKE_CXX_STANDARD=11 . -make install -j4 -cd .. +xmake f --root --static=true -m release +xmake --root subconverter +cp "$(find build -name subconverter -type f)" base/subconverter python -m ensurepip python -m pip install gitpython python scripts/update_rules.py -c scripts/rules_config.conf - -rm -f C:/Strawberry/perl/bin/pkg-config C:/Strawberry/perl/bin/pkg-config.bat -cmake -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" . -make -j4 -rm subconverter.exe -# shellcheck disable=SC2046 -g++ $(find CMakeFiles/subconverter.dir/src -name "*.obj") curl/lib/libcurl.a -o base/subconverter.exe -static -lbcrypt -lpcre2-8 -l:quickjs/libquickjs.a -llibcron -lyaml-cpp -liphlpapi -lcrypt32 -lws2_32 -lwsock32 -lz -s mv base subconverter + +set +xe diff --git a/src/generator/config/nodemanip.cpp b/src/generator/config/nodemanip.cpp index 6f133cb..6dc8511 100644 --- a/src/generator/config/nodemanip.cpp +++ b/src/generator/config/nodemanip.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include "handler/settings.h" @@ -18,10 +17,6 @@ #include "nodemanip.h" #include "subexport.h" -extern Settings global; - -bool applyMatcher(const std::string &rule, std::string &real_rule, const Proxy &node); - int explodeConf(const std::string &filepath, std::vector &nodes) { return explodeConfContent(fileGet(filepath), nodes); @@ -51,13 +46,14 @@ int addNodes(std::string link, std::vector &allNodes, int groupID, parse_ link = replaceAllDistinct(link, "\"", ""); /// script:filepath,arg1,arg2,... +#ifndef NO_JS_RUNTIME if(authorized) script_safe_runner(parse_set.js_runtime, parse_set.js_context, [&](qjs::Context &ctx) { if(startsWith(link, "script:")) /// process subscription with script { writeLog(0, "Found script link. Start running...", LOG_LEVEL_INFO); string_array args = split(link.substr(7), ","); - if(args.size() >= 1) + if(!args.empty()) { std::string script = fileGet(args[0], false); try @@ -82,7 +78,7 @@ int addNodes(std::string link, std::vector &allNodes, int groupID, parse_ } } } - catch(qjs::exception) + catch(qjs::exception&) { script_print_stack(ctx); } @@ -104,12 +100,13 @@ int addNodes(std::string link, std::vector &allNodes, int groupID, parse_ duk_pop(ctx); /// pop err } */ +#endif /// tag:group_name,link if(startsWith(link, "tag:")) { - string_size pos = link.find(","); - if(pos != link.npos) + string_size pos = link.find(','); + if(pos != std::string::npos) { custom_group = link.substr(4, pos - 4); link.erase(0, pos + 1); @@ -178,7 +175,7 @@ int addNodes(std::string link, std::vector &allNodes, int groupID, parse_ for(Proxy &x : nodes) { x.GroupId = groupID; - if(custom_group.size()) + if(!custom_group.empty()) x.Group = custom_group; } copyNodes(nodes, allNodes); @@ -232,7 +229,7 @@ int addNodes(std::string link, std::vector &allNodes, int groupID, parse_ bool chkIgnore(const Proxy &node, string_array &exclude_remarks, string_array &include_remarks) { - bool excluded = false, included = false; + bool excluded, included; //std::string remarks = UTF8ToACP(node.remarks); //std::string remarks = node.remarks; //writeLog(LOG_TYPE_INFO, "Comparing exclude remarks..."); @@ -247,7 +244,7 @@ bool chkIgnore(const Proxy &node, string_array &exclude_remarks, string_array &i else return false; }); - if(include_remarks.size() != 0) + if(!include_remarks.empty()) { //writeLog(LOG_TYPE_INFO, "Comparing include remarks..."); included = std::any_of(include_remarks.cbegin(), include_remarks.cend(), [&node](const auto &x) @@ -273,7 +270,7 @@ bool chkIgnore(const Proxy &node, string_array &exclude_remarks, string_array &i void filterNodes(std::vector &nodes, string_array &exclude_remarks, string_array &include_remarks, int groupID) { int node_index = 0; - std::vector::iterator iter = nodes.begin(); + auto iter = nodes.begin(); while(iter != nodes.end()) { if(chkIgnore(*iter, exclude_remarks, include_remarks)) @@ -380,6 +377,7 @@ void nodeRename(Proxy &node, const RegexMatchConfigs &rename_array, extra_settin for(const RegexMatchConfig &x : rename_array) { +#ifndef NO_JS_RUNTIME if(!x.Script.empty() && ext.authorized) { script_safe_runner(ext.js_runtime, ext.js_context, [&](qjs::Context &ctx) @@ -395,19 +393,19 @@ void nodeRename(Proxy &node, const RegexMatchConfigs &rename_array, extra_settin if(!returned_remark.empty()) remark = returned_remark; } - catch (qjs::exception) + catch (qjs::exception&) { script_print_stack(ctx); } }, global.scriptCleanContext); continue; } - if(applyMatcher(x.Match, real_rule, node) && real_rule.size()) +#endif + if(applyMatcher(x.Match, real_rule, node) && !real_rule.empty()) remark = regReplace(remark, real_rule, x.Replace); } if(remark.empty()) remark = original_remark; - return; } std::string removeEmoji(const std::string &orig_remark) @@ -432,6 +430,7 @@ std::string addEmoji(const Proxy &node, const RegexMatchConfigs &emoji_array, ex for(const RegexMatchConfig &x : emoji_array) { +#ifndef NO_JS_RUNTIME if(!x.Script.empty() && ext.authorized) { std::string result; @@ -448,7 +447,7 @@ std::string addEmoji(const Proxy &node, const RegexMatchConfigs &emoji_array, ex if(!ret.empty()) result = ret + " " + node.Remark; } - catch (qjs::exception) + catch (qjs::exception&) { script_print_stack(ctx); } @@ -457,9 +456,10 @@ std::string addEmoji(const Proxy &node, const RegexMatchConfigs &emoji_array, ex return result; continue; } +#endif if(x.Replace.empty()) continue; - if(applyMatcher(x.Match, real_rule, node) && real_rule.size() && regFind(node.Remark, real_rule)) + if(applyMatcher(x.Match, real_rule, node) && !real_rule.empty() && regFind(node.Remark, real_rule)) return x.Replace + " " + node.Remark; } return node.Remark; @@ -481,7 +481,8 @@ void preprocessNodes(std::vector &nodes, extra_settings &ext) if(ext.sort_flag) { bool failed = true; - if(ext.sort_script.size() && ext.authorized) +#ifndef NO_JS_RUNTIME + if(!ext.sort_script.empty() && ext.authorized) { std::string script = ext.sort_script; if(startsWith(script, "path:")) @@ -503,12 +504,13 @@ void preprocessNodes(std::vector &nodes, extra_settings &ext) std::stable_sort(nodes.begin(), nodes.end(), comparer); failed = false; } - catch(qjs::exception) + catch(qjs::exception&) { script_print_stack(ctx); } }, global.scriptCleanContext); } +#endif if(failed) std::stable_sort(nodes.begin(), nodes.end(), [](const Proxy &a, const Proxy &b) { return a.Remark < b.Remark; diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..de0865b --- /dev/null +++ b/xmake.lua @@ -0,0 +1,50 @@ +add_rules("mode.debug", "mode.release") + +option("static") + set_default(false) + set_showmenu(true) + set_category("option") + set_description("Build static binary.") +option_end() + +add_requires("libcurl >=8.4.0", "pcre2", "yaml-cpp", "rapidjson", "toml11", "quickjspp") +includes("xmake/libcron.lua") +includes("xmake/yaml-cpp-static.lua") +add_requires("libcron", {system = false}) +add_requires("yaml-cpp-static", {system = false}) + +target("subconverter") + set_kind("binary") + if is_os("windows") then + add_syslinks("ws2_32", "wsock32") + end + if not is_os("macosx") and has_config("static") then + add_ldflags("-static") + end + add_files("src/**.cpp|lib/wrapper.cpp|server/webserver_libevent.cpp|script/script.cpp|generator/template/template_jinja2.cpp") + add_includedirs("src") + add_includedirs("include") + add_packages("libcurl", "pcre2", "rapidjson", "toml11", "libcron", "quickjspp") + if has_config("static") then + add_packages("yaml-cpp-static") + else + add_packages("yaml-cpp") + end + add_defines("CURL_STATICLIB") + add_defines("PCRE2_STATIC") + add_defines("YAML_CPP_STATIC_DEFINE") + add_cxxflags("-std=c++20") + +target("subconverter_lib") + set_basename("subconverter") + set_kind("static") + add_files("src/**.cpp|handler/**.cpp|server/**.cpp|script/**.cpp|generator/template/template_jinja2.cpp") + add_includedirs("src") + add_includedirs("include") + add_packages("pcre2", "yaml-cpp", "rapidjson", "toml11") + add_defines("CURL_STATICLIB") + add_defines("PCRE2_STATIC") + add_defines("YAML_CPP_STATIC_DEFINE") + add_defines("NO_JS_RUNTIME") + add_defines("NO_WEBGET") + add_cxxflags("-std=c++20") diff --git a/xmake/libcron.lua b/xmake/libcron.lua new file mode 100644 index 0000000..13144d3 --- /dev/null +++ b/xmake/libcron.lua @@ -0,0 +1,11 @@ +package("libcron") + add_deps("cmake") + add_versions("1.3.1", "41f238ceb09d4179e7346d78584a0c978e5d0059") + set_urls("https://github.com/PerMalmberg/libcron.git") + on_install(function (package) + local configs = {} + table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release")) + table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) + import("package.tools.cmake").install(package, configs) + end) +package_end() diff --git a/xmake/yaml-cpp-static.lua b/xmake/yaml-cpp-static.lua new file mode 100644 index 0000000..8d56364 --- /dev/null +++ b/xmake/yaml-cpp-static.lua @@ -0,0 +1,11 @@ +package("yaml-cpp-static") + add_deps("cmake") + add_versions("0.8.0-SNAPSHOT", "eaf72053724814be3b99d38e292fca5797a57b7b") + set_urls("https://github.com/jbeder/yaml-cpp.git") + on_install(function (package) + local configs = {} + table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release")) + table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) + import("package.tools.cmake").install(package, configs) + end) +package_end()