Skip to content

Commit

Permalink
Add support to generate aarch64 bits for Linux
Browse files Browse the repository at this point in the history
This pr adds linux arm64 target to makefile and also make change to spec
file to generate right package for arm64.
  • Loading branch information
praveenkumar committed Jun 27, 2024
1 parent 9a55385 commit 5b4318e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 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
8 changes: 7 additions & 1 deletion packaging/rpm/crc.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ 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}
Expand Down Expand Up @@ -65,7 +71,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 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")
}
Expand Down

0 comments on commit 5b4318e

Please sign in to comment.