pd-rs / crankstart

A barely functional, wildly incomplete and basically undocumented Rust crate whose aim is to let you write Games for the Playdate handheld gaming system in Rust.
MIT License
235 stars 24 forks source link

Couldn't find pdz file main.pdz #41

Open pomettini opened 1 year ago

pomettini commented 1 year ago

Hi,

I've been using Crankstart to test my Chip-8 emulator on the Playdate Simulator and it's been a joy to use! <3

I was curious if my "game" would also run on my real Playdate, but every time try to I upload the package with Device > Upload the device crashes and displays the message: Couldn't find pdz file main.pdz

Curiously, I double-checked if it was also happening with the examples, with the Klondike and the Nine Lives demo, and it was indeed happening in all of the cases

The output .pdx file contains:

While on a Playdate game the package usually contains:

I'm on nightly-aarch64-apple-darwin and I'm running Crank and Crankstart on a M1 Pro Macbook Pro

Do you perhaps have any suggestions? I've tried everything but to no avail πŸ˜”

Thank you

rtsuk commented 1 year ago

That wasn't the case a few months ago, but I'll take a look tomorrow and see what I can learn.

rtsuk commented 1 year ago

I can't reproduce this with Klondike on my M1 MacBook Air running 13.3.1 (22E261).

What does crank -V tell you?

pomettini commented 1 year ago

I can't reproduce this with Klondike on my M1 MacBook Air running 13.3.1 (22E261).

What does crank -V tell you?

Hi @rtsuk thank you for the quick reply πŸ™‚

The command crank -V gives me crank 0.2.8

pomettini commented 1 year ago

I made the repository public if you want to give it a try https://github.com/Pomettini/yet-another-chip-8-emulator/tree/main/playdate (sorry the project is a bit messy haha πŸ˜…)

tjkirch commented 1 year ago

I know this is something that can happen with a game misconfiguration or a weird command rather than a crankstart issue because I see it once in a while when I change something, but I can't quite remember what it is at the moment... I'll see if I can track it down.

rtsuk commented 1 year ago

I was able to compile it and run it fine on the device.

What does rustc +nightly -V say?

pomettini commented 1 year ago

I was able to compile it and run it fine on the device.

What does rustc +nightly -V say?

It prints rustc 1.71.0-nightly (458d4dae8 2023-04-25)

pomettini commented 1 year ago

This is what is says if I run crank -v run --release

 INFO  crank > starting
 INFO  crank > manifest = Manifest {
    targets: [
        Target {
            name: "chip8-playdate",
            assets: Some(
                [],
            ),
            metadata: Some(
                Metadata {
                    name: Some(
                        "Chip8 Playdate",
                    ),
                    author: Some(
                        "Giorgio Pomettini",
                    ),
                    description: Some(
                        "",
                    ),
                    bundle_id: Some(
                        "com.pomettini.chip8pd",
                    ),
                    version: Some(
                        "0.1",
                    ),
                    build_number: None,
                    image_path: Some(
                        "assets/launcher",
                    ),
                    launch_sound_path: None,
                },
            ),
        },
    ],
}
 INFO  crank > building
 INFO  crank > build command: "cargo" "build" "--lib" "--release"
    Finished release [optimized] target(s) in 0.02s
 INFO  crank > make_source_dir
 INFO  crank > link_dylib
 INFO  crank > copy_assets
 INFO  crank > make_manifest
 INFO  crank > run_pdc
 INFO  crank > run_simulator
rtsuk commented 1 year ago

I was just going to ask that, but with --device.

pomettini commented 1 year ago

I was just going to ask that, but with --device.

Sure thing!

 INFO  crank > starting
 INFO  crank > manifest = Manifest {
    targets: [
        Target {
            name: "chip8-playdate",
            assets: Some(
                [],
            ),
            metadata: Some(
                Metadata {
                    name: Some(
                        "Chip8 Playdate",
                    ),
                    author: Some(
                        "Giorgio Pomettini",
                    ),
                    description: Some(
                        "",
                    ),
                    bundle_id: Some(
                        "com.pomettini.chip8pd",
                    ),
                    version: Some(
                        "0.1",
                    ),
                    build_number: None,
                    image_path: Some(
                        "assets/launcher",
                    ),
                    launch_sound_path: None,
                },
            ),
        },
    ],
}
 INFO  crank > building
 INFO  crank > build command: "cargo" "+nightly" "build" "--lib" "--release" "--target" "thumbv7em-none-eabihf"
