Improve mingw+docker for libaria2 compilation

This PR introduces a few improvements to the docker-based Windows builds
* compile any published branch/tag, not just the latest master branch.
  Use `docker build --build-arg GIT_TAG=<tag> ...`
* compile local code instead of downloading the github version.
  Use `docker build --build-arg SOURCE=local ...`
* Control libaria2 build
  Use `docker build --build-arg LIBARIA2=enable ...`
* Control static build.
  Use `docker build --build-arg ARIA2_STATIC=no ...`
* Automatically copy the resulting binaries to the shared volume if set.
  This is significantly simpler than copying from a running container.
  Use `docker run -v $PWD:/output ...`
pull/1867/head
Yuri Astrakhan 2021-12-26 23:37:03 -05:00
parent c546fa492c
commit df4f6b325a
3 changed files with 119 additions and 12 deletions

51
.dockerignore Normal file
View File

@ -0,0 +1,51 @@
Dockerfile*
.gitignore
.dockerignore
#### The rest of the file is a verbatim copy of the .gitignore
*~
*.o
*.lo
*.la
*.ce
*.cce
*.he
depcomp
*.m4
Makefile
Makefile.in
missing
autom4te.cache/
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
install-sh
.deps/
stamp-h1
INSTALL
*.gmo
ABOUT-NLS
README.html
config.rpath
aria2c.1
aria2c.1.html
intl/
libtool
ltmain.sh
po/aria2.pot
po/remove-potcdate.sed
src/libaria2.pc
test-driver
libaria2api
libaria2ex
libaria2wx
.dirstamp
.libs
compile
main.log
main.trs
test-suite.log

View File

@ -1,17 +1,33 @@
# Dockerfile to build aria2 Windows binary using ubuntu mingw-w64 # Dockerfile to build aria2 Windows binary using ubuntu mingw-w64
# cross compiler chain. # cross compiler chain.
# #
# $ sudo docker build -t aria2-mingw - < Dockerfile.mingw # $ sudo docker build -t aria2-mingw -f Dockerfile.mingw .
# #
# After successful build, windows binary is located at # After successful build, windows binary is located at
# /aria2/src/aria2c.exe. You can copy the binary using following # /aria2/src/aria2c.exe. You can copy the binary to the current dir
# commands: # using following command (replace $PWD with any other full path if desired):
# #
# $ id=$(sudo docker create aria2-mingw) # $ sudo docker run --rm -v $PWD:/output aria2-mingw
# $ sudo docker cp $id:/aria2/src/aria2c.exe <dest>
# $ sudo docker rm -v $id
FROM ubuntu:20.04 # Additional arguments can be set with --build-arg. For example, to build local source code instead of
# the latest master on github, set SOURCE=local:
#
# $ sudo docker build -t aria2-mingw -f Dockerfile.mingw --build-arg SOURCE=local .
#
# Available build parameters:
# SOURCE - "git" (default) to use Aria2 code from github. "local" to copy current directory.
# GIT_TAG - if SOURCE=git (default), set which branch or tag to download.
# LIBARIA2 - disable (default) / enable -- should the libaria2 library be built
# ARIA2_STATIC - yes (default) / no -- compile as a dynamic or static code
#
# Note that LIBARIA2 and ARIA2_STATIC params might not work for older versions.
#
ARG SOURCE=git
ARG GIT_TAG=master
ARG LIBARIA2=disable
ARG ARIA2_STATIC=yes
FROM ubuntu:20.04 as build_base
MAINTAINER Tatsuhiro Tsujikawa MAINTAINER Tatsuhiro Tsujikawa
@ -109,7 +125,38 @@ RUN tar xf libssh2-1.9.0.tar.gz && \
--with-wincng \ --with-wincng \
LIBS="-lws2_32" && \ LIBS="-lws2_32" && \
make install make install
ADD https://api.github.com/repos/aria2/aria2/git/refs/heads/master version.json
RUN git clone https://github.com/aria2/aria2 && \
cd aria2 && autoreconf -i && ./mingw-config && make && \ #
$HOST-strip src/aria2c.exe # The above "build_base" stage builds common steps,
# before copying/downloading aria2 source code. The following
# two steps will either copy sources from the local dir,
# or will download a specific tag/branch from github.
# The last stage will use the needed stage, running the delayed steps.
#
ARG SOURCE GIT_TAG LIBARIA2 ARIA2_STATIC
FROM build_base as build_local
ONBUILD COPY . /aria2
ARG SOURCE GIT_TAG LIBARIA2 ARIA2_STATIC
FROM build_base as build_git
ONBUILD ADD https://api.github.com/repos/aria2/aria2/git/refs/heads/${GIT_TAG} version.json
ONBUILD RUN echo "Downloading '${GIT_TAG}' from https://github.com/aria2/aria2" && \
git clone https://github.com/aria2/aria2 --depth 1 --branch "${GIT_TAG}"
ARG SOURCE GIT_TAG LIBARIA2 ARIA2_STATIC
FROM build_${SOURCE}
RUN cd /aria2 && \
autoreconf -i \
export LIBARIA2=${LIBARIA2} && \
export ARIA2_STATIC=${ARIA2_STATIC} && \
./mingw-config && \
make \
(test -f /aria2/src/aria2c.exe && $HOST-strip /aria2/src/aria2c.exe) && \
(test -f /aria2/src/main.o && $HOST-strip /aria2/src/main.o)
CMD test ! -d /output && \
echo 'The /output dir is not set. Use "docker run -v $PWD:/output ..." to copy build results into the current dir. To explore this container, append "bash" at the end of docker run command.' || \
cp -v /aria2/src/aria2c.exe* /aria2/src/main.o /output

