Skip to content

Commit

Permalink
Add linux-musl and windows 386
Browse files Browse the repository at this point in the history
  • Loading branch information
zengxs committed Nov 22, 2024
1 parent a7543c5 commit 191f79d
Showing 1 changed file with 45 additions and 15 deletions.
60 changes: 45 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ ZIG_CXX := $(ZIG) c++ -w

LIPO := $(CURDIR)/scripts/helpers/lipo.sh

LINUX_GOFLAGS := --ldflags '-linkmode external -w' -tags 'sqlite_json,sqlite_foreign_keys,sqlite_fts5'
LINUX_GLIBC_VERSION := 2.17
COMMON_GOFLAGS := -tags 'sqlite_json,sqlite_foreign_keys,sqlite_fts5'

DARWIN_GOFLAGS = --ldflags '-linkmode external -w' -tags 'sqlite_json,sqlite_foreign_keys,sqlite_fts5'
LINUXGNU_GOFLAGS := --ldflags '-linkmode external -w' $(COMMON_GOFLAGS)
LINUXGNU_GLIBC_VERSION := 2.17

LINUXMUSL_GOFLAGS := --ldflags '-linkmode external -w -extldflags -static' $(COMMON_GOFLAGS)

DARWIN_GOFLAGS = --ldflags '-linkmode external -w' $(COMMON_GOFLAGS)
DARWIN_SDKROOT = $(shell bash $(CURDIR)/scripts/find-darwin-sdkroot.sh)
DARWIN_ZIG_FLAGS = \
-I$(DARWIN_SDKROOT)/usr/include \
-L$(DARWIN_SDKROOT)/usr/lib \
-F$(DARWIN_SDKROOT)/System/Library/Frameworks

WINDOWS_GOFLAGS := -tags 'sqlite_json,sqlite_foreign_keys,sqlite_fts5'
WINDOWS_GOFLAGS := $(COMMON_GOFLAGS)

# Always use build with cgo enabled
export CGO_ENABLED = 1
Expand All @@ -30,24 +34,42 @@ all: linux macos windows
clean:
rm -rf dist

.PHONY: linux
linux: dist/linux-amd64/demo dist/linux-arm64/demo
.PHONY: linux linuxgnu linuxmusl
linux: linuxgnu linuxmusl
linuxgnu: dist/linuxgnu-amd64/demo dist/linuxgnu-arm64/demo
linuxmusl: dist/linuxmusl-amd64/demo dist/linuxmusl-arm64/demo

dist/linuxgnu-amd64/demo: $(SOURCES)
$(eval export CC = $(ZIG_CC) --target=x86_64-linux-gnu.$(LINUXGNU_GLIBC_VERSION))
$(eval export CXX = $(ZIG_CXX) --target=x86_64-linux-gnu.$(LINUXGNU_GLIBC_VERSION))
$(eval export GOOS = linux)
$(eval export GOARCH = amd64)
@echo CC="$(CC)" CXX="$(CXX)" GOOS="$(GOOS)" GOARCH="$(GOARCH)"
go build $(LINUXGNU_GOFLAGS) -o $@ $(MAIN_PACKAGE_PATH)

dist/linuxgnu-arm64/demo: $(SOURCES)
$(eval export CC = $(ZIG_CC) --target=aarch64-linux-gnu.$(LINUXGNU_GLIBC_VERSION))
$(eval export CXX = $(ZIG_CXX) --target=aarch64-linux-gnu.$(LINUXGNU_GLIBC_VERSION))
$(eval export GOOS = linux)
$(eval export GOARCH = arm64)
@echo CC="$(CC)" CXX="$(CXX)" GOOS="$(GOOS)" GOARCH="$(GOARCH)"
go build $(LINUXGNU_GOFLAGS) -o $@ $(MAIN_PACKAGE_PATH)

dist/linux-amd64/demo: $(SOURCES)
$(eval export CC = $(ZIG_CC) --target=x86_64-linux-gnu.$(LINUX_GLIBC_VERSION))
$(eval export CXX = $(ZIG_CXX) --target=x86_64-linux-gnu.$(LINUX_GLIBC_VERSION))
dist/linuxmusl-amd64/demo: $(SOURCES)
$(eval export CC = $(ZIG_CC) --target=x86_64-linux-musl)
$(eval export CXX = $(ZIG_CXX) --target=x86_64-linux-musl)
$(eval export GOOS = linux)
$(eval export GOARCH = amd64)
@echo CC="$(CC)" CXX="$(CXX)" GOOS="$(GOOS)" GOARCH="$(GOARCH)"
go build $(LINUX_GOFLAGS) -o $@ $(MAIN_PACKAGE_PATH)
go build $(LINUXMUSL_GOFLAGS) -o $@ $(MAIN_PACKAGE_PATH)

dist/linux-arm64/demo: $(SOURCES)
$(eval export CC = $(ZIG_CC) --target=aarch64-linux-gnu.$(LINUX_GLIBC_VERSION))
$(eval export CXX = $(ZIG_CXX) --target=aarch64-linux-gnu.$(LINUX_GLIBC_VERSION))
dist/linuxmusl-arm64/demo: $(SOURCES)
$(eval export CC = $(ZIG_CC) --target=aarch64-linux-musl)
$(eval export CXX = $(ZIG_CXX) --target=aarch64-linux-musl)
$(eval export GOOS = linux)
$(eval export GOARCH = arm64)
@echo CC="$(CC)" CXX="$(CXX)" GOOS="$(GOOS)" GOARCH="$(GOARCH)"
go build $(LINUX_GOFLAGS) -o $@ $(MAIN_PACKAGE_PATH)
go build $(LINUXMUSL_GOFLAGS) -o $@ $(MAIN_PACKAGE_PATH)

.PHONY: macos
macos: dist/darwin/demo
Expand All @@ -73,7 +95,7 @@ dist/darwin-arm64/demo: $(SOURCES)
go build $(DARWIN_GOFLAGS) -o $@ $(MAIN_PACKAGE_PATH)

.PHONY: windows
windows: dist/windows-amd64/demo.exe dist/windows-arm64/demo.exe
windows: dist/windows-amd64/demo.exe dist/windows-arm64/demo.exe dist/windows-386/demo.exe

dist/windows-amd64/demo.exe: $(SOURCES)
$(eval export CC = $(ZIG_CC) --target=x86_64-windows-gnu)
Expand All @@ -90,3 +112,11 @@ dist/windows-arm64/demo.exe: $(SOURCES)
$(eval export GOARCH = arm64)
@echo CC="$(CC)" CXX="$(CXX)" GOOS="$(GOOS)" GOARCH="$(GOARCH)"
go build $(WINDOWS_GOFLAGS) -o $@ $(MAIN_PACKAGE_PATH)

dist/windows-386/demo.exe: $(SOURCES)
$(eval export CC = $(ZIG_CC) --target=x86-windows-gnu)
$(eval export CXX = $(ZIG_CXX) --target=x86-windows-gnu)
$(eval export GOOS = windows)
$(eval export GOARCH = 386)
@echo CC="$(CC)" CXX="$(CXX)" GOOS="$(GOOS)" GOARCH="$(GOARCH)"
go build $(WINDOWS_GOFLAGS) -o $@ $(MAIN_PACKAGE_PATH)

0 comments on commit 191f79d

Please sign in to comment.