LukasBanana / LLGL

Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal
BSD 3-Clause "New" or "Revised" License
2.05k stars 139 forks source link

iOS and macOS compilation issues #133

Closed measuredweighed closed 1 month ago

measuredweighed commented 1 month ago

LLGL looks really interesting and I'm keen to dig into it a little more, but I seem to be running into a few problems when trying to compile the library for both iOS and macOS. The provided BuildIOS.command fails with the following error: make: *** No rule to make targetiphonesimulator'.`

BuildMacOS.command succeeds, but the examples in build_macos/build all seem to crash on launch. Running the provided RunExamplesMacOS.command results in the following output:

measuredweighed@MBP LLGL % ./RunExamplesMacOS.command
Run examples from build directory: build_macos/build
1) Animation          7) Mapping      13) ShadowMapping
2) ClothPhysics       8) MultiContext     14) StencilBuffer
3) Fonts          9) PostProcessing   15) StreamOutput
4) HelloTriangle     10) Queries      16) Tessellation
5) IndirectDraw      11) RenderTarget     17) Texturing
6) Instancing        12) ResourceBinding  18) VolumeRendering
Select example: 4
selected renderer: Metal
Renderer:             Metal 2.1
Device:               Apple M1 Pro
Vendor:               Apple
Shading Language:     Metal Shading Language
Swap Chain Format:    BGRA8UNorm
Depth/Stencil Format: Undefined
cannot create Metal graphics PSO without valid vertex function

Here's the BuildIOS.command output for reference:

measuredweighed@MBP LLGL % ./BuildIOS.command
-- ~~~ Build Summary ~~~
-- Target Platform: iOS
-- Target Architecture: arm64
-- Target Library: Shared
-- Build Renderer: Metal
-- Build Examples
-- ~~~~~~~~~~~~~~~~~~~~~
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/measuredweighed/LLGL/build_ios
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0
Reading makefiles...
Reading makefile `Makefile'...
Updating makefiles....
 Considering target file `Makefile'.
  Looking for an implicit rule for `Makefile'.
  No implicit rule found for `Makefile'.
  Finished prerequisites of target file `Makefile'.
 No need to remake target `Makefile'.
Updating goal targets....
Considering target file `iphonesimulator'.
 File `iphonesimulator' does not exist.
 Looking for an implicit rule for `iphonesimulator'.
 No implicit rule found for `iphonesimulator'.
 Finished prerequisites of target file `iphonesimulator'.
Must remake target `iphonesimulator'.
make: *** No rule to make target `iphonesimulator'.
Failed to remake target file `iphonesimulator'.

The build machine is an Apple M1 Pro running macOS Sonoma 14.5 (23F79).

LukasBanana commented 1 month ago

Thanks for reporting this issue.

I haven't used the build scripts for macOS and iOS in a while and the RunExamplesMacOS.command seem to have broken since I refactored the resource loading to be generic for all platforms. The error cannot create Metal graphics PSO without valid vertex function indicates that the vertex shader could not be loaded (a better error message here would be helpful of course). It fails to load it because using the build script doesn't generate the default.metallib file. Xcode will generate it automatically when you build and run from the development environment. I converted the examples to load the shaders this way because it made loading shaders easier on iOS. The temporary solution would be to generate the project files and then build the examples within Xcode. Just run the build script from the Terminal app and add the -p argument:

$ ./BuildMacOS.command -p

Once you built the apps you should be able to either run them within Xcode or as you would usually run an app from within Finder.

As for the iOS build issue, I don't know if the newer Xcode versions use a different simulator SDK name or if you haven't installed the simulator yet as this is a separate package and doesn't come with Xcode out of the box as far as I remember. But if you want to test it on your physical iOS device, you can do the same as for the macOS solution by just generating the project files. The build script is only intended to build for the simulator for testing purposes. If you want to run the examples on a physical device, it's a bit easier to select the connected device within Xcode. Alternatively, you can replace the identifier iphonesimulator in the build script with whatever name is used in your Xcode installation.

I hope this helps. I will fix the Run*.command script soon.

measuredweighed commented 1 month ago

Thank you for the quick response! I can confirm that BuildMacOS.command -p seems to work after building the LLGL, LLGL_Metal and Example_HelloTriangle targets.

Unfortunately BuildIOS.command -p runs into the following issue while launching Example_HelloTriangle for an iOS Simulator via Xcode:

dyld[89890]: Library not loaded: @rpath/libLLGLD.dylib
  Referenced from: <783D525B-B085-364B-BB66-52474B056683> /Users/measuredweighed/Library/Developer/CoreSimulator/Devices/{redacted}/data/Containers/Bundle/Application/{redacted}/Example_HelloTriangle.app/Example_HelloTriangle

I can confirm that libLLGLD.dylib exists inside build_ios/build/Debug and that the generated xproj contains that path in the Runtime Search Paths.

LukasBanana commented 1 month ago

I haven't seen this error before and I just tried it with a clean build but that worked for me. Having said that, I do have an older Xcode installation so maybe the default deployment target 11.0 is not the right choice for you. You can change the deployment target by adding -t 13.0 (or other versions) to the build script. Also see -h/--help for further options in the build scripts.

Another option would be to build as a static lib (add -s to the build script), which also simplifies building in Xcode since you only have to build the example targets which automatically builds all dependencies. With dynamic libs on the other hand, you have to build the backend (such as _LLGLMetal) and then the example project separately because all backends are loaded dynamically without the knowledge of Xcode.

Please also note that HelloTriangle is the only example that is currently not supported on iOS because those apps cannot use the plain old main entry point. I will put that on my TODO list as it's understandably quite confusing that the most basic example is not working. The other ones should be fine, though.

LukasBanana commented 1 month ago

I closed this with 12ebc70 as it fixes the missing default.metallib file for the BuildMacOS.command script. I will work on the other issues separately but feel free to re-open this issue or keep posting updates.