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

Ensure each published platform uses matching hostfxr library #2272

Merged
merged 3 commits into from
Nov 13, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Task("InstallMonoAssets")
.WithCriteria(() => !Platform.Current.IsWindows)
.Does(() =>
{
if (DirectoryHelper.Exists(env.Folders.Mono))
if (DirectoryHelper.Exists(env.Folders.Mono) && !publishAll)
{
Information("Skipping Mono assets installation, because they already exist.");
return;
Expand Down Expand Up @@ -716,7 +716,7 @@ Task("Test")
}
});

void CopyMonoBuild(BuildEnvironment env, string sourceFolder, string outputFolder)
void CopyMonoBuild(BuildEnvironment env, string sourceFolder, string outputFolder, string platformName = null)
{
DirectoryHelper.Copy(sourceFolder, outputFolder, copySubDirectories: false);

Expand All @@ -725,8 +725,52 @@ void CopyMonoBuild(BuildEnvironment env, string sourceFolder, string outputFolde
// Copy MSBuild runtime and libraries
DirectoryHelper.Copy($"{env.Folders.MSBuild}", msbuildFolder);

var msbuildBinFolder = CombinePaths(msbuildFolder, "bin", "Current");
var msbuildBinFolder = CombinePaths(msbuildFolder, "Current", "Bin");
EnsureDirectoryExists(msbuildBinFolder);

if (platformName == null)
{
return;
}

// We built the .msbuild folder initially based on the current platform.
// We are now copying Mono for a particular platform and need to ensure that
// we are including the appropriate hostfxr library.

var platformParts = platformName.Split("-");
var platform = platformParts[0];
var architecture = platformParts.Length > 1 ? platformParts[1] : "x64";

// Since multiple linux builds will be generated we need to
JoeRobich marked this conversation as resolved.
Show resolved Hide resolved
var msbuildSdkResolverTargetFolder = CombinePaths(msbuildBinFolder, "SdkResolvers", "Microsoft.DotNet.MSBuildSdkResolver");
var hostfxrDylibPath = CombinePaths(msbuildSdkResolverTargetFolder, "libhostfxr.dylib");
var hostfxrSoPath = CombinePaths(msbuildSdkResolverTargetFolder, "libhostfxr.so");

if (FileHelper.Exists(hostfxrSoPath))
{
// Remove the Linux hostfxr library.
FileHelper.Delete(hostfxrSoPath);
}
else if (FileHelper.Exists(hostfxrDylibPath))
{
// Remove the MacOS hostfxr library.
FileHelper.Delete(hostfxrDylibPath);
}

if (platform == "osx")
{
CopyDotNetHostResolver(env, "osx", "x64", "libhostfxr.dylib", msbuildSdkResolverTargetFolder, copyToArchSpecificFolder: false);
}
else if (platform == "linux")
{
if (architecture == "x86")
{
// There is no x86 hostfxr use x64 instead.
architecture = "x64";
}

CopyDotNetHostResolver(env, "linux", architecture, "libhostfxr.so", msbuildSdkResolverTargetFolder, copyToArchSpecificFolder: false);
}
}

void CopyExtraDependencies(BuildEnvironment env, string outputFolder)
Expand Down Expand Up @@ -829,7 +873,7 @@ string PublishMonoBuildForPlatform(string project, MonoRuntime monoRuntime, Buil
var sourceFolder = CombinePaths(env.Folders.ArtifactsPublish, project, "mono");
var omnisharpFolder = CombinePaths(outputFolder, "omnisharp");

CopyMonoBuild(env, sourceFolder, omnisharpFolder);
CopyMonoBuild(env, sourceFolder, omnisharpFolder, monoRuntime.PlatformName);

CopyExtraDependencies(env, outputFolder);
AddOmniSharpBindingRedirects(omnisharpFolder);
Expand Down