8000 Introduce cross-platform compatibility and pipeline by swernli · Pull Request #205 · UbiquityDotNET/Llvm.NET · GitHub
[go: up one dir, main page]

Skip to content

Introduce cross-platform compatibility and pipeline #205

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

Closed

Conversation

swernli
Copy link
@swernli swernli commented Jan 20, 2021

This change introduces infrastructure for cross-platform build of native components in LibLlvm, allowing the eventual .NET core package to build in all the binaries and enable execution on Linux and MacOS. This also updates the GitHub Actions workflow as a first attempt to support the full cross-platform build and test.

This addresses #193

Alan Geller and others added 24 commits January 19, 2021 12:52
This is a big change because it includes cached binaries and headers from the release versions of Mac and Linux LLVM along with the cached build output for Windows. The default behavior of the pipeline is now to use the cached binaries, resulting in about a 20 min build time, while the full 3 hour build of LLVM is still an option. Lots of clean-up on the scripts is still left to do, as well as creating a multistage pipeline that can actually produce and test the fully formed nuget package, but this is a big chunk of the way there.
Enable multi-stage pipeline with skipped tests.
@swernli swernli force-pushed the swernli/xplat-pipeline branch 2 times, most recently from 58b8ab5 to 697a364 Compare January 20, 2021 09:48
@swernli swernli marked this pull request as draft January 20, 2021 23:23
@swernli
Copy link
Author
swernli commented Jan 20, 2021

Converting this PR to draft in favor of breaking it up into smaller chunks to make reviewing easier.

Copy link
Collaborator
@alan-geller alan-geller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this is awesome!!!

@@ -18,7 +18,7 @@ namespace LlvmBindingsGenerator.Templates
/// Class to produce the template output
/// </summary>

#line 1 "D:\GitHub\Ubiquity.NET\Ubiquity.NET.Llvm\src\Interop\LlvmBindingsGenerator\Templates\T4\ExportsTemplate.tt"
#line 1 "D:\github\Llvm.NET\src\Interop\LlvmBindingsGenerator\Templates\T4\ExportsTemplate.tt"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change to match the new build scripts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is generated by T4 (https://docs.microsoft.com/en-us/visualstudio/modeling/code-generation-and-t4-text-templates) and inherits line numbers from the system where they were generated. At some point it might be worth adding these files to the gitignore and then incorporating T4 generation into the build instead of relying on a developer opening the project in VS to regenerate them, but I didn’t find an easy way to do that, so deferred to the existing process.

@@ -19,61 +19,6 @@ namespace Ubiquity.NET.Llvm.Interop
/// <summary>Interop methods for the Ubiquity.NET LibLLVM library</summary>
public static partial class NativeMethods
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to delete this file? It looks empty...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The static string in there is needed by the infrastructure that uses the dll name, but I can put that into another file to avoid the seemingly empty file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if that const string is all that is left, it can move easy enough

@@ -6,11 +6,11 @@ Param(
[System.String]$BuildMode = 'All'
)

pushd $PSScriptRoot
Push-Location $PSScriptRoot
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please retain the original alias forms, they are standard powershell commands

