Skip to content

Commit d1e189c

Browse files
author
Reda.Drissi.e
committed
Updated building recipes to build for different architectures
1 parent 3622498 commit d1e189c

File tree

3 files changed

+58
-15
lines changed

3 files changed

+58
-15
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ output
55
*.html
66
*.jpg
77
bin/
8-
*.sh
8+
*.sh
9+
vendor
10+
fyne-cross

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM joseluisq/docker-osxcross:1.0.0-beta.2
2+
3+
LABEL version="0.0.1" \
4+
description="Docker image for cross-compiling Go programs for macOS using osxcross + o64-clang" \
5+
maintainer="Reda Drissi <reda@example.com>"
6+
7+
# Go version
8+
ARG GO_VERSION=1.22.2
9+
ENV GO_VERSION=${GO_VERSION} \
10+
PATH=/usr/local/go/bin:/usr/local/osxcross/bin:$PATH \
11+
CGO_ENABLED=1
12+
13+
# Install Go
14+
RUN set -eux; \
15+
curl -fsSL https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz | tar -C /usr/local -xzf -
16+
17+
# Set default CC/CXX to osxcross clang
18+
ENV CC=o64-clang
19+
ENV CXX=o64-clang++
20+
21+
# Workdir
22+
WORKDIR /root/src
23+
24+
# Default command
25+
CMD ["bash"]

Makefile

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,53 @@
1-
.PHONY: all linux windows macos run clean install-deps
1+
.PHONY: all linux windows macos run clean install-deps docker-image macos clean-deps
22

33
APP_NAME := snap-memory-downloader
44
BUILD_DIR := bin
55
SRC_DIR := .
6+
DOCKER_IMAGE := smd-osxcross:darwin
67

78
all: linux windows macos
89

910
linux:
10-
@echo "Building for Linux..."
11-
go build -o $(BUILD_DIR)/$(APP_NAME) $(SRC_DIR)/gui_main.go
11+
@echo "Building for Linux using fyne-cross..."
12+
fyne-cross linux -arch=amd64 -app-id="com.snapmemory.downloader"
13+
mkdir -p $(BUILD_DIR)
14+
mv fyne-cross/bin/linux-amd64/$(APP_NAME) $(BUILD_DIR)/$(APP_NAME) || true
1215
@echo "Linux build complete: $(BUILD_DIR)/$(APP_NAME)"
1316

1417
windows:
15-
@echo "Building for Windows..."
16-
GOOS=windows go build -ldflags -H=windowsgui -o $(BUILD_DIR)/$(APP_NAME).exe $(SRC_DIR)/gui_main.go
18+
@echo "Building for Windows using fyne-cross..."
19+
fyne-cross windows -arch=amd64 -app-id="com.snapmemory.downloader"
20+
mkdir -p $(BUILD_DIR)
21+
mv fyne-cross/bin/windows-amd64/$(APP_NAME).exe $(BUILD_DIR)/$(APP_NAME).exe || mv fyne-cross/bin/windows-amd64/$(APP_NAME) $(BUILD_DIR)/$(APP_NAME).exe
1722
@echo "Windows build complete: $(BUILD_DIR)/$(APP_NAME).exe"
1823

19-
macos:
20-
@echo "Building for macOS..."
21-
go build -o $(BUILD_DIR)/$(APP_NAME) $(SRC_DIR)/gui_main.go
22-
@echo "macOS build complete: $(BUILD_DIR)/$(APP_NAME)"
24+
docker-image:
25+
@echo "Building Docker image: $(DOCKER_IMAGE) (without source code)..."
26+
docker build -t $(DOCKER_IMAGE) -f Dockerfile .
27+
@echo "Docker image built: $(DOCKER_IMAGE)"
2328

24-
run:
29+
macos: docker-image
30+
@echo "Building darwin binary using Docker container..."
31+
mkdir -p $(BUILD_DIR)
32+
docker run --rm -v $$(pwd):/root/src $(DOCKER_IMAGE) bash -c "cd /root/src && GOFLAGS=-mod=vendor GOOS=darwin CGO_ENABLED=1 go build -o $(BUILD_DIR)/$(APP_NAME)-darwin -buildvcs=false ./gui_main.go"
33+
@echo "Darwin build complete: $(BUILD_DIR)/$(APP_NAME)-mac"
34+
35+
run: linux
2536
@echo "Running application..."
26-
go run gui_main.go
37+
bin/snap-memory-downloader
2738

2839
clean:
2940
@echo "Cleaning up..."
3041
rm -rf $(BUILD_DIR)
3142
@echo "Cleanup complete."
3243

44+
clean-deps:
45+
@echo "Removing vendored dependencies..."
46+
rm -rf vendor/
47+
@echo "Vendor folder cleaned."
48+
3349
install-deps:
34-
@echo "Installing dependencies..."
50+
@echo "Installing dependencies to local vendor folder..."
3551
go mod download
36-
go mod tidy
37-
@echo "Dependencies installed."
52+
go mod vendor
53+
@echo "Dependencies installed to vendor."

0 commit comments

Comments
 (0)