rutabaga_gfx: fix build on Darwin (#298441)

* gfxstream: fix build on Darwin

- Add patch from upstream to remove libdrm dependency;
- Modify `meson.build` to support Objective-C;
- Add required Darwin frameworks; and
- Ensure everything that’s required is linked on Darwin.

* rutabaga_gfx: fix build on Darwin
This commit is contained in:
Randy Eckenrode 2024-03-25 16:42:39 -04:00 committed by GitHub
parent 90f6939439
commit 03adc266bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 79 additions and 7 deletions

View File

@ -1,5 +1,5 @@
{ lib, stdenv, fetchFromGitiles, meson, ninja, pkg-config, python3
, aemu, libdrm, libglvnd, vulkan-headers, vulkan-loader, xorg
{ lib, stdenv, fetchFromGitiles, fetchpatch, meson, ninja, pkg-config, python3
, aemu, darwin, libdrm, libglvnd, vulkan-headers, vulkan-loader, xorg
}:
stdenv.mkDerivation {
@ -12,14 +12,45 @@ stdenv.mkDerivation {
hash = "sha256-IYXkaHZPEYIE9KW731GN6x6yRS+FYtP1zyHcaSofhIM=";
};
patches = [
# Make libdrm an optional dependency, which is required to build on Darwin.
(fetchpatch {
url = "https://android.googlesource.com/platform/hardware/google/gfxstream/+/a8df2a3eb099b419a7b3638e68ea30b4cffb751b%5E%21/?format=TEXT";
decode = "base64 -d";
hash = "sha256-shjeNuxtQokscCGBKEUbOPKOWRELBAnHFNj3Y5w87Nw=";
})
];
# Ensure that meson can find an Objective-C compiler on Darwin.
postPatch = lib.optionalString stdenv.isDarwin ''
substituteInPlace meson.build \
--replace-fail "project('gfxstream_backend', 'cpp', 'c'" "project('gfxstream_backend', 'cpp', 'c', 'objc'"
'';
nativeBuildInputs = [ meson ninja pkg-config python3 ];
buildInputs = [ aemu libglvnd vulkan-headers vulkan-loader xorg.libX11 ]
++ lib.optional (lib.meta.availableOn stdenv.hostPlatform libdrm) libdrm;
++ lib.optionals (lib.meta.availableOn stdenv.hostPlatform libdrm) [ libdrm ]
++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.Cocoa
darwin.apple_sdk.frameworks.CoreGraphics
darwin.apple_sdk.frameworks.IOKit
darwin.apple_sdk.frameworks.IOSurface
darwin.apple_sdk.frameworks.OpenGL
darwin.apple_sdk.frameworks.QuartzCore
];
env = lib.optionalAttrs stdenv.isDarwin {
NIX_LDFLAGS = toString [
"-framework Cocoa"
"-framework IOKit"
"-framework IOSurface"
"-framework OpenGL"
"-framework QuartzCore"
"-needed-lvulkan"
];
};
# dlopens libvulkan.
#
# XXX: Unsure if this is required on Darwin. If it is, it probably
# needs to be done using install_name_tool.
preConfigure = lib.optionalString (!stdenv.isDarwin) ''
mesonFlagsArray=(-Dcpp_link_args="-Wl,--push-state -Wl,--no-as-needed -lvulkan -Wl,--pop-state")
'';

View File

@ -0,0 +1,31 @@
diff --git a/rutabaga_gfx/ffi/Makefile b/rutabaga_gfx/ffi/Makefile
index f8c7820bf..e88a6c308 100644
--- a/rutabaga_gfx/ffi/Makefile
+++ b/rutabaga_gfx/ffi/Makefile
@@ -47,24 +47,16 @@ build:
cargo build $(gfxstream_feature) $(release)
install: build
-ifeq ($(UNAME), Linux)
install -D -m 755 $(OUT)/$(LIB_NAME) $(DESTDIR)$(libdir)/$(LIB_NAME).$(RUTABAGA_VERSION)
-endif
ifeq ($(UNAME), Darwin)
- install_name_tool -id $(DESTDIR)$(libdir)/$(LIB_NAME).$(RUTABAGA_VERSION) $(DESTDIR)$(libdir)/$(LIB_NAME)
+ install_name_tool -id $(DESTDIR)$(libdir)/$(LIB_NAME).$(RUTABAGA_VERSION) $(DESTDIR)$(libdir)/$(LIB_NAME).$(RUTABAGA_VERSION)
endif
ln -sf $(LIB_NAME).$(RUTABAGA_VERSION) $(DESTDIR)$(libdir)/$(LIB_NAME).$(RUTABAGA_VERSION_MAJOR)
ln -sf $(LIB_NAME).$(RUTABAGA_VERSION) $(DESTDIR)$(libdir)/$(LIB_NAME)
-ifeq ($(UNAME), Linux)
install -D -m 0644 $(SRC)/share/rutabaga_gfx_ffi.pc $(DESTDIR)$(libdir)/pkgconfig/rutabaga_gfx_ffi.pc
install -D -m 0644 $(SRC)/include/rutabaga_gfx_ffi.h $(DESTDIR)$(includedir)/rutabaga_gfx_ffi.h
-endif
-ifeq ($(UNAME), Darwin)
- install -m 0644 $(SRC)/share/rutabaga_gfx_ffi.pc $(DESTDIR)$(libdir)/pkgconfig/rutabaga_gfx_ffi.pc
- install -m 0644 $(SRC)/include/rutabaga_gfx_ffi.h $(DESTDIR)$(includedir)/rutabaga_gfx_ffi.h
-endif
clean:
cargo clean $(release)

View File

@ -8,6 +8,7 @@
, aemu
, gfxstream
, libdrm
, libiconv
}:
stdenv.mkDerivation (finalAttrs: {
@ -29,10 +30,19 @@ stdenv.mkDerivation (finalAttrs: {
decode = "base64 -d";
hash = "sha256-Ji1bK7jnRlg0OpDfCLcTHfPSiz3zYcdgsWL4n3EoIYI=";
})
# Fix error in Makefile where it uses eight spaces instead of a tab
# https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4863380
(fetchpatch {
url = "https://chromium.googlesource.com/crosvm/crosvm/+/fc415bccc43d36f63a2fd4c28878591bb1053450%5E%21/?format=TEXT";
decode = "base64 -d";
hash = "sha256-SLzlZ4o1+R2bGTPvA0a5emq97hOIIIHrubFhcQjqYwg=";
})
# Install the dylib on Darwin.
./darwin-install.patch
];
nativeBuildInputs = [ cargo pkg-config rustPlatform.cargoSetupHook ];
buildInputs = lib.optionals (lib.meta.availableOn stdenv.hostPlatform gfxstream) ([
buildInputs = [ libiconv ] ++ lib.optionals (lib.meta.availableOn stdenv.hostPlatform gfxstream) ([
aemu
gfxstream
] ++ lib.optionals (lib.meta.availableOn stdenv.hostPlatform libdrm) [