Skip to content

Commit 6f1e767

Browse files
authored
fix(composer): add -trimpath flag to Go build commands for consistency (#339)
I am getting errors when re-uploading the `.so` file to the dynamic module directory which is solved by adding this flag. This also makes the output more consistent when comparing the sha256sum (?) --------- Signed-off-by: Sjouke de Vries <info@sdvservices.nl>
1 parent 9957a13 commit 6f1e767

5 files changed

Lines changed: 5 additions & 4 deletions

File tree

cli/internal/extensions/libcomposer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func BuildExtensionFromPath(logger *slog.Logger, dirs *xdg.Directories, manifest
7474
// Build the extension and save the binary in the local cache directory for composer to load.
7575
dest := LocalCacheExtension(dirs, manifest)
7676
// #nosec G204
77-
cmd = exec.Command("go", "build", "-buildmode=plugin", "-o", dest, "./standalone")
77+
cmd = exec.Command("go", "build", "-trimpath", "-buildmode=plugin", "-o", dest, "./standalone")
7878
cmd.Dir = path
7979
logger.Debug("building local extension", "version", manifest.Version, "path", path, "cmd", cmd.String())
8080
output, err = cmd.CombinedOutput()

extensions/composer/Dockerfile.plugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ RUN go mod download all
2020
# BUILD_TAG is used to to include coraza waf build tags, populated by Makefile.plugin via --build-arg
2121
ARG BUILD_TAG=""
2222
# Build go plugin
23-
RUN CGO_ENABLED=1 go build -buildmode=plugin ${BUILD_TAG} -o plugin.so ./$EXTENSION_PATH/standalone
23+
RUN CGO_ENABLED=1 go build -trimpath -buildmode=plugin ${BUILD_TAG} -o plugin.so ./$EXTENSION_PATH/standalone
2424

2525
FROM scratch AS final
2626

extensions/composer/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ create_builder:
127127

128128
.PHONY: build
129129
build:
130-
CGO_ENABLED=1 go build -buildmode=c-shared $(COMPOSER_BUILD_TAG) -o lib$(NAME).so ./main
130+
CGO_ENABLED=1 go build -trimpath -buildmode=c-shared $(COMPOSER_BUILD_TAG) -o lib$(NAME).so ./main
131131

132132
.PHONY: install
133133
install: build

extensions/composer/Makefile.plugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ create_builder:
9595

9696
.PHONY: build
9797
build:
98-
CGO_ENABLED=1 go build -buildmode=plugin $(PLUGIN_BUILD_TAG) -o $(NAME).so ./$(EXTENSION_PATH)/standalone
98+
CGO_ENABLED=1 go build -trimpath -buildmode=plugin $(PLUGIN_BUILD_TAG) -o $(NAME).so ./$(EXTENSION_PATH)/standalone
9999

100100
.PHONY: install
101101
install: build

extensions/composer/goplugin-loader/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Plugins must:
2525

2626
- Be compiled with the same Go version as the host binary
2727
- Use `-buildmode=plugin` when building
28+
- Use the same build flags as the host binary, including `-trimpath` when the host uses it
2829
- Have identical versions of all shared dependencies
2930
- Export a `WellKnownHttpFilterConfigFactories` function with signature:
3031
```go

0 commit comments

Comments
 (0)