Skip to content

Commit

Permalink
Fix builds on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
lyonsil committed Jun 3, 2024
1 parent 5979f1c commit baa9186
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 22 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/CI-CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ jobs:
name: "Build and Test"
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
os: [windows-latest, ubuntu-latest, macos-12]
runs-on: ${{ matrix.os }}

steps:
- name: Install MacPorts
if: ${{ matrix.os == 'macos-12' }}
uses: melusina-org/setup-macports@v1

- name: Install icu4c on macOS
if: ${{ matrix.os == 'macos-12' }}
run: |
sudo port -v install icu
echo "DYLD_FALLBACK_LIBRARY_PATH=$HOME/lib:/usr/local/lib:/usr/lib:/opt/local/lib" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
Expand All @@ -35,7 +45,7 @@ jobs:
- name: Install .NET Core
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x

- name: Build
run: dotnet build --configuration Release source/icu.net.sln
Expand Down
2 changes: 1 addition & 1 deletion source/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFrameworks>net40;net451;netstandard1.6;net6.0</TargetFrameworks>
<TargetFrameworks>net40;net451;netstandard1.6;net8.0</TargetFrameworks>
<PlatformAlias>netstandard</PlatformAlias>
<OutputPath>$(MSBuildThisFileDirectory)\..\output\$(Configuration)</OutputPath>
<PackageOutputPath>$(MSBuildThisFileDirectory)\..\output</PackageOutputPath>
Expand Down
2 changes: 1 addition & 1 deletion source/TestHelper/TestHelper.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net461;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<OutputPath>../../output/$(Configuration)/TestHelper</OutputPath>
<OutputType>Exe</OutputType>
<RootNamespace>Icu.Tests</RootNamespace>
Expand Down
16 changes: 8 additions & 8 deletions source/icu.net.tests/IcuWrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public void IcuVersion()
Assert.That(int.TryParse(result.Substring(0, result.IndexOf(".", StringComparison.Ordinal)), out var major), Is.True);
}

[Platform(Exclude = "Linux",
Reason = "These tests require ICU4C installed from NuGet packages which isn't available on Linux")]
[Platform(Include = "Win",
Reason = "These tests require ICU4C installed from NuGet packages which is only available on Windows")]
[Test]
public void ConfineVersions_WorksAfterInit()
{
Expand All @@ -105,8 +105,8 @@ public void ConfineVersions_WorksAfterInit()
Assert.That(Wrapper.DataDirectory, Is.EqualTo("Test"));
}

[Platform(Exclude = "Linux",
Reason = "These tests require ICU4C installed from NuGet packages which isn't available on Linux")]
[Platform(Include = "Win",
Reason = "These tests require ICU4C installed from NuGet packages which is only available on Windows")]
[Test]
public void ConfineVersions_LoadFromDifferentDirectory_LowerVersion()
{
Expand All @@ -130,8 +130,8 @@ public void ConfineVersions_LoadFromDifferentDirectory_LowerVersion()
Assert.That(result, Is.EqualTo(NativeMethodsTests.MinIcuLibraryVersion));
}

[Platform(Exclude = "Linux",
Reason = "These tests require ICU4C installed from NuGet packages which isn't available on Linux")]
[Platform(Include = "Win",
Reason = "These tests require ICU4C installed from NuGet packages which is only available on Windows")]
[Test]
public void ConfineVersions_LoadFromDifferentDirectory_HigherVersion()
{
Expand All @@ -155,8 +155,8 @@ public void ConfineVersions_LoadFromDifferentDirectory_HigherVersion()
Assert.That(result, Is.EqualTo(NativeMethodsTests.FullIcuLibraryVersion));
}

