Repository navigation
Add Microsoft.DotNet.CMake.Sdk MSBuild SDK for integrating native builds into MSBuild. - #4533
Conversation
| <CMakeBuildDependsOn></CMakeBuildDependsOn> | ||
| </PropertyGroup> | ||
|
|
||
| <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" /> |
There was a problem hiding this comment.
Does this SDK really need to import the entire .NET sdk with the C# and VB compilation support? Can we just import Microsoft.Common.props/targets to get the necessary ProjectReference and PackageReference stuff?
There was a problem hiding this comment.
I should be able to just import Microsoft.Common.props/targets. Does that also enable importing of Directory.Build.props/targets? The reason I initially included the Microsoft.NET.Sdk was to get all of the niceties, not just PackageReference.
There was a problem hiding this comment.
Yea, Directory.Build.props/targets support is in the common props/targets, along with PackageReferences.
There was a problem hiding this comment.
I don't think I can remove this without breaking a scenario. When I tried to remove this locally, I lost the automatic setting of the Configuration property as well as all output path properties, which this SDK uses as defaults unless otherwise specified.
|
cc @janvorli |
| <ItemGroup Condition="'$(_IsMultiConfigurationGenerator)' != 'true'"> | ||
|
|
||
| <!-- ############################################################### --> | ||
| <!-- The following is required because the single configuration --> |
There was a problem hiding this comment.
This does not look pretty. Do we have this in the existing "run cmake from .cmd/.sh" solution?
If we have this, where is it?
If we do not have this, can we do the same?
There was a problem hiding this comment.
Yes we do. This particular file is used by the CoreCLR test build only. It's located at https://github.com/dotnet/runtime/blob/master/src/coreclr/tests/src/Directory.Build.targets#L113-L170.
This MSBuild file is only used for the "managed project needs native assets in its output directory and we don't want to include all CMake outputs or have to duplicate our directory structure in our install directory" scenario. Basically the CoreCLR test tree and likely the WinForms test tree scenarios, not any product build scenarios.
This version is a significantly cleaned-up version of that implementation that also supports single-configuration generators on Windows (such as NMake or Ninja) instead of on Unix platforms only.
There was a problem hiding this comment.
This particular file is used by the CoreCLR test build only.
Would it be better for this to stay next to CoreCLR tests only if it is only used by them?
There was a problem hiding this comment.
The WinForms scenario will also use this feature (thats what #4008 is about). Also, I plan to use this feature in the dotnet/benchmarks repository to enable interop testing without having to flow the native test assets. If it weren't for the WinForms scenario, these targets would likely live in the dotnet/runtime repo.
…Visual Studio generator.
|
@jkoritzinsky can you please share the bringup script it generates so that I can get some idea about it? |
| <_VSNativeCompilerComponentName>Microsoft.VisualStudio.Component.VC.Tools.$(_VSNativeCompilerComponentArchName)</_VSNativeCompilerComponentName> | ||
| </PropertyGroup> | ||
|
|
||
| <Target Name="ResolveVSGenerator" Condition="'$(CMakeGenerator)' == 'Visual Studio'"> |
There was a problem hiding this comment.
I do not see equivalent resolve steps for clang/gcc in your change (like https://github.com/dotnet/runtime/blob/master/src/coreclr/src/pal/tools/find-gcc.sh). How are those going to work?
There was a problem hiding this comment.
Paths to those scripts will be passed into the CMake SDK by setting the CMakeCompilerSearchScript property. The value of that property will be run before the configure step and before the build step and inserted into the bringup script before the configure and build commands respectively.
There was a problem hiding this comment.
Would it be better for this to be symmetric between platforms? Why to hardcode stuff for Windows, but not for Unix?
There was a problem hiding this comment.
How would we be able to choose clang compiler version to use? I have many versions installed on my devbox. And how about all the other command line options that our current build.cmd/.sh scripts have?
There was a problem hiding this comment.
We'd add support in what would be the coreclr.cmakeproj project file to allow you to pass MSBuild properties to configure which compiler to use as matches for the current parameters into build.sh. The PGO related arguments could be easily converted over to MSBuild properties. The ninja parameter converts directly to a /p:CMakeGenerator=Ninja argument. And we could wrap these properties with command line switches on coreclr.sh or build.sh in dotnet/runtime.
As mentioned in one of the top-level comments below, this isn't particularly useful in the CoreCLR build at the moment, but if/when we move towards Arcadifying the build, this will enable us to allow developers to use the all-up build scripts to build the native component without extra layers of wrapping when leaving MSBuild to build the native project (Bash->MSBuild->CMake) instead of going Bash->MSBuild->Bash->CMake.
There was a problem hiding this comment.
There's a significant difference IMO in how we have to put in the work to find compilers on Windows vs Unix. On Windows you need to find a VS installation (likely with vswhere), and find the VC tools, which is significantly more convoluted than looking for a program on PATH. These targets also ensure that the VS install we pick actually has the toolset required. Our current scripts don't validate that you have the right toolsets for the architecture you're targeting, so you'll get a less clean error output.
Additionally, the reasoning behind not including the find-gcc.sh and find-clang.sh scripts here was for bringup reasons. If they were in the package, then we'd have to have a way to restore the package to get the scripts on the machine where we're building, which isn't possible, copy the files to the output, or inline them into the bringup script. My initial thought was to keep the find-gcc and find-clang scripts local to dotnet/runtime so the bringup script generation could be as simple as possible (one file, only call a script the user specifies and call cmake and cmake --build).
There was a problem hiding this comment.
Can the find-vs.bat, find-gcc.bat or find-clang.bat scripts can be under runtime\eng, potentially part of the file set that arcade copies around? It would make the solution symmetric, not part of any package, and potentially usable by any repo.
There was a problem hiding this comment.
That's a great idea! We should definitely be able to move them into eng/common and use them from this SDK.
@janvorli was concerned about the bringup scenarios. My primary concern about this is the layer of complexity that this adds. I understand why you may want to use this for small tests where you would like to build a random little helper unmanaged binaries with as little ceremony as possible. I am fine with that. I do not understand why this makes the unmanaged product build better. It is just more stuff that can go wrong and somebody needs to understand. |
|
I haven't ported over the CoreCLR build to use this yet, but I can post the bringup script that is generated when I use this on Windows for the build of the hosting components: If I had passed in a script such as the |
|
The main reasons I had for using this to make the product build better:
I agree that this doesn't add much today to coreclr's build, but if/when we go through the Arcadification process for coreclr, this becomes more valuable. |
|
I have an additional question about some more logic. How are we going to do the target distro rid detection, CPU type detection and the OS detection that we now have in the _build-commons.sh? |
|
We're going to have to solve those questions as part of Arcadifiying coreclr. They don't need to be done as part of this SDK. Just to clarify in case there's confusion, using this SDK in the current product build would only replace the following portions of src/coreclr/build.cmd and src/coreclr/build.sh:
As I mentioned previously, there isn't a good value proposition for moving the CoreCLR build to using this SDK until/if we Arcadify coreclr's build. Many of the other items you mentioned can either be done within MSBuild (as is done for corehost's build) or added to the eng/build.sh and eng/build.cmd scripts that wrap the Arcade-based build of dotnet/runtime. |
|
One more thought about coreclr. More than 50% of the build.sh script deals with native build. It looks like we could strip dealing with the managed stuff (managed assemblies build, package creation, optimization data restoration) and leave just the stuff relevant for native components build. We have a similar thing in the former corefx where the build-native.sh script basically does just that. |
|
That's something we can definitely do. I personally feel that we have a lot of duplication between a "native logic only" build.sh/.cmd in coreclr, the Keeping the .sh and .cmd scripts exclusively for bringup scenarios feels like we might be optimizing our development for a few weeks/month or two every few years instead of the more common scenarios when we aren't doing bringup on new platforms. Bringup on new platforms doesn't require all of the options in the scripts as we have today to support all of our supported platforms; the compiler version and the CMake parameters can be hard-coded and the invocation could be a 3 line script (excluding return code handling) to do the whole build instead of the hundereds of lines of logic in each of the build/build-native scripts. As a result, we have a lot of additional complexity in our scripts that are just duplicating logic that in many cases is already in MSBuild. |
Many of the Arcade build system designs and ideas are managed code centric. I do not believe they work well for repos with large unmanaged components. We are having this discussion because we do not have shared understanding where we want to land. It may be best to first get a shared understanding where we want to land (e.g what does Arcadification looks like - for both CoreCLR and Mono) and then work back from there. I like the old CoreCLR build system better - for the same max process depth reason I have mentioned in dotnet/runtime#672 (comment). I believe that this (max process depth 3) is better: than this (max process depth 4): |
|
I don't want to optimize for the bringup scenarios, but I would also like to not to have to reinvent the wheel that we already had and was working fine when someone wants to bring up a new platform. I see the scripts as a nice and simple to debug way to prepare cmake command line arguments. I expect only a very minor changes to these scripts when bringing up new platforms and also a very minor changes to these scripts over the time. During the last years, we were mostly just adding support for a new clang version (until your recent changes, of course). |
I agree. We should make sure we understand what Arcadification looks like for CoreCLR before making a decision on what to do for the native portion.
I've been thinking about the process tree from the outer Building from the The proposed solution would make the process tree from the root build script: Bringing down the process tree size by one.
One option here would be to use the SDK for supported platforms, and have a I just want to make sure that this SDK has enough utility to present as a possible option during our CoreCLR Arcadification discussions and that it has the needed features to enable developers of CoreCLR to easily build the product if we were to choose it as an option, either now or in the future. |
|
I agree with @jkotas on having cmake build on the same level as msbuild. Arcade does not require msbuild to drive everything. The downside of not building everything via msbuild is serialization of the builds (first all cmake "projects" will build, then all msbuild projects). But that's given by having 2 different build systems (make, msbuild) that don't communicate dependencies with each other. |
|
If we go that route of running the CMake builds completely outside of MSBuild, then I agree that we would not need or want to use this SDK for product builds. This SDK is still useful for the CoreCLR test tree, WinForms' test tree, and as a mechanism to create native assets in dotnet/performance. |
|
My 2¢ on this PR: Would it be possible to publish this SDK to the main NuGet feed? As currently written, it would be useful for many other projects than just .NET Core. In fact, I have been meaning to research writing this exact library myself for some time for use in some of my mixed-language C++/C# projects. Once again, you beat me to it! 😃 Thanks! |
Co-Authored-By: William Kent <[email protected]>
Yes that is true, but the behavior with
I'll see if I can make something work.
Looks like in the time between when I started this PR and now Arcade changed how they discover vswhere. I'll need to adapt my design to support the change.
Looks like your solution doesn't have an x64 platform configuration set up. The solution file needs to have that set up separately in VS in the platform drop down so that it propagates through correctly. |
…ces so a single restore from the root will restore everything.
|
@hughbe I've fixed the vswhere lookup and hooked into the regular restore process. |
|
@markwilkie anywhere in particular you'd like me to add a link to this from the Arcade docs? |
|
|
||
| - CMakeLists | ||
| - The root CMakeLists.txt of the native build. | ||
| - The root CMakeLists.txt of the native build. This is required. |
There was a problem hiding this comment.
is there an argument for making this CMakeLists.txt by defau;t?
There was a problem hiding this comment.
I personally don't like that implicit behavior since it's such a small entry. I want to be able to look at a project file and see at a glance what I'm building. If it's default it adds more cognitive load. I feel that this is different than a csproj because the csproj is actually building the output, whereas this SDK is just driving something else getting built. If that something else isn't explicitly in the project, then it makes it harder to reason about.
Are you sure? I'm seeing it in the sln file
I get the errors running |
|
I see the issue now. In the solution file, it's set to build the System.Windows.Forms.Interop.Tests assembly as AnyCPU even when platform is set to x86 or x64. If you look in the |
alexperovich
left a comment
There was a problem hiding this comment.
I don't have any concerns with the current implementation. Please get signoff from @jkotas as well.
|
No concerns from me. I do not know much about the art of writing .NET SDKs, so I am able to comment on whether the details are right. |
|
Would love to get this merged in and used. @jkoritzinsky would you mind helping out with dotnet/winforms#1932 if I encounter any problems? Thanks so much! |
|
@mmitche can I get signoff or review on this PR? cc: @markwilkie |
|
Adding @jaredpar as there was a cmake discussion earlier that this might help with. |
| <PropertyGroup> | ||
| <CMakeOutputDir Condition="'$(CMakeOutputDir)' != ''">$([MSBuild]::NormalizePath($(CMakeOutputDir)))</CMakeOutputDir> | ||
| <CMakeOutputDir Condition="'$(CMakeOutputDir)' == ''">$([MSBuild]::NormalizePath($(IntermediateOutputPath)))</CMakeOutputDir> | ||
| <CMakeOutputDir>$(CMakeOutputDir.TrimEnd('\'))</CMakeOutputDir> |
There was a problem hiding this comment.
Does forward slash on non-windows platforms need to be trimmed?
There was a problem hiding this comment.
Yes. The forward slash was causing the script to escape the following space and was breaking the script parsing. By removing the slash, we stop that escaping.
|
I believe this is ready to be merged. Can someone with merge permissions merge this in? |
|
When should we expect this to be available? It doesn't look like it is available in 20200424.11 /cc: @hughbe |
|
As this was merged in 4/27, you shouldn't see it in a version from 4/24. The change is available in the latest build that we are sending to repos tomorrow. |
|
Hah, silly me, should have made a connection that the version contains the date |
|
Also, you can always check the repo's README to see which version is the latest that we are sending to consumer repos after it goes through our validation pipeline. |
|
I have found an error using this on my Mac: Seems like we are incorrectly passing a |
| <ItemGroup> | ||
| <_CMakeArguments Include="-G "$(CMakeGenerator)"" /> | ||
| <_CMakeArguments Condition="'$(CMakeToolset)' != ''" Include="-T $(CMakeToolset)" /> | ||
| <_CMakeArguments Condition="'$(_CMakePassArchitectureToGenerator)' != ''" Include="-A $(Platform)" /> |
There was a problem hiding this comment.
we actually set _CMakePassArchitectureToGenerator to False, so this test fails.
|
Upon fixing the architecture parameter (#5388), I get the following errors: I confirmed that the generator script worked. However, the code that doesn't work is the <Target Name="_ResolveNonMSVCCompilerToolchain" Condition="'$(CMakeCompilerToolchain)' != 'MSVC' and '$(CMakeCompilerSearchScript)' == ''">
<Error Condition="$([MSBuild]::IsOsPlatform(Windows))" Text="This SDK does not support using non-MSVC toolchains on Windows." />
<PropertyGroup>
<CMakeCompilerSearchScript>
. $([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)', '$(RepositoryEngineeringDir)common/native/find-native-compiler.sh') $(CMakeCompilerToolchain) $(CMakeCompilerMajorVersion) $(CMakeCompilerMinorVersion)
</CMakeCompilerSearchScript>
</PropertyGroup>
</Target>There appears to be two bugs here:
Updated #5388 |
|
Also, running |
Adds a new MSBuild SDK for driving CMake invocations and easily referencing native built assets from managed projects. Additionally, it provides a mechanism for a managed project to reference a native project and have its assets copied to the output directory. It also has a feature to support outputting a script that runs the configure and build steps as MSBuild would have run them to more easily enable supporting standing up native builds on platforms where MSBuild is not currently available (bringup scenarios).
TODO: Open a PR into dotnet/arcade-services to recognize Microsoft.DotNet.CMake.Sdk as an MSBuild SDK for Maestro++
Fixes #4008
cc: @hughbe, @AaronRobinsonMSFT
Also @jkotas, can you take a look at the design here for supporting bringup scenarios and let me know if there's anything more needed to better support bringup? I'd like to enable us to use this for all native build scenarios, but I know there are concerns around the team about supporting new platforms.