I have a go program which does not require any dynamic library dependencies, and as such I would like to link it statically and use the `base: base` for this snap, so I have tried this:
which I can't use with the bare base snap. What works instead is to do this manually:
```
override-build: |
mkdir -p $SNAPCRAFT_PART_INSTALL/bin
cd $SNAPCRAFT_PART_SRC
go build -o $SNAPCRAFT_PART_INSTALL/bin ./...
```
It would be nice if snapcraft either:
1. automatically detected that CGO_ENABLED=0 was set in the build-environment and didn't manually link things
2. automatically detected that the built binaries from go build -o ./bin ./... were not dynamically linked at all and skipped the final link step
3. had a property or otherwise first-class mechanism to specify that a go part built with the go plugin should be statically compiled (perhaps an option to the plugin yaml, etc.), this could also potentially replace setting the build-environment for CGO_ENABLED=0 as well
I have a go program which does not require any dynamic library dependencies, and as such I would like to link it statically and use the `base: base` for this snap, so I have tried this:
``` environment:
parts:
etrace:
build-
- CGO_ENABLED: "0"
plugin: go
source: .
```
but it still produces a dynamically linked executable against libc, because snapcraft internally does this command always:
``` etrace/ install/ bin ./... etrace/ install/ bin ./... com/anonymouse6 4/etrace/ cmd/etrace
Building etrace
go build -o /root/parts/
go build -ldflags -linkmode=external -o /root/parts/
# github.
loadinternal: cannot find runtime/cgo
```
which completes, but gives me this:
``` root/bin/ etrace
linux- vdso.so. 1 (0x00007ffd91f7 7000) 64-linux- gnu/libc. so.6 (0x00007f3d0241 4000)
/lib64/ ld-linux- x86-64. so.2 (0x00007f3d0262 4000)
$ ldd ./squashfs-
libc.so.6 => /lib/x86_
```
which I can't use with the bare base snap. What works instead is to do this manually:
``` PART_INSTALL/ bin PART_INSTALL/ bin ./...
override-build: |
mkdir -p $SNAPCRAFT_
cd $SNAPCRAFT_PART_SRC
go build -o $SNAPCRAFT_
```
It would be nice if snapcraft either:
1. automatically detected that CGO_ENABLED=0 was set in the build-environment and didn't manually link things
2. automatically detected that the built binaries from go build -o ./bin ./... were not dynamically linked at all and skipped the final link step
3. had a property or otherwise first-class mechanism to specify that a go part built with the go plugin should be statically compiled (perhaps an option to the plugin yaml, etc.), this could also potentially replace setting the build-environment for CGO_ENABLED=0 as well