Skip to content

Commit aea8446

Browse files
committed
feat: implement multiple solutions for building
Signed-off-by: Xinwei Xiong(cubxxw) <[email protected]>
1 parent c0fc0c4 commit aea8446

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

scripts/build.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#!/usr/bin/env bash
22

3+
# Copyright © 2022 Alibaba Group Holding Ltd.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# ==============================================================================
18+
319
## Build script
420

521
# Build helper functions. These functions help to set up, save, and load the following variables:

scripts/make-rules/common.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ endif
8383

8484
# platforms: The OS must be linux when building docker images
8585
PLATFORMS ?= linux_amd64 linux_arm64
86-
# TODO(sealer?): The OS can be linux/windows/darwin when building binaries? if only support linux
87-
# PLATFORMS ?= darwin_amd64 windows_amd64 linux_amd64 linux_arm64
8886

8987
# only support linux
9088
GOOS=linux

scripts/make-rules/golang.mk

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ ifeq ($(DEBUG), 1)
3333
GO_BUILD_FLAGS += -gcflags "all=-N -l"
3434
GO_LDFLAGS=
3535
endif
36-
GO_BUILD_FLAGS += -tags "containers_image_openpgp netgo exclude_graphdriver_devicemapper static osusergo exclude_graphdriver_btrfs" -trimpath -ldflags "$(GO_LDFLAGS)"
36+
# Fixed container dependency issues
37+
# Link -> https://github.com/containers/image/pull/271/files
38+
# For btrfs, we are currently only using overlays, so we don't need to include btrfs, otherwise we need to fix some lib issues
39+
GO_BUILD_FLAGS += -tags "containers_image_openpgp exclude_graphdriver_devicemapper exclude_graphdriver_btrfs"
3740

3841
# ifeq ($(GOOS),windows)
3942
# GO_OUT_EXT := .exe
@@ -103,7 +106,7 @@ go.bin.%:
103106
$(eval COMMAND := $(word 2,$(subst ., ,$*)))
104107
$(eval PLATFORM := $(word 1,$(subst ., ,$*)))
105108
@echo "===========> Verifying binary $(COMMAND) $(VERSION) for $(PLATFORM)"
106-
@if [ ! -f $(BIN_DIR)/$(PLATFORM)/$(COMMAND) ]; then echo $(MAKE) go.build PLATFORM=$(PLATFORM); fi
109+
@if [ ! -f $(BIN_DIR)/$(COMMAND)/$(PLATFORM)/$(COMMAND) ]; then echo $(MAKE) go.build PLATFORM=$(PLATFORM); fi
107110

108111
## go.build.%: Build binary for specific platform
109112
.PHONY: go.build.%
@@ -114,22 +117,23 @@ go.build.%:
114117
$(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM))))
115118
@echo "COMMAND=$(COMMAND)"
116119
@echo "PLATFORM=$(PLATFORM)"
117-
@echo "OS=$(OS)"
118-
@echo "ARCH=$(ARCH)"
119-
@echo "BINS=$(BINS)"
120120
@echo "BIN_DIR=$(BIN_DIR)"
121-
@echo "===========> Building binary $(COMMAND) $(VERSION) for $(OS) $(ARCH)"
122-
@mkdir -p $(OUTPUT_DIR)/bin/$(OS)/$(ARCH)
123-
124-
# @CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o $(OUTPUT_DIR)/bin/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_PACKAGE)/cmd/$(COMMAND)
121+
@echo "===========> Building binary $(COMMAND) $(VERSION) for $(OS)_$(ARCH)"
122+
@mkdir -p $(BIN_DIR)/$(COMMAND)/$(PLATFORM)
123+
@if [ "$(COMMAND)" == "sealer" ] || [ "$(COMMAND)" == "seautil" ]; then \
124+
CGO_ENABLED=1; \
125+
CC=x86_64-linux-gnu-gcc; \
126+
if [ "$(ARCH)" == "arm64" ]; then \
127+
CC=aarch64-linux-gnu-gcc; \
128+
fi; \
129+
CGO_ENABLED=$$CGO_ENABLED CC=$$CC GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(COMMAND)/$(PLATFORM) -mod vendor $(ROOT_PACKAGE)/cmd/$(COMMAND); \
130+
else \
131+
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(COMMAND)/$(PLATFORM) -mod vendor $(ROOT_PACKAGE)/cmd/$(COMMAND); \
132+
fi
125133

126134
## go.build: Build binaries
127135
.PHONY: go.build
128136
go.build: go.build.verify $(addprefix go.build., $(addprefix $(PLATFORM)., $(BINS)))
129-
@echo "COMMAND=$(COMMAND)"
130-
@echo "PLATFORM=$(PLATFORM)"
131-
@echo "OS=$(OS)"
132-
@echo "ARCH=$(ARCH)"
133137
@echo "===========> Building binary $(BINS) $(VERSION) for $(PLATFORM)"
134138

135139
## go.build.multiarch: Build multi-arch binaries
@@ -153,7 +157,7 @@ go.lint: tools.verify.golangci-lint
153157
## go.test: Run unit test
154158
.PHONY: go.test
155159
go.test:
156-
@$(GO) test ./...
160+
@$(GO) test $(GO_BUILD_FLAGS) ./...
157161

158162
## go.test.junit-report: Run unit test
159163
.PHONY: go.test.junit-report

0 commit comments

Comments
 (0)