From 5254ce861696bf215bf4d4cfa91fc7098c1d6476 Mon Sep 17 00:00:00 2001 From: ybyang <10629930+berlinsaint@users.noreply.github.com> Date: Tue, 5 Jul 2022 14:59:56 +0800 Subject: [PATCH] fix: no longer explicitly specify cgo_enabled (#1253) Signed-off-by: maybaby --- DEVELOPGUIDE.md | 15 ++++++++++++++- scripts/make-rules/golang.mk | 8 ++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/DEVELOPGUIDE.md b/DEVELOPGUIDE.md index 1c479acc0..20e966f5f 100644 --- a/DEVELOPGUIDE.md +++ b/DEVELOPGUIDE.md @@ -12,11 +12,24 @@ cd sealos make build ``` -You can scp the bin file to your linux host. +You can scp the bin file to your linux host. If you use multipaas, you can mount the bin dir to the vm: + ```shell script multipass mount /your-bin-dir [:] ``` +## Notice About build and cross build + +Since Golang CGO_ENABLED is enabled by default if it is not specified, if you compile the sealos binary of linuxos on +macos, it is cross-compiled, and since CGO_ENABLED is not explicitly specified, go will close CGO_ENABLED by default, +that is, CGO_ENABLED=0, and compile at this time Some functions of sealos will not be supported, such as +'images' subcommand depends on cgo for overlay. At this time, sealos does not support overlay driver by default, and +will report "driver not supported" error. Therefore, if you are developing or debugging images storage related +functions, it is best to compile sealos in a linux environment such as ubuntu. + +In addition, the final release build of sealos is based on the ubuntu environment of Github Action. The built binary +defaults to open CGO and supports overlay driver. + Then test it locally. diff --git a/scripts/make-rules/golang.mk b/scripts/make-rules/golang.mk index e75c71ac4..d932964b9 100644 --- a/scripts/make-rules/golang.mk +++ b/scripts/make-rules/golang.mk @@ -48,11 +48,11 @@ go.build.%.sealos: $(eval PLATFORM := $(word 1,$(subst ., ,$*))) $(eval OS := $(word 1,$(subst _, ,$(PLATFORM)))) $(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM)))) - $(eval GO_LDFLAGS += -linkmode external) + $(eval GO_LDFLAGS += "") @echo "===========> Building binary $(COMMAND) for $(PLATFORM)" @mkdir -p $(BIN_DIR)/$(PLATFORM) - CGO_ENABLED=1 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(PLATFORM)/$(COMMAND) $(ROOT_PACKAGE)/cmd/$(COMMAND) + GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(PLATFORM)/$(COMMAND) $(ROOT_PACKAGE)/cmd/$(COMMAND) .PHONY: go.build.%.sealctl go.build.%.sealctl: @@ -60,10 +60,10 @@ go.build.%.sealctl: $(eval PLATFORM := $(word 1,$(subst ., ,$*))) $(eval OS := $(word 1,$(subst _, ,$(PLATFORM)))) $(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM)))) - @echo "===========> Building binary $(COMMAND) for $(PLATFORM)" @mkdir -p $(BIN_DIR)/$(PLATFORM) - CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(PLATFORM)/$(COMMAND) $(ROOT_PACKAGE)/cmd/$(COMMAND) + GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(PLATFORM)/$(COMMAND) $(ROOT_PACKAGE)/cmd/$(COMMAND) + .PHONY: go.build go.build: go.build.verify $(addprefix go.build., $(addprefix $(PLATFORM)., $(BINS)))