support and describe building static binaries
This commit is contained in:
15
Dockerfile.build
Normal file
15
Dockerfile.build
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
FROM ubuntu
|
||||||
|
RUN apt-get update -yy && \
|
||||||
|
apt-get install -yy git make curl libxml2-dev libxmlsec1-dev pkg-config
|
||||||
|
|
||||||
|
RUN curl -s https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz | tar -C /usr/local -xzf -
|
||||||
|
ENV GOPATH=/go
|
||||||
|
ENV PATH=$PATH:/usr/local/go/bin:/go/bin
|
||||||
|
RUN mkdir -p /go/bin
|
||||||
|
|
||||||
|
ADD . /go/src/github.com/crewjam/go-xmlsec
|
||||||
|
WORKDIR /go/src/github.com/crewjam/go-xmlsec
|
||||||
|
RUN go get github.com/crewjam/errset
|
||||||
|
RUN go build -o /bin/xmldsig ./examples/xmldsig.go
|
||||||
|
RUN ldd /bin/xmldsig || true
|
||||||
|
RUN /bin/xmldsig --help || true
|
||||||
98
Dockerfile.build-static
Normal file
98
Dockerfile.build-static
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
FROM ubuntu
|
||||||
|
RUN apt-get update -yy && \
|
||||||
|
apt-get install -yy git make curl pkg-config
|
||||||
|
|
||||||
|
RUN curl -s https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz | tar -C /usr/local -xzf -
|
||||||
|
ENV GOPATH=/go
|
||||||
|
ENV PATH=$PATH:/usr/local/go/bin:/go/bin
|
||||||
|
RUN mkdir -p /go/bin
|
||||||
|
|
||||||
|
RUN curl -sL ftp://xmlsoft.org/libxml2/libxml2-2.9.4.tar.gz | tar -xzf - && \
|
||||||
|
cd /libxml2-2.9.4 && \
|
||||||
|
./configure \
|
||||||
|
--enable-static \
|
||||||
|
--disable-shared \
|
||||||
|
--without-gnu-ld \
|
||||||
|
--with-c14n \
|
||||||
|
--without-catalog \
|
||||||
|
--without-debug \
|
||||||
|
--without-docbook \
|
||||||
|
--without-fexceptions \
|
||||||
|
--without-ftp \
|
||||||
|
--without-history \
|
||||||
|
--without-html \
|
||||||
|
--without-http \
|
||||||
|
--without-iconv \
|
||||||
|
--without-icu \
|
||||||
|
--without-iso8859x \
|
||||||
|
--without-legacy \
|
||||||
|
--without-mem-debug \
|
||||||
|
--without-minimum \
|
||||||
|
--with-output \
|
||||||
|
--without-pattern \
|
||||||
|
--with-push \
|
||||||
|
--without-python \
|
||||||
|
--without-reader \
|
||||||
|
--without-readline \
|
||||||
|
--without-regexps \
|
||||||
|
--without-run-debug \
|
||||||
|
--with-sax1 \
|
||||||
|
--without-schemas \
|
||||||
|
--without-schematron \
|
||||||
|
--without-threads \
|
||||||
|
--without-thread-alloc \
|
||||||
|
--with-tree \
|
||||||
|
--without-valid \
|
||||||
|
--without-writer \
|
||||||
|
--without-xinclude \
|
||||||
|
--without-xpath \
|
||||||
|
--with-xptr \
|
||||||
|
--without-modules \
|
||||||
|
--without-zlib \
|
||||||
|
--without-lzma \
|
||||||
|
--without-coverage && \
|
||||||
|
make install
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
curl -sL ftp://ftp.openssl.org/source/openssl-1.0.2h.tar.gz | tar -xzf - && \
|
||||||
|
cd openssl-1.0.2h && \
|
||||||
|
./config \
|
||||||
|
no-shared \
|
||||||
|
no-weak-ssl-ciphers \
|
||||||
|
no-ssl2 \
|
||||||
|
no-ssl3 \
|
||||||
|
no-comp \
|
||||||
|
no-idea \
|
||||||
|
no-dtls \
|
||||||
|
no-hw \
|
||||||
|
no-threads \
|
||||||
|
no-dso && \
|
||||||
|
make depend install
|
||||||
|
|
||||||
|
RUN curl -sL http://www.aleksey.com/xmlsec/download/xmlsec1-1.2.22.tar.gz | tar -xzf - && \
|
||||||
|
cd xmlsec1-1.2.22 && \
|
||||||
|
./configure \
|
||||||
|
--enable-static \
|
||||||
|
--disable-shared \
|
||||||
|
--disable-crypto-dl \
|
||||||
|
--disable-apps-crypto-dl \
|
||||||
|
--enable-static-linking \
|
||||||
|
--without-gnu-ld \
|
||||||
|
--with-default-crypto=openssl \
|
||||||
|
--with-openssl=/usr/local/ssl \
|
||||||
|
--with-libxml=/usr/local \
|
||||||
|
--without-nss \
|
||||||
|
--without-nspr \
|
||||||
|
--without-gcrypt \
|
||||||
|
--without-gnutls \
|
||||||
|
--without-libxslt && \
|
||||||
|
make -C src install && \
|
||||||
|
make -C include install && \
|
||||||
|
make install-pkgconfigDATA
|
||||||
|
|
||||||
|
ADD . /go/src/github.com/crewjam/go-xmlsec
|
||||||
|
WORKDIR /go/src/github.com/crewjam/go-xmlsec
|
||||||
|
RUN go get github.com/crewjam/errset
|
||||||
|
RUN go build -tags static -ldflags '-s -extldflags "-static"' -o /bin/xmldsig ./examples/xmldsig.go
|
||||||
|
RUN ldd /bin/xmldsig || true
|
||||||
|
RUN /bin/xmldsig --help || true
|
||||||
44
README.md
44
README.md
@@ -42,7 +42,7 @@ As seems to be the case for many things in the XMLish world, the xmldsig and xml
|
|||||||
|
|
||||||
This package uses cgo to wrap libxmlsec. As such, you'll need libxmlsec headers and a C compiler to make it work. On linux, this might look like:
|
This package uses cgo to wrap libxmlsec. As such, you'll need libxmlsec headers and a C compiler to make it work. On linux, this might look like:
|
||||||
|
|
||||||
$ apt-get install libxml2-dev libxmlsec1-dev
|
$ apt-get install libxml2-dev libxmlsec1-dev pkg-config
|
||||||
$ go get github.com/crewjam/go-xmlsec
|
$ go get github.com/crewjam/go-xmlsec
|
||||||
|
|
||||||
On Mac with homebrew, this might look like:
|
On Mac with homebrew, this might look like:
|
||||||
@@ -50,4 +50,46 @@ On Mac with homebrew, this might look like:
|
|||||||
$ brew install libxmlsec1 libxml2 pkg-config
|
$ brew install libxmlsec1 libxml2 pkg-config
|
||||||
$ go get github.com/crewjam/go-xmlsec
|
$ go get github.com/crewjam/go-xmlsec
|
||||||
|
|
||||||
|
# Static Linking
|
||||||
|
|
||||||
|
It may annoy you to grow a depenency on the shared libraries for libxmlsec, libxml2, etc. After some fighting, here is what I made work on Linux to get
|
||||||
|
a static binary. See also `Dockerfile.build-static` which build the example
|
||||||
|
program using this method.
|
||||||
|
|
||||||
|
## Compile libxml
|
||||||
|
|
||||||
|
```
|
||||||
|
curl -sL ftp://xmlsoft.org/libxml2/libxml2-2.9.4.tar.gz | tar -xzf -
|
||||||
|
cd /libxml2-2.9.4
|
||||||
|
./configure --enable-static --disable-shared --without-gnu-ld --with-c14n --without-catalog --without-debug --without-docbook --without-fexceptions --without-ftp --without-history --without-html --without-http --without-iconv --without-icu --without-iso8859x --without-legacy --without-mem-debug --without-minimum --with-output --without-pattern --with-push --without-python --without-reader --without-readline --without-regexps --without-run-debug --with-sax1 --without-schemas --without-schematron --without-threads --without-thread-alloc --with-tree --without-valid --without-writer --without-xinclude --without-xpath --with-xptr --without-modules --without-zlib --without-lzma --without-coverage
|
||||||
|
make install
|
||||||
|
```
|
||||||
|
|
||||||
|
## Compile openssl
|
||||||
|
|
||||||
|
```
|
||||||
|
curl -sL ftp://ftp.openssl.org/source/openssl-1.0.2h.tar.gz | tar -xzf -
|
||||||
|
cd openssl-1.0.2h
|
||||||
|
./config no-shared no-weak-ssl-ciphers no-ssl2 no-ssl3 no-comp no-idea no-dtls no-hw no-threads no-dso
|
||||||
|
make install
|
||||||
|
```
|
||||||
|
|
||||||
|
## Compile libxmlsec
|
||||||
|
|
||||||
|
```
|
||||||
|
curl -sL http://www.aleksey.com/xmlsec/download/xmlsec1-1.2.22.tar.gz | tar -xzf -
|
||||||
|
./configure --enable-static --disable-shared --disable-crypto-dl --disable-apps-crypto-dl --enable-static-linking --without-gnu-ld --with-default-crypto=openssl --with-openssl=/usr/local/ssl --with-libxml=/usr/local --without-nss --without-nspr --without-gcrypt --without-gnutls --without-libxslt
|
||||||
|
make -C src install
|
||||||
|
make -C include install
|
||||||
|
make install-pkgconfigDATA
|
||||||
|
```
|
||||||
|
|
||||||
|
## Build with static tag
|
||||||
|
|
||||||
|
```
|
||||||
|
go build -tags static -ldflags '-s -extldflags "-static"' -o /bin/xmldsig-static.bin ./examples/xmldsig.go
|
||||||
|
```
|
||||||
|
|
||||||
|
Running `ldd` on the output should produce `not a dynamic executable`.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
19
cgo_dl.go
Normal file
19
cgo_dl.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package xmlsec
|
||||||
|
|
||||||
|
// +build !static
|
||||||
|
|
||||||
|
// #cgo linux CFLAGS: -w
|
||||||
|
// #cgo darwin CFLAGS: -Wno-invalid-pp-token -Wno-header-guard
|
||||||
|
// #cgo pkg-config: xmlsec1
|
||||||
|
// #include <xmlsec/xmlsec.h>
|
||||||
|
// #include <xmlsec/xmltree.h>
|
||||||
|
// #include <xmlsec/xmlenc.h>
|
||||||
|
// #include <xmlsec/templates.h>
|
||||||
|
// #include <xmlsec/crypto.h>
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
// #cgo pkg-config: libxml-2.0
|
||||||
|
// #include <libxml/parser.h>
|
||||||
|
// #include <libxml/parserInternals.h>
|
||||||
|
// #include <libxml/xmlmemory.h>
|
||||||
|
import "C"
|
||||||
24
cgo_static.go
Normal file
24
cgo_static.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package xmlsec
|
||||||
|
|
||||||
|
// +build static
|
||||||
|
|
||||||
|
// #cgo linux CFLAGS: -w
|
||||||
|
// #cgo darwin CFLAGS: -Wno-invalid-pp-token -Wno-header-guard
|
||||||
|
// #cgo pkg-config: --static xmlsec1
|
||||||
|
// #include <xmlsec/xmlsec.h>
|
||||||
|
// #include <xmlsec/xmltree.h>
|
||||||
|
// #include <xmlsec/xmlenc.h>
|
||||||
|
// #include <xmlsec/templates.h>
|
||||||
|
// #include <xmlsec/crypto.h>
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
// #cgo pkg-config: --static libxml-2.0
|
||||||
|
// #include <libxml/parser.h>
|
||||||
|
// #include <libxml/parserInternals.h>
|
||||||
|
// #include <libxml/xmlmemory.h>
|
||||||
|
// #include <xmlsec/xmlsec.h>
|
||||||
|
// #include <xmlsec/xmltree.h>
|
||||||
|
// #include <xmlsec/xmlenc.h>
|
||||||
|
// #include <xmlsec/templates.h>
|
||||||
|
// #include <xmlsec/crypto.h>
|
||||||
|
import "C"
|
||||||
@@ -5,9 +5,6 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// #cgo linux CFLAGS: -w
|
|
||||||
// #cgo darwin CFLAGS: -Wno-invalid-pp-token -Wno-header-guard
|
|
||||||
// #cgo pkg-config: xmlsec1
|
|
||||||
// #include <xmlsec/xmlsec.h>
|
// #include <xmlsec/xmlsec.h>
|
||||||
// #include <xmlsec/xmltree.h>
|
// #include <xmlsec/xmltree.h>
|
||||||
// #include <xmlsec/xmlenc.h>
|
// #include <xmlsec/xmlenc.h>
|
||||||
@@ -15,7 +12,6 @@ import (
|
|||||||
// #include <xmlsec/crypto.h>
|
// #include <xmlsec/crypto.h>
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
// #cgo pkg-config: libxml-2.0
|
|
||||||
// #include <libxml/parser.h>
|
// #include <libxml/parser.h>
|
||||||
// #include <libxml/parserInternals.h>
|
// #include <libxml/parserInternals.h>
|
||||||
// #include <libxml/xmlmemory.h>
|
// #include <libxml/xmlmemory.h>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package xmlsec
|
package xmlsec
|
||||||
|
|
||||||
// #cgo pkg-config: xmlsec1
|
|
||||||
// #include <xmlsec/xmlsec.h>
|
// #include <xmlsec/xmlsec.h>
|
||||||
// #include <xmlsec/xmltree.h>
|
// #include <xmlsec/xmltree.h>
|
||||||
// #include <xmlsec/xmlenc.h>
|
// #include <xmlsec/xmlenc.h>
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// #cgo pkg-config: xmlsec1
|
|
||||||
// #include <xmlsec/xmlsec.h>
|
// #include <xmlsec/xmlsec.h>
|
||||||
// #include <xmlsec/xmltree.h>
|
// #include <xmlsec/xmltree.h>
|
||||||
// #include <xmlsec/xmlenc.h>
|
// #include <xmlsec/xmlenc.h>
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import "unsafe"
|
|||||||
// brew install libxmlsec1 libxml2
|
// brew install libxmlsec1 libxml2
|
||||||
// brew link libxml2 --force
|
// brew link libxml2 --force
|
||||||
|
|
||||||
// #cgo pkg-config: xmlsec1
|
|
||||||
// #include <xmlsec/xmlsec.h>
|
// #include <xmlsec/xmlsec.h>
|
||||||
// #include <xmlsec/xmltree.h>
|
// #include <xmlsec/xmltree.h>
|
||||||
// #include <xmlsec/xmlenc.h>
|
// #include <xmlsec/xmlenc.h>
|
||||||
@@ -15,7 +14,6 @@ import "unsafe"
|
|||||||
// #include <xmlsec/crypto.h>
|
// #include <xmlsec/crypto.h>
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
// #cgo pkg-config: libxml-2.0
|
|
||||||
// #include <libxml/parser.h>
|
// #include <libxml/parser.h>
|
||||||
// #include <libxml/parserInternals.h>
|
// #include <libxml/parserInternals.h>
|
||||||
// #include <libxml/xmlmemory.h>
|
// #include <libxml/xmlmemory.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user