Skip to content

Instantly share code, notes, and snippets.

@myfreeer
Last active December 18, 2019 15:36
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save myfreeer/a780c730b7282e090f238e8286f815f3 to your computer and use it in GitHub Desktop.
Save myfreeer/a780c730b7282e090f238e8286f815f3 to your computer and use it in GitHub Desktop.
aria2 build scripts for msys2
version: 1.33.1-{build}
install:
- ps: >-
$gitData = ConvertFrom-StringData (git log -1 --format=format:"commitId=%H%nmessage=%s%ncommitted=%aD" | out-string)
if ($gitData['message'] -eq "") { $gitData['message'] = "No commit message available for $($gitData['commitid'])" }
# View the data with Write-Output @gitData
Update-AppveyorBuild @gitData
build_script:
- cmd: >-
C:\msys64\usr\bin\pacman -Syyuu --noconfirm --ask=20
C:\msys64\usr\bin\pacman -Suu --noconfirm --ask=20
C:\msys64\usr\bin\pacman -S --noconfirm --needed --ask=20 base-devel zlib-devel sqlite git unzip zip tar gmp gmp-devel libssh2 libssh2-devel openssl-devel
set MSYSTEM=MINGW64
C:\msys64\usr\bin\bash -lc "cd \"$APPVEYOR_BUILD_FOLDER\" && exec ./build-aria2.sh"
7z a aria2c.7z .\aria2\src\aria2c.exe
appveyor PushArtifact aria2c.7z
rd /s /q aria2
set MSYSTEM=MINGW32
C:\msys64\usr\bin\bash -lc "cd \"$APPVEYOR_BUILD_FOLDER\" && exec ./build-aria2.sh"
7z a aria2c_x86.7z .\aria2\src\aria2c.exe
appveyor PushArtifact aria2c_x86.7z
test: off
From a21c65112cac1d392c35ce7ced5eac17638d27e7 Mon Sep 17 00:00:00 2001
From: myfreeer <myfreeer@users.noreply.github.com>
Date: Mon, 29 May 2017 22:06:13 +0800
Subject: [PATCH 1/2] options: change default path to current dir
---
src/OptionHandlerFactory.cc | 2 +-
src/util.cc | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc
index 6f352cd4..79705aab 100644
--- a/src/OptionHandlerFactory.cc
+++ b/src/OptionHandlerFactory.cc
@@ -1276,7 +1276,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
}
{
OptionHandler* op(new LocalFilePathOptionHandler(
- PREF_NETRC_PATH, TEXT_NETRC_PATH, util::getHomeDir() + "/.netrc",
+ PREF_NETRC_PATH, TEXT_NETRC_PATH, File::getCurrentDir() + "/.netrc",
/* acceptStdin = */ false, 0, /* mustExist = */ false));
handlers.push_back(op);
}
diff --git a/src/util.cc b/src/util.cc
index 40fc55f2..71f9cc0b 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -1452,9 +1452,9 @@ std::string getXDGDir(const std::string& environmentVariable,
std::string getConfigFile()
{
- std::string filename = getHomeDir() + "/.aria2/aria2.conf";
+ std::string filename = File::getCurrentDir() + "/.aria2/aria2.conf";
if (!File(filename).exists()) {
- filename = getXDGDir("XDG_CONFIG_HOME", getHomeDir() + "/.config") +
+ filename = getXDGDir("XDG_CONFIG_HOME", File::getCurrentDir() + "/.config") +
"/aria2/aria2.conf";
}
return filename;
@@ -1463,9 +1463,9 @@ std::string getConfigFile()
std::string getDHTFile(bool ipv6)
{
std::string filename =
- getHomeDir() + (ipv6 ? "/.aria2/dht6.dat" : "/.aria2/dht.dat");
+ File::getCurrentDir() + (ipv6 ? "/.aria2/dht6.dat" : "/.aria2/dht.dat");
if (!File(filename).exists()) {
- filename = getXDGDir("XDG_CACHE_HOME", getHomeDir() + "/.cache") +
+ filename = getXDGDir("XDG_CACHE_HOME", File::getCurrentDir() + "/.cache") +
(ipv6 ? "/aria2/dht6.dat" : "/aria2/dht.dat");
}
return filename;
--
2.12.1
From ac269cf2b9c7e6896439b26ee422d33af30fbcd7 Mon Sep 17 00:00:00 2001
From: myfreeer <myfreeer@users.noreply.github.com>
Date: Mon, 29 May 2017 22:11:33 +0800
Subject: [PATCH 2/2] options: unlock connection-per-server limit
---
src/OptionHandlerFactory.cc | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc
index 79705aab..6ce0b946 100644
--- a/src/OptionHandlerFactory.cc
+++ b/src/OptionHandlerFactory.cc
@@ -158,7 +158,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
}
{
OptionHandler* op(new BooleanOptionHandler(
- PREF_CONTINUE, TEXT_CONTINUE, A2_V_FALSE, OptionHandler::OPT_ARG, 'c'));
+ PREF_CONTINUE, TEXT_CONTINUE, A2_V_TRUE, OptionHandler::OPT_ARG, 'c'));
op->addTag(TAG_BASIC);
op->addTag(TAG_FTP);
op->addTag(TAG_HTTP);
@@ -432,7 +432,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
{
OptionHandler* op(new NumberOptionHandler(PREF_MAX_CONCURRENT_DOWNLOADS,
TEXT_MAX_CONCURRENT_DOWNLOADS,
- "5", 1, -1, 'j'));
+ "16", 1, -1, 'j'));
op->addTag(TAG_BASIC);
op->setChangeGlobalOption(true);
handlers.push_back(op);
@@ -440,7 +440,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
{
OptionHandler* op(new NumberOptionHandler(PREF_MAX_CONNECTION_PER_SERVER,
TEXT_MAX_CONNECTION_PER_SERVER,
- "1", 1, 16, 'x'));
+ "16", 1, -1, 'x'));
op->addTag(TAG_BASIC);
op->addTag(TAG_FTP);
op->addTag(TAG_HTTP);
@@ -501,7 +501,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
}
{
OptionHandler* op(new UnitNumberOptionHandler(
- PREF_MIN_SPLIT_SIZE, TEXT_MIN_SPLIT_SIZE, "20M", 1_m, 1_g, 'k'));
+ PREF_MIN_SPLIT_SIZE, TEXT_MIN_SPLIT_SIZE, "1M", 1_k, 1_g, 'k'));
op->addTag(TAG_BASIC);
op->addTag(TAG_FTP);
op->addTag(TAG_HTTP);
@@ -834,7 +834,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
}
{
OptionHandler* op(new NumberOptionHandler(
- PREF_CONNECT_TIMEOUT, TEXT_CONNECT_TIMEOUT, "60", 1, 600));
+ PREF_CONNECT_TIMEOUT, TEXT_CONNECT_TIMEOUT, "30", 1, 600));
op->addTag(TAG_FTP);
op->addTag(TAG_HTTP);
op->setInitialOption(true);
@@ -905,7 +905,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
}
{
OptionHandler* op(new UnitNumberOptionHandler(
- PREF_PIECE_LENGTH, TEXT_PIECE_LENGTH, "1M", 1_m, 1_g));
+ PREF_PIECE_LENGTH, TEXT_PIECE_LENGTH, "1M", 1_k, 1_g));
op->addTag(TAG_ADVANCED);
op->addTag(TAG_FTP);
op->addTag(TAG_HTTP);
@@ -926,7 +926,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
}
{
OptionHandler* op(
- new NumberOptionHandler(PREF_RETRY_WAIT, TEXT_RETRY_WAIT, "0", 0, 600));
+ new NumberOptionHandler(PREF_RETRY_WAIT, TEXT_RETRY_WAIT, "1", 0, 600));
op->addTag(TAG_FTP);
op->addTag(TAG_HTTP);
op->setInitialOption(true);
@@ -971,7 +971,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
}
{
OptionHandler* op(
- new NumberOptionHandler(PREF_SPLIT, TEXT_SPLIT, "5", 1, -1, 's'));
+ new NumberOptionHandler(PREF_SPLIT, TEXT_SPLIT, "128", 1, -1, 's'));
op->addTag(TAG_BASIC);
op->addTag(TAG_FTP);
op->addTag(TAG_HTTP);
--
2.12.1
From 7e4a9461e83ff802e3e834e72039ed8b0703e24d Mon Sep 17 00:00:00 2001
From: myfreeer <myfreeer@users.noreply.github.com>
Date: Sat, 18 Nov 2017 11:55:04 +0800
Subject: [PATCH] download: retry on slow speed and conection close
This would provide better speed on bad network conditions
---
src/DownloadCommand.cc | 2 +-
src/SocketBuffer.cc | 3 ++-
src/SocketCore.cc | 2 +-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc
index 91042ef..f777dec 100644
--- a/src/DownloadCommand.cc
+++ b/src/DownloadCommand.cc
@@ -306,7 +306,7 @@ void DownloadCommand::checkLowestDownloadSpeed() const
startupIdleTime_) {
int nowSpeed = peerStat_->calculateDownloadSpeed();
if (nowSpeed <= lowestDownloadSpeedLimit_) {
- throw DL_ABORT_EX2(fmt(EX_TOO_SLOW_DOWNLOAD_SPEED, nowSpeed,
+ throw DL_RETRY_EX2(fmt(EX_TOO_SLOW_DOWNLOAD_SPEED, nowSpeed,
lowestDownloadSpeedLimit_,
getRequest()->getHost().c_str()),
error_code::TOO_SLOW_DOWNLOAD_SPEED);
diff --git a/src/SocketBuffer.cc b/src/SocketBuffer.cc
index 62862ff..1906173 100644
--- a/src/SocketBuffer.cc
+++ b/src/SocketBuffer.cc
@@ -39,6 +39,7 @@
#include "SocketCore.h"
#include "DlAbortEx.h"
+#include "DlRetryEx.h"
#include "message.h"
#include "fmt.h"
#include "LogFactory.h"
@@ -158,7 +159,7 @@ ssize_t SocketBuffer::send()
}
ssize_t slen = socket_->writeVector(iov, num);
if (slen == 0 && !socket_->wantRead() && !socket_->wantWrite()) {
- throw DL_ABORT_EX(fmt(EX_SOCKET_SEND, "Connection closed."));
+ throw DL_RETRY_EX(fmt(EX_SOCKET_SEND, "Connection closed."));
}
// A2_LOG_NOTICE(fmt("num=%zu, amount=%d, bufq.size()=%zu, SEND=%d",
// num, amount, bufq_.size(), slen));
diff --git a/src/SocketCore.cc b/src/SocketCore.cc
index d0a205f..79a90a3 100644
--- a/src/SocketCore.cc
+++ b/src/SocketCore.cc
@@ -1009,7 +1009,7 @@ bool SocketCore::tlsHandshake(TLSContext* tlsctx, const std::string& hostname)
if (rv == TLS_ERR_ERROR) {
// Damn those error.
- throw DL_ABORT_EX(fmt("SSL/TLS handshake failure: %s",
+ throw DL_RETRY_EX(fmt("SSL/TLS handshake failure: %s",
handshakeError.empty()
? tlsSession_->getLastErrorString().c_str()
: handshakeError.c_str()));
--
2.14.2
#!bash
case $MSYSTEM in
MINGW32)
export MINGW_PACKAGE_PREFIX=mingw-w64-i686
export HOST=i686-w64-mingw32
;;
MINGW64)
export MINGW_PACKAGE_PREFIX=mingw-w64-x86_64
export HOST=x86_64-w64-mingw32
;;
esac
# workaround for appveyor
git config --global user.email "you@example.com"
git config --global user.name "You"
pacman -S --noconfirm --needed $MINGW_PACKAGE_PREFIX-toolchain \
$MINGW_PACKAGE_PREFIX-expat $MINGW_PACKAGE_PREFIX-gmp $MINGW_PACKAGE_PREFIX-c-ares
PREFIX=/usr/local/$HOST
CPUCOUNT=$(grep -c ^processor /proc/cpuinfo)
curl_opts=(/usr/bin/curl --connect-timeout 15 --retry 3
--retry-delay 5 --silent --location --insecure --fail)
clean_html_index() {
local url="$1"
local filter="${2:-(?<=href=\")[^\"]+\.(tar\.(gz|bz2|xz)|7z)}"
"${curl_opts[@]}" -l "$url" | grep -ioP "$filter" | sort -uV
}
clean_html_index_sqlite() {
local url="$1"
local filter="${2:-(\d+\/sqlite-autoconf-\d+\.tar\.gz)}"
"${curl_opts[@]}" -l "$url" | grep -ioP "$filter" | sort -uV | tail -1
}
get_last_version() {
local filelist="$1"
local filter="$2"
local version="$3"
local ret
ret="$(echo "$filelist" | /usr/bin/grep -E "$filter" | sort -V | tail -1)"
[[ -n "$version" ]] && ret="$(echo "$ret" | /usr/bin/grep -oP "$version")"
echo "$ret"
}
expat_ver="$(clean_html_index https://sourceforge.net/projects/expat/files/expat/ 'expat/[0-9]+\.[0-9]+\.[0-9]+')"
expat_ver="$(get_last_version "${expat_ver}" expat '2\.\d+\.\d+')"
expat_ver="${expat_ver:-2.2.5}"
wget -c --no-check-certificate "https://downloads.sourceforge.net/project/expat/expat/${expat_ver}/expat-${expat_ver}.tar.bz2"
tar xf "expat-${expat_ver}.tar.bz2"
cd "expat-${expat_ver}"
./configure \
--disable-shared \
--enable-static \
--prefix=/usr/local/$HOST \
--host=$HOST
make install -j$CPUCOUNT
cd ..
rm -rf "expat-${expat_ver}"
sqlite_ver=$(clean_html_index_sqlite "https://www.sqlite.org/download.html")
[[ ! "$sqlite_ver" ]] && sqlite_ver="2018/sqlite-autoconf-3220000.tar.gz"
sqlite_file=$(echo ${sqlite_ver} | grep -ioP "(sqlite-autoconf-\d+\.tar\.gz)")
wget -c --no-check-certificate "https://www.sqlite.org/${sqlite_ver}"
tar xf "${sqlite_file}"
echo ${sqlite_ver}
sqlite_name=$(echo ${sqlite_ver} | grep -ioP "(sqlite-autoconf-\d+)")
cd "${sqlite_name}"
./configure \
--disable-shared \
--enable-static \
--prefix=/usr/local/$HOST \
--host=$HOST
make install -j$CPUCOUNT
cd ..
rm -rf "${sqlite_name}"
[[ ! "$cares_ver" ]] &&
cares_ver="$(clean_html_index https://c-ares.haxx.se/)" &&
cares_ver="$(get_last_version "$cares_ver" c-ares "1\.\d+\.\d")"
cares_ver="${cares_ver:-1.13.0}"
echo "c-ares-${cares_ver}"
wget -c --no-check-certificate "https://c-ares.haxx.se/download/c-ares-${cares_ver}.tar.gz"
tar xf "c-ares-${cares_ver}.tar.gz"
cd "c-ares-${cares_ver}" && \
./configure \
--disable-shared \
--enable-static \
--without-random \
--prefix=/usr/local/$HOST \
--host=$HOST \
LIBS="-lws2_32"
make install -j$CPUCOUNT
cd ..
rm -rf "c-ares-${cares_ver}"
[[ ! "$ssh_ver" ]] &&
ssh_ver="$(clean_html_index https://libssh2.org/download/)" &&
ssh_ver="$(get_last_version "$ssh_ver" tar.gz "1\.\d+\.\d")"
ssh_ver="${ssh_ver:-1.8.0}"
echo "${ssh_ver}"
wget -c --no-check-certificate "https://libssh2.org/download/libssh2-${ssh_ver}.tar.gz"
tar xf "libssh2-${ssh_ver}.tar.gz"
cd "libssh2-${ssh_ver}"
./configure \
--disable-shared \
--enable-static \
--prefix=/usr/local/$HOST \
--host=$HOST \
--without-openssl \
--with-wincng \
LIBS="-lws2_32"
make install -j$CPUCOUNT
cd ..
rm -rf "libssh2-${ssh_ver}"
git clone https://github.com/aria2/aria2 --depth=1 --config http.sslVerify=false
cd aria2
git am ../aria2-*.patch
# Bump up version number to 1.33.1
wget https://github.com/aria2/aria2/commit/b9d74ca88bb8d8c53ccbfc7e95e05f9e2a155455.patch
git am b9d74ca88bb8d8c53ccbfc7e95e05f9e2a155455.patch
autoreconf -fi
./configure \
--host=$HOST \
--prefix=$PREFIX \
--without-included-gettext \
--disable-nls \
--with-libcares \
--without-gnutls \
--without-openssl \
--with-sqlite3 \
--without-libxml2 \
--with-libexpat \
--with-libz \
--with-libgmp \
--with-libssh2 \
--without-libgcrypt \
--without-libnettle \
--with-cppunit-prefix=$PREFIX \
ARIA2_STATIC=yes \
CPPFLAGS="-I$PREFIX/include" \
LDFLAGS="-L$PREFIX/lib" \
PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig"
make -j$CPUCOUNT
strip src/aria2c.exe
@echo off
pushd "%~dp0"
setlocal EnableExtensions EnableDelayedExpansion
:Deps
set MSYSTEM=MINGW64
REM MINGW64 means 64-bit build; MINGW32 means 32-bit build;
set msysbin=msys64\usr\bin
set sh=%msysbin%\bash
set pacman=%msysbin%\pacman
if exist msys64\mingw64.exe goto :Update
if exist busybox.exe if exist msys2-x86_64-latest.tar.xz goto :Extract
echo. dependency broken. download msys2-x86_64-latest.tar.xz and busybox.exe and put them in the same folder of the script.
echo. download busybox.exe from https://frippery.org/files/busybox/busybox.exe
echo. and deonload msys2-x86_64-latest.tar.xz from http://repo.msys2.org/distrib/msys2-x86_64-latest.tar.xz
pause
exit /B -1
:Extract
busybox tar -Jxvf msys2-x86_64-latest.tar.xz
:Init
%sh% -lc "pacman-key --init && exit" 2>&1 | busybox tee -a init.log
:Chi_Mirror
for %%i in ( mirrorlist.mingw32 mirrorlist.mingw64 mirrorlist.msys) do if exist %%i copy /y %%i msys64\etc\pacman.d\
:Update
%pacman% -Syyuu --needed --noconfirm 2>&1 | busybox tee -a update.log
%pacman% -Suu --needed --noconfirm 2>&1 | busybox tee -a update.log
:Install
%pacman% -S --needed --noconfirm base-devel zlib-devel sqlite git unzip zip tar gmp gmp-devel libssh2 libssh2-devel openssl-devel 2>&1 | busybox tee -a install.log
%pacman% -Sc --noconfirm 2>&1 | busybox tee -a install.log
:Clone
%sh% -lc "if [[ -d ~/aria2 ]]; then cd aria2; git pull; else git clone https://gist.github.com/a780c730b7282e090f238e8286f815f3.git aria2; cd aria2; git pull; fi" 2>&1 | busybox tee -a clone.log
:Build
%sh% -lc "cd ~/aria2 && exec ./build-aria2.sh" 2>&1 | busybox tee -a build.log
pause
@myfreeer
Copy link
Author

myfreeer commented May 24, 2017

Moved to GitHub

Moved to https://github.com/myfreeer/aria2-build-msys2

Readme

aria2 build scripts for msys2 with custom patches.

Build Status

Build status

License

GPL-2.0, as it included codes from aria2 project.

Changes

  • option max-connection-per-server: change maximum value to *, default value to 16
  • option min-split-size: change minimum value to 1K, default value to 1M
  • option piece-length: change minimum value to 1K, default value to 1M
  • option connect-timeout: change default value to 30
  • option split: change default value to 128
  • option continue: change default value to true
  • option retry-wait: change default value to 1
  • option max-concurrent-downloads: change default value to 16
  • option netrc-path conf-path dht-file-path dht-file-path6: change default value to sub-folder of current directory
  • download: retry on slow speed and connection close

Environment

MSYS2
Should be set up with commands below:

pacman -Syyuu --noconfirm
pacman -S --noconfirm --needed base-devel zlib-devel sqlite git unzip zip tar gmp gmp-devel libssh2 libssh2-devel openssl-devel

Artifacts

  • x86_64 (64-bits) version: aria2c.7z
  • x86 (32-bits) version: aria2c_x86.7z

Credits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment