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

macOS Sonoma Build Bugs #15201

Closed
leanderhutton opened this issue Sep 6, 2023 · 41 comments · Fixed by #15258
Closed

macOS Sonoma Build Bugs #15201

leanderhutton opened this issue Sep 6, 2023 · 41 comments · Fixed by #15258
Assignees
Labels
scope: macos support macos related issues and PR

Comments

@leanderhutton
Copy link

leanderhutton commented Sep 6, 2023

Describe the bug

I'm doing some test builds on a macOS Sonoma VM and have found some issues with the process. Documenting them here, potentially fixing some. I compiled Mac Ports from source as there is no Sonoma package available yet. This is a clean install of Sonoma Beta 8 for the sole purpose of testing darktable building. Figured it's a good time to get out in front of this and test it out before Sonoma proper is released.

Steps to reproduce

  1. Follow instructions in packaging/macosx/build.txt file after a checkout of release-4.4.2 (also testing master)
  2. Build fails on macOS Sonoma
  3. First error was libomp wasn't detected:
    CMake Error at /opt/local/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) (Required is at least version "4.5") Call Stack (most recent call first): /opt/local/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE) /opt/local/share/cmake-3.24/Modules/FindOpenMP.cmake:545 (find_package_handle_standard_args) CMakeLists.txt:90 (find_package)

This was fixed with port install libomp so I think that should probably be added to the package list in the documentation maybe?

Second error I cannot get past is:

-- Missing intltool-merge
-- Missing desktop-file-validate, problems in org.darktable.darktable.desktop might go unnoticed
-- Could NOT find LLVM (missing: LLVM_DIR)
CMake Warning at CMakeLists.txt:352 (message):
  Could not find LLVM 7 or above


CMake Warning at CMakeLists.txt:353 (message):
  Test-compilation of OpenCL programs can not be done.

I've got Xcode beta 15 installed and the command line tools beta, clang reports the following:

% clang --version
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin23.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Expected behavior

produce dmg file and .app package

Where did you install darktable from?

self compiled

darktable version

4.4.2

What OS are you using?

Mac

What is the version of your OS?

macOS 14 Sonoma

Describe your system?

VM on M2 Max

Are you using OpenCL GPU in darktable?

Yes

If yes, what is the GPU card and driver?

M2 Max

Please provide additional context if applicable. You can attach files too, but might need to rename to .txt or .zip

No response

@zisoft zisoft added the scope: macos support macos related issues and PR label Sep 6, 2023
@MStraeten
Copy link
Collaborator

libomp is mentioned in https://github.com/darktable-org/darktable/blob/master/packaging/macosx/BUILD-ARM64.txt
If you build for silicon you should use this description
Intltool issue indicates that not all prerequisites are installed

@leanderhutton
Copy link
Author

leanderhutton commented Sep 6, 2023

That would explain it, opened the wrong file on the build instructions. Wondered what changed so much between now and my Ventura VM.

Need to upgrade my Intel machine to Sonoma later and see if those work.

@leanderhutton
Copy link
Author

