godot-docs
godot-docs copied to clipboard
[Compiling for macOS on Linux] Adding instructions on how to install required MoltenVK
Your Godot version: 4.2
Issue description: Adding information about how to cross-compile for macOS from Linux with Vulkan support.
URL to the documentation page (if already existing): https://docs.godotengine.org/en/stable/contributing/development/compiling/compiling_for_macos.html#cross-compiling-for-macos-from-linux
I recently tried to cross-compile export templates for macOS, using my Linux server. I ran in to an error saying the Vulkan SDK couldn't be found. There are no instructions on how to install it (for MoltenVK). It seems like this part was copied from 3.x because no Vulkan support was introduced back then. I suggest an addition because the build process is not working with this setup. (also I don't know how to do it, so I can't contribute)
You can download it from https://github.com/KhronosGroup/MoltenVK/releases, and set path to extracted archive using vulkan_sdk_path={PATH} build flag.
But OSXCross build might require a custom build of MoltenVK with the -fno-objc-msgsend-selector-stubs flag added (I think the issue is solved in LLVM 17, but older versions probably won't work), and it's only possible to do on macOS.
You can download it from https://github.com/KhronosGroup/MoltenVK/releases, and set path to extracted archive using
vulkan_sdk_path={PATH}build flag.But OSXCross build might require a custom build of MoltenVK with the
-fno-objc-msgsend-selector-stubsflag added (I think the issue is solved in LLVM 17, but older versions probably won't work), and it's only possible to do on macOS.
~I downloaded it from the releases page as suggested, found the libMoltenVK.a file that Godot was looking for, placed it in the folder /usr/local/homebrew/lib (and also moved the whole downloaded release of MoltenVK folder over there as well although I don't think it's necessary) and it worked. I was able to build my OSX export template using osxcross on WSL ubuntu sucessfully.
So maybe that should be included in the documentation? Took me a moment searching around to land here and find this info hahahah.~
- Edit - Huh, I was wrong, it didn't build correctly, not sure if it is related:
[ 99%] progress_finish(["progress_finish"], [])
[100%] Linking Static Library core/libcore.macos.template_release.x86_64.a ...
/home/daniel/osxcross/target/bin/x86_64-apple-darwin22.4-ranlib: file: core/libcore.macos.template_release.x86_64.a(math_fieldwise.macos.template_release.x86_64.o) has no symbols
/home/daniel/osxcross/target/bin/x86_64-apple-darwin22.4-ranlib: file: core/libcore.macos.template_release.x86_64.a(extension_api_dump.macos.template_release.x86_64.o) has no symbols
Ranlib Library core/libcore.macos.template_release.x86_64.a ...
/home/daniel/osxcross/target/bin/x86_64-apple-darwin22.4-ranlib: file: core/libcore.macos.template_release.x86_64.a(math_fieldwise.macos.template_release.x86_64.o) has no symbols
/home/daniel/osxcross/target/bin/x86_64-apple-darwin22.4-ranlib: file: core/libcore.macos.template_release.x86_64.a(extension_api_dump.macos.template_release.x86_64.o) has no symbols
[100%] Linking Program bin/godot.macos.template_release.x86_64 ...
ld: warning: option -s is obsolete and being ignored
Undefined symbols for architecture x86_64:
"___isPlatformVersionAtLeast", referenced from:
OS_MacOS::create_process(String const&, List<String, DefaultAllocator> const&, long long*, bool) in os_macos.macos.template_release.x86_64.o
DisplayServerMacOS::is_dark_mode_supported() const in display_server_macos.macos.template_release.x86_64.o
DisplayServerMacOS::is_dark_mode() const in display_server_macos.macos.template_release.x86_64.o
DisplayServerMacOS::get_accent_color() const in display_server_macos.macos.template_release.x86_64.o
_make_accessory_view(NSSavePanel*, Vector<String> const&) in display_server_macos.macos.template_release.x86_64.o
-[TTS_MacOS init] in tts_macos.macos.template_release.x86_64.o
-[TTS_MacOS update] in tts_macos.macos.template_release.x86_64.o
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
scons: *** [bin/godot.macos.template_release.x86_64] Error 1
` if env["vulkan"]: env.Append(CPPDEFINES=["VULKAN_ENABLED"]) env.Append(LINKFLAGS=["-framework", "Metal", "-framework", "IOSurface"]) if not env["use_volk"]: env.Append(LINKFLAGS=["-lMoltenVK"]) mvk_found = False
mvk_list = [get_mvk_sdk_path(), "/opt/homebrew/lib", "/usr/local/homebrew/lib", "/opt/local/lib"]
if env["vulkan_sdk_path"] != "":
mvk_list.insert(0, os.path.expanduser(env["vulkan_sdk_path"]))
mvk_list.insert(
0,
os.path.join(
os.path.expanduser(env["vulkan_sdk_path"]), "MoltenVK/MoltenVK.xcframework/macos-arm64_x86_64/"
),
)
for mvk_path in mvk_list:
if mvk_path and os.path.isfile(os.path.join(mvk_path, "libMoltenVK.a")):
mvk_found = True
print("MoltenVK found at: " + mvk_path)
env.Append(LINKFLAGS=["-L" + mvk_path])
break
if not mvk_found:
print(
"MoltenVK SDK installation directory not found, use 'vulkan_sdk_path' SCons parameter to specify SDK path."
)
sys.exit(255)`
Looking at this it does look like the whole MoltenVK folder might need to be in one of those paths for it to find the `libMoltenVK.a``file.
Looking at this it does look like the whole MoltenVK folder might need to be in one of those paths for it to find the
That's default locations on macOS, you can always set a custom path by adding vulkan_sdk_path={PATH} flag to the build command. Only libMoltenVK.a library is necessary.
Actually I was wrong about it building without issues. Edited my previous post.
"___isPlatformVersionAtLeast", referenced from
See https://github.com/tpoechtrager/osxcross/issues/278, you need compiler-rt part of OSXCross.
"___isPlatformVersionAtLeast", referenced from
See tpoechtrager/osxcross#278, you need compiler-rt part of OSXCross.
Thank you that worked :) build done with WPL osxcross
I tried now doing an arm build and it failed:
-[CAMetalLayer(MoltenVK) privateScreenMVKImpl] in libMoltenVK.a(libMoltenVK.a-arm64-master.o)
"_objc_msgSend$windows", referenced from:
-[CAMetalLayer(MoltenVK) privateScreenMVKImpl] in libMoltenVK.a(libMoltenVK.a-arm64-master.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
scons: *** [bin/godot.macos.template_debug.arm64] Error 1
scons: building terminated because of errors.
[Time elapsed: 00:24:16.844]
It's looking like it's having trouble linking the MoltenVK in arm?
That's the issue my first comment was about.
Check if you are using the latest clang and SDK from Xcode 14+. But it's possible that it's still not fixed, if this is the case only option is a custom MoltenVK build (which is supposed only on macOS, to be more specific, it only supports Xcode project as a build system).
That's the issue my first comment was about.
Check if you are using the latest clang and SDK from Xcode 14+. But it's possible that it's still not fixed, if this is the case only option is a custom MoltenVK build (which is supposed only on macOS, to be more specific, it only supports Xcode project as a build system).
I see, that's unfortunate :( sorry for the misunderstanding, it seems that indeed it's only possible to compile arm doing that.
I can confirm that ./build_compiler_rt.sh is required to build.
I agree the documentation is way to vague for the MacOS build. I'm trying to compile templates on MacOS and not cross platform. Even adding this supposed flag doesn't work and I can't access scons help to see if I'm doing it right because it'll just error out on the, "MoltenVK SDK installation directory not found, use 'vulkan_sdk_path' SCons parameter to specify SDK path."