warning: dropping unsupported crate type `cdylib` for target `thumbv7em-none-eabihf`

warning: `chip8_playdate` (lib) generated 1 warning
    Finished release [optimized] target(s) in 0.03s
 INFO  crank > make_source_dir
 INFO  crank > compile_setup: "/usr/local/bin/arm-none-eabi-gcc" "-g" "-c" "-mthumb" "-mcpu=cortex-m7" "-mfloat-abi=hard" "-mfpu=fpv4-sp-d16" "-D__FPU_USED=1" "-O2" "-falign-functions=16" "-fomit-frame-pointer" "-gdwarf-2" "-Wall" "-Wno-unused" "-Wstrict-prototypes" "-Wno-unknown-pragmas" "-fverbose-asm" "-ffunction-sections" "-fdata-sections" "-DTARGET_PLAYDATE=1" "-DTARGET_EXTENSION=1" "/Users/pomettini/Developer/PlaydateSDK/C_API/buildsupport/setup.c" "-I" "/Users/pomettini/Developer/PlaydateSDK/C_API" "-o" "/Users/pomettini/Git/yet-another-chip-8-emulator/playdate/target/thumbv7em-none-eabihf/release/setup.o"
 INFO  crank > link_binary: "/usr/local/bin/arm-none-eabi-gcc" "/Users/pomettini/Git/yet-another-chip-8-emulator/playdate/target/thumbv7em-none-eabihf/release/setup.o" "/Users/pomettini/Git/yet-another-chip-8-emulator/playdate/target/thumbv7em-none-eabihf/release/libchip8_playdate.a" "-mthumb" "-mcpu=cortex-m7" "-mfloat-abi=hard" "-mfpu=fpv4-sp-d16" "-D__FPU_USED=1" "-Wl,--gc-sections,--no-warn-mismatch" "-T" "/Users/pomettini/Developer/PlaydateSDK/C_API/buildsupport/link_map.ld" "-o" "/Users/pomettini/Git/yet-another-chip-8-emulator/playdate/target/thumbv7em-none-eabihf/release/chip8_playdate.elf"
 INFO  crank > make_binary: "/usr/local/bin/arm-none-eabi-objcopy" "-O" "binary" "/Users/pomettini/Git/yet-another-chip-8-emulator/playdate/target/thumbv7em-none-eabihf/release/chip8_playdate.elf" "/Users/pomettini/Git/yet-another-chip-8-emulator/playdate/target/thumbv7em-none-eabihf/release/chip8_playdate.bin"
 INFO  crank > copy_assets
 INFO  crank > make_manifest
 INFO  crank > run_pdc
 INFO  crank > run_target
tjkirch commented 1 year ago

It prints rustc 1.71.0-nightly (458d4dae8 2023-04-25)

It's worth trying an older nightly - I've been using nightly-2023-02-09 for some time with no issues. Newer nightlies introduce problems like https://github.com/rust-lang/rust/issues/109934 that cause compilation failures, and are taking some time to address upstream.

rtsuk commented 1 year ago

It's working fine for me on almost exactly the same host hardware and rustc 1.71.0-nightly (458d4dae8 2023-04-25).

rtsuk commented 1 year ago

So, I went back and reread your initial message and see you're trying to useDevice > Upload, which I've not tried in years and which shouldn't be necessary. crank run should copy the package to the device and launch it.

rtsuk commented 1 year ago

I also see that when you run, logging stops after INFO crank > run_target. I get