Ran into an issue building cargo-c (a dependency for libgphoto2) in MacPorts, more of an upstream issue than a darktable one. Even if I let it download a pre-built binary instead of building from source, it's no go, will try to report it to MacPorts.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString stringByStandardizingPath]: unrecognized selector sent to instance 0x60000363c390'
:info:extract *** First throw call stack:
:info:extract (
:info:extract   0   CoreFoundation                      0x0000000184cf48c0 __exceptionPreprocess + 176
:info:extract   1   libobjc.A.dylib                     0x00000001847edeb4 objc_exception_throw + 60
:info:extract   2   CoreFoundation                      0x0000000184da63dc -[NSObject(NSObject) __retain_OA] + 0
:info:extract   3   CoreFoundation                      0x0000000184c5e9e4 ___forwarding___ + 1572
:info:extract   4   CoreFoundation                      0x0000000184c5e300 _CF_forwarding_prep_0 + 96
:info:extract   5   Foundation                          0x0000000185d334f0 -[NSProcessInfo arguments] + 188
:info:extract   6   CoreFoundation                      0x0000000184d6fff8 __getDefaultArguments_block_invoke + 96
:info:extract   7   libdispatch.dylib                   0x00000001849f5910 _dispatch_client_callout + 20
:info:extract   8   libdispatch.dylib                   0x00000001849f714c _dispatch_once_callout + 32
:info:extract   9   CoreFoundation                      0x0000000184d6f994 _addBackstopValuesForIdentifierAndSource + 640
:info:extract   10  CoreFoundation                      0x0000000184c2a254 __81-[_CFXPreferences(SourceAdditions) withNamedVolatileSourceForIdentifier:perform:]_block_invoke + 144
:info:extract   11  CoreFoundation                      0x0000000184d6f63c -[_CFXPreferences withNamedVolatileSourceForIdentifier:perform:] + 272
:info:extract   12  CoreFoundation                      0x0000000184c305c4 -[CFPrefsSearchListSource addNamedVolatileSourceForIdentifier:] + 136
:info:extract   13  CoreFoundation                      0x0000000184dae8bc __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke.155 + 296
:info:extract   14  CoreFoundation                      0x0000000184dae564 -[_CFXPreferences withSearchLists:] + 84
:info:extract   15  CoreFoundation                      0x0000000184c2bb18 __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke + 300
:info:extract   16  CoreFoundation                      0x0000000184dae710 -[_CFXPreferences withSearchListForIdentifier:container:cloudConfigurationURL:perform:] + 384
:info:extract   17  CoreFoundation                      0x0000000184c2b440 -[_CFXPreferences copyAppValueForKey:identifier:container:configurationURL:] + 156
:info:extract   18  CoreFoundation                      0x0000000184c2b368 _CFPreferencesCopyAppValueWithContainerAndConfiguration + 112
:info:extract   19  SystemConfiguration                 0x00000001859bb478 SCDynamicStoreCopyProxiesWithOptions + 180
:info:extract   20  libcurl.4.dylib                     0x0000000104161208 Curl_macos_init + 16
:info:extract   21  libcurl.4.dylib                     0x0000000104148140 global_init + 172
:info:extract   22  libcurl.4.dylib                     0x0000000104148084 curl_global_init + 68
:info:extract   23  cargo                               0x0000000102fbbe24 _ZN3std4sync4once4Once9call_once28_$u7b$$u7b$closure$u7d$$u7d$17h9969c74c6cd47fe4E + 36
:info:extract   24  cargo                               0x00000001030c90b8 _ZN3std10sys_common4once5queue4Once4call17hcf0ec3e1860a2be3E + 724
:info:extract   25  cargo                               0x0000000102fbc008 _ZN4curl9INIT_CTOR9init_ctor17hcaba8dae76a2e3deE + 96
:info:extract   26  dyld                                0x00000001848455c8 ___ZZNK5dyld46Loader25findAndRunAllInitializersERNS_12RuntimeStateEENK3$_0clEv_block_invoke + 168
:info:extract   27  dyld                                0x000000018488a920 ___ZNK5dyld313MachOAnalyzer18forEachInitializerER11DiagnosticsRKNS0_15VMAddrConverterEU13block_pointerFvjEPKv_block_invoke.209 + 340
:info:extract   28  dyld                                0x000000018487dc60 ___ZNK5dyld39MachOFile14forEachSectionEU13block_pointerFvRKNS0_11SectionInfoEbRbE_block_invoke + 496
:info:extract   29  dyld                                0x00000001848252fc _ZNK5dyld39MachOFile18forEachLoadCommandER11DiagnosticsU13block_pointerFvPK12load_commandRbE + 300
:info:extract   30  dyld                                0x000000018487cc98 _ZNK5dyld39MachOFile14forEachSectionEU13block_pointerFvRKNS0_11SectionInfoEbRbE + 192
:info:extract   31  dyld                                0x000000018488a434 _ZNK5dyld313MachOAnalyzer18forEachInitializerER11DiagnosticsRKNS0_15VMAddrConverterEU13block_pointerFvjEPKv + 516
:info:extract   32  dyld                                0x0000000184841798 _ZNK5dyld46Loader25findAndRunAllInitializersERNS_12RuntimeStateE + 448
:info:extract   33  dyld                                0x0000000184847b14 _ZNK5dyld416JustInTimeLoader15runInitializersERNS_12RuntimeStateE + 36
:info:extract   34  dyld                                0x0000000184841b4c _ZNK5dyld46Loader23runInitializersBottomUpERNS_12RuntimeStateERN5dyld35ArrayIPKS0_EE + 220
:info:extract   35  dyld                                0x0000000184845654 _ZZNK5dyld46Loader38runInitializersBottomUpPlusUpwardLinksERNS_12RuntimeStateEENK3$_1clEv + 112
:info:extract   36  dyld                                0x0000000184841ccc _ZNK5dyld46Loader38runInitializersBottomUpPlusUpwardLinksERNS_12RuntimeStateE + 304
:info:extract   37  dyld                                0x0000000184866ad4 _ZN5dyld44APIs25runAllInitializersForMainEv + 464
:info:extract   38  dyld                                0x0000000184829f34 _ZN5dyld4L7prepareERNS_4APIsEPKN5dyld313MachOAnalyzerE + 3192
:info:extract   39  dyld                                0x0000000184828f44 start + 1948
:info:extract )
:info:extract libc++abi: terminating due to uncaught exception of type NSException

