Skip to content

Enable P2P's to determine their own compilation RID #828

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,7 @@ project.json.template

# Ignore Generated project template files
Project.csproj
Project.vbproj
Project.vbproj

# VS Code
.vscode/
2 changes: 1 addition & 1 deletion DotnetCLIVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0-rc4-004771
1.0.0-rc4-004828
15 changes: 15 additions & 0 deletions TestAssets/TestProjects/AppWithLibraryAndRid/App/App.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
<RuntimeIdentifiers>osx.10.11-x64;ubuntu.14.04-x64;win10-x64</RuntimeIdentifiers>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\LibraryWithRid\LibraryWithRid.csproj" />
<ProjectReference Include="..\LibraryWithRids\LibraryWithRids.csproj" />
<ProjectReference Include="..\LibraryWithoutRid\LibraryWithoutRid.csproj" />
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions TestAssets/TestProjects/AppWithLibraryAndRid/App/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace App
{
class Program
{
static void Main(string[] args)
{
var libraryWithRidNativeOutput = LibraryWithRid.NativeCode.InvokeNativeCodeAndReturnAString();

var libraryWithRidsNativeOutput = LibraryWithRid.NativeCode.InvokeNativeCodeAndReturnAString();

var libraryWithRidCompileTimeRid = LibraryWithRid.NativeCode.GetRidStoredInAssemblyDescriptionAttribute();

var libraryWithRidsCompileTimeRid = LibraryWithRids.NativeCode.GetRidStoredInAssemblyDescriptionAttribute();

var libraryWithRidStatus = $"{libraryWithRidNativeOutput} {libraryWithRidCompileTimeRid}";

var libraryWithRidsStatus = $"{libraryWithRidsNativeOutput} {libraryWithRidsCompileTimeRid}";

var portableLibraryStatus = LibraryWithoutRid.PortableClass.GetHelloWorld();

Console.WriteLine($"{libraryWithRidStatus} {libraryWithRidsStatus} {portableLibraryStatus}");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
<RuntimeIdentifier>$(TestRuntimeIdentifier)</RuntimeIdentifier>
</PropertyGroup>
<PropertyGroup>
<Description>'$(RuntimeIdentifier)'</Description>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SQLite">
<Version>3.13.0</Version>
</PackageReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Runtime.InteropServices;

namespace LibraryWithRid
{
public static class LinuxNativeMethods
{
[DllImport("libsqlite3", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr sqlite3_libversion();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Runtime.InteropServices;

namespace LibraryWithRid
{
public static class MacNativeMethods
{
[DllImport("libsqlite3", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr sqlite3_libversion();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Reflection;
using System.Runtime.InteropServices;

namespace LibraryWithRid
{
public class NativeCode
{
public static string InvokeNativeCodeAndReturnAString()
{
switch(GetRidStoredInAssemblyDescriptionAttribute())
{
case "'ubuntu.14.04-x64'":
return Marshal.PtrToStringAnsi(LinuxNativeMethods.sqlite3_libversion());
case "'osx.10.11-x64'":
return Marshal.PtrToStringAnsi(MacNativeMethods.sqlite3_libversion());
case "'win10-x64'":
return Marshal.PtrToStringAnsi(WindowsNativeMethods.sqlite3_libversion());
default:
return "Unexpected RID. Cannot find sqlite3.";
}
}

public static string GetRidStoredInAssemblyDescriptionAttribute()
{
return typeof(NativeCode)
.GetTypeInfo()
.Assembly
.GetCustomAttribute<AssemblyDescriptionAttribute>()
?.Description;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Runtime.InteropServices;

namespace LibraryWithRid
{
public static class WindowsNativeMethods
{
[DllImport("sqlite3", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr sqlite3_libversion();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
<RuntimeIdentifiers>osx.10.11-x64;ubuntu.14.04-x64;win10-x64</RuntimeIdentifiers>
<Description>'$(RuntimeIdentifier)'</Description>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SQLite">
<Version>3.13.0</Version>
</PackageReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Runtime.InteropServices;

namespace LibraryWithRids
{
public static class LinuxNativeMethods
{
[DllImport("libsqlite3", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr sqlite3_libversion();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Runtime.InteropServices;

namespace LibraryWithRids
{
public static class MacNativeMethods
{
[DllImport("libsqlite3", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr sqlite3_libversion();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Reflection;
using System.Runtime.InteropServices;

namespace LibraryWithRids
{
public class NativeCode
{
public static string InvokeNativeCodeAndReturnAString()
{
switch(GetRidStoredInAssemblyDescriptionAttribute())
{
case "'ubuntu.14.04-x64'":
return Marshal.PtrToStringAnsi(LinuxNativeMethods.sqlite3_libversion());
case "'osx.10.11-x64'":
return Marshal.PtrToStringAnsi(MacNativeMethods.sqlite3_libversion());
case "'win10-x64'":
return Marshal.PtrToStringAnsi(WindowsNativeMethods.sqlite3_libversion());
default:
return "Unexpected RID. Cannot find sqlite3.";
}
}

public static string GetRidStoredInAssemblyDescriptionAttribute()
{
return typeof(NativeCode)
.GetTypeInfo()
.Assembly
.GetCustomAttribute<AssemblyDescriptionAttribute>()
?.Description;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Runtime.InteropServices;

namespace LibraryWithRids
{
public static class WindowsNativeMethods
{
[DllImport("sqlite3", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr sqlite3_libversion();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace LibraryWithoutRid
{
public class PortableClass
{
public static string GetHelloWorld()
{
return "Hello World";
}
}
}
1 change: 1 addition & 0 deletions build/build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
DestinationFolder="$(TestsDirectory)"
/>

<Message Text="$(DotNetTool) &quot;$(TestsDirectory)\xunit.console.netcore.exe&quot; &quot;@(TestAssembly, '&quot; &quot;')&quot; -xml &quot;@(XmlTestFile)&quot;" Importance="High" />
Copy link
Contributor

@nguerrera nguerrera Feb 16, 2017

Choose a reason for hiding this comment

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

Did you mean to check this in? I like it, but the formatting is off and it would be nice not to duplicate the command in Message and Exec.

<Exec Command="$(DotNetTool) &quot;$(TestsDirectory)\xunit.console.netcore.exe&quot; &quot;@(TestAssembly, '&quot; &quot;')&quot; -xml &quot;@(XmlTestFile)&quot;"
LogStandardErrorAsError="true"
WorkingDirectory="$(TestsDirectory)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ Copyright (c) .NET Foundation. All rights reserved.
with the referencing project's target framework.
============================================================
-->
<Target Name="GetTargetFrameworkProperties" Returns="TargetFramework=$(NearestTargetFramework);ProjectHasSingleTargetFramework=$(_HasSingleTargetFramework)">
<Target Name="GetTargetFrameworkProperties" Returns="TargetFramework=$(NearestTargetFramework);ProjectHasSingleTargetFramework=$(_HasSingleTargetFramework);ProjectIsRidAgnostic=$(_IsRidAgnostic)">

<PropertyGroup>
<!-- indicate to caller that project is RID agnostic so that a global property RuntimeIdentifier value can be removed -->
<_IsRidAgnostic>false</_IsRidAgnostic>
<_IsRidAgnostic Condition=" '$(RuntimeIdentifier)' == '' and '$(RuntimeIdentifiers)' == '' ">true</_IsRidAgnostic>

<!-- If a ReferringTargetFramework was not specified, and we only have one TargetFramework, then don't try to check compatibility -->
<_SkipNearestTargetFrameworkResolution Condition="'$(TargetFramework)' != '' and '$(ReferringTargetFramework)' == ''">true</_SkipNearestTargetFrameworkResolution>
<NearestTargetFramework Condition="'$(_SkipNearestTargetFrameworkResolution)' == 'true'">$(TargetFramework)</NearestTargetFramework>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Commands;
using Microsoft.NET.TestFramework.Assertions;
using System.IO;
using Xunit;
using static Microsoft.NET.TestFramework.Commands.MSBuildTest;

namespace Microsoft.NET.Build.Tests
{
public class GivenThatWeWantToBuildASelfContainedAppWithLibrariesAndRid : SdkTest
{
[Fact]
public void It_builds_a_RID_specific_runnable_output()
{
if (UsingFullFrameworkMSBuild)
{
// Disable this test on full framework, as the current build won't have access to
// https://github.com/Microsoft/msbuild/pull/1674
// See https://github.com/dotnet/sdk/issues/877
return;
}

var runtimeIdentifier = RuntimeEnvironment.GetRuntimeIdentifier();
var testAsset = _testAssetsManager
.CopyTestAsset("AppWithLibraryAndRid")
.WithSource();

var projectPath = Path.Combine(testAsset.TestRoot, "App");

var restoreCommand = new RestoreCommand(Stage0MSBuild, projectPath, "App.csproj");
restoreCommand
.Execute($"/p:TestRuntimeIdentifier={runtimeIdentifier}")
.Should()
.Pass();

var buildCommand = new BuildCommand(Stage0MSBuild, projectPath);

buildCommand
.Execute($"/p:RuntimeIdentifier={runtimeIdentifier}", $"/p:TestRuntimeIdentifier={runtimeIdentifier}")
.Should()
.Pass();

var outputDirectory = buildCommand.GetOutputDirectory("netcoreapp1.0");
var selfContainedExecutable = $"App{Constants.ExeSuffix}";

Command.Create(Path.Combine(outputDirectory.FullName, selfContainedExecutable), new string[] { })
.CaptureStdOut()
.Execute()
.Should()
.Pass()
.And
.HaveStdOutContaining($"3.13.0 '{runtimeIdentifier}' 3.13.0 '{runtimeIdentifier}' Hello World");
}
}
}