INFO  crank > datadisk cmd: Command {
    program: "/Users/rob/Developer/PlaydateSDK/bin/pdutil",
    args: [
        "/Users/rob/Developer/PlaydateSDK/bin/pdutil",
        "/dev/cu.usbmodemPDU1_Y0005491",
        "datadisk",
        "/Users/rob/projects/playdate/yet-another-chip-8-emulator/playdate/target/Chip8 Playdate.pdx",
    ],
}
 INFO  crank > copy_directory "/Users/rob/projects/playdate/yet-another-chip-8-emulator/playdate/target/Chip8 Playdate.pdx" -> "/Volumes/PLAYDATE/Games/Chip8 Playdate.pdx"
 INFO  crank > copy_file "/Users/rob/projects/playdate/yet-another-chip-8-emulator/playdate/target/Chip8 Playdate.pdx/pdex.dylib" -> "/Volumes/PLAYDATE/Games/Chip8 Playdate.pdx/pdex.dylib"
 INFO  crank > copy_file "/Users/rob/projects/playdate/yet-another-chip-8-emulator/playdate/target/Chip8 Playdate.pdx/pdxinfo" -> "/Volumes/PLAYDATE/Games/Chip8 Playdate.pdx/pdxinfo"
 INFO  crank > copy_file "/Users/rob/projects/playdate/yet-another-chip-8-emulator/playdate/target/Chip8 Playdate.pdx/pdex.bin" -> "/Volumes/PLAYDATE/Games/Chip8 Playdate.pdx/pdex.bin"
 INFO  crank > eject cmd: Command {
    program: "diskutil",
    args: [
        "diskutil",
        "eject",
        "/Volumes/PLAYDATE",
    ],
}
Disk /Volumes/PLAYDATE ejected
 INFO  crank > run cmd: Command {
    program: "/Users/rob/Developer/PlaydateSDK/bin/pdutil",
    args: [
        "/Users/rob/Developer/PlaydateSDK/bin/pdutil",
        "/dev/cu.usbmodemPDU1_Y0005491",
        "run",
        "/Games/Chip8 Playdate.pdx",
    ],
}

If you are up for it, you could improve the logging in crank around the run command and see where it is failing.

rtsuk commented 1 year ago

Also, Device > Upload works for me.

pomettini commented 1 year ago

Unfortunately downgrading Rust to nightly-2023-02-09 didn't help. By the way, I fear that even if the .pdx would be uploaded without using the emulator, it's still missing the main.pdz file in the package, so the game crashes as the device won't find an entry point πŸ˜”

rtsuk commented 1 year ago

I'm not sure why there needs to be a main.pdz file. I don't have one and it works fine for me.

rob@RoboAir ~ % ls -l /Volumes/PLAYDATE/Games/Chip8\ Playdate.pdx 
total 264
-rwxrwxrwx  1 rob  staff  27784 Apr 27 07:39 pdex.bin
-rwxrwxrwx  1 rob  staff  99092 Apr 27 07:39 pdex.dylib
-rwxrwxrwx  1 rob  staff     37 Apr 27 07:39 pdxinfo
pomettini commented 1 year ago

I'm not sure why there needs to be a main.pdz file. I don't have one and it works fine for me.

rob@RoboAir ~ % ls -l /Volumes/PLAYDATE/Games/Chip8\ Playdate.pdx 
total 264
-rwxrwxrwx  1 rob  staff  27784 Apr 27 07:39 pdex.bin
-rwxrwxrwx  1 rob  staff  99092 Apr 27 07:39 pdex.dylib
-rwxrwxrwx  1 rob  staff     37 Apr 27 07:39 pdxinfo

I tried uploading the game from the simulator out of curiosity and... Inexplicably, it worked 🀯

I can't say exactly what caused this. I thought that was related to the main.pdz file since the device was telling me it needed that file, but apparently it wasn't the case. I will investigate on the matter, and also try to figure out why crank run --device hangs on my machine πŸ’ͺ

Meanwhile, thank you so much @rtsuk and @tjkirch for the patience and the quick replies! I really appreciate it! 😊

tjkirch commented 1 year ago

I'm curious to see what you find about the hanging, if it's reproducible! I'd try running through strace - that's how I figured out an issue with the commands pdutil (via PlaydateSimulator) was sending to the device. Something like strace -f -s256 -o sim.trace -- PlaydateSimulator and then try to upload the game from the simulator. Or run crank run --device through strace instead, if that's the problem area. There will be a ton in the output file, but something may stick out about the pdutil call, or something else in that area.

My understanding is that pdz files are compiled lua, and since with crankstart we don't use any lua, it shouldn't be necessary; if it's looking for pdz, my suspicion is that the pdx is missing something that tells Playdate it's a C game. The target/GAME.pdx should have pdxinfo, pdex.bin, and pdex.so/pdex.dylib files, which yours does, so I'm not sure. FWIW, my pdxinfo only has name, version, pdxversion, and buildtime, so not much is required there. I really wish I could remember what caused this for me before, I'm sorry.

pomettini commented 1 year ago

