Skip to content

Commit e5922f6

Browse files
nohajcslp
authored andcommitted
init: another macOS build fix
need to set path to gcc libs within the sysroot Signed-off-by: Jan Noha <[email protected]>
1 parent 7c5292c commit e5922f6

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ OS = $(shell uname -s)
5959
ARCH = $(shell uname -m)
6060
DEBIAN_DIST ?= bookworm
6161
ROOTFS_DIR = linux-sysroot
62+
GCC_VERSION ?= 12
6263

6364
KRUN_BINARY_Linux = libkrun$(VARIANT).so.$(FULL_VERSION)
6465
KRUN_SONAME_Linux = libkrun$(VARIANT).so.$(ABI_VERSION)
@@ -94,8 +95,13 @@ ifeq ($(SYSROOT_LINUX),)
9495
else
9596
SYSROOT_TARGET =
9697
endif
98+
# The GCC runtime dir (e.g. usr/lib/gcc/aarch64-linux-gnu/12) holds crtbeginT.o,
99+
# crtend.o, libgcc.a and libgcc_eh.a. Apple clang does not search it
100+
# automatically, so we pass it via -B (startup files) and -L (libraries).
101+
GCC_TRIPLET = $(subst arm64,aarch64,$(ARCH))-linux-gnu
102+
GCC_LIB_DIR = $(abspath $(SYSROOT_LINUX))/usr/lib/gcc/$(GCC_TRIPLET)/$(GCC_VERSION)
97103
# Cross-compile on macOS with the LLVM linker (brew install lld)
98-
CC_LINUX=/usr/bin/clang -target $(ARCH)-linux-gnu -fuse-ld=lld -Wl,-strip-debug --sysroot $(shell realpath $(SYSROOT_LINUX)) -Wno-c23-extensions
104+
CC_LINUX=/usr/bin/clang -target $(GCC_TRIPLET) -fuse-ld=lld -Wl,-strip-debug --sysroot $(abspath $(SYSROOT_LINUX)) -B$(GCC_LIB_DIR) -L$(GCC_LIB_DIR) -Wno-c23-extensions
99105
else
100106
# Build on Linux host
101107
CC_LINUX=$(CC)
@@ -110,7 +116,7 @@ $(AWS_NITRO_INIT_BINARY): $(AWS_NITRO_INIT_SRC)
110116
$(CC) -O2 -static -s -Wall $(AWS_NITRO_INIT_LD_FLAGS) -o $@ $(AWS_NITRO_INIT_SRC) $(AWS_NITRO_INIT_LD_FLAGS)
111117

112118
# Sysroot preparation rules for cross-compilation on macOS
113-
DEBIAN_PACKAGES = libc6 libc6-dev libgcc-12-dev linux-libc-dev
119+
DEBIAN_PACKAGES = libc6 libc6-dev libgcc-$(GCC_VERSION)-dev linux-libc-dev
114120
ROOTFS_TMP = $(ROOTFS_DIR)/.tmp
115121
PACKAGES_FILE = $(ROOTFS_TMP)/Packages.xz
116122

0 commit comments

Comments
 (0)