View File

@ -35,6 +35,12 @@
# build on Debian Linux using mingw-w64. Some environment variables # build on Debian Linux using mingw-w64. Some environment variables
# can be adjusted to change build settings: # can be adjusted to change build settings:
# #
# LIBARIA2: must be "enable" or "disable" (default). If enabled,
# enabled, builds libaria2 lib, either static or dynamic depending
# on the ARIA2_STATIC setting.
#
# ARIA2_STATIC: must be "yes" (default) or "no".
#
# HOST: cross-compile to build programs to run on HOST. It defaults to # HOST: cross-compile to build programs to run on HOST. It defaults to
# i686-w64-mingw32. To build 64 bit binary, specify # i686-w64-mingw32. To build 64 bit binary, specify
# x86_64-w64-mingw32. # x86_64-w64-mingw32.
@ -55,6 +61,8 @@
# * libssh2 # * libssh2
# * cppunit # * cppunit
test -z "$LIBARIA2" && LIBARIA2=disable
test -z "$ARIA2_STATIC" && ARIA2_STATIC=yes
test -z "$HOST" && HOST=i686-w64-mingw32 test -z "$HOST" && HOST=i686-w64-mingw32
test -z "$PREFIX" && PREFIX=/usr/local/$HOST test -z "$PREFIX" && PREFIX=/usr/local/$HOST
@ -75,7 +83,8 @@ test -z "$PREFIX" && PREFIX=/usr/local/$HOST
--without-libgcrypt \ --without-libgcrypt \
--without-libnettle \ --without-libnettle \
--with-cppunit-prefix=$PREFIX \ --with-cppunit-prefix=$PREFIX \
ARIA2_STATIC=yes \ --${LIBARIA2}-libaria2 \
ARIA2_STATIC=${ARIA2_STATIC} \
CPPFLAGS="-I$PREFIX/include" \ CPPFLAGS="-I$PREFIX/include" \
LDFLAGS="-L$PREFIX/lib" \ LDFLAGS="-L$PREFIX/lib" \
PKG_CONFIG="/usr/bin/pkg-config" \ PKG_CONFIG="/usr/bin/pkg-config" \