Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable arm64 builds for Linux #4162

Merged
merged 5 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ $(BUILD_DIR)/macos-arm64/crc: $(SOURCES)
$(BUILD_DIR)/linux-amd64/crc: $(SOURCES)
GOOS=linux GOARCH=amd64 go build -tags "$(BUILDTAGS)" -ldflags="$(LDFLAGS)" -o $@ $(GO_EXTRA_BUILDFLAGS) ./cmd/crc

$(BUILD_DIR)/linux-arm64/crc: $(SOURCES)
GOOS=linux GOARCH=arm64 go build -tags "$(BUILDTAGS)" -ldflags="$(LDFLAGS)" -o $@ $(GO_EXTRA_BUILDFLAGS) ./cmd/crc

$(BUILD_DIR)/windows-amd64/crc.exe: $(SOURCES)
GOARCH=amd64 GOOS=windows go build -tags "$(BUILDTAGS)" -ldflags="$(LDFLAGS)" -o $@ $(GO_EXTRA_BUILDFLAGS) ./cmd/crc

Expand Down Expand Up @@ -294,7 +297,7 @@ gen_release_info:

.PHONY: linux-release-binary macos-release-binary windows-release-binary
linux-release-binary: LDFLAGS+= $(RELEASE_VERSION_VARIABLES)
linux-release-binary: $(BUILD_DIR)/linux-amd64/crc
linux-release-binary: $(BUILD_DIR)/linux-${GOARCH}/crc

macos-release-binary: LDFLAGS+= -X '$(MODULEPATH)/pkg/crc/version.installerBuild=true' $(RELEASE_VERSION_VARIABLES)
macos-release-binary: $(BUILD_DIR)/macos-universal/crc
Expand All @@ -307,20 +310,20 @@ release: clean linux-release macos-release-binary windows-release-binary check
linux-release: clean lint linux-release-binary embed_crc_helpers gen_release_info
mkdir $(RELEASE_DIR)

@mkdir -p $(BUILD_DIR)/crc-linux-$(CRC_VERSION)-amd64
@cp LICENSE $(BUILD_DIR)/linux-amd64/crc $(BUILD_DIR)/crc-linux-$(CRC_VERSION)-amd64
tar cJSf $(RELEASE_DIR)/crc-linux-amd64.tar.xz -C $(BUILD_DIR) crc-linux-$(CRC_VERSION)-amd64 --owner=0 --group=0
@mkdir -p $(BUILD_DIR)/crc-linux-$(CRC_VERSION)-${GOARCH}
@cp LICENSE $(BUILD_DIR)/linux-amd64/crc $(BUILD_DIR)/crc-linux-$(CRC_VERSION)-${GOARCH}
tar cJSf $(RELEASE_DIR)/crc-linux-${GOARCH}.tar.xz -C $(BUILD_DIR) crc-linux-$(CRC_VERSION)-${GOARCH} --owner=0 --group=0

@cp $(RELEASE_INFO) $(RELEASE_DIR)/$(RELEASE_INFO)

cd $(RELEASE_DIR) && sha256sum * > sha256sum.txt

.PHONY: embed_crc_helpers
embed_crc_helpers: $(BUILD_DIR)/linux-amd64/crc $(HOST_BUILD_DIR)/crc-embedder
embed_crc_helpers: $(BUILD_DIR)/linux-${GOARCH}/crc $(HOST_BUILD_DIR)/crc-embedder
ifeq ($(CUSTOM_EMBED),false)
$(HOST_BUILD_DIR)/crc-embedder embed --log-level debug --goos=linux $(BUILD_DIR)/linux-amd64/crc
$(HOST_BUILD_DIR)/crc-embedder embed --log-level debug --goos=linux $(BUILD_DIR)/linux-${GOARCH}/crc
else
$(HOST_BUILD_DIR)/crc-embedder embed --log-level debug --cache-dir=$(EMBED_DOWNLOAD_DIR) --no-download --goos=linux $(BUILD_DIR)/linux-amd64/crc
$(HOST_BUILD_DIR)/crc-embedder embed --log-level debug --cache-dir=$(EMBED_DOWNLOAD_DIR) --no-download --goos=linux $(BUILD_DIR)/linux-${GOARCH}/crc
praveenkumar marked this conversation as resolved.
Show resolved Hide resolved
endif

.PHONY: update-go-version
Expand Down
18 changes: 8 additions & 10 deletions packaging/rpm/crc.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ CRC's main executable}
%global golicenses LICENSE
%global godocs *.md

