zegervdv / homebrew-zathura

Homebrew formulae to build Zathura on Mac OS X
538 stars 41 forks source link

Fail to install zathura with synctex option on Apple silicon machines #99

Closed m-zheng closed 1 year ago

m-zheng commented 1 year ago

I have been struggling to install zathura with synctex option on macos ventura (apple silicon chip).

Below is the command I have used. It works perfectly fine on macos ventura (intel chip) except changing the EXTERNAL on /usr/local/opt/dbus/share/dbus-1/session.conf.

brew reinstall dbus
echo 'export DBUS_SESSION_BUS_ADDRESS="unix:path=$DBUS_LAUNCHD_SESSION_BUS_SOCKET"' >> ~/.zshrc
sed -i -e "s|\(<auth>\)EXTERNAL\(</auth>\)|\1DBUS_COOKIE_SHA1\2|" /opt/homebrew/opt/dbus/share/dbus-1/session.conf
brew services start dbus
brew tap zegervdv/zathura
brew install girara --HEAD
brew install zathura --HEAD --with-synctex
brew install zathura-pdf-poppler
mkdir -p $(brew --prefix zathura)/lib/zathura
ln -s $(brew --prefix zathura-pdf-poppler)/libpdf-poppler.dylib $(brew --prefix zathura)/lib/zathura/libpdf-poppler.dylib

Below is the output from brew install zathura --HEAD --with-synctex

==> Fetching dependencies for zegervdv/zathura/zathura: synctex
==> Fetching zegervdv/zathura/synctex
==> Cloning https://github.com/jlaurens/synctex
Updating ~/Library/Caches/Homebrew/synctex--git
==> Checking out branch 2020
Already on '2020'
Your branch is up to date with 'origin/2020'.
HEAD is now at 17fd9f2 Merge pull request #52 from jlaurens/#49
==> Fetching zegervdv/zathura/zathura
==> Cloning https://github.com/pwmt/zathura.git
Updating ~/Library/Caches/Homebrew/zathura--git
==> Checking out branch develop
Already on 'develop'
Your branch is up to date with 'origin/develop'.
HEAD is now at 1df1581 Account for double errors
==> Installing zathura from zegervdv/zathura
==> Installing dependencies for zegervdv/zathura/zathura: synctex
==> Installing zegervdv/zathura/zathura dependency: synctex
==> clang -Wall -I. -lz -shared synctex_parser.c synctex_parser_utils.c -o libsynctex.dylib
Last 15 lines from ~/Library/Logs/Homebrew/synctex/01.clang:
libsynctex.dylib

synctex_parser.c:776:9: warning: unused label 'bailey' [-Wunused-label]
        bailey:
        ^~~~~~~
synctex_parser.c:3962:12: warning: variable 'tested_len' set but not used [-Wunused-but-set-variable]
    size_t tested_len = 0; /*  the number of characters at the beginning of the_string that match */
           ^
synctex_parser.c:5492:9: warning: unused label 'continue_scan' [-Wunused-label]
        continue_scan:
        ^~~~~~~~~~~~~~
synctex_parser.c:6120:14: error: use of undeclared label 'bailey'
        goto bailey;
             ^
3 warnings and 1 error generated.

Do not report this issue to Homebrew/brew or Homebrew/core!

These open issues may also help:
SyncTeX version confusion https://github.com/zegervdv/homebrew-zathura/issues/95
zathura isn't launched from ViM without --with-synctex https://github.com/zegervdv/homebrew-zathura/issues/50

Below is the content from ~/Library/Logs/Homebrew/synctex/01.clang

2022-12-16 23:37:44 +0000

clang
-Wall
-I.
-lz
-shared
synctex_parser.c
synctex_parser_utils.c
-o
libsynctex.dylib

synctex_parser.c:776:9: warning: unused label 'bailey' [-Wunused-label]
        bailey:
        ^~~~~~~