@@ -26,19 +26,31 @@ try
if((Test-Path -PathType Container $buildInfo['BuildOutputPath']) -and $ForceClean )
{
Write-Information "Cleaning output folder from previous builds"
rd -Recurse -Force -Path $buildInfo['BuildOutputPath']
Remove-Item -Recurse -Force -Path $buildInfo['BuildOutputPath']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the alias names, the style for this project prefers the alias names.

md $buildInfo['NuGetOutputPath'] -ErrorAction SilentlyContinue | Out-Null
$includePath = (Join-Path $PSScriptRoot llvm include)
$libPath = (Join-Path $PSScriptRoot llvm lib)
if ((Test-Path -PathType Container $includePath) -and $ForceClean) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style for this project places braces on a new line for all languages

@@ -0,0 +1,31 @@
Param(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this script needed? It's mostly overhead compared to what it does. This functionality is better suited inlined as it was.

pushd (Join-Path $buildInfo.BuildOutputPath 'bin\PatchVsForLibClang\Release\netcoreapp3.1')
try
{
Write-Information "Patching VS CRT for parsing with LibClang..."
.\PatchVsForLibClang.exe $vs.InstallationPath
if ($LASTEXITCODE -ne 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style, please follow style of this repo regarding braces on a new line

@@ -157,7 +157,6 @@
<ClInclude Include="targetver.h" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this if CMAKE is used to build the DLL, shouldn't this just be deleted?

@@ -18,6 +18,7 @@
#include <llvm/IR/Module.h>
#include <llvm/Transforms/Instrumentation.h>
#include <llvm/PassRegistry.h>
#include <llvm/LinkAllPasses.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this added? It wasn't needed to build the code before this change...

@@ -2,6 +2,7 @@
#include <llvm/ADT/Triple.h>
#include <llvm/Support/CBindingWrapping.h>
#include <llvm/Support/TargetParser.h>
#include <llvm/Config/llvm-config.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this added?

@@ -11,8 +11,8 @@
Due to current limitations of the CppSharp library NUGET package, this only supports the Windows Desktop .NET Framework (64 bit)
This means that this project can't use language features > 7.3 (Limits for .NET Framework)
-->
<TargetFramework>net47</TargetFramework>
<Nullable />
<TargetFramework>net48</TargetFramework>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change the TFM for this? It can't run on anything other than windows .NET framework anyway so why make this change?

@@ -72,13 +72,15 @@ public static void Initialize( TestContext ctx )
tm.EmitToFile( module, TestObjFileName, CodeGenFileType.ObjectFile );
}

[TestCategory("ObjFiles")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If all of these tests need to be skipped on some target, then something is either fundamentally wrong with the tests, or the object file support. so a bug should be filed for this as disabling these all for a platform is cutting off a big chunk of functionality of the library.

@swernli
Copy link
Author
swernli commented Jan 24, 2021

@smaillet Thanks for all the feedback. I'll respond to a few key repeated points here, and then work on different PRs that focus on specific parts of the infrastructure to hopefully allow for more targeted discussion.

  • Regarding removal of unused powershell, I didn't realize the module here was a copy of one that you use in other places. Perhaps a readme in that folder that points this outl could help until you take the steps you've described of making this its own repo that is treated as a true common source of the code. As I restructure these PRs, I'll avoid making any changes to this module that are not strictly necessary and not try to do any cleanup based on what seems to be unused.
  • This "all-up" PR includes a lot of changes and infrastructure introduced to support building the full LLVM source on Azure DevOps which is not compatible with the current GitHub Actions pipeline. Rather than merge that in we can just refer back to some of the working branches where that was developed, so I won't include that in future PRs until we know we want to start pulling that in.
  • Some of the changes to scripts and how errors were reported was done to make the scripts compatible with Azure DevOps, where error reporting from powershell works slightly differently. Given that we want to rely on GitHub Action workflows instead, I will not be making those changes.
  • As you mentioned on one of the other PRs the caching of LLVM binaries into the repo directly is probably the most controversial element of the changes, so rather than start there I will focus on the build changes that can be made without affecting the binary download step. That should give us some time to brainstorm alternate approaches to solving that problem.
  • Unfortunately, powershell aliases do not have consistent behavior across platforms, so to get the scripts ready for running on Linux and Mac we will need to replace aliases with the full cmldets. The issue of powershell cmdlet aliases shadowing Linux built-in shell commands has been a long discussed one (see Figure out aliases PowerShell/PowerShell#929 for some of the debate around this), but the end result was that several aliases were removed from the Linux version in order to avoid shadowing. The end result is that using a given alias is not guaranteed to resolve to the same command on every platform, possibly leading to script errors (which it did with these scripts). The recommendation is to avoid using alias in scripts in favor of the full cmdlet in order to ensure the right functionality is invoked and have the highest chance of compatibility. This is also why most powershell editor extensions treat aliases as warnings.

I should have a fresh PR with just first incremental step available for review shortly, and to avoid confusion I will just submit one PR at a time instead of using drafts to imply readiness.

@swernli swernli closed this Jan 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0