%ifarch x86_64
%global gohostarch amd64
%endif
%ifarch aarch64
%global gohostarch arm64
%endif

Name: %{goname}
Release: 1%{?dist}
Summary: CRC's main executable
License: APL 2.0
ExcludeArch: armv7hl i686
ExcludeArch: armv7hl i686 ppc64le s390x
URL: %{gourl}
ExcludeArch: s390x
Source0: %{gosource}

#generate_buildrequires
Expand Down Expand Up @@ -65,7 +70,7 @@ make COMMIT_SHA=__COMMIT_SHA__ GO_EXTRA_LDFLAGS="-B 0x$(head -c20 /dev/urandom|o
%install
# with fedora macros: gopkginstall
install -m 0755 -vd %{buildroot}%{_bindir}
install -m 0755 -vp %{gobuilddir}/src/%{goipath}/out/linux-amd64/crc %{buildroot}%{_bindir}/
install -m 0755 -vp %{gobuilddir}/src/%{goipath}/out/linux-%{gohostarch}/crc %{buildroot}%{_bindir}/

install -d %{buildroot}%{_datadir}/%{name}-redistributable/{linux,macos,windows}
install -m 0755 -vp %{gobuilddir}/src/%{goipath}/release/* %{buildroot}%{_datadir}/%{name}-redistributable/linux/
Expand All @@ -75,14 +80,7 @@ install -m 0755 -vp %{gobuilddir}/src/%{goipath}/out/macos-universal/crc %{build
%check
# with fedora macros: gocheck
export GOFLAGS="-mod=vendor"
# crc uses `go test -race`, which triggers gvisor issues on ppc64le:
# vendor/gvisor.dev/gvisor/pkg/sync/race_unsafe.go:47:6: missing function body
# and a ppc64le implementation is indeed missing on ppc64le:
# https://github.com/google/gvisor/blob/master/pkg/sync/race_unsafe.go
# https://github.com/google/gvisor/tree/master/pkg/sync
%ifnarch ppc64le
make test
%endif

%files
%license %{golicenses}
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const (

var adminHelperExecutableForOs = map[string]string{
"darwin": "crc-admin-helper-darwin",
"linux": "crc-admin-helper-linux",
"linux": fmt.Sprintf("crc-admin-helper-linux-%s", runtime.GOARCH),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a "platfrom" typo in the commit log.
I don't think the old binary name is cleaned up on upgrades?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the old binary name is cleaned up on upgrades?

No, older binary is not cleaned up as part of upgrade. Should we do it as part of preflight checks or as part of cache.go ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a "platfrom" typo in the commit log.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do it as part of preflight checks or as part of cache.go ?

In the past we've done this as part of preflight checks.

"windows": "crc-admin-helper-windows.exe",
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/crc/machine/libvirt/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package libvirt

import (
"fmt"
"runtime"

"github.com/crc-org/crc/v2/pkg/crc/constants"
)
Expand All @@ -25,7 +26,7 @@ const (
)

var (
MachineDriverDownloadURL = fmt.Sprintf("https://github.com/crc-org/machine-driver-libvirt/releases/download/%s/%s", MachineDriverVersion, machineDriverCommand)
MachineDriverDownloadURL = fmt.Sprintf("https://github.com/crc-org/machine-driver-libvirt/releases/download/%s/%s-%s", MachineDriverVersion, machineDriverCommand, runtime.GOARCH)
)

func MachineDriverPath() string {
Expand Down
13 changes: 11 additions & 2 deletions pkg/crc/preflight/preflight_checks_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,18 @@ func fixAdminHelperExecutableCached() error {

func checkSupportedCPUArch() error {
logging.Debugf("GOARCH is %s GOOS is %s", runtime.GOARCH, runtime.GOOS)
// Only supported arches are amd64, and arm64 on macOS
if runtime.GOARCH == "amd64" || (runtime.GOARCH == "arm64" && runtime.GOOS == "darwin") {
// Only supported arches are amd64, and arm64 on macOS & Linux
switch runtime.GOARCH {
case "amd64":
return nil
case "arm64":
if runtime.GOOS == "darwin" {
return nil
}
if runtime.GOOS == "linux" {
logging.Warnf("CRC is not officially supported on ARM64 CPUs for Linux.")
return nil
}
}
return fmt.Errorf("CRC can only run on AMD64/Intel64 CPUs and Apple silicon")
cfergeau marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
Loading