unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#61243] Add WASM-4 fantasy console and prerequisites
@ 2023-02-02 23:31 Thompson, David
  2023-02-03 12:48 ` Christine Lemmer-Webber
  2023-02-04  9:43 ` dan
  0 siblings, 2 replies; 4+ messages in thread
From: Thompson, David @ 2023-02-02 23:31 UTC (permalink / raw)
  To: 61243

[-- Attachment #1: Type: text/plain, Size: 526 bytes --]

Hello all,

This set of 4 patches adds WASM-4 (https://wasm4.org/), a fantasy
console that runs game "cartridges" compiled to WebAssembly.  It's a
fun way to learn about WebAssembly using a relatively simple system.
I've seen a WASM-4 game that was assembled using Racket, which I
thought was pretty neat.  It would be even cooler if someone did
something like that with Guile!

Packaging this thing was not exactly straightforward due to dependency
bundling via git submodules, but I was able to unbundle everything.

- Dave

[-- Attachment #2: 0002-gnu-Add-minifb.patch --]
[-- Type: text/x-patch, Size: 3015 bytes --]

From 110f6962f309ac3a7cb858210eed31b1098514f8 Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
Date: Thu, 2 Feb 2023 14:27:13 -0500
Subject: [PATCH 2/4] gnu: Add minifb.

* gnu/packages/graphics.scm (minifb): New variable.
---
 gnu/packages/graphics.scm | 44 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/gnu/packages/graphics.scm b/gnu/packages/graphics.scm
index ebf571d93e..1c5f429084 100644
--- a/gnu/packages/graphics.scm
+++ b/gnu/packages/graphics.scm
@@ -34,6 +34,7 @@
 ;;; Copyright © 2022 Paul A. Patience <paul@apatience.com>
 ;;; Copyright © 2022 dan <i@dan.games>
 ;;; Copyright © 2023 Sharlatan Hellseher <sharlatanus@gmail.com>
+;;; Copyright © 2023 David Thompson <dthompson2@worcester.edu>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -234,6 +235,49 @@ (define-public directfb
     (home-page "https://github.com/deniskropp/DirectFB")
     (license license:lgpl2.1+)))
 
+(define-public minifb
+  (let ((commit "43f8c1309341f4709a471b592d04434326042483")
+        (revision "1"))
+    (package
+      (name "minifb")
+      (version (git-version "0" revision commit))
+      (source (origin
+                (method git-fetch)
+                (uri
+                 (git-reference
+                  (url "https://github.com/emoon/minifb")
+                  (commit commit)))
+                (file-name (git-file-name name version))
+                (sha256
+                 (base32 "1z0720azsgi83yg4ysmfvpvsg0566s2cq59xx52w8w5rpkla4cjh"))))
+      (build-system cmake-build-system)
+      (arguments
+       '(#:configure-flags '("-DMINIFB_BUILD_EXAMPLES=0")
+         #:phases
+         (modify-phases %standard-phases
+           (replace 'install
+             (lambda* (#:key outputs #:allow-other-keys)
+               (let* ((out (assoc-ref outputs "out"))
+                      (includedir (string-append out "/include"))
+                      (libdir (string-append out "/lib")))
+                 (mkdir-p includedir)
+                 (mkdir-p libdir)
+                 (for-each (lambda (header)
+                             (copy-file header
+                                        (string-append includedir "/"
+                                                       (basename header))))
+                           (find-files "../source/include" "\\.h$"))
+                 (copy-file "libminifb.a" (string-append libdir "/libminifb.a"))))))
+         ;; No check target.
+         #:tests? #f))
+      ;; libminifb.a won't work without these libraries, so propagate them.
+      (propagated-inputs (list libx11 libxkbcommon mesa))
+      (synopsis "Small library for rendering pixels to a framebuffer")
+      (description "MiniFB (Mini FrameBuffer) is a small, cross-platform
+library that makes it easy to render (32-bit) pixels in a window.")
+      (home-page "https://github.com/emoon/minifb")
+      (license license:expat))))
+
 (define-public flux
   (package
     (name "flux")
-- 
2.39.1


[-- Attachment #3: 0004-gnu-Add-wasm4.patch --]
[-- Type: text/x-patch, Size: 3965 bytes --]

From e021e8a679693e92af76e7444eab86245d3763c7 Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
Date: Thu, 2 Feb 2023 17:50:03 -0500
Subject: [PATCH 4/4] gnu: Add wasm4.

* gnu/packages/emulators.scm (wasm4): New variable.
---
 gnu/packages/emulators.scm | 54 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 53 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/emulators.scm b/gnu/packages/emulators.scm
index 7c04465526..47cb175d81 100644
--- a/gnu/packages/emulators.scm
+++ b/gnu/packages/emulators.scm
@@ -3,7 +3,7 @@
 ;;; Copyright © 2015 Paul van der Walt <paul@denknerd.org>
 ;;; Copyright © 2015, 2016, 2021 Sou Bunnbu <iyzsong@member.fsf.org>
 ;;; Copyright © 2015, 2016 Taylan Ulrich Bayırlı/Kammer <taylanbayirli@gmail.com>
-;;; Copyright © 2015, 2018 David Thompson <dthompson2@worcester.edu>
+;;; Copyright © 2015, 2018, 2023 David Thompson <dthompson2@worcester.edu>
 ;;; Copyright © 2016 Manolis Fragkiskos Ragkousis <manolis837@gmail.com>
 ;;; Copyright © 2016, 2017, 2018, 2020 Efraim Flashner <efraim@flashner.co.il>
 ;;; Copyright © 2017-2023 Nicolas Goaziou <mail@nicolasgoaziou.fr>
@@ -74,6 +74,7 @@ (define-module (gnu packages emulators)
   #:use-module (gnu packages gl)
   #:use-module (gnu packages glib)
   #:use-module (gnu packages gnome)
+  #:use-module (gnu packages graphics)
   #:use-module (gnu packages gtk)
   #:use-module (gnu packages image)
   #:use-module (gnu packages libedit)
@@ -1506,6 +1507,57 @@ (define-public retroarch
 multi-system game/emulator system.")
     (license license:gpl3+)))
 
+(define-public wasm4
+  (package
+    (name "wasm4")
+    (version "2.5.4")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/aduros/wasm4")
+                    (commit (string-append "v" version))))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "0ycnznwy4i4fw6l507y5xm986rxqvnpl971725q8xinsnq2swpnl"))))
+    (build-system cmake-build-system)
+    (arguments
+     (list
+      #:tests? #f ; no check target
+      #:configure-flags
+      #~(list (string-append "-DCMAKE_C_FLAGS="
+                             "-I" #$minifb "/include "
+                             "-I" #$wasm3 "/include"))
+      #:phases
+      '(modify-phases %standard-phases
+         ;; WASM4's source is a combination of multiple runtimes.  We want to
+         ;; build the native one.
+         (add-after 'unpack 'chdir-to-native-runtime
+           (lambda _
+             (chdir "runtimes/native")))
+         ;; WASM4 uses git submodules to bundle several dependencies, which we
+         ;; have instead made dedicated packages for.  This phase hacks the
+         ;; build system to use our own stuff.
+         (add-after 'chdir-to-native-runtime 'unbundle
+           (lambda _
+             (substitute* "CMakeLists.txt"
+               ;; These directories do not exist because we aren't pulling in
+               ;; submodules.
+               (("add_subdirectory\\(vendor/minifb\\)") "")
+               (("add_subdirectory\\(vendor/cubeb\\)") "")
+               ;; Add additional libraries needed to successfully link the
+               ;; wasm4 executable using the unbundled dependencies.
+               (("target_link_libraries\\(wasm4 minifb cubeb\\)")
+                "target_link_libraries(wasm4 m GL X11 xkbcommon minifb cubeb m3)")))))))
+    (inputs (list cubeb minifb wasm3))
+    (synopsis "WebAssembly fantasy console")
+    (description "WASM-4 is a low-level fantasy game console for building
+small games with WebAssembly.  Game cartridges (ROMs) are small,
+self-contained .wasm files that can be built with any programming language
+that compiles to WebAssembly.")
+    (home-page "https://wasm4.org")
+    (license license:isc)))
+
 (define-public scummvm
   (package
     (name "scummvm")
-- 
2.39.1


[-- Attachment #4: 0003-gnu-Add-cubeb.patch --]
[-- Type: text/x-patch, Size: 2502 bytes --]

From fa77f71c3f16db398eae0ed11453b8db077c6fe3 Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
Date: Thu, 2 Feb 2023 15:06:59 -0500
Subject: [PATCH 3/4] gnu: Add cubeb.

* gnu/packages/audio.scm (cubeb): New variable.
---
 gnu/packages/audio.scm | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/gnu/packages/audio.scm b/gnu/packages/audio.scm
index 4fbfefafa3..9c4bfa7609 100644
--- a/gnu/packages/audio.scm
+++ b/gnu/packages/audio.scm
@@ -41,6 +41,7 @@
 ;;; Copyright © 2022 Simon Streit <simon@netpanic.org>
 ;;; Copyright © 2022 Andy Tai <atai@atai.org>
 ;;; Copyright © 2023 Sergiu Ivanov <sivanov@colimite.fr>
+;;; Copyright © 2023 David Thompson <dthompson2@worcester.edu>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -6159,3 +6160,39 @@ (define-public streamripper
 separation data, and uses that as a marker for where the track should
 be separated.")
     (license license:gpl2+)))
+
+(define-public cubeb
+  (let ((commit "9e29d728b0025c674904f83f5a13a88d1a6a5edc")
+        (revision "1"))
+    (package
+      (name "cubeb")
+      (version (git-version "0" revision commit))
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/mozilla/cubeb")
+                      (commit commit)))
+                (file-name (git-file-name name version))
+                (sha256
+                 (base32
+                  "1sxkr3h8a4hd3c3a3cjydrszz6npxk3vh6ra3y67lds3zgc69c7n"))))
+      (build-system cmake-build-system)
+      (arguments
+       '(#:configure-flags
+         ;; Sanitizers-cmake requires a git submodule.
+         '("-DUSE_SANITIZERS=0"
+           ;; Tests require a git submodule for googletest.
+           "-DBUILD_TESTS=0"
+           ;; Use our speex, not a bundled one.
+           "-DBUNDLE_SPEEX=0"
+           ;; A static library would be built by default.
+           "-DBUILD_SHARED_LIBS=1"
+           ;; Explicitly link against audio libraries so they are on the
+           ;; runpath.  Otherwise cubeb tries to dlopen them at runtime.
+           "-DCMAKE_SHARED_LINKER_FLAGS=-lasound -lpulse -lspeex")
+         #:tests? #f))
+      (inputs (list alsa-lib pulseaudio speex))
+      (synopsis "Cross-platform audio library")
+      (description "Cubeb is Mozilla's cross-platforom audio library.")
+      (home-page "https://github.com/mozilla/cubeb")
+      (license license:isc))))
-- 
2.39.1


