Skip to content

Commit 56ad323

Browse files
whybeyoungcuisongliu
authored andcommitted
fix: no longer explicitly specify cgo_enabled (labring#1253)
Signed-off-by: maybaby <[email protected]>
1 parent 533379a commit 56ad323

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

DEVELOPGUIDE.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,24 @@ cd sealos
1212
make build
1313
```
1414

15-
You can scp the bin file to your linux host.
15+
You can scp the bin file to your linux host.
1616

1717
If you use multipaas, you can mount the bin dir to the vm:
18+
1819
```shell script
1920
multipass mount /your-bin-dir <name>[:<path>]
2021
```
2122

23+
## Notice About build and cross build
24+
25+
Since Golang CGO_ENABLED is enabled by default if it is not specified, if you compile the sealos binary of linuxos on
26+
macos, it is cross-compiled, and since CGO_ENABLED is not explicitly specified, go will close CGO_ENABLED by default,
27+
that is, CGO_ENABLED=0, and compile at this time Some functions of sealos will not be supported, such as
28+
'images' subcommand depends on cgo for overlay. At this time, sealos does not support overlay driver by default, and
29+
will report "driver not supported" error. Therefore, if you are developing or debugging images storage related
30+
functions, it is best to compile sealos in a linux environment such as ubuntu.
31+
32+
In addition, the final release build of sealos is based on the ubuntu environment of Github Action. The built binary
33+
defaults to open CGO and supports overlay driver.
34+
2235
Then test it locally.

scripts/make-rules/golang.mk

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,22 @@ go.build.%.sealos:
4848
$(eval PLATFORM := $(word 1,$(subst ., ,$*)))
4949
$(eval OS := $(word 1,$(subst _, ,$(PLATFORM))))
5050
$(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM))))
51-
$(eval GO_LDFLAGS += -linkmode external)
51+
$(eval GO_LDFLAGS += "")
5252

5353
@echo "===========> Building binary $(COMMAND) for $(PLATFORM)"
5454
@mkdir -p $(BIN_DIR)/$(PLATFORM)
55-
CGO_ENABLED=1 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(PLATFORM)/$(COMMAND) $(ROOT_PACKAGE)/cmd/$(COMMAND)
55+
GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(PLATFORM)/$(COMMAND) $(ROOT_PACKAGE)/cmd/$(COMMAND)
5656

5757
.PHONY: go.build.%.sealctl
5858
go.build.%.sealctl:
5959
$(eval COMMAND := sealctl)
6060
$(eval PLATFORM := $(word 1,$(subst ., ,$*)))
6161
$(eval OS := $(word 1,$(subst _, ,$(PLATFORM))))
6262
$(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM))))
63-
6463
@echo "===========> Building binary $(COMMAND) for $(PLATFORM)"
6564
@mkdir -p $(BIN_DIR)/$(PLATFORM)
66-
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(PLATFORM)/$(COMMAND) $(ROOT_PACKAGE)/cmd/$(COMMAND)
65+
GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(PLATFORM)/$(COMMAND) $(ROOT_PACKAGE)/cmd/$(COMMAND)
66+
6767

6868
.PHONY: go.build
6969
go.build: go.build.verify $(addprefix go.build., $(addprefix $(PLATFORM)., $(BINS)))

0 commit comments

Comments
 (0)