-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for cross-compiling via the Makefile (#80)
- Loading branch information
Showing
9 changed files
with
97 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,19 @@ FROM debian:testing | |
|
||
WORKDIR /agent | ||
|
||
ARG arch=amd64 | ||
|
||
RUN apt-get update -y && apt-get dist-upgrade -y && apt-get install -y \ | ||
curl wget cmake dwz lsb-release software-properties-common gnupg git clang-16 llvm \ | ||
golang unzip jq && apt-get clean autoclean && apt-get autoremove --yes | ||
|
||
RUN wget -qO- https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.56.2 | ||
|
||
# cross_debian_arch: amd64 or arm64 | ||
# cross_pkg_arch: x86-64 or aarch64 | ||
RUN cross_debian_arch=$(uname -m | sed -e 's/aarch64/amd64/' -e 's/x86_64/arm64/'); \ | ||
cross_pkg_arch=$(uname -m | sed -e 's/aarch64/x86-64/' -e 's/x86_64/aarch64/'); \ | ||
apt-get update -y && \ | ||
apt-get dist-upgrade -y && \ | ||
apt-get install -y wget make git clang-16 golang unzip \ | ||
gcc-${cross_pkg_arch}-linux-gnu libc6-${cross_debian_arch}-cross && \ | ||
apt-get clean autoclean && \ | ||
apt-get autoremove --yes | ||
|
||
RUN wget -qO- https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \ | ||
| sh -s -- -b $(go env GOPATH)/bin v1.56.2 | ||
|
||
# gRPC dependencies | ||
RUN go install google.golang.org/protobuf/cmd/[email protected] | ||
|
@@ -20,7 +25,7 @@ RUN | |
PB_FILE="protoc-24.4-linux-$(uname -m | sed 's/aarch64/aarch_64/').zip"; \ | ||
INSTALL_DIR="/usr/local"; \ | ||
\ | ||
curl -LO "$PB_URL/$PB_FILE" \ | ||
wget -q "$PB_URL/$PB_FILE" \ | ||
&& unzip "$PB_FILE" -d "$INSTALL_DIR" 'bin/*' 'include/*' \ | ||
&& chmod +xr "$INSTALL_DIR/bin/protoc" \ | ||
&& find "$INSTALL_DIR/include" -type d -exec chmod +x {} \; \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,48 @@ | |
|
||
SHELL := /usr/bin/env bash | ||
|
||
# Detect native architecture and translate to GOARCH. | ||
NATIVE_ARCH := $(shell uname -m) | ||
ifeq ($(NATIVE_ARCH),x86_64) | ||
NATIVE_ARCH := amd64 | ||
else ifneq (,$(filter $(NATIVE_ARCH),aarch64 arm64)) | ||
NATIVE_ARCH := arm64 | ||
else | ||
$(error Unsupported architecture: $(NATIVE_ARCH)) | ||
endif | ||
|
||
# Valid values are: amd64, arm64. | ||
TARGET_ARCH ?= $(NATIVE_ARCH) | ||
|
||
ifeq ($(NATIVE_ARCH),$(TARGET_ARCH)) | ||
ARCH_PREFIX := | ||
else ifeq ($(TARGET_ARCH),arm64) | ||
ARCH_PREFIX := aarch64-linux-gnu- | ||
else ifeq ($(TARGET_ARCH),amd64) | ||
ARCH_PREFIX := x86_64-linux-gnu- | ||
else | ||
$(error Unsupported architecture: $(TARGET_ARCH)) | ||
endif | ||
|
||
export TARGET_ARCH | ||
export CGO_ENABLED = 1 | ||
export GOARCH = $(TARGET_ARCH) | ||
export CC = $(ARCH_PREFIX)gcc | ||
export OBJCOPY = $(ARCH_PREFIX)objcopy | ||
|
||
BRANCH = $(shell git rev-parse --abbrev-ref HEAD | tr -d '-' | tr '[:upper:]' '[:lower:]') | ||
COMMIT_SHORT_SHA = $(shell git rev-parse --short=8 HEAD) | ||
|
||
VERSION ?= v0.0.0 | ||
BUILD_TIMESTAMP ?= $(shell date +%s) | ||
REVISION ?= $(BRANCH)-$(COMMIT_SHORT_SHA) | ||
|
||
VC_LDFLAGS := -X github.com/elastic/otel-profiling-agent/vc.version=$(VERSION) \ | ||
LDFLAGS := -X github.com/elastic/otel-profiling-agent/vc.version=$(VERSION) \ | ||
-X github.com/elastic/otel-profiling-agent/vc.revision=$(REVISION) \ | ||
-X github.com/elastic/otel-profiling-agent/vc.buildTimestamp=$(BUILD_TIMESTAMP) | ||
-X github.com/elastic/otel-profiling-agent/vc.buildTimestamp=$(BUILD_TIMESTAMP) \ | ||
-extldflags=-static | ||
|
||
GO_FLAGS := -buildvcs=false -ldflags="$(LDFLAGS)" -tags osusergo,netgo | ||
|
||
all: generate ebpf binary | ||
|
||
|
@@ -25,11 +57,10 @@ clean: | |
@rm -rf go .cache | ||
|
||
generate: | ||
go install github.com/florianl/[email protected] | ||
go generate ./... | ||
|
||
binary: | ||
go build -buildvcs=false -ldflags="$(VC_LDFLAGS) -extldflags=-static" -tags osusergo,netgo | ||
go build $(GO_FLAGS) | ||
|
||
ebpf: | ||
$(MAKE) -j$(shell nproc) -C support/ebpf | ||
|
@@ -40,7 +71,7 @@ lint: generate | |
golangci-lint run --timeout 10m | ||
|
||
test: generate ebpf test-deps | ||
go test ./... | ||
go test $(GO_FLAGS) ./... | ||
|
||
TESTDATA_DIRS:= \ | ||
nativeunwind/elfunwindinfo/testdata \ | ||
|
@@ -62,23 +93,12 @@ integration-test-binaries: generate ebpf | |
./$(test_name)) || exit ; \ | ||
) | ||
|
||
# Detect native architecture. | ||
UNAME_NATIVE_ARCH:=$(shell uname -m) | ||
|
||
ifeq ($(UNAME_NATIVE_ARCH),x86_64) | ||
NATIVE_ARCH:=amd64 | ||
else ifneq (,$(filter $(UNAME_NATIVE_ARCH),aarch64 arm64)) | ||
NATIVE_ARCH:=arm64 | ||
else | ||
$(error Unsupported architecture: $(UNAME_NATIVE_ARCH)) | ||
endif | ||
|
||
docker-image: | ||
docker build -t profiling-agent --build-arg arch=$(NATIVE_ARCH) -f Dockerfile . | ||
docker build -t profiling-agent -f Dockerfile . | ||
|
||
agent: | ||
docker run -v "$$PWD":/agent -it --rm --user $(shell id -u):$(shell id -g) profiling-agent \ | ||
make VERSION=$(VERSION) REVISION=$(REVISION) BUILD_TIMESTAMP=$(BUILD_TIMESTAMP) | ||
"make TARGET_ARCH=$(TARGET_ARCH) VERSION=$(VERSION) REVISION=$(REVISION) BUILD_TIMESTAMP=$(BUILD_TIMESTAMP)" | ||
|
||
legal: | ||
@go install go.elastic.co/go-licence-detector@latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
.PHONY: all | ||
|
||
CC=gcc | ||
CFLAGS=-Wl,--build-id | ||
CC ?= cc | ||
CFLAGS = -Wl,--build-id | ||
|
||
all: test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,5 @@ import ( | |
_ "embed" | ||
) | ||
|
||
//go:embed ebpf/tracer.ebpf.x86 | ||
//go:embed ebpf/tracer.ebpf.amd64 | ||
var tracerData []byte |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters