finnvoor / PlaydateKit

Create games for Playdate using Swift.
https://finnvoor.github.io/PlaydateKit/documentation/playdatekit
Creative Commons Zero v1.0 Universal
198 stars 21 forks source link

swift package pdc crashes #56

Open cove opened 5 months ago

cove commented 5 months ago

Just going through the setup docs and on the swift package pdc command I get errors about mismatched arch (I'm on an M1 Mac FWIW), and then it crashes.

I have TOOLCHAINS set:

export PLAYDATE_SDK_PATH=/Users/cove/Developer/PlaydateSDK
export TOOLCHAINS=org.swift.59202406081a

It appears to be discoverable:

% xcrun --toolchain $TOOLCHAINS  --find swiftc
/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-06-08-a.xctoolchain/usr/bin/swiftc

Here's the abbreviated output:

% swift package pdc 
warning: 'playdate2': remark: In-process target-info query failed (open("dlopen(/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-06-08-a.xctoolchain/usr/lib/swift/macosx/lib_InternalSwiftScan.dylib, 0x0105): tried: \'/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-06-08-a.xctoolchain/usr/lib/swift/macosx/lib_InternalSwiftScan.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\' or \'arm64\')), \'/System/Volumes/Preboot/Cryptexes/OS/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-06-08-a.xctoolchain/usr/lib/swift/macosx/lib_InternalSwiftScan.dylib\' (no such file), \'/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-06-08-a.xctoolchain/usr/lib/swift/macosx/lib_InternalSwiftScan.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\' or \'arm64\')), \'/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-06-08-a.xctoolchain/usr/lib/swift/host/lib_InternalSwiftScan.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\' or \'arm64\')), \'/System/Volumes/Preboot/Cryptexes/OS/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-06-08-a.xctoolchain/usr/lib/swift/host/lib_InternalSwiftScan.dylib\' (no such file), \'/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-06-08-a.xctoolchain/usr/lib/swift/host/lib_InternalSwiftScan.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\' or \'arm64\'))")). Using fallback mechanism.
[cut]
1.      Apple Swift version 6.0-dev (LLVM 579155491d559cc, Swift 64869e5a42221b2)
2.      Compiling with the current language version
3.      While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for pladatekit_simulator)
4.      While running pass #5603 SILFunctionTransform "TransferNonSendable" on SILFunction "@$s20pladatekit_simulator8PlaydateO11playdateAPISo0cE0VSgvgZ".
 for getter for playdateAPI (at /Users/cove/Developer/playdate2/.build/checkouts/PlaydateKit/Sources/PlaydateKit/Playdate.swift:16:43)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x00000001073a88e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 40
1  swift-frontend           0x00000001073a6dd5 llvm::sys::RunSignalHandlers() + 85
2  swift-frontend           0x00000001073a8f3e SignalHandler(int) + 270
3  libsystem_platform.dylib 0x00007ff8133befdd _sigtramp + 29
4  libsystem_platform.dylib 0x00007ff04a8f7018 _sigtramp + 18446744040278032472
5  libsystem_c.dylib        0x00007ff8132b5a79 abort + 126
6  libsystem_c.dylib        0x00007ff8132b4d68 err + 0
0  swift-frontend           0x000000010ace78e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 40
7  swift-frontend           0x00000001077f3b43 swift::SILFunctionType::getSelfInstanceType(swift::SILModule&, swift::TypeExpansionContext) const (.cold.1) + 35
1  swift-frontend           0x000000010ace5dd5 llvm::sys::RunSignalHandlers() + 85
8  swift-frontend           0x00000001021b7781 swift::SILFunctionType::getSelfInstanceType(swift::SILModule&, swift::TypeExpansionContext) const + 161
2  swift-frontend           0x000000010ace7f3e SignalHandler(int) + 270
3  libsystem_platform.dylib 0x00007ff8133befdd _sigtramp + 29
4  libsystem_platform.dylib 0x00007fce8083f618 _sigtramp + 18446743895154361944
5  libsystem_c.dylib        0x00007ff8132b5a79 abort + 126
6  libsystem_c.dylib        0x00007ff8132b4d68 err + 0
[cut]
error: swiftcFailed(exitCode: 6)
finnvoor commented 5 months ago

Hi, you should be able to try again using the latest changes to PlaydateKit and PlaydateKitTemplate as well as the latest Swift toolchain. There are a few compiler bugs that I've worked around and everything seems to build now.

cove commented 5 months ago

That fixed that crash for me!

However I'm getting the "stdlib.h not found error" now:

cove@pico MyGame2 % swift package pdc
[cut]
In file included from /Users/cove/Developer/PlaydateSDK/C_API/buildsupport/setup.c:2:
/Users/cove/Developer/PlaydateSDK/C_API/pd_api.h:13:10: fatal error: 'stdlib.h' file not found
   13 | #include <stdlib.h>
      |          ^~~~~~~~~~
1 error generated.
error: clangFailed(exitCode: 1)

I'm not seeing stdlib.h in the included paths in Package.swift, and when I do force include a path with stdlib.h in it swift seg faults.

e.g. Seems to be in one of these dirs:

cove@pico MyGame2 % find /usr/local/playdate/gcc-arm-none-eabi-9-2019-q4-major|grep stdlib.h
/usr/local/playdate/gcc-arm-none-eabi-9-2019-q4-major/arm-none-eabi/include/ssp/stdlib.h
/usr/local/playdate/gcc-arm-none-eabi-9-2019-q4-major/arm-none-eabi/include/c++/9.2.1/stdlib.h
/usr/local/playdate/gcc-arm-none-eabi-9-2019-q4-major/arm-none-eabi/include/c++/9.2.1/tr1/stdlib.h
/usr/local/playdate/gcc-arm-none-eabi-9-2019-q4-major/arm-none-eabi/include/stdlib.h
/usr/local/playdate/gcc-arm-none-eabi-9-2019-q4-major/arm-none-eabi/include/machine/stdlib.h

Trying an obvious dir to include:

                    "-Xfrontend", "-disable-objc-interop",
                    "-Xfrontend", "-disable-stack-protector",
                    "-Xfrontend", "-function-sections",
                    "-Xfrontend", "-gline-tables-only",
                    "-Xcc", "-DTARGET_EXTENSION",
                    "-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/include",
                    "-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/include-fixed",
                    "-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/../../../../arm-none-eabi/include",
+                    "-I", "/usr/local/playdate/gcc-arm-none-eabi-9-2019-q4-major/arm-none-eabi/include"
                    "-I", "\(playdateSDKPath)/C_API",

Crashes:

cove@pico MyGame2 % swift package pdc
zsh: segmentation fault  swift package pdc

Update: Oh wait I see the path is included already with /../../../../arm-none-eabi/include, so I wonder why it can't find the header file?