-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide empty asset offsets without codegen
This removes the necessity to generate the empty asset file in the Makefile. Switch between the empty and generated files at compile time via the noembedbins go build tag. Signed-off-by: Tom Wieczorek <[email protected]>
- Loading branch information
Showing
5 changed files
with
43 additions
and
29 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
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 |
---|---|---|
|
@@ -30,7 +30,8 @@ EMBEDDED_BINS_BUILDMODE ?= docker | |
TARGET_OS ?= linux | ||
BUILD_UID ?= $(shell id -u) | ||
BUILD_GID ?= $(shell id -g) | ||
BUILD_GO_FLAGS := -tags osusergo -buildvcs=false -trimpath | ||
BUILD_GO_TAGS ?= osusergo | ||
BUILD_GO_FLAGS = -tags $(subst $(space),$(comma),$(BUILD_GO_TAGS)) -buildvcs=false -trimpath | ||
BUILD_CGO_CFLAGS := | ||
BUILD_GO_LDFLAGS_EXTRA := | ||
DEBUG ?= false | ||
|
@@ -157,17 +158,11 @@ static/zz_generated_assets.go: $(shell find $(static_asset_dirs) -type f) | |
CGO_ENABLED=0 $(GO) install github.com/kevinburke/go-bindata/go-bindata@v$(go-bindata_version) | ||
$(GO_ENV) go-bindata -o '$@' -pkg static -prefix static $(patsubst %,%/...,$(static_asset_dirs)) | ||
|
||
codegen_targets += pkg/assets/zz_generated_offsets_$(TARGET_OS).go | ||
zz_os = $(patsubst pkg/assets/zz_generated_offsets_%.go,%,$@) | ||
print_empty_generated_offsets = printf "%s\n\n%s\n%s\n" \ | ||
"package assets" \ | ||
"var BinData = map[string]struct{ offset, size, originalSize int64 }{}" \ | ||
"var BinDataSize int64" | ||
ifeq ($(EMBEDDED_BINS_BUILDMODE),none) | ||
pkg/assets/zz_generated_offsets_linux.go pkg/assets/zz_generated_offsets_windows.go: | ||
rm -f bindata_$(zz_os) && touch bindata_$(zz_os) | ||
$(print_empty_generated_offsets) > $@ | ||
BUILD_GO_TAGS += noembedbins | ||
else | ||
codegen_targets += pkg/assets/zz_generated_offsets_$(TARGET_OS).go | ||
zz_os = $(patsubst pkg/assets/zz_generated_offsets_%.go,%,$@) | ||
pkg/assets/zz_generated_offsets_linux.go: .bins.linux.stamp | ||
pkg/assets/zz_generated_offsets_windows.go: .bins.windows.stamp | ||
pkg/assets/zz_generated_offsets_linux.go pkg/assets/zz_generated_offsets_windows.go: .k0sbuild.docker-image.k0s go.sum | ||
|
@@ -176,10 +171,6 @@ pkg/assets/zz_generated_offsets_linux.go pkg/assets/zz_generated_offsets_windows | |
-prefix embedded-bins/staging/$(zz_os)/ embedded-bins/staging/$(zz_os)/bin | ||
endif | ||
|
||
# needed for unit tests on macos | ||
pkg/assets/zz_generated_offsets_darwin.go: | ||
$(print_empty_generated_offsets) > $@ | ||
|
||
k0s: TARGET_OS = linux | ||
k0s: BUILD_GO_CGO_ENABLED = 1 | ||
k0s: .k0sbuild.docker-image.k0s | ||
|
@@ -189,11 +180,15 @@ k0s.exe: BUILD_GO_CGO_ENABLED = 0 | |
|
||
k0s.exe k0s: $(GO_SRCS) $(codegen_targets) go.sum | ||
CGO_ENABLED=$(BUILD_GO_CGO_ENABLED) CGO_CFLAGS='$(BUILD_CGO_CFLAGS)' GOOS=$(TARGET_OS) $(GO) build $(BUILD_GO_FLAGS) -ldflags='$(LD_FLAGS)' -o $@.code main.go | ||
cat $@.code bindata_$(TARGET_OS) > $@.tmp \ | ||
&& rm -f $@.code \ | ||
&& printf "\nk0s size: %s\n\n" "$$(du -sh $@.tmp | cut -f1)" \ | ||
&& chmod +x $@.tmp \ | ||
&& mv $@.tmp $@ | ||
ifeq ($(EMBEDDED_BINS_BUILDMODE),none) | ||
mv -- [email protected] [email protected] | ||
else | ||
cat -- [email protected] bindata_$(TARGET_OS) >[email protected] | ||
rm -f -- [email protected] | ||
endif | ||
chmod +x -- [email protected] | ||
mv -- [email protected] $@ | ||
printf '\nk0s size: %s\n\n' "$$(du -sh -- $@ | cut -f1)" | ||
|
||
.bins.windows.stamp .bins.linux.stamp: embedded-bins/Makefile.variables | ||
$(MAKE) -C embedded-bins \ | ||
|
@@ -253,8 +248,8 @@ check-unit: GO_TEST_RACE ?= | |
else | ||
check-unit: GO_TEST_RACE ?= -race | ||
endif | ||
check-unit: go.sum codegen | ||
CGO_CFLAGS='$(BUILD_CGO_CFLAGS)' $(GO) test -tags=hack $(GO_TEST_RACE) -ldflags='$(LD_FLAGS)' `$(GO) list -tags=hack $(GO_CHECK_UNIT_DIRS)` | ||
check-unit: go.sum static/zz_generated_assets.go | ||
CGO_CFLAGS='$(BUILD_CGO_CFLAGS)' $(GO) test -tags=hack,noembedbins $(GO_TEST_RACE) -ldflags='$(LD_FLAGS)' `$(GO) list -tags=hack $(GO_CHECK_UNIT_DIRS)` | ||
|
||
.PHONY: check-image-validity | ||
check-image-validity: go.sum | ||
|
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//go:build noembedbins || (!linux && !windows) | ||
|
||
/* | ||
Copyright 2024 k0s authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package assets | ||
|
||
var BinData = map[string]struct{ offset, size, originalSize int64 }{} | ||
var BinDataSize int64 |