I'm curious to see what you find about the hanging, if it's reproducible! I'd try running through strace - that's how I figured out an issue with the commands pdutil (via PlaydateSimulator) was sending to the device. Something like strace -f -s256 -o sim.trace -- PlaydateSimulator and then try to upload the game from the simulator. Or run crank run --device through strace instead, if that's the problem area. There will be a ton in the output file, but something may stick out about the pdutil call, or something else in that area.

My understanding is that pdz files are compiled lua, and since with crankstart we don't use any lua, it shouldn't be necessary; if it's looking for pdz, my suspicion is that the pdx is missing something that tells Playdate it's a C game. The target/GAME.pdx should have pdxinfo, pdex.bin, and pdex.so/pdex.dylib files, which yours does, so I'm not sure. FWIW, my pdxinfo only has name, version, pdxversion, and buildtime, so not much is required there. I really wish I could remember what caused this for me before, I'm sorry.

I'm on Mac so I can't use strace I'm afraid πŸ˜”

By the way, while I was randomly testing stuff, the simulator was not updating the build on the device, so I deleted the target folder with cargo clean and... now I'm getting the same missing main.pdz error again πŸ˜”

rtsuk commented 1 year ago

Make sure that macOS isn't asking for permissions while crank is running. I think I saw some of those while testing just now and it caused crank to hang.

tjkirch commented 1 year ago

I'm on Mac so I can't use strace I'm afraid πŸ˜”

It looks like dtruss would do the same job on a Mac, maybe? I don't think SIP would come into play for the downloaded simulator binary, but it looks like codesign can remove its signature if it has one somehow.

By the way, while I was randomly testing stuff, the simulator was not updating the build on the device, so I deleted the target folder with cargo clean and... now I'm getting the same missing main.pdz error again πŸ˜”

I wonder if an empty main.pdz would work around the check, and the game would still run because it's not actually needed... :|

pomettini commented 1 year ago

I'm on Mac so I can't use strace I'm afraid πŸ˜”

It looks like dtruss would do the same job on a Mac, maybe? I don't think SIP would come into play for the downloaded simulator binary, but it looks like codesign can remove its signature if it has one somehow.

By the way, while I was randomly testing stuff, the simulator was not updating the build on the device, so I deleted the target folder with cargo clean and... now I'm getting the same missing main.pdz error again πŸ˜”

I wonder if an empty main.pdz would work around the check, and the game would still run because it's not actually needed... :|

I tried putting a main.pdz file and the stacktrace on the device says that the file is too small, no matter how large it is. Funnily enough, I noticed the pdex.bin file on the package is actually empty, maybe that is causing the issue? But if so, how is it running on the simulator?

rtsuk commented 1 year ago

That is certainly the cause. It works on the simulator because the simulator uses the dylib, not the binary.

pomettini commented 1 year ago

That is certainly the cause. It works on the simulator because the simulator uses the dylib, not the binary.

Ahhh that makes sense now! I made a quick test with crank run --device --release (which still hangs) and manually copied the .pdx file and yeah, it worked! So now I have to figure out how to make the transfer work and that should be it! Thanks again folks! πŸ’ͺ

rtsuk commented 1 year ago

Do check for permission requests that are popped up behind your active window.

SomeoneToIgnore commented 1 year ago

Just got my playdate and ran into this instantly, have anybody found a workaround for this?

paulyoung commented 1 year ago

I’m also unable to use crank run --device with it hanging. I’m doing crank build --device and then uploading via the simulator as a workaround.

I’m AFK now but wondering if this is only when my game is already running. I’ve noticed that I can’t upload to device from the simulator when a game is running (the β€œDevice” menu disappears and the Cmd+U shortcut is disabled)

paulyoung commented 1 year ago

I’m AFK now but wondering if this is only when my game is already running. I’ve noticed that I can’t upload to device from the simulator when a game is running (the β€œDevice” menu disappears and the Cmd+U shortcut is disabled)

I tried this and it made no difference. Being on the home screen didn't help.

paulyoung commented 1 year ago

I did some investigating and found that modem_path.exists() is false. I'll open an issue over in the crank repo.

paulyoung commented 1 year ago

Seems to be explained by https://github.com/pd-rs/crank/issues/24; modem_path defaults to /dev/cu.usbmodemPDU1_Y0005491 unless PLAYDATE_SERIAL_DEVICE is set.

There's apparently some way to try and find this but it's only for Linux: https://github.com/pd-rs/crank/pull/38