[-- Attachment #5: 0001-gnu-Add-wasm3.patch --]
[-- Type: text/x-patch, Size: 3096 bytes --]

From e227587b4e50313fdbda4acf7992b7a4ded23260 Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
Date: Thu, 2 Feb 2023 14:04:48 -0500
Subject: [PATCH 1/4] gnu: Add wasm3.

* gnu/packages/web.scm (wasm3): New variable.
---
 gnu/packages/web.scm | 48 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index a29f53108c..c527ff80df 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -61,6 +61,7 @@
 ;;; Copyright © 2022 jgart <jgart@dismail.de>
 ;;; Copyright © 2023 Paul A. Patience <paul@apatience.com>
 ;;; Copyright © 2022 Bruno Victal <mirai@makinata.eu>
+;;; Copyright © 2023 David Thompson <dthompson2@worcester.edu>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1557,6 +1558,53 @@ (define-public wabt
 other systems that want to manipulate WebAssembly files.")
     (license license:asl2.0)))
 
+(define-public wasm3
+  (package
+    (name "wasm3")
+    (version "0.5.0")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/wasm3/wasm3")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "07zzmk776j8ydyxhrnnjiscbhhmz182a62r6aix6kfk5kq2cwia2"))))
+    (build-system cmake-build-system)
+    (arguments
+     ;; The default WASI option "uvwasi" causes CMake to initiate a 'git
+     ;; clone' which cannot happen within the build container.
+     '(#:configure-flags '("-DBUILD_WASI=simple")
+       ;; No check target.  There are tests but they require a network
+       ;; connection to download the WebAssembly core test suite.
+       #:tests? #f
+       ;; There is no install target.  Instead, we have to manually copy the
+       ;; wasm3 build artifacts to the output directory.
+       #:phases
+       (modify-phases %standard-phases
+         (replace 'install
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (bindir (string-append out "/bin"))
+                    (includedir (string-append out "/include"))
+                    (libdir (string-append out "/lib")))
+               (mkdir-p bindir)
+               (mkdir-p includedir)
+               (mkdir-p libdir)
+               (copy-file "wasm3" (string-append bindir "/wasm3"))
+               (for-each (lambda (header)
+                           (copy-file header
+                                      (string-append includedir "/"
+                                                     (basename header))))
+                         (find-files "../source/source" "\\.h$"))
+               (copy-file "source/libm3.a"
+                          (string-append libdir "/libm3.a"))))))))
+    (home-page "https://github.com/wasm3/wasm3")
+    (synopsis "WebAssembly interpreter")
+    (description "WASM3 is a fast WebAssembly interpreter.")
+    (license license:expat)))
+
 (define-public websocketpp
   (package
     (name "websocketpp")
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [bug#61243] Add WASM-4 fantasy console and prerequisites
  2023-02-02 23:31 [bug#61243] Add WASM-4 fantasy console and prerequisites Thompson, David
@ 2023-02-03 12:48 ` Christine Lemmer-Webber
  2023-02-03 13:11   ` Thompson, David
  2023-02-04  9:43 ` dan
  1 sibling, 1 reply; 4+ messages in thread
From: Christine Lemmer-Webber @ 2023-02-03 12:48 UTC (permalink / raw)
  To: Thompson, David; +Cc: 61243

"Thompson, David" <dthompson2@worcester.edu> writes:

> Hello all,
>
> This set of 4 patches adds WASM-4 (https://wasm4.org/), a fantasy
> console that runs game "cartridges" compiled to WebAssembly.  It's a
> fun way to learn about WebAssembly using a relatively simple system.
> I've seen a WASM-4 game that was assembled using Racket, which I
> thought was pretty neat.  It would be even cooler if someone did
> something like that with Guile!

Wouldn't it be cool indeed?  I wonder if we can see progress on this in
Guile-land?  Maybe someone should take up the torch for the Guile and
WASM story.

> Packaging this thing was not exactly straightforward due to dependency
> bundling via git submodules, but I was able to unbundle everything.

Impressive!  This doesn't look like it was easy to figure out.

I reviewed all four patches.  Despite some custom stuff on most of
these, they all look well commented and sensible.  I say push it!

 - Christine





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [bug#61243] Add WASM-4 fantasy console and prerequisites
  2023-02-03 12:48 ` Christine Lemmer-Webber
@ 2023-02-03 13:11   ` Thompson, David
  0 siblings, 0 replies; 4+ messages in thread
From: Thompson, David @ 2023-02-03 13:11 UTC (permalink / raw)
  To: Christine Lemmer-Webber; +Cc: 61243-done, 61243

Hi Christine,

On Fri, Feb 3, 2023 at 7:53 AM Christine Lemmer-Webber
<cwebber@dustycloud.org> wrote:
>
> "Thompson, David" <dthompson2@worcester.edu> writes:
>
> > Hello all,
> >
> > This set of 4 patches adds WASM-4 (https://wasm4.org/), a fantasy
> > console that runs game "cartridges" compiled to WebAssembly.  It's a
> > fun way to learn about WebAssembly using a relatively simple system.
> > I've seen a WASM-4 game that was assembled using Racket, which I
> > thought was pretty neat.  It would be even cooler if someone did
> > something like that with Guile!
>
> Wouldn't it be cool indeed?  I wonder if we can see progress on this in
> Guile-land?  Maybe someone should take up the torch for the Guile and
> WASM story.

That sure would be cool!

Small correction: The thing I saw that used Racket to create
WebAssembly output doesn't actually run on WASM-4, it just kinda
looked like it did. Oops!  It's still very cool!
https://github.com/euhmeuh/wasm-adventure

> > Packaging this thing was not exactly straightforward due to dependency
> > bundling via git submodules, but I was able to unbundle everything.
>
> Impressive!  This doesn't look like it was easy to figure out.
>
> I reviewed all four patches.  Despite some custom stuff on most of
> these, they all look well commented and sensible.  I say push it!

Thanks for the review!  I found a typo in the description field of
cubeb that I've fixed, and I added some additional comments explaining
the minifb build customizations.  I pushed the patches with those
changes!

- Dave




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [bug#61243] Add WASM-4 fantasy console and prerequisites
  2023-02-02 23:31 [bug#61243] Add WASM-4 fantasy console and prerequisites Thompson, David
  2023-02-03 12:48 ` Christine Lemmer-Webber
@ 2023-02-04  9:43 ` dan
  1 sibling, 0 replies; 4+ messages in thread
From: dan @ 2023-02-04  9:43 UTC (permalink / raw)
  To: 61243

just saw this news: 
https://spritely.institute/news/guile-on-web-assembly-project-underway.html

-- 
dan




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-02-04  9:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 23:31 [bug#61243] Add WASM-4 fantasy console and prerequisites Thompson, David
2023-02-03 12:48 ` Christine Lemmer-Webber
2023-02-03 13:11   ` Thompson, David
2023-02-04  9:43 ` dan

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).