Skip to content

Commit

Permalink
Disable CGO for improved compatibility across distros (#276)
Browse files Browse the repository at this point in the history
This PR disables CGO so we don't have any dependencies on C libraries
expected to be found in the environment, in order to achieve a better
compatibility across distros.

Tested by running `make install` before and after the changes and
inspecting the produced binary from a Linux machine (Debian in this
case).
**Before**
```sh
ldd $(which grpcui)
	linux-vdso.so.1 (0x00007ffe2cb2e000)
	libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007fcc13946000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fcc13924000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fcc13750000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fcc1396a000)
```
**After**
```sh
ldd $(which grpcui)
	not a dynamic executable
```

Follow-up of the same changes in `grpcurl`:
fullstorydev/grpcurl#420
  • Loading branch information
gpassini authored Oct 24, 2023
1 parent dab14f0 commit 73a517a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ dev_build_version=$(shell git describe --tags --always --dirty)

export PATH := $(shell pwd)/.tmp/protoc/bin:$(PATH)
export PROTOC_VERSION := 22.0
# Disable CGO for improved compatibility across distros
export CGO_ENABLED=0

# TODO: run golint and errcheck, but only to catch *new* violations and
# decide whether to change code or not (e.g. we need to be able to whitelist
Expand Down Expand Up @@ -91,7 +93,8 @@ errcheck:

.PHONY: test
test:
go test -race ./...
# The race detector requires CGO: https://github.com/golang/go/issues/6508
CGO_ENABLED=1 go test -race ./...

.tmp/protoc/bin/protoc: ./Makefile ./download_protoc.sh
./download_protoc.sh
Expand Down

0 comments on commit 73a517a

Please sign in to comment.