@zisoft
Copy link
Collaborator

zisoft commented Sep 7, 2023

Since github runner builds are based on Homebrew it would be interesting to see how that goes on Sonoma.
Can you test this as well on your VM?

@kmilos
Copy link
Contributor

kmilos commented Sep 7, 2023

an issue building cargo-c (a dependency for libgphoto2)

Hm, pretty sure ligphoto2 has no Rust code, so it's probably a dependency of something else...

@leanderhutton
Copy link
Author

Hm, pretty sure ligphoto2 has no Rust code, so it's probably a dependency of something else...

That's what I thought too but MacPorts computes it as a prerequisite, it might be a dependency of a dependency or something too. libgphoto2 has several dependencies.

@kmilos
Copy link
Contributor

kmilos commented Sep 7, 2023

it might be a dependency of a dependency or something too. libgphoto2 has several dependencies

That's what I meant. It's definitely not a direct dependency of libgphoto2. Most likely ligphoto2->gd2->libavif/libheif->rav1e 🙄

So you could also try building w/ -DUSE_CAMERA_SUPPORT=OFF -DUSE_AVIF=OFF -DUSE_HEIF=OFF and skip those libs for now (and possibly even w/o gmic, GraphicsMagick, and ImageMagick as those depend on libheif as well).

@leanderhutton
Copy link
Author

Since github runner builds are based on Homebrew it would be interesting to see how that goes on Sonoma.
Can you test this as well on your VM?

I can do that, are the release binaries still built against MacPorts as Homebrew doesn't allow building against previous releases?

@zisoft
Copy link
Collaborator

zisoft commented Sep 7, 2023

I can do that, are the release binaries still built against MacPorts as Homebrew doesn't allow building against previous releases?

The release binaries for x86_64 are built with Homebrew for macos-11 or higher.

@leanderhutton
Copy link
Author

Homebrew steps work to build the bundle, only catch was I had to manually specify export PKG_CONFIG_PATH=/opt/homebrew/lib/pkgconfig before running ./3_make_hb_darktable_package.sh otherwise it couldn't find the gtk3 pc file.

However the resulting app package fails to launch with:

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000