[Platform(Exclude = "Linux",
Reason = "These tests require ICU4C installed from NuGet packages which isn't available on Linux")]
[Platform(Include = "Win",
Reason = "These tests require ICU4C installed from NuGet packages which is only available on Windows")]
[Test]
public void ConfineVersions_LoadFromDifferentDirectory_NotInPreferredDir()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class NativeMethodsHelperTests
{
private string _filenameWindows;
private string _filenameLinux;
private string _filenameMac;

private int CallGetIcuVersionInfoForNetCoreOrWindows()
{
Expand All @@ -36,13 +37,16 @@ public void Setup()
File.WriteAllText(_filenameWindows, "just a dummy file");
_filenameLinux = Path.Combine(NativeMethodsTests.OutputDirectory, $"libicuuc.so.{Wrapper.MaxSupportedIcuVersion}.1");
File.WriteAllText(_filenameLinux, "just a dummy file");
_filenameMac = Path.Combine(NativeMethodsTests.OutputDirectory, $"libicuuc.{Wrapper.MaxSupportedIcuVersion}.dylib");
File.WriteAllText(_filenameMac, "just a dummy file");
}

[TearDown]
public void TearDown()
{
File.Delete(_filenameWindows);
File.Delete(_filenameLinux);
File.Delete(_filenameMac);
Wrapper.Cleanup();
}

Expand Down
4 changes: 2 additions & 2 deletions source/icu.net.tests/NativeMethods/NativeMethodsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

namespace Icu.Tests
{
[Platform(Exclude = "Linux",
Reason = "These tests require ICU4C installed from NuGet packages which isn't available on Linux")]
[Platform(Include = "Win",
Reason = "These tests require ICU4C installed from NuGet packages which is only available on Windows")]
[TestFixture]
public class NativeMethodsTests
{
Expand Down
10 changes: 6 additions & 4 deletions source/icu.net.tests/ResourceBundleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ public void GetStringContentsWithKeys()
}
}

[TestCase("en_US", ExpectedResult = "[a b c d e f g h i j k l m n o p q r s t u v w x y z]")]
[TestCase("de_DE", ExpectedResult = "[a ä b c d e f g h i j k l m n o ö p q r s ß t u ü v w x y z]")]
[TestCase("fr_FR", ExpectedResult = "[a à â æ b c ç d e é è ê ë f g h i î ï j k l m n o ô œ p q r s t u ù û ü v w x y ÿ z]")]
[TestCase("en_US", ExpectedResult = "[abcdefghijklmnopqrstuvwxyz]")]
[TestCase("de_DE", ExpectedResult = "[aäbcdefghijklmnoöpqrsßtuüvwxyz]")]
[TestCase("fr_FR",ExpectedResult = "[aàâæbcçdeéèêëfghiîïjklmnoôœpqrstuùûüvwxyÿz]")]
public string GetStringByKey(string localeId)
{
using (var resourceBundle = new ResourceBundle(null, localeId))
{
return resourceBundle.GetStringByKey("ExemplarCharacters");
// Ideally this should be parsed by something that understands UnicodeSet structures
// Since spaces aren't meaningful in UnicodeSets, we'll take a shortcut and remove them
return resourceBundle.GetStringByKey("ExemplarCharacters").Replace(" ", "");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions source/icu.net.tests/TimeZoneTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void GetOffsetTimeZonesTest()
Assert.GreaterOrEqual(timezones.Count(), 3);
}

[Platform(Exclude = "MacOsX", Reason = "The timezone ID for UTC can come in as Universal")]
[Test]
public void GetDefaultTimeZoneTest()
{
Expand Down
2 changes: 1 addition & 1 deletion source/icu.net.tests/icu.net.tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net461;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<RootNamespace>Icu.Tests</RootNamespace>
<AssemblyTitle>icu.net.tests</AssemblyTitle>
<IsPackable>false</IsPackable>
Expand Down
7 changes: 4 additions & 3 deletions source/icu.net/NativeMethods/NativeMethodsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ internal static class NativeMethodsHelper
private const string Icu4c = nameof(Icu4c);
private const string IcuRegexLinux = @"libicu\w+.so\.(?<version>[0-9]{2,})(\.[0-9])*";
private const string IcuRegexWindows = @"icu\w+(?<version>[0-9]{2,})(\.[0-9])*\.dll";
private const string IcuRegexMac = @"libicu\w+.(?<version>[0-9]{2,})(\.[0-9])*.dylib";

private static readonly Regex IcuBinaryRegex = new Regex($"{IcuRegexWindows}|{IcuRegexLinux}$", RegexOptions.Compiled);
private static readonly string IcuSearchPattern = Platform.OperatingSystem == OperatingSystemType.Windows ? "icu*.dll" : "libicu*.so.*";
private static readonly Regex IcuBinaryRegex = new ($"{IcuRegexWindows}|{IcuRegexLinux}|{IcuRegexMac}$", RegexOptions.Compiled);
private static readonly string IcuSearchPattern = Platform.OperatingSystem == OperatingSystemType.Windows ? "icu*.dll" : Platform.OperatingSystem == OperatingSystemType.MacOSX ? "libicu*.*.dylib" : "libicu*.so.*";
private static readonly string NugetPackageDirectory = GetDefaultPackageDirectory(Platform.OperatingSystem);

// ReSharper disable once InconsistentNaming
Expand Down Expand Up @@ -81,7 +82,7 @@ public static IcuVersionInfo GetIcuVersionInfoForNetCoreOrWindows()
// If this is false, something went wrong. These files should have
// either been found above or we should have been able to locate the
// asset paths (for .NET Core and NuGet v3+ projects).
if (!TryGetNativeAssetPaths(context, out var nativeAssetPaths))
if (!TryGetNativeAssetPaths(context, out var nativeAssetPaths))
{
Trace.WriteLine("Could not locate icu native assets from DependencyModel.");
return IcuVersion;
Expand Down
9 changes: 9 additions & 0 deletions source/icu.net/icu.net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
<Compile Remove="SortKey.cs" />
</ItemGroup>

<!-- ICU must be installed using MacPorts before this will work -->
<ItemGroup>
<Content Include="/opt/local/lib/*.dylib" Condition="$([MSBuild]::IsOSPlatform('OSX'))">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<!-- Also add the following to .zprofile file. It is already included in the GitHub build. -->
<!-- export DYLD_FALLBACK_LIBRARY_PATH="$HOME/lib:/usr/local/lib:/usr/lib:/opt/local/lib" -->

<ItemGroup>
<None Include="App.config" Pack="true" PackagePath="contentFiles\any\any\$(AssemblyTitle).dll.config" />
<None Include="../../README.md" Pack="true" PackagePath="/">
Expand Down

0 comments on commit baa9186

Please sign in to comment.