synctex_parser.c:3962:12: warning: variable 'tested_len' set but not used [-Wunused-but-set-variable]
    size_t tested_len = 0; /*  the number of characters at the beginning of the_string that match */
           ^
synctex_parser.c:5492:9: warning: unused label 'continue_scan' [-Wunused-label]
        continue_scan:
        ^~~~~~~~~~~~~~
synctex_parser.c:6120:14: error: use of undeclared label 'bailey'
        goto bailey;
             ^
3 warnings and 1 error generated.

HOMEBREW_VERSION: 3.6.15
ORIGIN: https://github.com/Homebrew/brew
HEAD: 11cdffb4fef84828a7e02860212b30ce4fac85f5
Last commit: 8 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 1e96c8ef383218293a9eef05af0b8725a3ada1fd
Core tap last commit: 32 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: /private/tmp/com.apple.launchd.ZJBBVPdcd3/org.xquartz:0
HOMEBREW_EDITOR: vim
HOMEBREW_MAKE_JOBS: 10
HOMEBREW_NO_AUTO_UPDATE: set
HOMEBREW_NO_BOOTSNAP: set
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: 10-core 64-bit arm_firestorm_icestorm
Clang: 14.0.0 build 1400
Git: 2.39.0 => /opt/homebrew/bin/git
Curl: 7.85.0 => /usr/bin/curl
macOS: 13.1-arm64
CLT: 14.2.0.0.1.1668646533
Xcode: N/A
Rosetta 2: false

HOMEBREW_CC: clang
HOMEBREW_CXX: clang++
MAKEFLAGS: -j10
CMAKE_PREFIX_PATH: /opt/homebrew/opt/zlib:/opt/homebrew
CMAKE_INCLUDE_PATH: /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers
CMAKE_LIBRARY_PATH: /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries
PKG_CONFIG_PATH: /opt/homebrew/opt/zlib/lib/pkgconfig
PKG_CONFIG_LIBDIR: /usr/lib/pkgconfig:/opt/homebrew/Library/Homebrew/os/mac/pkgconfig/13
HOMEBREW_GIT: git
HOMEBREW_SDKROOT: /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk
ACLOCAL_PATH: /opt/homebrew/share/aclocal
PATH: /opt/homebrew/Library/Homebrew/shims/mac/super:/usr/bin:/bin:/usr/sbin:/sbin

I have reboot the computer to make sure $DBUS_LAUNCHD_SESSION_BUS_SOCKET and echo $(launchctl getenv DBUS_LAUNCHD_SESSION_BUS_SOCKET) are not empty before running brew install zathura --HEAD --with-synctex. But no luck.

I also observed that dbus service is never running after checking 'brew services info dbus`.

dbus (org.freedesktop.dbus-session)
Running: ✘
Loaded: ✔
Schedulable: ✘

Any help would be highly appreciated.

zegervdv commented 1 year ago

I don't really see why this would be failing on M1/M2 specifically. Can you try installing synctex directly: brew install zegervdv/zathure/synctex?

You may want to brew uninstall synctex first to clean up.

m-zheng commented 1 year ago

