diff mbox series

[bug#57861,v2] gnu: Add ultrastar-deluxe.

Message ID Yyr67L9d78IDtOTK@noor.fritz.box
State New
Headers show
Series [bug#57861,v2] gnu: Add ultrastar-deluxe. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git-branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Lars-Dominik Braun Sept. 21, 2022, 11:52 a.m. UTC
Hi Maxime,

oh, I didn’t know gexp’s wouldn’t play nicely with input transformations. Fixed in v2.

Cheers,
Lars

---
 gnu/local.mk                                  |  1 +
 gnu/packages/games.scm                        | 91 +++++++++++++++++++
 .../ultrastar-deluxe-no-freesans.patch        | 31 +++++++
 3 files changed, 123 insertions(+)
 create mode 100644 gnu/packages/patches/ultrastar-deluxe-no-freesans.patch

Comments

Ludovic Courtès Oct. 17, 2022, 8:33 a.m. UTC | #1
Hello!

Lars-Dominik Braun <lars@6xq.net> skribis:

> +;; Lazily resolve to avoid a circular dependency.
> +(define fpc*
> +  (delay (module-ref (resolve-interface '(gnu packages pascal))
> +                     'fpc)))

I think this is unnecessary: you can just #:use-module (gnu packages
pascal) and have ‘fpc’ in ‘native-inputs’.  Everything will be fine
because ‘inputs’ is a thunked field (IOW, its evaluation is delayed).

Apart from that LGTM!

Thanks,
Ludo’.
Ludovic Courtès Oct. 17, 2022, 8:35 a.m. UTC | #2
Hello!

Lars-Dominik Braun <lars@6xq.net> skribis:

> +;; Lazily resolve to avoid a circular dependency.
> +(define fpc*
> +  (delay (module-ref (resolve-interface '(gnu packages pascal))
> +                     'fpc)))

I think this is unnecessary: you can just #:use-module (gnu packages
pascal) and have ‘fpc’ in ‘native-inputs’.  Everything will be fine
because ‘inputs’ is a thunked field (IOW, its evaluation is delayed).

Apart from that LGTM!

Thanks,
Ludo’.
M Oct. 17, 2022, 1:25 p.m. UTC | #3
On 17-10-2022 10:33, Ludovic Courtès wrote:
> Hello!
> 
> Lars-Dominik Braun <lars@6xq.net> skribis:
> 
>> +;; Lazily resolve to avoid a circular dependency.
>> +(define fpc*
>> +  (delay (module-ref (resolve-interface '(gnu packages pascal))
>> +                     'fpc)))
> 
> I think this is unnecessary: you can just #:use-module (gnu packages
> pascal) and have ‘fpc’ in ‘native-inputs’.  Everything will be fine
> because ‘inputs’ is a thunked field (IOW, its evaluation is delayed).

That's still a circular dependency.  Why import (gnu packages pascal) 
when you don't need it (e.g. when installing another, non-pascal, 
package)?  There is some bug report on the excessive dependencies among 
Guix modules with some proposed solutions.

Greetings,
Maxime.
\( Oct. 17, 2022, 1:28 p.m. UTC | #4
On Mon Oct 17, 2022 at 2:25 PM BST, Maxime Devos wrote:
> That's still a circular dependency.  Why import (gnu packages pascal) 
> when you don't need it (e.g. when installing another, non-pascal, 
> package)?  There is some bug report on the excessive dependencies among 
> Guix modules with some proposed solutions.

Wouldn't using #:autoload be a cleaner way that still lazily resolves the variables?

    -- (
M Oct. 17, 2022, 1:37 p.m. UTC | #5
On 17-10-2022 15:28, ( wrote:
> On Mon Oct 17, 2022 at 2:25 PM BST, Maxime Devos wrote:
>> That's still a circular dependency.  Why import (gnu packages pascal)
>> when you don't need it (e.g. when installing another, non-pascal,
>> package)?  There is some bug report on the excessive dependencies among
>> Guix modules with some proposed solutions.
> 
> Wouldn't using #:autoload be a cleaner way that still lazily resolves the variables?
> 
>      -- (

Possibly, I proposed this in
<https://issues.guix.gnu.org/54539#28>.  I tried this in 
<https://issues.guix.gnu.org/54539#62> for a few package modules, with a 
relatively small but noticable improvement (presumably it would be more 
improved by doing it for all package modules instead of only a selection 
and presumably it would be more noticable on a spinning disk instead of 
an SSD).

Greetings,
Maxime.
Ludovic Courtès Oct. 17, 2022, 4:44 p.m. UTC | #6
Maxime Devos <maximedevos@telenet.be> skribis:

> On 17-10-2022 10:33, Ludovic Courtès wrote:
>> Hello!
>> Lars-Dominik Braun <lars@6xq.net> skribis:
>> 
>>> +;; Lazily resolve to avoid a circular dependency.
>>> +(define fpc*
>>> +  (delay (module-ref (resolve-interface '(gnu packages pascal))
>>> +                     'fpc)))
>> I think this is unnecessary: you can just #:use-module (gnu packages
>> pascal) and have ‘fpc’ in ‘native-inputs’.  Everything will be fine
>> because ‘inputs’ is a thunked field (IOW, its evaluation is delayed).
>
> That's still a circular dependency.  Why import (gnu packages pascal)
> when you don't need it

That’s what every package module does.

We can discuss the drawbacks of this and ways to avoid it, but this
particular patch and review is not the right place to do that IMO.

Thanks,
Ludo’.
M Oct. 17, 2022, 5:26 p.m. UTC | #7
On 17-10-2022 18:44, Ludovic Courtès wrote:
> Maxime Devos <maximedevos@telenet.be> skribis:
>[...]
>> That's still a circular dependency.  Why import (gnu packages pascal)
>> when you don't need it
> 
> That’s what every package module does.
> 
> We can discuss the drawbacks of this and ways to avoid it, but this
> particular patch and review is not the right place to do that IMO.

I tried to do that, in https://issues.guix.gnu.org/54539, but there were 
no further responses.

Greetings,
Maxime.
Lars-Dominik Braun Oct. 18, 2022, 7:56 a.m. UTC | #8
Hi Ludo and Maxim,

> I think this is unnecessary: you can just #:use-module (gnu packages
> pascal) and have ‘fpc’ in ‘native-inputs’.  Everything will be fine
> because ‘inputs’ is a thunked field (IOW, its evaluation is delayed).
the problem is that `make` fails with an error in that case. For me it’s

    ice-9/eval.scm:293:34: error: gash: unbound variable
    hint: Did you forget a `use-modules' form?

but YMMV. With #:autoload `make` succeeds, but throws similar
errors/warnings(?) in the process:

    ;;; Failed to autoload fpc in (gnu packages pascal):
    ;;; Throw to key `unbound-variable' with args `("resolve-interface" "no binding `~A' in module ~A" (fpc (gnu packages pascal)) #f)'.

That’s why I went for the route implemented in the initial patch. What
do we do now?

Lars
M Oct. 18, 2022, 12:44 p.m. UTC | #9
On 18-10-2022 09:56, Lars-Dominik Braun wrote:
> [...]
> the problem is that `make` fails with an error in that case. For me it’s
> 
>      ice-9/eval.scm:293:34: error: gash: unbound variable
>      hint: Did you forget a `use-modules' form?
> 
> but YMMV. With #:autoload `make` succeeds, but throws similar
> errors/warnings(?) in the process:
> 
>      ;;; Failed to autoload fpc in (gnu packages pascal):
>      ;;; Throw to key `unbound-variable' with args `("resolve-interface" "no binding `~A' in module ~A" (fpc (gnu packages pascal)) #f)'

Don't know what's up with that, maybe when compiling (gnu packages 
pascal) is imported anyway because 'fpc' might be a macro?

But if I try that in a REPL:

(define-module (foo) #:autoload (bar) ( baz))
;;; Failed to determine exported bindings from module (bar):
;;; no code for module (bar)
;;; Failed to determine exported bindings from module (bar):
;;; no code for module (bar)
$1 = #<directory (foo) 7f31caf71820>

I get other messages (warnings, in this case), so maybe an incorrect 
hypothesis.

> 
> That’s why I went for the route implemented in the initial patch. What
> do we do now?

I think the issue is that (gnu packages pascal) imports (gnu packages 
commencement), even though according to the comment in (gnu packages 
commencement), you aren't supposed to do that (because of cycles).

You could give doing the resolve-module trick in (gnu packages pascal) a 
try.

Greetings,
Maxime
M Oct. 18, 2022, 12:49 p.m. UTC | #10
(To add to my previous reply):

It appears that other package modules may need a similar change, 
according to a "git grep -F":

gnu/packages/engineering.scm:  #:use-module (gnu packages commencement)
gnu/packages/instrumentation.scm:  #:use-module (gnu packages commencement)
gnu/packages/pascal.scm:  #:use-module (gnu packages commencement)
gnu/packages/raspberry-pi.scm:  #:use-module (gnu packages commencement)

Alternatively, importing commencement could be accepted though the 
indirect dependency on 'games' from 'commencement' may need to be broken 
to resolve the error (?) message,  as done in 
<https://issues.guix.gnu.org/54539#62>

I don't remember if (gnu packages games) was one of the modules that was 
removed from the dependencies, though, and I'm not sure if this change 
would resolve things here.

Greetings,
Maxime.
diff mbox series

Patch

diff --git a/gnu/local.mk b/gnu/local.mk
index cd41e6794d..9d9f6b3406 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1900,6 +1900,7 @@  dist_patch_DATA =						\
   %D%/packages/patches/u-boot-sifive-prevent-reloc-initrd-fdt.patch	\
   %D%/packages/patches/u-boot-rk3399-enable-emmc-phy.patch	\
   %D%/packages/patches/ucx-tcp-iface-ioctl.patch		\
+  %D%/packages/patches/ultrastar-deluxe-no-freesans.patch		\
   %D%/packages/patches/ungoogled-chromium-extension-search-path.patch	\
   %D%/packages/patches/ungoogled-chromium-ffmpeg-compat.patch	\
   %D%/packages/patches/ungoogled-chromium-RUNPATH.patch		\
diff --git a/gnu/packages/games.scm b/gnu/packages/games.scm
index 60ce0167a6..30ac153c9a 100644
--- a/gnu/packages/games.scm
+++ b/gnu/packages/games.scm
@@ -11169,6 +11169,97 @@  (define-public freerct
 and unsafe rides.  Which path will you take?")
     (license license:gpl2)))
 
+;; Lazily resolve to avoid a circular dependency.
+(define fpc*
+  (delay (module-ref (resolve-interface '(gnu packages pascal))
+                     'fpc)))
+
+(define-public ultrastar-deluxe
+  ;; The last release is quite old and does not support recent versions of ffmpeg.
+  (let ((commit "43484b0a10ce6aae339e19d81ae2f7b37caf6baa")
+        (revision "1"))
+    (package
+      (name "ultrastar-deluxe")
+      (version (git-version "2020.4.0" revision commit))
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/UltraStar-Deluxe/USDX.git")
+                      (commit commit)))
+                (file-name (git-file-name name version))
+                (sha256
+                 (base32
+                  "078g1rbm1ympmwq9s64v68sxvcms7rr0qid12d2wgm4r04ana47r"))
+                (patches (search-patches "ultrastar-deluxe-no-freesans.patch"))
+                (modules '((guix build utils)))
+                (snippet
+                 `(begin
+                    ;; Remove Windows binaries.
+                    (for-each delete-file (find-files "game" "\\.dll$"))
+                    ;; Remove font blobs.
+                    (let ((font-directories (list "DejaVu" "FreeSans" "NotoSans"
+                                                  "wqy-microhei")))
+                      (for-each
+                        (lambda (d) (delete-file-recursively
+                                      (string-append "game/fonts/" d)))
+                        font-directories))))))
+      (build-system gnu-build-system)
+      (arguments
+        (list
+         #:tests? #f ; No tests.
+         #:phases
+         #~(modify-phases %standard-phases
+           (add-after 'unpack 'fix-configure
+             (lambda* (#:key inputs configure-flags outputs #:allow-other-keys)
+               ;; The configure script looks for lua$version, but we provide lua-$version.
+               (substitute* "configure.ac"
+                 (("lua\\$i") "lua-$i"))
+               ;; fpc does not pass -lfoo to the linker, but uses its own linker script,
+               ;; which references libs. Pass the libraries listed in that linker script,
+               ;; so our custom linker adds a correct rpath.
+               (substitute* "src/Makefile.in"
+                 (("linkflags\\s+:= ")
+                  (string-append "linkflags := -lpthread -lsqlite3 -lSDL2"
+                                 " -lSDL2_image -ldl "
+                                 " -lz -lfreetype -lportaudio -lavcodec"
+                                 " -lavformat -lavutil -lswresample"
+                                 " -lswscale -llua -ldl -lX11 -lportmidi"
+                                 " -L" (dirname (search-input-file inputs "lib/libz.so"))
+                                 " -L" (dirname (search-input-file inputs "lib/libX11.so"))
+                                 " -L" (dirname (search-input-file inputs "lib/libportmidi.so")))))))
+           (add-after 'install 'font-paths
+             (lambda* (#:key outputs #:allow-other-keys)
+               (substitute* (string-append
+                              (assoc-ref outputs "out")
+                              "/share/ultrastardx/fonts/fonts.ini")
+                 (("=NotoSans/") (string-append "=" #$font-google-noto
+                                                "/share/fonts/truetype/"))
+                 (("=DejaVu/") (string-append "=" #$font-dejavu
+                                              "/share/fonts/truetype/"))))))))
+      (inputs (list ffmpeg
+                    font-dejavu
+                    font-google-noto
+                    ; Not needed, since we don’t have freesans.
+                    ;font-wqy-microhei
+                    freetype
+                    libx11
+                    lua
+                    portaudio
+                    portmidi
+                    sdl2
+                    sdl2-image
+                    sqlite
+                    zlib))
+      (native-inputs (list pkg-config (force fpc*) autoconf automake))
+      (synopsis "Karaoke game")
+      (description
+       "UltraStar Deluxe (USDX) is a free and open source karaoke game.  It
+allows up to six players to sing along with music using microphones
+in order to score points, depending on the pitch of the voice and the
+rhythm of singing.")
+      (home-page "https://usdx.eu/")
+      (license license:gpl2+))))
+
 (define-public steam-devices-udev-rules
   ;; Last release from 2019-04-10
   (let ((commit "d87ef558408c5e7a1a793d738db4c9dc2cb5f8fa")
diff --git a/gnu/packages/patches/ultrastar-deluxe-no-freesans.patch b/gnu/packages/patches/ultrastar-deluxe-no-freesans.patch
new file mode 100644
index 0000000000..7beba80774
--- /dev/null
+++ b/gnu/packages/patches/ultrastar-deluxe-no-freesans.patch
@@ -0,0 +1,31 @@ 
+Remove references to FreeSans font, which is not packaged for Guix.
+
+--- a/game/fonts/fonts.ini	1970-01-01 01:00:01.000000000 +0100
++++ b/game/fonts/fonts.ini	2022-09-16 14:31:51.483096847 +0200
+@@ -116,26 +116,6 @@
+ BoldHighResPreCache=0
+ BoldHighResOutline=0.02
+ 
+-[Font_FreeSans]
+-Name=Free Sans
+-RegularFile=FreeSans/FreeSans.ttf
+-RegularFallbackFile1=wqy-microhei/wqy-microhei.ttc
+-;RegularGlyphSpacing=1.4
+-;RegularStretch=1.2
+-BoldFile=FreeSans/FreeSansBold.ttf
+-BoldFallbackFile1=wqy-microhei/wqy-microhei.ttc
+-;BoldEmbolden=0.06
+-OutlineFile=FreeSans/FreeSansBold.ttf
+-OutlineOutline=0.06
+-;OutlineColorR=0.3
+-;OutlineColorG=0.3
+-;OutlineColorB=0.3
+-;OutlineColorA=0.3
+-BoldHighResFile=FreeSans/FreeSansBold.ttf
+-BoldHighResMaxResolution=256
+-BoldHighResPreCache=0
+-BoldHighResOutline=0.02
+-
+ [Font_DejaVuSans]
+ Name=DejaVu Sans
+ RegularFile=DejaVu/DejaVuSans.ttf