Skip to content

Commit

Permalink
Merge pull request #194 from lyonsil/master
Browse files Browse the repository at this point in the history
Fix builds on macOS
  • Loading branch information
lyonsil authored Jun 5, 2024
2 parents 5979f1c + c6328e6 commit 0342df4
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 25 deletions.
22 changes: 18 additions & 4 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,13 +45,17 @@ 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

- name: Test
run: dotnet test --configuration Release --no-build source/icu.net.sln -- NUnit.TestOutputXml=TestResults
- name: Test on .NET 8.0
run: dotnet test -p:TargetFramework=net8.0 --configuration Release --no-build source/icu.net.sln -- NUnit.TestOutputXml=TestResults

- name: Test on .NET Framework 4.6.1 (Windows only)
if: ${{ matrix.os == 'windows-latest' }}
run: dotnet test -p:TargetFramework=net461 --configuration Release --no-build source/icu.net.sln -- NUnit.TestOutputXml=TestResults

- name: Upload Test Results
if: always()
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>net461;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
16 changes: 13 additions & 3 deletions source/icu.net.tests/icu.net.tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net461;net6.0</TargetFrameworks>
<!--
If you only want to test on a particular target framework, run "dotnet test -p:TargetFramework=XXX"
For example, on macOS you probably want to run "dotnet test -p:TargetFramework=net8.0" since 4.6.1 isn't supported
-->
<TargetFrameworks>net461;net8.0</TargetFrameworks>
<RootNamespace>Icu.Tests</RootNamespace>
<AssemblyTitle>icu.net.tests</AssemblyTitle>
<IsPackable>false</IsPackable>
Expand All @@ -10,8 +14,14 @@
<PackageReference Include="Icu4c.Win.Min" Version="59.1.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Console" Version="3.15.2" />
<!--
Only version 4.3.2 of NUnit3TestAdapter is able to run tests for both .NET 8.0 and .NET Framework 4.6.1.
https://docs.nunit.org/articles/vs-test-adapter/Supported-Frameworks.html
Going forward we're going to have to drop 4.6.1 support to be able to support newer .NET versions.
-->
<PackageReference Include="NUnit3TestAdapter" Version="4.3.2" />
<PackageReference Include="NUnit.Console" Version="3.17.0" />
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
</ItemGroup>
Expand Down
5 changes: 3 additions & 2 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
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 0342df4

Please sign in to comment.