From 59af9bd85580057fb6ba3130fa94a49fea109d81 Mon Sep 17 00:00:00 2001 From: AndersonTorres Date: Thu, 28 Oct 2021 00:43:40 -0300 Subject: [PATCH] arcan.arcan: fix static openal issues Arcan has some interesting idiosyncrasies. One of them is using cmake. The other is using cmake to vendor some low-level, custom-patched dependencies. In order to work around them, I have created ... a set of custom patches! And on top of it, I have factored the vendored sources in a separate file, in order to clean up the `default.nix` file. --- pkgs/desktops/arcan/arcan/000-openal.patch | 15 +++ pkgs/desktops/arcan/arcan/001-luajit.patch | 17 ++++ pkgs/desktops/arcan/arcan/002-libuvc.patch | 15 +++ pkgs/desktops/arcan/arcan/003-freetype.patch | 14 +++ pkgs/desktops/arcan/arcan/clone-sources.nix | 25 +++++ pkgs/desktops/arcan/arcan/default.nix | 98 +++++++++++++------- 6 files changed, 149 insertions(+), 35 deletions(-) create mode 100644 pkgs/desktops/arcan/arcan/000-openal.patch create mode 100644 pkgs/desktops/arcan/arcan/001-luajit.patch create mode 100644 pkgs/desktops/arcan/arcan/002-libuvc.patch create mode 100644 pkgs/desktops/arcan/arcan/003-freetype.patch create mode 100644 pkgs/desktops/arcan/arcan/clone-sources.nix diff --git a/pkgs/desktops/arcan/arcan/000-openal.patch b/pkgs/desktops/arcan/arcan/000-openal.patch new file mode 100644 index 000000000000..f8e02a4cb0c6 --- /dev/null +++ b/pkgs/desktops/arcan/arcan/000-openal.patch @@ -0,0 +1,15 @@ +diff -Naur source-old/src/CMakeLists.txt source-new/src/CMakeLists.txt +--- source-old/src/CMakeLists.txt 1969-12-31 21:00:01.000000000 -0300 ++++ source-new/src/CMakeLists.txt 2021-10-29 12:03:06.461399341 -0300 +@@ -362,10 +360,8 @@ + if (EXISTS ${EXTERNAL_SRC_DIR}/git/openal AND STATIC_OPENAL) + amsg("${CL_YEL}Building OpenAL static from external/git mirror${CL_RST}") + ExternalProject_Add(OpenAL +- SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/openal ++ SOURCE_DIR "${EXTERNAL_SRC_DIR}/git/openal" + BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/openal_static +- UPDATE_COMMAND "" +- GIT_REPOSITORY "${EXTERNAL_SRC_DIR}/git/openal" + ${EXTERNAL_DEFS} + ${CMAKE_EXTERNAL_DEFS} + -DALSOFT_BACKEND_DSOUND=OFF diff --git a/pkgs/desktops/arcan/arcan/001-luajit.patch b/pkgs/desktops/arcan/arcan/001-luajit.patch new file mode 100644 index 000000000000..eff3c0a5aad0 --- /dev/null +++ b/pkgs/desktops/arcan/arcan/001-luajit.patch @@ -0,0 +1,17 @@ +diff -Naur source-old/src/CMakeLists.txt source-new/src/CMakeLists.txt +--- source-old/src/CMakeLists.txt 1969-12-31 21:00:01.000000000 -0300 ++++ source-new/src/CMakeLists.txt 2021-10-29 12:03:06.461399341 -0300 +@@ -419,12 +415,7 @@ + set(LUA_TAG "luajit51") + if (EXISTS ${EXTERNAL_SRC_DIR}/git/luajit) + ExternalProject_Add(luajit +- SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/luajit +- GIT_REPOSITORY "${EXTERNAL_SRC_DIR}/git/luajit" +- CONFIGURE_COMMAND "" +- GIT_TAG "v2.1.0-beta3" +- UPDATE_COMMAND "" +- INSTALL_COMMAND "" ++ SOURCE_DIR "${EXTERNAL_SRC_DIR}/git/luajit" + BUILD_IN_SOURCE 1 + BUILD_COMMAND "${EXTMAKE_CMD}" + DEFAULT_CC=${CMAKE_C_COMPILER} diff --git a/pkgs/desktops/arcan/arcan/002-libuvc.patch b/pkgs/desktops/arcan/arcan/002-libuvc.patch new file mode 100644 index 000000000000..48d25fe8271e --- /dev/null +++ b/pkgs/desktops/arcan/arcan/002-libuvc.patch @@ -0,0 +1,15 @@ +diff -Naur source-old/src/frameserver/decode/default/CMakeLists.txt source-new/src/frameserver/decode/default/CMakeLists.txt +--- source-old/src/frameserver/decode/default/CMakeLists.txt 1969-12-31 21:00:01.000000000 -0300 ++++ source-new/src/frameserver/decode/default/CMakeLists.txt 2021-10-29 12:01:31.989933725 -0300 +@@ -62,10 +62,8 @@ + if (STATIC_LIBUVC) + pkg_check_modules(LIBUSB_1 REQUIRED libusb-1.0) + ExternalProject_Add(libuvc +- SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/frameserver/decode/libuvc" ++ SOURCE_DIR "${EXTERNAL_SRC_DIR}/git/libuvc" + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/libuvc_static" +- UPDATE_COMMAND "" +- GIT_REPOSITORY "${EXTERNAL_SRC_DIR}/git/libuvc" + ${EXTERNAL_DEFS} + ${CMAKE_EXTERNAL_DEFS} + -DBUILD_UVC_STATIC=ON diff --git a/pkgs/desktops/arcan/arcan/003-freetype.patch b/pkgs/desktops/arcan/arcan/003-freetype.patch new file mode 100644 index 000000000000..e38d329b0260 --- /dev/null +++ b/pkgs/desktops/arcan/arcan/003-freetype.patch @@ -0,0 +1,14 @@ +diff -Naur source-old/src/CMakeLists.txt source-new/src/CMakeLists.txt +--- source-old/src/CMakeLists.txt 1969-12-31 21:00:01.000000000 -0300 ++++ source-new/src/CMakeLists.txt 2021-10-29 12:03:06.461399341 -0300 +@@ -317,9 +317,7 @@ + find_package(BZip2 REQUIRED QUIET) + pkg_check_modules(HARFBUZZ REQUIRED QUIET harfbuzz) + ExternalProject_Add(Freetype +- SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/freetype" +- UPDATE_COMMAND "" +- GIT_REPOSITORY "${EXTERNAL_SRC_DIR}/git/freetype" ++ SOURCE_DIR "${EXTERNAL_SRC_DIR}/git/freetype" + ${EXTERNAL_DEFS} + ${CMAKE_EXTERNAL_DEFS} + -DWITH_ZLIB=OFF diff --git a/pkgs/desktops/arcan/arcan/clone-sources.nix b/pkgs/desktops/arcan/arcan/clone-sources.nix new file mode 100644 index 000000000000..2ade63e70bfa --- /dev/null +++ b/pkgs/desktops/arcan/arcan/clone-sources.nix @@ -0,0 +1,25 @@ +{ fetchgit, fetchFromGitHub }: +{ + letoram-openal-src = fetchFromGitHub { + owner = "letoram"; + repo = "openal"; + rev = "1c7302c580964fee9ee9e1d89ff56d24f934bdef"; + hash = "sha256-InqU59J0zvwJ20a7KU54xTM7d76VoOlFbtj7KbFlnTU="; + }; + freetype-src = fetchgit { + url = "git://git.sv.nongnu.org/freetype/freetype2.git"; + rev = "94cb3a2eb96b3f17a1a3bd0e6f7da97c0e1d8f57"; + sha256 = "sha256-LzjqunX/T8khF2UjPlPYiQOwMGem8MqPYneR2LdZ5Fg="; + }; + libuvc-src = fetchgit { + owner = "libuvc"; + repo = "libuvc"; + rev = "b2b01ae6a2875d05c99eb256bb15815018d6e837"; + sha256 = "sha256-2zCTjyodRARkHM/Q0r4bdEH9LO1Z9xPCnY2xE4KZddA="; + }; + luajit-src = fetchgit { + url = "https://luajit.org/git/luajit-2.0.git"; + rev = "d3294fa63b344173db68dd612c6d3801631e28d4"; + sha256 = "sha256-1iHBXcbYhWN4M8g5oH09S1j1WrjYzI6qcRbHsdfpRkk="; + }; +} diff --git a/pkgs/desktops/arcan/arcan/default.nix b/pkgs/desktops/arcan/arcan/default.nix index 48d4f9a54813..8420df5e7e21 100644 --- a/pkgs/desktops/arcan/arcan/default.nix +++ b/pkgs/desktops/arcan/arcan/default.nix @@ -1,6 +1,7 @@ { lib , stdenv , fetchFromGitHub +, fetchgit , SDL2 , cmake , espeak @@ -23,6 +24,7 @@ , libvncserver , libxcb , libxkbcommon +, lua , luajit , makeWrapper , mesa @@ -36,22 +38,16 @@ , xcbutil , xcbutilwm , xz -, buildManpages ? true, ruby +, buildManPages ? true, ruby +, useBuiltinLua ? true +, useStaticFreetype ? false +, useStaticLibuvc ? false +, useStaticOpenAL ? true +, useStaticSqlite ? false }: -let - # TODO: investigate vendoring, especially OpenAL - # WARN: vendoring of OpenAL is required for running arcan_lwa - # INFO: maybe it needs leaveDotGit, but it is dangerous/impure - letoram-openal-src = fetchFromGitHub { - owner = "letoram"; - repo = "openal"; - rev = "1c7302c580964fee9ee9e1d89ff56d24f934bdef"; - hash = "sha256-InqU59J0zvwJ20a7KU54xTM7d76VoOlFbtj7KbFlnTU="; - }; -in stdenv.mkDerivation rec { - pname = "arcan"; + pname = "arcan" + lib.optionalString useStaticOpenAL "-static-openal"; version = "0.6.1pre1+unstable=2021-10-16"; src = fetchFromGitHub { @@ -61,28 +57,11 @@ stdenv.mkDerivation rec { hash = "sha256-4FodFuO51ehvyjH4YaF/xBY9dwA6cP/e6/BvEsH4w7U="; }; - postUnpack = '' - pushd . - cd $sourceRoot/external/git/ - cp -a ${letoram-openal-src}/ openal/ - chmod --recursive 744 openal/ - popd - ''; - - # TODO: work with upstream in order to get rid of these hardcoded paths - postPatch = '' - substituteInPlace ./src/platform/posix/paths.c \ - --replace "/usr/bin" "$out/bin" \ - --replace "/usr/share" "$out/share" - - substituteInPlace ./src/CMakeLists.txt --replace "SETUID" "# SETUID" - ''; - nativeBuildInputs = [ cmake makeWrapper pkg-config - ] ++ lib.optionals buildManpages [ + ] ++ lib.optionals buildManPages [ ruby ]; @@ -108,6 +87,7 @@ stdenv.mkDerivation rec { libvncserver libxcb libxkbcommon + lua luajit mesa openal @@ -121,11 +101,54 @@ stdenv.mkDerivation rec { xz ]; + patches = [ + # Nixpkgs-specific: redirect vendoring + ./000-openal.patch + ./001-luajit.patch + ./002-libuvc.patch + ./003-freetype.patch + ]; + + # Emulate external/git/clone.sh + postUnpack = let + inherit (import ./clone-sources.nix { inherit fetchFromGitHub fetchgit; }) + letoram-openal-src freetype-src libuvc-src luajit-src; + in + '' + pushd $sourceRoot/external/git/ + '' + + (lib.optionalString useStaticOpenAL '' + cp -a ${letoram-openal-src}/ openal + chmod --recursive 744 openal + '') + + (lib.optionalString useStaticFreetype '' + cp -a ${freetype-src}/ freetype + chmod --recursive 744 freetype + '') + + (lib.optionalString useStaticLibuvc '' + cp -a ${libuvc-src}/ libuvc + chmod --recursive 744 libuvc + '') + + (lib.optionalString useBuiltinLua '' + cp -a ${luajit-src}/ luajit + chmod --recursive 744 luajit + '') + + '' + popd + ''; + + postPatch = '' + substituteInPlace ./src/platform/posix/paths.c \ + --replace "/usr/bin" "$out/bin" \ + --replace "/usr/share" "$out/share" + + substituteInPlace ./src/CMakeLists.txt --replace "SETUID" "# SETUID" + ''; + # INFO: According to the source code, the manpages need to be generated before # the configure phase - preConfigure = lib.optionalString buildManpages '' - pushd . - cd doc + preConfigure = lib.optionalString buildManPages '' + pushd doc ruby docgen.rb mangen popd ''; @@ -136,7 +159,12 @@ stdenv.mkDerivation rec { "-DDISTR_TAG=Nixpkgs" "-DENGINE_BUILDTAG=${version}" "-DHYBRID_SDL=on" - "-DSTATIC_OPENAL=off" + "-DBUILTIN_LUA=${if useBuiltinLua then "on" else "off"}" + "-DDISABLE_JIT=${if useBuiltinLua then "on" else "off"}" + "-DSTATIC_FREETYPE=${if useStaticFreetype then "on" else "off"}" + "-DSTATIC_LIBUVC=${if useStaticLibuvc then "on" else "off"}" + "-DSTATIC_OPENAL=${if useStaticOpenAL then "on" else "off"}" + "-DSTATIC_SQLite3=${if useStaticSqlite then "on" else "off"}" "../src" ];