From 03846fc69b28ebcefb12030c2695865decee0ba3 Mon Sep 17 00:00:00 2001 From: Matt Lyons Date: Mon, 25 Nov 2024 14:42:38 -0600 Subject: [PATCH] Fix macOS icu dylib loading problems when MacPorts is not installed (#1346) --- .github/workflows/package-main.yml | 28 +++++++++++++++++++++++++++- .github/workflows/publish.yml | 28 +++++++++++++++++++++++++++- .github/workflows/test.yml | 29 ++++++++++++++++++++++++++++- c-sharp/ParanextDataProvider.csproj | 4 ++-- c-sharp/Program.cs | 8 ++++++++ 5 files changed, 92 insertions(+), 5 deletions(-) diff --git a/.github/workflows/package-main.yml b/.github/workflows/package-main.yml index bb107f069e..b7b6b44172 100644 --- a/.github/workflows/package-main.yml +++ b/.github/workflows/package-main.yml @@ -27,10 +27,36 @@ jobs: if: ${{ matrix.os == 'macos-latest' }} uses: melusina-org/setup-macports@v1 + - name: Install loader tools on macOS + if: ${{ matrix.os == 'macos-latest' }} + run: | + sudo port -v install ld64 + - name: Install icu4c on macOS if: ${{ matrix.os == 'macos-latest' }} run: | - sudo port -v install icu + sudo port -v install icu @74.2_0 +universal + + - name: Fixup loader paths for icu4c + if: ${{ matrix.os == 'macos-latest' }} + # LIB_DEPENDENCIES are of the form " " + # For example, libicuuc (shortened to "uc") depends on libicudata (shortened to "data") + # Dependencies can be seen by running "dyld_info -dependents /path/to/something.dylib" + run: | + ICU_VERSION=74 + LIB_DEPENDENCIES=" + i18n data + i18n uc + io data + io i18n + io uc + uc data + " + LIB_DEPENDENCIES=$(echo "$LIB_DEPENDENCIES" | sed '/^$/d') + while IFS= read -r line; do + set -- $line + sudo install_name_tool -change "/opt/local/lib/libicu$2.$ICU_VERSION.dylib" "@loader_path/libicu$2.$ICU_VERSION.dylib" "/opt/local/lib/libicu$1.$ICU_VERSION.dylib" + done <<< "$LIB_DEPENDENCIES" - name: Checkout git repo uses: actions/checkout@v4 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ae29240a3f..75f0c86b64 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -27,10 +27,36 @@ jobs: if: ${{ matrix.os == 'macos-latest' }} uses: melusina-org/setup-macports@v1 + - name: Install loader tools on macOS + if: ${{ matrix.os == 'macos-latest' }} + run: | + sudo port -v install ld64 + - name: Install icu4c on macOS if: ${{ matrix.os == 'macos-latest' }} run: | - sudo port -v install icu + sudo port -v install icu @74.2_0 +universal + + - name: Fixup loader paths for icu4c + if: ${{ matrix.os == 'macos-latest' }} + # LIB_DEPENDENCIES are of the form " " + # For example, libicuuc (shortened to "uc") depends on libicudata (shortened to "data") + # Dependencies can be seen by running "dyld_info -dependents /path/to/something.dylib" + run: | + ICU_VERSION=74 + LIB_DEPENDENCIES=" + i18n data + i18n uc + io data + io i18n + io uc + uc data + " + LIB_DEPENDENCIES=$(echo "$LIB_DEPENDENCIES" | sed '/^$/d') + while IFS= read -r line; do + set -- $line + sudo install_name_tool -change "/opt/local/lib/libicu$2.$ICU_VERSION.dylib" "@loader_path/libicu$2.$ICU_VERSION.dylib" "/opt/local/lib/libicu$1.$ICU_VERSION.dylib" + done <<< "$LIB_DEPENDENCIES" - name: Checkout git repo uses: actions/checkout@v4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2f5b8558ba..e29adc1bf8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,9 +30,36 @@ jobs: if: ${{ matrix.os == 'macos-latest' }} uses: melusina-org/setup-macports@v1 + - name: Install loader tools on macOS + if: ${{ matrix.os == 'macos-latest' }} + run: | + sudo port -v install ld64 + - name: Install icu4c on macOS if: ${{ matrix.os == 'macos-latest' }} - run: sudo port -v install icu + run: | + sudo port -v install icu @74.2_0 +universal + + - name: Fixup loader paths for icu4c + if: ${{ matrix.os == 'macos-latest' }} + # LIB_DEPENDENCIES are of the form " " + # For example, libicuuc (shortened to "uc") depends on libicudata (shortened to "data") + # Dependencies can be seen by running "dyld_info -dependents /path/to/something.dylib" + run: | + ICU_VERSION=74 + LIB_DEPENDENCIES=" + i18n data + i18n uc + io data + io i18n + io uc + uc data + " + LIB_DEPENDENCIES=$(echo "$LIB_DEPENDENCIES" | sed '/^$/d') + while IFS= read -r line; do + set -- $line + sudo install_name_tool -change "/opt/local/lib/libicu$2.$ICU_VERSION.dylib" "@loader_path/libicu$2.$ICU_VERSION.dylib" "/opt/local/lib/libicu$1.$ICU_VERSION.dylib" + done <<< "$LIB_DEPENDENCIES" - name: Check out Git repository uses: actions/checkout@v4 diff --git a/c-sharp/ParanextDataProvider.csproj b/c-sharp/ParanextDataProvider.csproj index 222e08e9a6..6d46b31de0 100644 --- a/c-sharp/ParanextDataProvider.csproj +++ b/c-sharp/ParanextDataProvider.csproj @@ -28,7 +28,7 @@ - + @@ -60,7 +60,7 @@ by default. --> - + PreserveNewest diff --git a/c-sharp/Program.cs b/c-sharp/Program.cs index 7e4cfce959..76e77fb14b 100644 --- a/c-sharp/Program.cs +++ b/c-sharp/Program.cs @@ -16,6 +16,14 @@ public static async Task Main() Console.WriteLine("Paranext data provider starting up"); Thread.CurrentThread.Name = "Main"; + // Turn on additional logging to help diagnose failures on macOS + if (OperatingSystem.IsMacOS()) + { + System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.ConsoleTraceListener()); + System.Diagnostics.Trace.AutoFlush = true; + System.Diagnostics.Trace.WriteLine("Trace logging enabled"); + } + using PapiClient papi = new(); try {