steeve / libtorrent-go

SWIG Go bindings for libtorrent-rasterbar
BSD 3-Clause "New" or "Revised" License
103 stars 56 forks source link

Building how-to #3

Closed colthreepv closed 9 years ago

colthreepv commented 9 years ago

Hello steeve, i really appreciate your work, as a beginner-intermediate go programmer, building the lib is something outside the usual learning curve.

What I am doing currently:

$ go get github.com/steeve/libtorrent-go
## it then fails, because it needs building
$ cd $GOPATH/src/go/github.com/steeve/libtorrent-go
$ make build-envs
## after 1 hour something fails (usually openssl), so I download pre-built images
$ docker pull steeve/libtorrent-go:linux-x64
$ docker pull steeve/libtorrent-go:windows-x64
$ make alldist
## at this point, linux-x64 fails to build, and windows-x64 succeeds
## now.. ???

I have a bit of confusion what I should be doing to get myself working asap with this project, I also noticed there are pre-built docker images for EACH platform (great work)

From what i understand, the easiest route is to download those (with a decent connection downloading is faster than compiling, and more reliable, since some builds fail), then just do a make in the library directory and everything should fall in place.

Aside from theory, I can't get this to work. I would be happy to write a little readme if I can reproduce the compilation, a library like this would be very useful to all the community ;)

steeve commented 9 years ago

hey, thanks for reaching out :) i'll try and see if i have some outstanding commit or changes that have yet to be pushed.

there was a regression in libtorrent 1.0.2 so I had to roll a custom version, but now that 1.0.3 is released, i can switch back

i'll let you know :)

colthreepv commented 9 years ago

I've noticed you updated the docker images on docker registry, most of them got updated, except windows-x64.

I succeded rebuilding it with libtorrent-1.0.3 and golang-1.4, modifying windows-x64/Dockerfile as following:

FROM 7df5b915dbae

# Somehow this is needed or libtorrent complains about boost
RUN ${CROSS_TRIPLE}-ranlib ${CROSS_ROOT}/lib/*.a

# Install libtorrent
# Changes:
# - define WIN32, _UNICODE, IPV6_TCLASS=39
ENV LIBTORRENT_VERSION 1.0.3
RUN curl -L http://sourceforge.net/projects/libtorrent/files/libtorrent/libtorrent-rasterbar-${LIBTORRENT_VERSION}.tar.gz/download | tar xvz && \
    cd libtorrent-rasterbar-${LIBTORRENT_VERSION}/ && \
    sed -i 's/$PKG_CONFIG openssl --libs-only-/$PKG_CONFIG openssl --static --libs-only-/' ./configure && \
    sed -i -e s/Windows.h/windows.h/ -e s/Wincrypt.h/wincrypt.h/ ./ed25519/src/seed.cpp && \
    \
    PKG_CONFIG_PATH=${CROSS_ROOT}/lib/pkgconfig/ \
    CC=${CROSS_TRIPLE}-cc CXX=${CROSS_TRIPLE}-c++ \
    CFLAGS="${CFLAGS} -O2 -DUNICODE -D_UNICODE -DWIN32 -DIPV6_TCLASS=39" \
    CXXFLAGS="${CXXFLAGS} ${CFLAGS}" \
    ./configure --enable-static --disable-shared --disable-deprecated-functions \
    --host=${CROSS_TRIPLE} --prefix=${CROSS_ROOT} \
    --with-boost=${CROSS_ROOT} --with-boost-libdir=${CROSS_ROOT}/lib && \
    \
    make && make install && \
    rm -rf `pwd`

# Install SWIG
# Need to build from >3.0.2 because Go 1.4
# Also, revert https://github.com/swig/swig/commit/255c929c5636f54c16261bd92b8eea2005d61b11 as it breaks boost
ENV SWIG_VERSION 01faf1baf92f3dc9c6c26b61c3e6db4f9d4e7784
RUN apt-get update && apt-get install -y libpcre3-dev bison yodl
RUN curl -L https://github.com/swig/swig/archive/${SWIG_VERSION}.tar.gz | tar xvz && \
    cd swig-${SWIG_VERSION}/ && \
    curl -L https://github.com/swig/swig/commit/255c929c5636f54c16261bd92b8eea2005d61b11.diff | patch -Rp1 && \
    curl -L https://github.com/steeve/swig/compare/swig:${SWIG_VERSION}...packed-structs.diff | patch -p1 && \
    curl -L https://github.com/steeve/swig/compare/swig:${SWIG_VERSION}...fix-windows.diff | patch -p1 && \
    ./autogen.sh && \
    ./configure && make && make install && \
    rm -rf `pwd`

# Install Golang
ENV GO_VERSION 1.4
RUN cd /usr/local && \
    curl -L http://golang.org/dl/go${GO_VERSION}.src.tar.gz | tar xvz && \
    cd /usr/local/go/src && \
    CC_FOR_TARGET=${CROSS_TRIPLE}-cc CXX_FOR_TARGET=${CROSS_TRIPLE}-c++ GOOS=windows GOARCH=amd64 CGO_ENABLED=1 ./make.bash
ENV PATH ${PATH}:/usr/local/go/bin

WORKDIR /
RUN rm -rf /build

to use it:

$ docker pull steeve/libtorrent-go:windows-x64 (from 2014-11-13 build)
$ docker build . -t steeve/libtorrent-go:windows-x64_golang-1.4

In short what I did was pick the layer 7df5b915dbae in which OpenSSL was compiled (compilation always fails for me), then compile the other libraries.

Makefile has to be modified accordingly!

steeve commented 9 years ago

Yeah I need to sort out windows-x64, it seems i'm doing something wrong with OpenSSL, haven't got time to look into it unfortunately

steeve commented 9 years ago

Okay found, it was a badly configured tag push for steeve/cross-compiler:windows-x86

It should be fixed in an hour or so

colthreepv commented 9 years ago

I rebuilt and everything is fine since 8 days ;) thanks