mirror of
https://github.com/daeuniverse/dae.git
synced 2025-01-18 16:29:11 +07:00
chore: support cross compilation
This commit is contained in:
parent
2b9a4052f7
commit
c2b5acb423
2
.github/workflows/kernel-test.yml
vendored
2
.github/workflows/kernel-test.yml
vendored
@ -28,7 +28,7 @@ jobs:
|
||||
- name: Generate and build
|
||||
run: |
|
||||
git submodule update --init
|
||||
make GOFLAGS="-buildvcs=false" CC=clang
|
||||
make GOFLAGS="-buildvcs=false"
|
||||
|
||||
- name: Store executable
|
||||
uses: actions/upload-artifact@v4
|
||||
|
15
Makefile
15
Makefile
@ -25,7 +25,18 @@ else
|
||||
STRIP_FLAG := -strip=$(STRIP_PATH)
|
||||
endif
|
||||
|
||||
GOARCH ?= $(shell go env GOARCH)
|
||||
ifndef CGO_ENABLED
|
||||
CGO_ENABLED_NDEF := 1
|
||||
CGO_ENABLED := $(shell go env CGO_ENABLED)
|
||||
endif
|
||||
ifndef CC
|
||||
CC_NDEF := 1
|
||||
CC := $(shell go env CC)
|
||||
endif
|
||||
ifndef GOARCH
|
||||
GOARCH_NDEF := 1
|
||||
GOARCH := $(shell go env GOARCH)
|
||||
endif
|
||||
|
||||
# Do NOT remove the line below. This line is for CI.
|
||||
#export GOMODCACHE=$(PWD)/go-mod
|
||||
@ -54,7 +65,9 @@ dae: ebpf
|
||||
$(info CGO_ENABLED=$(CGO_ENABLED))
|
||||
$(info GO_LDFLAGS=$(GO_LDFLAGS))
|
||||
$(info CC=$(CC))
|
||||
$(info GOARCH=$(GOARCH))
|
||||
go build -tags=$(shell cat $(BUILD_TAGS_FILE)) -o $(OUTPUT) $(GO_BUILD_ARGS) .
|
||||
@$(STRIP) $(OUTPUT) || llvm-strip $(OUTPUT) || strip $(OUTPUT) || true
|
||||
## End Dae Build
|
||||
|
||||
## Begin Git Submodules
|
||||
|
@ -2,20 +2,33 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
# Copyright (c) 2022-2024, daeuniverse Organization <dae@v2raya.org>
|
||||
#
|
||||
|
||||
ifneq ($(KEEP_CGO_ENVS),1)
|
||||
ifndef CGO_ENABLED
|
||||
ifdef CGO_ENABLED_NDEF
|
||||
export CGO_ENABLED := 0
|
||||
endif
|
||||
ifeq ($(CGO_ENABLED),0)
|
||||
ifdef GOARCH_NDEF
|
||||
ifeq ($(CC),cc)
|
||||
ifneq ($(shell which musl-gcc),)
|
||||
export CGO_ENABLED := 1
|
||||
export CC := musl-gcc
|
||||
GO_LDFLAGS += -linkmode external -extldflags=-static
|
||||
$(info * Building dae with musl-gcc static linking instead of CGO_ENABLED=0. See https://github.com/daeuniverse/dae/issues/557)
|
||||
else ifneq ($(shell which zig),)
|
||||
export CC := zig cc -target $(shell . install/musl-targets.sh && echo $$GOARCH_$(GOARCH))
|
||||
else
|
||||
$(info ! CGO_ENABLED=0 is not recommended. Use static link instead. See https://github.com/daeuniverse/dae/issues/557)
|
||||
$(info ! CGO_ENABLED=0 is not recommended. Please consider to install musl-gcc for static link instead. See https://github.com/daeuniverse/dae/issues/557)
|
||||
endif
|
||||
endif
|
||||
else ifneq ($(shell which zig),)
|
||||
export CC := zig cc -target $(shell . install/musl-targets.sh && echo $$GOARCH_$(GOARCH))
|
||||
else
|
||||
$(info ! CGO_ENABLED=0 is not recommended. See https://github.com/daeuniverse/dae/issues/557)
|
||||
endif
|
||||
endif
|
||||
ifneq ($(CC),cc)
|
||||
export CGO_ENABLED := 1
|
||||
GO_LDFLAGS += -linkmode external -extldflags=-static
|
||||
$(info * Building dae with "$(CC)" static linking instead of CGO_ENABLED=0. See https://github.com/daeuniverse/dae/issues/557)
|
||||
endif
|
||||
else
|
||||
export CGO_ENABLED := 0
|
||||
endif
|
||||
|
@ -18,8 +18,7 @@ git clone https://github.com/daeuniverse/dae.git
|
||||
cd dae
|
||||
git submodule update --init
|
||||
## Minimal dependency build
|
||||
make GOFLAGS="-buildvcs=false" \
|
||||
CC=clang
|
||||
make GOFLAGS="-buildvcs=false" CC=clang KEEP_CGO_ENVS=1
|
||||
|
||||
## Normal build
|
||||
#make
|
||||
|
9
install/musl-targets.sh
Normal file
9
install/musl-targets.sh
Normal file
@ -0,0 +1,9 @@
|
||||
GOARCH_386=i386-linux-musl
|
||||
GOARCH_amd64=x86_64-linux-musl
|
||||
GOARCH_arm=arm-linux-musleabi
|
||||
GOARCH_arm64=aarch64-linux-musl
|
||||
GOARCH_mips64le=mips64el-linux-musl
|
||||
GOARCH_mips64=mips64-linux-musl
|
||||
GOARCH_mipsle=mipsel-linux-musl
|
||||
GOARCH_mips=mips-linux-musl
|
||||
GOARCH_riscv64=riscv64-linux-musl
|
Loading…
Reference in New Issue
Block a user