Merge pull request #973 from alvistack/master-linux-amd64

Build static binary with `buildGoModule`
This commit is contained in:
Daniel J Walsh 2020-08-11 17:42:05 -04:00 committed by GitHub
commit ea10e61f7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 9 deletions

View File

@ -88,6 +88,7 @@ help:
@echo @echo
@echo " * 'install' - Install binaries and documents to system locations" @echo " * 'install' - Install binaries and documents to system locations"
@echo " * 'binary' - Build skopeo with a container" @echo " * 'binary' - Build skopeo with a container"
@echo " * 'static' - Build statically linked binary"
@echo " * 'bin/skopeo' - Build skopeo locally" @echo " * 'bin/skopeo' - Build skopeo locally"
@echo " * 'test-unit' - Execute unit tests" @echo " * 'test-unit' - Execute unit tests"
@echo " * 'test-integration' - Execute integration tests" @echo " * 'test-integration' - Execute integration tests"
@ -103,12 +104,19 @@ binary: cmd/skopeo
${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd):/src/github.com/containers/skopeo \ ${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd):/src/github.com/containers/skopeo \
skopeobuildimage make bin/skopeo $(if $(DEBUG),DEBUG=$(DEBUG)) BUILDTAGS='$(BUILDTAGS)' skopeobuildimage make bin/skopeo $(if $(DEBUG),DEBUG=$(DEBUG)) BUILDTAGS='$(BUILDTAGS)'
# Update nix/nixpkgs.json its latest master commit # Update nix/nixpkgs.json its latest stable commit
.PHONY: nixpkgs .PHONY: nixpkgs
nixpkgs: nixpkgs:
@nix run -f channel:nixos-20.03 nix-prefetch-git -c nix-prefetch-git \ @nix run -f channel:nixos-20.03 nix-prefetch-git -c nix-prefetch-git \
--no-deepClone https://github.com/nixos/nixpkgs > nix/nixpkgs.json --no-deepClone https://github.com/nixos/nixpkgs > nix/nixpkgs.json
# Build statically linked binary
.PHONY: static
static:
@nix build -f nix/
mkdir -p ./bin
cp -rfp ./result/bin/* ./bin/
# Build w/o using containers # Build w/o using containers
.PHONY: bin/skopeo .PHONY: bin/skopeo
bin/skopeo: bin/skopeo:

View File

@ -6,6 +6,16 @@ let
gpgme = (static pkg.gpgme); gpgme = (static pkg.gpgme);
libassuan = (static pkg.libassuan); libassuan = (static pkg.libassuan);
libgpgerror = (static pkg.libgpgerror); libgpgerror = (static pkg.libgpgerror);
libseccomp = (static pkg.libseccomp);
glib = (static pkg.glib).overrideAttrs(x: {
outputs = [ "bin" "out" "dev" ];
mesonFlags = [
"-Ddefault_library=static"
"-Ddevbindir=${placeholder ''dev''}/bin"
"-Dgtk_doc=false"
"-Dnls=disabled"
];
});
}; };
}; };
}); });
@ -21,14 +31,15 @@ let
enableStatic = true; enableStatic = true;
}); });
self = with pkgs; buildGoPackage rec { self = with pkgs; buildGoModule rec {
name = "skopeo"; name = "skopeo";
src = ./..; src = ./..;
goPackagePath = "github.com/containers/skopeo"; vendorSha256 = null;
doCheck = false; doCheck = false;
enableParallelBuilding = true; enableParallelBuilding = true;
nativeBuildInputs = [ git go-md2man installShellFiles makeWrapper pkg-config ]; outputs = [ "out" ];
buildInputs = [ glibc glibc.static gpgme libassuan libgpgerror ]; nativeBuildInputs = [ bash git go-md2man installShellFiles makeWrapper pkg-config which ];
buildInputs = [ glibc glibc.static gpgme libassuan libgpgerror libseccomp ];
prePatch = '' prePatch = ''
export CFLAGS='-static' export CFLAGS='-static'
export LDFLAGS='-s -w -static-libgcc -static' export LDFLAGS='-s -w -static-libgcc -static'
@ -36,7 +47,6 @@ let
export BUILDTAGS='static netgo exclude_graphdriver_btrfs exclude_graphdriver_devicemapper' export BUILDTAGS='static netgo exclude_graphdriver_btrfs exclude_graphdriver_devicemapper'
''; '';
buildPhase = '' buildPhase = ''
pushd go/src/${goPackagePath}
patchShebangs . patchShebangs .
make bin/skopeo make bin/skopeo
''; '';

View File

@ -1,7 +1,7 @@
{ {
"url": "https://github.com/nixos/nixpkgs", "url": "https://github.com/nixos/nixpkgs",
"rev": "87c5724af9f61be5e77034229078960690c1abe2", "rev": "d6a445fe821052861b379d9b6c02d21623c25464",
"date": "2020-06-28T22:14:24+01:00", "date": "2020-08-11T04:28:16+01:00",
"sha256": "1vg6iajb945b33nx674nnask6wai8zkjd4m0i9fcpdkwhwr0s46s", "sha256": "064scwaxg8qg4xbmq07hag57saa4bhsb4pgg5h5vfs4nhhwvchg9",
"fetchSubmodules": false "fetchSubmodules": false
} }