Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile bug: iOS version able to build not not able to run #10922

Open
Animaxx opened this issue Dec 20, 2024 · 4 comments
Open

Compile bug: iOS version able to build not not able to run #10922

Animaxx opened this issue Dec 20, 2024 · 4 comments

Comments

@Animaxx
Copy link

Animaxx commented Dec 20, 2024

Git commit

43ed389

Operating systems

Mac

GGML backends

Metal

Problem description & steps to reproduce

related to #10747

I have follow with the CI action for macOS

mkdir build
cd build

cmake -G Xcode .. \
    -DGGML_METAL_USE_BF16=ON \
    -DGGML_METAL_EMBED_LIBRARY=ON \
    -DLLAMA_BUILD_EXAMPLES=OFF \
    -DLLAMA_BUILD_TESTS=OFF \
    -DLLAMA_BUILD_SERVER=OFF \
    -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
    -DCMAKE_SYSTEM_NAME=Darwin \
    -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \
    -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=ggml
    
cmake --build . --config Release -j $(sysctl -n hw.logicalcpu) -- CODE_SIGNING_ALLOWED=NO
sudo cmake --install . --config Release

# build for swift package
cd ..
xcodebuild -scheme llama-Package -destination 'generic/platform=macOS'

or build for iOS

mkdir build
cd build
cmake -G Xcode .. \
    -DGGML_METAL_USE_BF16=ON \
    -DGGML_METAL_EMBED_LIBRARY=ON \
    -DLLAMA_BUILD_EXAMPLES=OFF \
    -DLLAMA_BUILD_TESTS=OFF \
    -DLLAMA_BUILD_SERVER=OFF \
    -DCMAKE_SYSTEM_NAME=iOS \
    -DCMAKE_OSX_DEPLOYMENT_TARGET=14.0 \
    -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=ggml

cmake --build . --config Release -j $(sysctl -n hw.logicalcpu) -- CODE_SIGNING_ALLOWED=NO
sudo cmake --install . --config Release

# build for swift package
cd ..
xcodebuild -scheme llama-Package -destination 'generic/platform=iOS'

the build is success but when run it shows error dyld[70862]: Library not loaded: @rpath/libggml.dylib

First Bad Commit

No response

Relevant log output

dyld[70862]: Library not loaded: @rpath/libggml.dylib
  Referenced from: <4A6AE769-FE07-3AAE-84F0-552992A8720C> /Users/animax/Library/Developer/Xcode/DerivedData/LocalLLM-ctyejtpossqslxdwvdukottbyflj/Build/Products/Debug/LocalLLM.app/Contents/MacOS/LocalLLM.debug.dylib
  Reason: tried: '/Users/animax/Library/Developer/Xcode/DerivedData/LocalLLM-ctyejtpossqslxdwvdukottbyflj/Build/Products/Debug/libggml.dylib' (no such file), '/usr/lib/system/introspection/libggml.dylib' (no such file, not in dyld cache), '/Users/animax/Library/Developer/Xcode/DerivedData/LocalLLM-ctyejtpossqslxdwvdukottbyflj/Build/Products/Debug/PackageFrameworks/libggml.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/animax/Library/Developer/Xcode/DerivedData/LocalLLM-ctyejtpossqslxdwvdukottbyflj/Build/Products/Debug/PackageFrameworks/libggml.dylib' (no such file), '/Users/animax/Library/Developer/Xcode/DerivedData/LocalLLM-ctyejtpossqslxdwvdukottbyflj/Build/Products/Debug/LocalLLM.app/Contents/MacOS/Frameworks/libggml.dylib' (no such file), '/Users/animax/Library/Developer/Xcode/DerivedData/LocalLLM-ctyejtpossqslxdwvdukottbyflj/Build/Products/Debug/LocalLLM.app/Contents/MacOS/libggml.dylib' (no such file), '/Users/animax/Library/Developer/Xcode/DerivedData/LocalLLM-ctyejtpossqslxdwvdukottbyflj/Build/Products/Debug/PackageFrameworks/libggml.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/animax/Library/Developer/Xcode/DerivedData/LocalLLM-ctyejtpossqslxdwvdukottbyflj/Build/Products/Debug/PackageFrameworks/libggml.dylib' (no such file), '/Users/animax/Library/Developer/Xcode/DerivedData/LocalLLM-ctyejtpossqslxdwvdukottbyflj/Build/Products/Debug/LocalLLM.app/Contents/MacOS/Frameworks/libggml.dylib' (no such file), '/Users/animax/Library/Developer/Xcode/DerivedData/LocalLLM-ctyejtpossqslxdwvdukottbyflj/Build/Products/Debug/LocalLLM.app/Contents/MacOS/libggml.dylib' (no such file), '/Users/animax/Library/Developer/Xcode/DerivedData/LocalLLM-ctyejtpossqslxdwvdukottbyflj/Build/Products/Debug/PackageFrameworks/libggml.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/animax/Library/Developer/Xcode/DerivedData/LocalLLM-ctyejtpossqslxdwvdukottbyflj/Build/Products/Debug/PackageFrameworks/libggml.dylib' (no such file), '/Users/animax/Library/Developer/Xcode/DerivedData/LocalLLM-ctyejtpossqslxdwvdukottbyflj/Build/Products/Debug/LocalLLM.app/Contents/MacOS/Frameworks/libggml.dylib' (no such file)
Message from debugger: Terminated due to signal 6
@Animaxx
Copy link
Author

Animaxx commented Dec 20, 2024

update: looks like dylib files are not able to copy into the product folder while the app build. I used this script to build for macOS version

mkdir build
cd build
cmake -G Xcode .. \
  -DCMAKE_INSTALL_RPATH="@rpath" \
  -DCMAKE_INSTALL_PREFIX="PRODUCT/macOS" \
  -DGGML_METAL_USE_BF16=ON \
  -DGGML_METAL_EMBED_LIBRARY=ON \
  -DLLAMA_BUILD_EXAMPLES=OFF \
  -DLLAMA_BUILD_TESTS=OFF \
  -DLLAMA_BUILD_SERVER=OFF \
  -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake --build . --config Release -j $(sysctl -n hw.logicalcpu)
cmake --install . --config Release

cd ..
xcodebuild -scheme llama-Package -destination 'generic/platform=macOS'

and based on @ggerganov suggestion #10747 (comment) to add the search path the problem still not solve.

also tried add all "PRODUCT/macOS/lib" files in Build Phases -> new copy files phases, still not luck. but manually copy paste these files works.

I am trying to see if there any better way to do it, please let me know if any advice

@edisonzf2020
Copy link

It is recommended to restore the maintenance of Package.swift, which is very convenient for encapsulating other Swift projects.

@Animaxx
Copy link
Author

Animaxx commented Dec 22, 2024

mkdir build
cd build

echo "=== cmake for iOS"
cmake -G Xcode .. \
  -DCMAKE_INSTALL_RPATH="@rpath" \
  -DGGML_METAL_USE_BF16=ON \
  -DGGML_METAL_EMBED_LIBRARY=ON \
  -DLLAMA_BUILD_EXAMPLES=OFF \
  -DLLAMA_BUILD_TESTS=OFF \
  -DLLAMA_BUILD_SERVER=OFF \
  -DCMAKE_SYSTEM_NAME=iOS \
  -DCMAKE_OSX_DEPLOYMENT_TARGET=16.0 \
  -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=ggml

cmake --build . --config Release -j $(sysctl -n hw.logicalcpu) -- CODE_SIGNING_ALLOWED=NO

cmake --install . --prefix ../../llama_product_ios

cd ..
xcodebuild -scheme llama-Package -destination 'generic/platform=iOS'

with set the search paths and have "copy file phases" for all the "lib" dylib as Frameworks section works for both iOS and MacOS for real device, but it not build for simulator.

@Tongziqi
Copy link

Have you solved this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants