Skip to content

Commit 5a4c741

Browse files
Add debugging setup & re-add release optimizations (#12)
Co-authored-by: Joel Scheuner <[email protected]>
1 parent db1cead commit 5a4c741

File tree

14 files changed

+104
-27
lines changed

14 files changed

+104
-27
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
go-version: '~1.18.2'
2121

2222
- name: Build
23+
env:
24+
RELEASE_BUILD_LINKER_FLAGS: "-s -w"
2325
run: make compile-lambda-linux-all
2426

2527
- uses: actions/upload-artifact@v3

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# RELEASE_BUILD_LINKER_FLAGS disables DWARF and symbol table generation to reduce binary size
66
#RELEASE_BUILD_LINKER_FLAGS=-s -w
77

8-
98
BINARY_NAME=aws-lambda-rie
109
ARCH=x86_64
1110
GO_ARCH_x86_64 := amd64
@@ -25,7 +24,7 @@ compile-with-docker:
2524
docker run --rm --env GOPROXY=direct -v $(shell pwd):/LambdaRuntimeLocal -w /LambdaRuntimeLocal golang:1.18 make ARCH=${ARCH} compile-lambda-linux
2625

2726
compile-lambda-linux:
28-
CGO_ENABLED=0 GOOS=linux GOARCH=${GO_ARCH_${ARCH}} go build -ldflags "${RELEASE_BUILD_LINKER_FLAGS}" -gcflags="all=-N -l" -o ${DESTINATION_${ARCH}} ./cmd/localstack
27+
CGO_ENABLED=0 GOOS=linux GOARCH=${GO_ARCH_${ARCH}} go build -ldflags "${RELEASE_BUILD_LINKER_FLAGS}" -gcflags="${GC_FLAGS}" -o ${DESTINATION_${ARCH}} ./cmd/localstack
2928

3029
tests:
3130
go test ./...

custom-tests/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

custom-tests/Makefile

Lines changed: 0 additions & 16 deletions
This file was deleted.

custom-tests/README.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

custom-tests/dlv

-15.9 MB
Binary file not shown.
File renamed without changes.

debugging/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
aws-lambda-rie
2+
build-delve/dlv
3+
init/var/rapid/init
4+
init/var/rapid/dlv
File renamed without changes.

debugging/Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Golang EOL overview: https://endoflife.date/go
2+
DOCKER_GOLANG_IMAGE ?= golang:1.18.2
3+
4+
# On ARM hosts, use: make ARCH=arm64 build-init
5+
# Check host architecture: uname -m
6+
# x86_64 or arm64
7+
ARCH ?= x86_64
8+
9+
ifeq ($(ARCH), arm64)
10+
GOARCH=arm64
11+
else
12+
GOARCH=amd64
13+
endif
14+
15+
# Limitation: Debugging x86_64 lambdas does not work on ARM machines due to missing ptrace implementation in qemu used by Docker
16+
# The function aborts with "could not launch process: fork/exec /var/rapid/init: function not implemented"
17+
# * Discussion: https://github.com/aws/aws-sam-cli/discussions/4706
18+
# * Docker for Mac: https://github.com/docker/for-mac/issues/5191#issuecomment-834154431
19+
20+
21+
all: build
22+
23+
# build & "package" necessary files for debugging
24+
build build-init: build-rapid build-delve/dlv
25+
cp ../bin/aws-lambda-rie-$(ARCH) ./init/var/rapid/init
26+
cp ./build-delve/dlv ./init/var/rapid/dlv
27+
28+
build-rapid:
29+
cd .. && GC_FLAGS="all=-N -l" make ARCH=$(ARCH) compile-lambda-linux
30+
31+
build-delve/dlv:
32+
docker run --rm -v $$(pwd)/build-delve/:/app/ $(DOCKER_GOLANG_IMAGE) \
33+
bash -c "cd /app && export GOARCH=$(GOARCH) && ./build.sh"
34+
35+
clean clean-init: clean-rapid clean-delve
36+
37+
clean-rapid:
38+
rm -rf ../bin/aws-lambda-rie-*
39+
rm -rf ./init/var/rapid/init
40+
41+
clean-delve:
42+
rm -rf ./build-delve/dlv
43+
rm -rf ./init/var/rapid/dlv
44+
45+
.PHONY: build build-rapid clean clean-rapid clean-delve

0 commit comments

Comments
 (0)