From a5fef0d0f4bc225fa6742506fe0758dd0ef49e78 Mon Sep 17 00:00:00 2001 From: "Alexander V. Nikolaev" Date: Wed, 8 Jan 2025 15:56:31 +0200 Subject: [PATCH] libnvidia-container: fix cross-compilation for aarch64-linux Signed-off-by: Alexander V. Nikolaev --- pkgs/by-name/li/libnvidia-container/package.nix | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkgs/by-name/li/libnvidia-container/package.nix b/pkgs/by-name/li/libnvidia-container/package.nix index 7f8e75e6ac9a14..bdebfa16221e1b 100644 --- a/pkgs/by-name/li/libnvidia-container/package.nix +++ b/pkgs/by-name/li/libnvidia-container/package.nix @@ -84,12 +84,19 @@ stdenv.mkDerivation rec { # libtirpc (for now) # 4. prevent installation of static libraries because of step 3 # 5. prevent installation of libnvidia-container-go.so twice + # 6. Replace pkg-config and objcopy with target platform's one + # 7. Stub ldconfig + # sed -i Makefile \ -e 's#DESTDIR=\$(DEPS_DIR)#DESTDIR=""#g' \ -e 's#\$(DEPS_DIR)\$#\$#g' \ -e 's#all: shared static tools#all: shared tools#g' \ -e '/$(INSTALL) -m 644 $(LIB_STATIC) $(DESTDIR)$(libdir)/d' \ - -e '/$(INSTALL) -m 755 $(libdir)\/$(LIBGO_SHARED) $(DESTDIR)$(libdir)/d' + -e '/$(INSTALL) -m 755 $(libdir)\/$(LIBGO_SHARED) $(DESTDIR)$(libdir)/d' \ + -e "s,pkg-config,$PKG_CONFIG,g" + substituteInPlace mk/common.mk \ + --replace-fail objcopy '$(OBJCOPY)' \ + --replace-fail ldconfig true ''; enableParallelBuilding = true; @@ -98,7 +105,12 @@ stdenv.mkDerivation rec { HOME="$(mktemp -d)" ''; - env.NIX_CFLAGS_COMPILE = toString [ "-I${lib.getInclude libtirpc}/include/tirpc" ]; + env = { + NIX_CFLAGS_COMPILE = toString [ "-I${lib.getInclude libtirpc}/include/tirpc" ]; + CGO_ENABLED = "1"; # Needed for cross-compilation + GOFLAGS = "-trimpath"; # Don't include paths to Go stdlib to resulting binary + inherit (go) GOARCH GOOS; + }; NIX_LDFLAGS = [ "-L${lib.getLib libtirpc}/lib" "-ltirpc"