Termination Reason:    Namespace DYLD, Code 1 Library missing
Library not loaded: @loader_path/../../../../opt/imath/lib/libImath-3_1.29.dylib
Referenced from: <9F7AA069-0A29-30F3-9426-C6C72260DD2D> /Applications/darktable.app/Contents/Resources/lib/libOpenEXR-3_2.31.dylib
Reason: tried: '/Applications/darktable.app/Contents/Resources/lib/../../../../opt/imath/lib/libImath-3_1.29.dylib' (no such file), '/usr/local/lib/libImath-3_1.29.dylib' (no such file), '/usr/lib/libImath-3_1.29.dylib' (no such file, not in dyld cache)Library not loaded: @rpath/libsharpyuv.0.dylib
Referenced from: <EC500041-6307-3D2A-B392-745A2A7C818E> /Applications/darktable.app/Contents/Resources/lib/libwebp.7.dylib
Reason: tried: '/Applications/darktable.app/Contents/Resources/lib/../lib/libsharpyuv.0.dylib' (no such file), '/Applications/darktable.app/Contents/MacOS/../Resources/lib/darktable/libsharpyuv.0.dylib' (no such file), '/Applications/darktable.app/Contents/MacOS/../Resources/lib/darktable/libsharpyuv.0.dylib' (no such file), '/usr/local/lib/libsharpyuv.0.dylib' (no such file),
(terminated at launch; ignore backtrace)

@leanderhutton
Copy link
Author

leanderhutton commented Sep 7, 2023

And the resulting binary cannot run on Ventura at all.

@zisoft
Copy link
Collaborator

zisoft commented Sep 7, 2023

Library not loaded: @loader_path/../../../../opt/imath/lib/libImath-3_1.29.dylib

Did you run the 3_make_hb_darktable_package_sh script after the build?

@leanderhutton
Copy link
Author

Library not loaded: @loader_path/../../../../opt/imath/lib/libImath-3_1.29.dylib

Did you run the 3_make_hb_darktable_package_sh script after the build?

Yes.

@zisoft
Copy link
Collaborator

zisoft commented Sep 7, 2023

Please post the output of

brew --prefix

@leanderhutton
Copy link
Author

% brew --prefix
/opt/homebrew

@zisoft
Copy link
Collaborator

zisoft commented Sep 7, 2023

Ok, Homebrew on M1 systems is installed in a different base directory than on x86_64 systems.
I have recently updated the script to handle library relative paths accordingly, but couldn't test on M1 systems.

Can you please redirect the output of 3_make_hb_darktable_package_sh to a text file and attach it here (lot of text).

@leanderhutton
Copy link
Author

3_output.log

@zisoft
Copy link
Collaborator

zisoft commented Sep 7, 2023

hmm, the @loader_paths are not updated at all.

What gives

cd /Applications/darktable.app/Contents/Resources/lib
otool -L libOpenEXR-3_2.31.dylib

@zisoft
Copy link
Collaborator

zisoft commented Sep 7, 2023

Your log is full of messages like this:

install_name_tool: warning: changes being made to the file will invalidate the code signature in: ...

which seems to be a macOS arm64 specific issue

@leanderhutton
Copy link
Author

Your log is full of messages like this:

install_name_tool: warning: changes being made to the file will invalidate the code signature in: ...

which seems to be a macOS arm64 specific issue

Yup, I noticed that. It's been a while but I do recall building it successfully in a Ventura VM on ARM with homebrew a few months back (since then I went to the MacPorts method). Has something changed in Sonoma.

@leanderhutton
Copy link
Author

hmm, the @loader_paths are not updated at all.

What gives

cd /Applications/darktable.app/Contents/Resources/lib
otool -L libOpenEXR-3_2.31.dylib

Output from that shows nothing:

% otool -o libOpenEXR-3_2.31.dylib libOpenEXR-3_2.31.dylib:

@zisoft
Copy link
Collaborator

zisoft commented Sep 7, 2023

otool -L ..., you used otool -o ...