After hours of debugging, I have fixed it myself. It is something to do with the dbus on Apple silicon chip. For those who also run into this rabbit hole, below is my solution.

  1. back up all shell realated config with command below, pretending that we are doing a clean installation. Then exit and reopen the terminal. After that, remove org.freedesktop.dbus-session.plist from folder ~/Library/LaunchAgents, /Library/LaunchAgents and /Library/LaunchDaemons if it exists there.
    mv ~/.zshrc ~/.zshrc_bak
    mv ~/.zprofile ~/.zprofile_bak
    mv ~/.profile ~/.profile_bak
    mv ~/.bashrc ~/.bashrc_bak
    mv ~/.bash-profile ~/.bash-profil_bak
    mv ~/.profile ~/.profile_bak
  2. install Homebrew in terminal normally with /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  3. add export PATH=/opt/homebrew/bin:$PATH to ~/.zshrc. Then source ~/.zshrc, and make sure echo $(brew --prefix) return /opt/homebrew
  4. run brew uninstall dbus girara zathura zathura-pdf-poppler if you have previously installed these packages.
  5. install Rosetta with /usr/sbin/softwareupdate --install-rosetta --agree-to-license
  6. now exit the terminal and reopen it
  7. run arch -x86_64 zsh
  8. comment export PATH=/opt/homebrew/bin:$PATH in ~/.zshrc
  9. install Homebrew in terminal normally with /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  10. add export PATH=/usr/local/bin:$PATH to ~/.zshrc. Then source ~/.zshrc, and make sure echo $(brew --prefix) return /usr/local
  11. now install dbus with brew install dbus
  12. add export DBUS_SESSION_BUS_ADDRESS="unix:path=$DBUS_LAUNCHD_SESSION_BUS_SOCKET" to ~/.zshrc
  13. change the value of <auth><\auth> in /usr/local/opt/dbus/share/dbus-1/session.conf from EXTERNAL to DBUS_COOKIE_SHA1.
  14. run brew services start dbus
  15. reboot
  16. run arch -x86_64 zsh and make sure echo $(brew --prefix) return /usr/local and echo $(launchctl getenv DBUS_LAUNCHD_SESSION_BUS_SOCKET) is not empty. If it is empty inside tmux, check it without the tmux.
  17. run below line by line
    brew tap zegervdv/zathura
    brew install girara --HEAD
    brew install zathura --HEAD --with-synctex
    brew install zathura-pdf-poppler
    mkdir -p $(brew --prefix zathura)/lib/zathura
    ln -s $(brew --prefix zathura-pdf-poppler)/libpdf-poppler.dylib $(brew --prefix zathura)/lib/zathura/libpdf-poppler.dylib
  18. prevent these packages from upgrading with brew pin dbus girara zathura zathura-pdf-poppler. You can upgrade brew packages with brew update && brew upgrade --ignore-pinned --formula if needed in the future.
  19. exit the terminal, remove previous export PATH=/opt/homebrew/bin:$PATH and export PATH=/usr/local/bin:$PATH in ~/.zshrc. Then add below to the top of ~/.zshrc. This will get rid of errors when you try to use intel brew.
    
    # Homebrew setup
    if [[ $(uname -m) == 'arm64' ]]; then
    BREWPATH=/opt/homebrew/bin
    else
    BREWPATH=/usr/local/bin
    fi
    export PATH=$BREWPATH:$PATH
20. exit the terminal, and run below line by line to prevent these packages from upgrading. Again, You can upgrade brew packages with `brew update && brew upgrade --ignore-pinned --formula` if needed in the future.

brew pin dbus brew pin girara brew pin zathura brew pin zathura-pdf-poppler

21. below is my `$PATH`. You can check it against yours if something goes wrong.

/opt/homebrew/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/opt/homebrew/Caskroom/miniconda/base/bin:/opt/homebrew/Caskroom/miniconda/base/condabin:/opt/homebrew/bin


22. enjoy.
23. if everything works well, manually bring back your previous zsh config to `~/.zshrc`. If seeing errors related to brew path for your alias, update it with `$BREWPATH` or `$(brew --prefix)`. In my case, a single `~/.zshrc` can do all the job and no need to deal with files in step 1.

Summary:
This method installs two versions of Homebrew on apple silicon machines. The system will look for executable files from `/opt/homebrew/bin` first. Because you cannot install some packages with apple silicon brew, the system will look for executable files from `/usr/local/bin` which are installed by intel brew.

With this method, particularly from step 5 to 11, you can install all old or scientific packages that can only run on intel machines, such as `python2`, `java jdk 8`. Meanwhile, your apple silicon brew still takes advantages of the chip.