Skip to content

Commit 9396edf

Browse files
authored
Merge pull request #39 from Junnplus/cross
update test for cross compile
2 parents 0be7614 + 7d127d7 commit 9396edf

File tree

2 files changed

+33
-43
lines changed

2 files changed

+33
-43
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
name: Integration tests
1313
strategy:
1414
matrix:
15-
platform: [macos-10.15, macos-11]
15+
platform: [macos-11]
1616
runs-on: ${{ matrix.platform }}
1717
timeout-minutes: 40
1818
steps:
@@ -26,47 +26,19 @@ jobs:
2626
ifconfig
2727
- name: Install build dependencies of VDE
2828
run: brew install autoconf automake
29-
- name: Make and Install VDE
29+
- name: Make Install (x86_64)
3030
run: |
31-
git clone https://github.com/virtualsquare/vde-2.git /tmp/vde-2
32-
cd /tmp/vde-2
33-
# Dec 12, 2021
34-
git checkout 74278b9b7cf816f0356181f387012fdeb6d65b52
35-
autoreconf -fis
3631
# compile for x86_64
37-
./configure --prefix=/opt/vde
38-
make PREFIX=/opt/vde
39-
sudo make PREFIX=/opt/vde install
40-
# cleanup
41-
make distclean
42-
# cross-compile for arm64
43-
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
44-
export CC=$(xcrun --sdk macosx --find clang)
45-
export CXX=$(xcrun --sdk macosx --find clang++)
46-
export CFLAGS="-arch arm64e -isysroot $SDKROOT -Wno-error=implicit-function-declaration"
47-
export CXXFLAGS=$CFLAGS
48-
./configure --prefix=/opt/vde.arm64 --host=arm-apple-darwin --target=arm-apple-darwin --build=x86_64-apple-darwin
49-
make PREFIX=/opt/vde.arm64
50-
sudo make PREFIX=/opt/vde.arm64 install
51-
unset SDKROOT CC CXX CFLAGS CXXFLAGS
52-
- name: Make and Install vde_vmnet (x86_64)
53-
run: |
54-
git clone https://github.com/lima-vm/vde_vmnet.git /tmp/vde_vmnet
55-
cd /tmp/vde_vmnet
56-
make PREFIX=/opt/vde
5732
sudo make PREFIX=/opt/vde install
33+
file /opt/vde/bin/* | grep -c x86_64
5834
- name: Cleanup
5935
run: |
60-
make clean
61-
- name: Make and Install vde_vmnet (arm64)
36+
sudo make clean
37+
- name: Make Install (arm64)
6238
run: |
63-
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
64-
export CC=$(xcrun --sdk macosx --find clang)
65-
export CXX=$(xcrun --sdk macosx --find clang++)
66-
export CFLAGS="-arch arm64e -isysroot $SDKROOT -Wno-error=implicit-function-declaration"
67-
export CXXFLAGS=$CFLAGS
68-
make PREFIX=/opt/vde.arm64
69-
sudo make PREFIX=/opt/vde.arm64 install
39+
# cross-compile for arm64
40+
sudo make PREFIX=/opt/vde.arm64 ARCH=arm64 install
41+
file /opt/vde.arm64/bin/* | grep -c arm64
7042
- name: Print launchd status (shared mode)
7143
run: launchctl print system/io.github.lima-vm.vde_vmnet.plist
7244
- name: Install test dependencies

Makefile

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,26 @@ PREFIX ?= /opt/vde
44
# VDEPREFIX should be only writable by the root to avoid privilege escalation with launchd or sudo
55
VDEPREFIX ?= $(PREFIX)
66

7-
CFLAGS ?= -O3
7+
VMNET_CFLAGS ?= -O3
88

99
VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags)
10-
CFLAGS += -I"$(VDEPREFIX)/include" -DVERSION=\"$(VERSION)\"
1110

12-
LDFLAGS += -L"$(VDEPREFIX)/lib" -lvdeplug -framework vmnet
11+
VMNET_CFLAGS += -I"$(VDEPREFIX)/include" -DVERSION=\"$(VERSION)\"
12+
13+
VMNET_LDFLAGS += -L"$(VDEPREFIX)/lib" -lvdeplug -framework vmnet
14+
15+
# ARCH support arm64 and x86_64
16+
ARCH ?=
17+
18+
ifneq (,$(findstring arm64,$(ARCH)))
19+
HOST ?= --host arm-apple-darwin
20+
VMNET_CFLAGS += -arch arm64
21+
VDE2_CFLAGS += -arch arm64 -Wno-error=implicit-function-declaration
22+
else ifneq (,$(findstring x86_64,$(ARCH)))
23+
HOST ?= --host x86_64-apple-darwin
24+
VMNET_CFLAGS += -arch x86_64
25+
VDE2_CFLAGS += -arch x86_64 -Wno-error=implicit-function-declaration
26+
endif
1327

1428
# Interface name for bridged mode. Empty value (default) disables bridged mode.
1529
BRIDGED ?=
@@ -19,17 +33,17 @@ all: vde_vmnet
1933
OBJS = $(patsubst %.c, %.o, $(wildcard *.c))
2034

2135
%.o: %.c *.h
22-
$(CC) $(CFLAGS) -c $< -o $@
36+
$(CC) $(VMNET_CFLAGS) -c $< -o $@
2337

2438
vde_vmnet: $(OBJS)
25-
$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(OBJS)
39+
$(CC) $(VMNET_CFLAGS) -o $@ $(VMNET_LDFLAGS) $(OBJS)
2640

2741
install.bin: vde_vmnet
2842
install vde_vmnet "$(DESTDIR)/$(PREFIX)/bin/vde_vmnet"
2943

3044
install.vde-2:
3145
git submodule update --init
32-
cd vde-2 && autoreconf -fis && CFLAGS="" LDFLAGS="" ./configure --prefix=$(VDEPREFIX) && make && make install
46+
cd vde-2 && autoreconf -fis && CFLAGS="$(VDE2_CFLAGS)" ./configure --prefix=$(VDEPREFIX) $(HOST) && make && make install
3347

3448
install.launchd.plist: launchd/*.plist
3549
sed -e "s@/opt/vde@$(PREFIX)@g" launchd/io.github.virtualsquare.vde-2.vde_switch.plist > "$(DESTDIR)/Library/LaunchDaemons/io.github.virtualsquare.vde-2.vde_switch.plist"
@@ -77,6 +91,10 @@ endif
7791

7892
uninstall: uninstall.launchd.plist uninstall.bin uninstall.vde-2
7993

94+
.PHONY: clean.vde-2
95+
clean.vde-2:
96+
cd vde-2 && make distclean
97+
8098
.PHONY: clean
81-
clean:
99+
clean: clean.vde-2
82100
rm -f vde_vmnet *.o

0 commit comments

Comments
 (0)