@leanderhutton
Copy link
Author

otool -L ..., you used otool -o ...

so I did, sorry bouncing between work and this at the moment:


	@executable_path/../Resources/lib/libOpenEXR-3_2.31.dylib (compatibility version 31.0.0, current version 31.3.2)
	@rpath/libIlmThread-3_2.31.dylib (compatibility version 31.0.0, current version 31.3.2)
	@rpath/libOpenEXRCore-3_2.31.dylib (compatibility version 31.0.0, current version 31.3.2)
	@rpath/libIex-3_2.31.dylib (compatibility version 31.0.0, current version 31.3.2)
	@loader_path/../../../../opt/imath/lib/libImath-3_1.29.dylib (compatibility version 29.0.0, current version 29.8.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.100.3)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1500.65.0)

@zisoft
Copy link
Collaborator

zisoft commented Sep 8, 2023

That looks ok and should be handled by the package building script accordingly.
So we need to solve the install_name_tool issues.

@MStraeten
Copy link
Collaborator

And the resulting binary cannot run on Ventura at all.

That’s the reason to use macports when you need to set a deployment target older than the os on your build machine…

@zisoft
Copy link
Collaborator

zisoft commented Sep 8, 2023

@leanderhutton: Can you please edit 3_make_hb_darktable_package_sh and insert the following line at line position 112:

codesign --verbose --force --preserve-metadata=entitlements,requirements,flags,runtime -i "org.darktable" -s - $hbDependency

The script should then look as follows at that position:

# Store file name
dynDepOrigFile=$(basename "$hbDependency")
dynDepTargetFile="$dtResourcesDir/lib/$dynDepOrigFile"

echo "Resetting executable path for dependency <$hbDependency> of <$1>"

codesign --verbose --force --preserve-metadata=entitlements,requirements,flags,runtime -i "org.darktable" -s - $hbDependency

# Set correct executable path
install_name_tool -change "$hbDependency" "@executable_path/../Resources/lib/$dynDepOrigFile" "$1"

Then re-run the script

@leanderhutton
Copy link
Author

And the resulting binary cannot run on Ventura at all.

That’s the reason to use macports when you need to set a deployment target older than the os on your build machine…

Yeah, that's why I was using MacPorts the first go around. I thought the Homebrew builds were for nightlies only?

@leanderhutton: Can you please edit 3_make_hb_darktable_package_sh and insert the following line at line position 112:

codesign --verbose --force --preserve-metadata=entitlements,requirements,flags,runtime -i "org.darktable" -s - $hbDependency

The script should then look as follows at that position:

# Store file name
dynDepOrigFile=$(basename "$hbDependency")
dynDepTargetFile="$dtResourcesDir/lib/$dynDepOrigFile"

echo "Resetting executable path for dependency <$hbDependency> of <$1>"

codesign --verbose --force --preserve-metadata=entitlements,requirements,flags,runtime -i "org.darktable" -s - $hbDependency

# Set correct executable path
install_name_tool -change "$hbDependency" "@executable_path/../Resources/lib/$dynDepOrigFile" "$1"

Then re-run the script

Doing that now, that block shows up at line 102 in the repo, but got it in there. Thanks.

@leanderhutton
Copy link
Author

New crash report from fresh .app package after script modifications:

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               darktable [98097]
Path:                  /Applications/darktable.app/Contents/MacOS/darktable
Identifier:            org.darktable
Version:               4.4.2 (4.4.2.0)
Code Type:             ARM-64 (Native)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2023-09-11 11:20:39.1189 -0400
OS Version:            macOS 14.0 (23A5337a)
Report Version:        12
Anonymous UUID:        E960BEA0-4210-4C5E-DECB-3E8FC9FC492D


Time Awake Since Boot: 1400 seconds

System Integrity Protection: enabled

Crashed Thread:        0

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000

