massung / r-cade

Retro Game Engine for Racket
https://r-cade.io
Other
273 stars 13 forks source link

How to create a standalone executable for r-cade? #20

Open sjqtentacles opened 4 years ago

sjqtentacles commented 4 years ago

Hello!

I was wondering how I could create a distribution with raco and r-cade. I tried something like

raco exe --gui main.rkt then raco distribute maindist main.app

it produced a directory called maindist with main.app inside, but when I tried to give it to a friend, they ran it and nothing happened. Just using the tetris music tutorial program as an example. I'm wondering if there are any special instructions for creating a distribution for r-cade that I'm missing? I usually just went into DrRacket to make these but I'm using the cli more for this library.

massung commented 4 years ago

Well, on Mac I'm not 100% sure since the .app is supposed to have everything it needs.

But, you'll need to package up all the dynamic libraries (dylib) with your app as well. For example, the CSFML dynamic libraries, libsndfile, and OpenAL.

I assume you can add these inside the .app folder (right-click your .app and choose "Open Contents" to see it in the Finder so you can drag/drop stuff in there) and they can just sit next to your executable. Or there may be a special "libraries" folder inside it where you are supposed to put them. I don't know.

On Windows, I just make a ZIP file of the final executable produced by Racket and copy all the DLL files into the ZIP and they are in the same folder as the EXE file.

Let me know if this helps. You may want to ask on the Racket Slack as well. It's possible there's an option when building that will include all the libraries for you?

massung commented 4 years ago

@Nixonite I had a couple other thoughts/things to check:

  1. I assumed originally that you could successfully run the .app on your machine. Is that the case?
  2. If the answer to (1) is "no", then make sure your code actually does something (this has bit me in the past). For example:
(define (play-game)
  (run ...))

That program will "launch" in that will load and then immediate exit because it never actually calls the play-game function. Make sure it does:

(define (play-game)
  (run ...))

;; actually run the program
(play-game)
sjqtentacles commented 4 years ago

Hello @massung

I took your advice and went onto the racket slack channel, seems like it's not so active there :/ even with 1000+ users in general. I tried copying whole directories like /usr/local/Cellar/csfml/ to various locations in the main.app package like under Contents/MacOS/ and Contents/Resources/ and just in Contents/, my friend who tested the variations said "nothing happened". And yes! It "works on my machine"

I tried the tetris song, didn't work on my friend's machine.

I also tried a drawing program to make a triforce, still nothing

full source:

#lang racket

(require r-cade)

(define (triforce x y)
    (color 10)
    (draw x y '(#b00011000))
    (draw x (+ 1 y) '(#b00111100))
    (draw x (+ 2 y) '(#b01111110))
    (draw x (+ 3 y) '(#b11111111))

    (draw (- x 5) (+ 5 y) '(#b00011000))
    (draw (- x 5) (+ 6 y) '(#b00111100))
    (draw (- x 5) (+ 7 y) '(#b01111110))
    (draw (- x 5) (+ 8 y) '(#b11111111))

    (draw (+ 5 x) (+ 5 y) '(#b00011000))
    (draw (+ 5 x) (+ 6 y) '(#b00111100))
    (draw (+ 5 x) (+ 7 y) '(#b01111110))
    (draw (+ 5 x) (+ 8 y) '(#b11111111)))

(define (game-loop)
  (cls)
  ; draw a box with a redicule
  (when (btn-z)
    (let ([x (mouse-x)]
          [y (mouse-y)])
         (triforce x y))))

(define (play-game)
  (run game-loop 128 128))

(play-game)

with your modification ^

compiled with raco exe --gui main.rkt to produce main.app

$ tree main.app/
main.app/
└── Contents
    ├── Info.plist
    ├── MacOS
    │   └── main
    ├── PkgInfo
    └── Resources
        └── Starter.icns
sjqtentacles commented 4 years ago

@massung Update!

I ran this command to package up the libraries you mentioned in your setup page:

raco distribute ++collects-copy /usr/local/Cellar/csfml/ ++collects-copy /usr/local/Cellar/openal-soft/ ++collects-copy /usr/local/Cellar/libsndfile/ ++collects-copy /usr/local/Cellar/libffi/ dist main.app

At first I didn't include the libffi directory, but after seeing the following error (reported by my friend) I included it

ffi-lib: couldn't open "libcsfml-audio.dylib" (dlopen(libcsfml-audio.dylib, 6): image not found)
  context...:
   /Applications/Racket v7.6/collects/ffi/unsafe.rkt:131:0: get-ffi-lib
   '#%embedded:csfml/audio:: [running body]
   temp35_0
   for-loop
   run-module-instance!
   for-loop
   [repeats 1 more time]
   run-module-instance!
   for-loop
   [repeats 1 more time]
   run-module-instance!
   for-loop
   [repeats 1 more time]
   run-module-instance!
   perform-require!
   top-level: [running body]
   ...
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

strangely I still get the same error... not sure whatsup there