-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dependency on default .NET extraction process on program startup
Complete refactoring the integration of native dependencies to move the remaining ones that triggered the default .NET extraction process on program startup. In earlier versions, on MacOS environments, we observed crashes with error messages like the following: ``` Failure processing application bundle. Failed to determine location for extracting embedded files. DOTNET_BUNDLE_EXTRACT_BASE_DIR is not set, and a read-write cache directory couldn't be created. ``` The changes in this commit complete the refactoring around native dependencies to avoid these crashes. + Adapt consumers of LibGit2Sharp to invoke the setup of native dependencies if necessary. + Refactor moving common functionality around the setup of native dependencies in a shared module. + Adapt the build automation to disable the extraction and adapt the collection of files for releases to avoid noise in the downloads for users. + Expand the testing automation to adapt to the recent observations of problems with integrating native dependencies: Add the `self-test` command on the command-line interface to run tests for functionality that depends on native dependencies, such as libgit2 and ClearScript.V8. Expand the automated checks to integrate these new tests with the same builds published with releases (single-file!).
- Loading branch information
Showing
16 changed files
with
587 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using ElmTime.NativeDependency; | ||
using Pine; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Threading.Tasks; | ||
|
||
namespace ElmTime.Git; | ||
|
||
public class LibGit2Sharp | ||
{ | ||
private static readonly IReadOnlyDictionary<OSPlatform, IReadOnlyList<DependencyFile>> DependenciesFilesByOs = | ||
ImmutableDictionary<OSPlatform, IReadOnlyList<DependencyFile>>.Empty | ||
.Add( | ||
OSPlatform.Linux, | ||
ImmutableList.Create( | ||
new DependencyFile( | ||
HashBase16: "7ca026cf714e14fbab252d83974c04b843affe035e041aa1eda0d0bc258426be", | ||
ExpectedFileName: "libgit2-e632535.so", | ||
RemoteSources: new[] { "https://www.nuget.org/api/v2/package/LibGit2Sharp.NativeBinaries/2.0.320" }))) | ||
.Add( | ||
OSPlatform.Windows, | ||
ImmutableList.Create( | ||
new DependencyFile( | ||
HashBase16: "76b97b411e73b7487825dd0f98cba7ce7f008bef3cbe8a35bf1af8c651a0f4a0", | ||
ExpectedFileName: "git2-e632535.dll", | ||
RemoteSources: new[] { "https://www.nuget.org/api/v2/package/LibGit2Sharp.NativeBinaries/2.0.320" }))) | ||
.Add( | ||
OSPlatform.OSX, | ||
ImmutableList.Create( | ||
new DependencyFile( | ||
HashBase16: "9dc84237ca835b189636697cbe1439b0894303798efd95b55a3353ca4f12b1bb", | ||
ExpectedFileName: "libgit2-e632535.dylib", | ||
RemoteSources: new[] { "https://www.nuget.org/api/v2/package/LibGit2Sharp.NativeBinaries/2.0.320" }))); | ||
|
||
public static readonly Lazy<Task> SetupTask = new(() => | ||
{ | ||
EnsureNativeLibrariesAvailableForCurrentPlatform(); | ||
return Task.CompletedTask; | ||
}); | ||
|
||
public static void EnsureNativeLibrariesAvailableForCurrentPlatform() | ||
{ | ||
var setupForCurrentOs = | ||
DependenciesFilesByOs.FirstOrDefault(c => RuntimeInformation.IsOSPlatform(c.Key)).Value | ||
?? | ||
throw new Exception("Unknown OS: " + RuntimeInformation.OSDescription); | ||
|
||
var cacheDirectory = Path.GetDirectoryName(DotNetAssembly.ProgramExecutableFileName.Value)!; | ||
|
||
foreach (var dependency in setupForCurrentOs) | ||
{ | ||
NativeDependencies.SetUpDependency( | ||
cacheDirectory: cacheDirectory, | ||
dependency: dependency); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace ElmTime.NativeDependency; | ||
|
||
|
||
public record DependencyFile( | ||
string HashBase16, | ||
string ExpectedFileName, | ||
IReadOnlyList<string> RemoteSources); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Pine; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Security.Cryptography; | ||
|
||
namespace ElmTime.NativeDependency; | ||
|
||
public class NativeDependencies | ||
{ | ||
public static void SetUpDependency( | ||
string cacheDirectory, | ||
DependencyFile dependency) | ||
{ | ||
var hash = CommonConversion.ByteArrayFromStringBase16(dependency.HashBase16); | ||
|
||
var fileAbsolutePath = Path.Combine(cacheDirectory, dependency.ExpectedFileName); | ||
|
||
if (File.Exists(fileAbsolutePath)) | ||
{ | ||
var fileContent = File.ReadAllBytes(fileAbsolutePath); | ||
|
||
var fileContentHash = SHA256.HashData(fileContent); | ||
|
||
if (fileContentHash.SequenceEqual(hash)) | ||
{ | ||
return; | ||
} | ||
} | ||
|
||
var file = BlobLibrary.GetBlobWithSHA256Cached( | ||
sha256: hash, | ||
getIfNotCached: | ||
() => | ||
BlobLibrary.DownloadFromUrlAndExtractBlobWithMatchingHashFromListOfRemoteSources( | ||
dependency.RemoteSources, hash)) | ||
?? throw new Exception( | ||
"Did not find dependency " + dependency.HashBase16 + " (" + dependency.ExpectedFileName + ") in any of the " + | ||
dependency.RemoteSources.Count + " remote sources"); | ||
|
||
ExecutableFile.CreateAndWriteFileToPath(fileAbsolutePath, file, executable: true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.