Termination Reason:    Namespace DYLD, Code 1 Library missing
Library not loaded: @loader_path/../../../../opt/imath/lib/libImath-3_1.29.dylib
Referenced from: <9F7AA069-0A29-30F3-9426-C6C72260DD2D> /Applications/darktable.app/Contents/Resources/lib/libOpenEXR-3_2.31.dylib
Reason: tried: '/Applications/darktable.app/Contents/Resources/lib/../../../../opt/imath/lib/libImath-3_1.29.dylib' (no such file), '/usr/local/lib/libImath-3_1.29.dylib' (no such file), '/usr/lib/libImath-3_1.29.dylib' (no such file, not in dyld cache)Library not loaded: @rpath/libsharpyuv.0.dylib
Referenced from: <EC500041-6307-3D2A-B392-745A2A7C818E> /Applications/darktable.app/Contents/Resources/lib/libwebp.7.dylib
Reason: tried: '/Applications/darktable.app/Contents/Resources/lib/../lib/libsharpyuv.0.dylib' (no such file), '/Applications/darktable.app/Contents/MacOS/../Resources/lib/darktable/libsharpyuv.0.dylib' (no such file), '/Applications/darktable.app/Contents/MacOS/../Resources/lib/darktable/libsharpyuv.0.dylib' (no such file), '/usr/local/lib/libsharpyuv.0.dylib' (no such file),
(terminated at launch; ignore backtrace)

@leanderhutton
Copy link
Author

this is what that whole block of the script looks like after modification, lines 91-109:

    # Check for any homebrew dependencies
    if [[ -n "$hbDependencies" && "$hbDependencies" != "" ]]; then

        # Iterate over homebrew dependencies to reset path accordingly
        for hbDependency in $hbDependencies; do

            # Store file name 
            dynDepOrigFile=$(basename "$hbDependency")
            dynDepTargetFile="$dtResourcesDir/lib/$dynDepOrigFile"
    
            echo "Resetting executable path for dependency <$hbDependency> of <$1>"

            codesign --verbose --force --preserve-metadata=entitlements,requirements,flags,runtime -i "org.darktable" -s - $hbDependency
    
            # Set correct executable path
            install_name_tool -change "$hbDependency" "@executable_path/../Resources/lib/$dynDepOrigFile" "$1"
        done
    
    fi 

@zisoft
Copy link
Collaborator

zisoft commented Sep 11, 2023

Are the warnings still in the log?

install_name_tool: warning: changes being made to the file will invalidate the code signature in: ...

@zisoft
Copy link
Collaborator

zisoft commented Sep 11, 2023

I thought the Homebrew builds were for nightlies only?

Some people use Macports, others use Homebrew as their package manager.
darktable provides build scripts for both.

@leanderhutton
Copy link
Author

Yes, please see attached.
3_output.log

@zisoft
Copy link
Collaborator

zisoft commented Sep 12, 2023

Ok, changing the libraries signatures does not help here. Please reset the script to its original state.

For some reason, the packaging script 3_make_hb_darktable_package_sh fails to detect the @loader_path on your system (line 116 of the script). To further debug the issue can you please save the following script to a file hb_test.sh i.e. in your home directory and execute it: bash hb_test.sh. Then post the full output of the script here.

The script does not make any modifications, it just prints some results on how the libraries in the darktable package are handled during the packaging process. For that, it only uses /usr/local/lib/libOpenEXR-3_2.31.dylib

#!/bin/bash

LIB=/usr/local/lib/libOpenEXR-3_2.31.dylib

homebrewHome=$(brew --prefix)
hbDependencies=""

echo "homebrewHome: ${homebrewHome}"
echo

echo "otool output:"
otool -L $LIB
echo

function output {
    for e in $1; do
        echo $e 
    done
}



echo "Dependencies:"
oToolLDependencies=$(otool -L "$LIB" 2>/dev/null | grep compatibility | cut -d\( -f1 | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//' | uniq)
output "$oToolLDependencies"
echo

echo "Handle relative paths:"
oToolLDependencies=$(echo "$oToolLDependencies" | sed "s#@loader_path/[../]*opt/#${homebrewHome}/opt/#")
output "$oToolLDependencies"
echo

echo "Homebrew dependencies:"
if [[ "$oToolLDependencies" == *"$homebrewHome"* ]]; then
    hbDependencies=$(echo "$oToolLDependencies" | grep "$homebrewHome")
fi
output "$hbDependencies"
echo

echo "Modifications:"
if [[ -n "$hbDependencies" && "$hbDependencies" != "" ]]; then

    # Iterate over homebrew dependencies to reset path accordingly
    for hbDependency in $hbDependencies; do
        echo "  $hbDependency"

        # Store file name
        dynDepOrigFile=$(basename "$hbDependency")

        echo "  Executable path: @executable_path/../Resources/lib/$dynDepOrigFile"

        # Check for loader path
        oToolLoader=$(otool -L "$LIB" 2>/dev/null | grep '@loader_path')
        echo "  oToolLoader step 1: $oToolLoader"
        oToolLoader=$(otool -L "$LIB" 2>/dev/null | grep '@loader_path' | grep $dynDepOrigFile)
        echo "  oToolLoader step 2: $oToolLoader"
        oToolLoader=$(otool -L "$LIB" 2>/dev/null | grep '@loader_path' | grep $dynDepOrigFile | cut -d\( -f1 | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')
        echo "  oToolLoader step 3: $oToolLoader"
        oToolLoader=$(otool -L "$LIB" 2>/dev/null | grep '@loader_path' | grep $dynDepOrigFile | cut -d\( -f1 | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//' ) || true
        if [[ -n "$oToolLoader" ]]; then
            echo "  Loader path old: $oToolLoader"
            oToolLoaderNew=$(echo $oToolLoader | sed "s#@loader_path/##" | sed "s#../../../../opt/.*##")
            echo "  Loader path new: @loader_path/${oToolLoaderNew}${dynDepOrigFile}"
        fi

        echo
    done
fi

@leanderhutton
Copy link
Author

Updated the LIB path for Apple Silicon:

LIB=/opt/homebrew/lib/libOpenEXR-3_2.31.dylib

Output:

./hb_test.bsh  
homebrewHome: /opt/homebrew

otool output:
/opt/homebrew/lib/libOpenEXR-3_2.31.dylib:
	/opt/homebrew/opt/openexr/lib/libOpenEXR-3_2.31.dylib (compatibility version 31.0.0, current version 31.3.2)
	@rpath/libIlmThread-3_2.31.dylib (compatibility version 31.0.0, current version 31.3.2)
	@rpath/libOpenEXRCore-3_2.31.dylib (compatibility version 31.0.0, current version 31.3.2)
	@rpath/libIex-3_2.31.dylib (compatibility version 31.0.0, current version 31.3.2)
	@loader_path/../../../../opt/imath/lib/libImath-3_1.29.dylib (compatibility version 29.0.0, current version 29.8.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.100.3)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1500.65.0)

Dependencies:
/opt/homebrew/opt/openexr/lib/libOpenEXR-3_2.31.dylib
@rpath/libIlmThread-3_2.31.dylib
@rpath/libOpenEXRCore-3_2.31.dylib
@rpath/libIex-3_2.31.dylib
@loader_path/../../../../opt/imath/lib/libImath-3_1.29.dylib
/usr/lib/libSystem.B.dylib
/usr/lib/libc++.1.dylib

Handle relative paths:
/opt/homebrew/opt/openexr/lib/libOpenEXR-3_2.31.dylib
@rpath/libIlmThread-3_2.31.dylib
@rpath/libOpenEXRCore-3_2.31.dylib
@rpath/libIex-3_2.31.dylib
/opt/homebrew/opt/imath/lib/libImath-3_1.29.dylib
/usr/lib/libSystem.B.dylib
/usr/lib/libc++.1.dylib

Homebrew dependencies:
/opt/homebrew/opt/openexr/lib/libOpenEXR-3_2.31.dylib
/opt/homebrew/opt/imath/lib/libImath-3_1.29.dylib

Modifications:
  /opt/homebrew/opt/openexr/lib/libOpenEXR-3_2.31.dylib
  Executable path: @executable_path/../Resources/lib/libOpenEXR-3_2.31.dylib
  oToolLoader step 1: 	@loader_path/../../../../opt/imath/lib/libImath-3_1.29.dylib (compatibility version 29.0.0, current version 29.8.0)
  oToolLoader step 2: 
  oToolLoader step 3: 

  /opt/homebrew/opt/imath/lib/libImath-3_1.29.dylib
  Executable path: @executable_path/../Resources/lib/libImath-3_1.29.dylib
  oToolLoader step 1: 	@loader_path/../../../../opt/imath/lib/libImath-3_1.29.dylib (compatibility version 29.0.0, current version 29.8.0)
  oToolLoader step 2: 	@loader_path/../../../../opt/imath/lib/libImath-3_1.29.dylib (compatibility version 29.0.0, current version 29.8.0)
  oToolLoader step 3: @loader_path/../../../../opt/imath/lib/libImath-3_1.29.dylib
  Loader path old: @loader_path/../../../../opt/imath/lib/libImath-3_1.29.dylib
  Loader path new: @loader_path/libImath-3_1.29.dylib

@leanderhutton
Copy link
Author

Some people use Macports, others use Homebrew as their package manager.
darktable provides build scripts for both.

Yes, I was just surprised that a switch had been made to HB for the official builds given the backwards compatibility issues for older releases of MacOS.

I'm thankful to have both as Homebrew ran over my dog while his buddy pointed and laughed so I prefer MacPorts myself. Also more familiar with ports from my FreeBSD days.

@zisoft
Copy link
Collaborator

zisoft commented Sep 13, 2023

The output of hb_test.sh is exactly as expected.
The only reason I can imagine for the @loader_path not being updated is that due to the warnings of install_name_tool the processing loop is aborted.

So can you please edit 3_make_hb_darktable_package_sh and append || true at the end of each install_name_tool call:

line 88:
install_name_tool -rpath @loader_path/../lib/darktable @loader_path/../Resources/lib/darktable "$1" || true

line 113:
install_name_tool -change "$hbDependency" "@executable_path/../Resources/lib/$dynDepOrigFile" "$1" || true

line 120:
install_name_tool -change "$oToolLoader" "@loader_path/${oToolLoaderNew}${dynDepOrigFile}" "$1" || true

line 138:
install_name_tool -id "@executable_path/../Resources/lib/$libraryOrigFile" "$1" || true

The re-run 3_make_hb_darktable_package_sh and see if darktable.app runs.

@leanderhutton
Copy link
Author

leanderhutton commented Sep 15, 2023

Sorry for the delay @zisoft but I finally got a chance to try this today. I was building the release-4.4.2 branch so that's why my line numbers weren't lining up, switched to master. Nonetheless, this worked I now have a working darktable app package in Sonoma.

@zisoft
Copy link
Collaborator

zisoft commented Sep 15, 2023

Great to hear that, thank you!
I will prepare a PR. 👍

@leanderhutton
Copy link
Author

Still no luck with the MacPorts build but that's more to do with problems with MacPorts than darktable. I'll keep checking with the MacPorts project for that.

@esafak
Copy link

esafak commented Oct 11, 2023

Still no luck with the MacPorts build but that's more to do with problems with MacPorts than darktable. I'll keep checking with the MacPorts project for that.

If this is still a problem please file a ticket at macports

@MStraeten
Copy link
Collaborator

macports released a sonoma package several days ago, so there are no longer issues expected - at least all darktable dependencies were built fine for m1 last week…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: macos support macos related issues and PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants