ultralight-ux / Ultralight

Lightweight, high-performance HTML renderer for game and app developers.
https://ultralig.ht
4.65k stars 194 forks source link

CMake build issues on M1 Mac #370

Open ameliadiedrich opened 2 years ago

ameliadiedrich commented 2 years ago

When trying to follow the getting started guide on https://docs.ultralig.ht/docs/writing-your-first-app CMake throws this error on M1 Macs:

ld: symbol(s) not found for architecture arm64

This is most likely related to this issue: #88

eyashi commented 2 years ago

Would also love some arm64 binaries for this-- ran into this problem getting started with the M1 mac... The warnings are in the style: ld: warning: ignoring file /Users/edward/code/learning/ultralight-quick-start/build/SDK/bin/libWebCore.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64 for each of the core libraries for Ultralight.

In the meantime, setting the architecture with the command arch -x86_64 zsh before running cmake allowed me to work with Ultralight for now.

maggie44 commented 2 years ago

Using arch -x86_64 zsh did the trick for getting the build to go through, but after building from the starter project (https://github.com/ultralight-ux/ultralight-quick-start) the built executable doesn't run:

Termination Reason:    Namespace DYLD, Code 1 Library missing
Library not loaded: '/usr/local/opt/pcre/lib/libpcre.1.dylib'
Referenced from: '/Users/USER/Documents/*/MyApp.app/Contents/MacOS/libglib-2.0.0.dylib'
Reason: tried: '/usr/local/opt/pcre/lib/libpcre.1.dylib' (no such file), '' (no such file), '' (no such file)
(terminated at launch; ignore backtrace)

Thread 0 Crashed:
0   Rosetta Runtime Routines           0x104f3b940 ???
1   <translation info unavailable>         0x104f8d3a4 ???
2   dyld                                   0x205323a72 abort_with_payload_wrapper_internal + 80
3   dyld                                   0x205323aa4 abort_with_payload + 9
4   dyld                                   0x2052d1699 dyld4::halt(char const*) + 615
5   dyld                                   0x2052cd5b5 dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 3995
6   dyld                                   0x2052cc4e4 start + 388

It is trying to run in Rosetta, understandably because of the build architecture, but feels like it kind of defeats the object of creating light builds as it will have a performance impact.

Adding here as an update, I think it is probably best to see if arm64 support is added before considering Ultralight for cross platform builds.

thejustinwalsh commented 1 year ago

Running Ultralight nightly on Apple Silicon

  1. Set proper architecture in CMakeLists.txt

    set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE INTERNAL "" FORCE)
  2. Add the unsigned dylibs from the bin folder to spctl. This can also be done by right-clicking each binary, selecting Open, then approving the file

    cd bin
    find ./ -maxdepth 1 -type f -exec spctl --add {} \;
  3. Install homebrew for x86_64 using this guide: https://medium.com/mkdir-awesome/how-to-install-x86-64-homebrew-packages-on-apple-m1-macbook-54ba295230f

  4. Install pcre using our x86_64 homebrew env

    arch -x86_64 /usr/local/homebrew/bin/brew install pcre
  5. Symlink the x86_64 hombrew lib dirctory to /usr/local/lib so that the application can find it when loading

    sudo ln -s /usr/local/homebrew/lib /usr/local/lib