Skip to content

Ensure macOS build includes the required runtime library#382

Merged
amakropoulos merged 2 commits intoundreamai:release/v3.0.2from
taku689:bug/macos_library_bundling
Feb 18, 2026
Merged

Ensure macOS build includes the required runtime library#382
amakropoulos merged 2 commits intoundreamai:release/v3.0.2from
taku689:bug/macos_library_bundling

Conversation

@taku689
Copy link

@taku689 taku689 commented Feb 14, 2026

Hello,

I always find LLMUnity extremely easy to use and really appreciate your work.

I created this PR because when I build for macOS and launch the app, it fails with an error and does not run.
I believe the cause is a mismatch between the libraries bundled at build time and the library selected at runtime.

Specifically, the following code specifies the runtime library to load:
https://github.com/undreamai/LLMUnity/blob/main/Runtime/LlamaLib/LlamaLib.cs#L684-L687
(it uses osx-arm64 for Apple Silicon and osx-x64 for Intel)

However, the build-time library selection below bundles osx-universal, which leads to the mismatch:
https://github.com/undreamai/LLMUnity/blob/main/Runtime/LLMBuilder.cs#L210-L212

To address this, I added osx-arm64 and osx-x64 to the list of libraries bundled during the build. Since this is an additive change, I believe the only side effect is an increase in the macOS build size.

I would be grateful if you could consider merging it.

Thank you and best regards.

@amakropoulos
Copy link
Collaborator

Thanks a lot for the PR!

osx-universal is a universal library that bundles both osx-arm64 and osx-x64.
In theory macOS should be able to recognize on runtime which architecture of the bundled library to use and run that.

The alternative would be to include osx-arm64 and osx-x64 and at runtime (in Unity) figure out which mac architecture to use.
The selection matters here because if the wrong architecture is selected, i.e. arm64 instead of x64, the app will crash.
That's how I had it in the past, but I moved to a universal library because it simplifies the code.
However I only have one mac that I can test things so may not be the best solution.

What errors do you see with the universal library?

@taku689
Copy link
Author

taku689 commented Feb 17, 2026

Thank you for the review.

I built the application on a MacBook Pro (M2 Max, Apple silicon) and when I ran it, I got the following error:

Failed to create LLM service: Library libllamalib_osx-arm64_runtime.dylib not found!
UnityEngine.Debug:ExtractStackTraceNoAlloc (byte*,int,string)
UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/StackTrace.cs:35)
UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[]) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Logging/DebugLogHandler.cs:9)
UnityEngine.Logger:Log (UnityEngine.LogType,object) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Logging/Logger.cs:60)
UnityEngine.Debug:LogError (object) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Debug/Debug.bindings.cs:151)
LLMUnity.LLMUnitySetup:LogError (string,bool) (at ./Packages/ai.undream.llm@180b57d2f7f6/Runtime/LLMUnitySetup.cs:195)
LLMUnity.LLM/<StartServiceAsync>d__107:MoveNext () (at ./Packages/ai.undream.llm@180b57d2f7f6/Runtime/LLM.cs:439)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start<LLMUnity.LLM/<StartServiceAsync>d__107> (LLMUnity.LLM/<StartServiceAsync>d__107&)
LLMUnity.LLM:StartServiceAsync ()
LLMUnity.LLM/<Awake>d__102:MoveNext () (at ./Packages/ai.undream.llm@180b57d2f7f6/Runtime/LLM.cs:363)
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start<LLMUnity.LLM/<Awake>d__102> (LLMUnity.LLM/<Awake>d__102&)
LLMUnity.LLM:Awake ()

The build target architecture is set to Intel 64-bit + Apple silicon.

Based on the error message, I think that when running on Apple silicon hardware, the runtime selects the arm64 library, but since it is not bundled in the build, it fails and results in this error.

@amakropoulos
Copy link
Collaborator

You are right!
I have hardcoded the platform from the LlamaLib side.

Could you remove completely the line
https://github.com/undreamai/LLMUnity/blob/main/Runtime/LLMBuilder.cs#L211

and then also modify here
https://github.com/undreamai/LLMUnity/blob/main/Editor/LLMBuildProcessor.cs#L47-L48
to

            libraryFileNames.Add("libllamalib_osx-x64_acc.dylib");
            libraryFileNames.Add("libllamalib_osx-x64_no-acc.dylib");
            libraryFileNames.Add("libllamalib_osx-arm64_acc.dylib");
            libraryFileNames.Add("libllamalib_osx-arm64_no-acc.dylib");

I will then test it as soon as possible, merge it, and create a new release!

@taku689
Copy link
Author

taku689 commented Feb 17, 2026

Thank you for the review!
I’ve fixed the relevant part and would appreciate another look.

@amakropoulos
Copy link
Collaborator

Awesome, thank you!
I'll probably test it tonight.

@amakropoulos amakropoulos changed the base branch from main to release/v3.0.2 February 18, 2026 07:53
@amakropoulos amakropoulos merged commit fff0692 into undreamai:release/v3.0.2 Feb 18, 2026
@amakropoulos
Copy link
Collaborator

Merged it for the upcoming patch release, thank you for the fix!

@taku689
Copy link
Author

taku689 commented Feb 18, 2026

Thank you for merging it!

@taku689 taku689 deleted the bug/macos_library_bundling branch February 18, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments