Include project.json dependencies for native

This commit is contained in:
Senthil 2016-02-03 16:34:03 -08:00 committed by schellap
parent e8ef94e93f
commit ef00f0331e
15 changed files with 98 additions and 56 deletions

View file

@ -13,7 +13,7 @@ namespace Microsoft.DotNet.Cli.Build
public class CompileTargets public class CompileTargets
{ {
public static readonly string CoreCLRVersion = "1.0.1-rc2-23811"; public static readonly string CoreCLRVersion = "1.0.1-rc2-23811";
public static readonly string AppDepSdkVersion = "1.0.5-prerelease-00001"; public static readonly string AppDepSdkVersion = "1.0.6-prerelease-00001";
public static readonly List<string> AssembliesToCrossGen = GetAssembliesToCrossGen(); public static readonly List<string> AssembliesToCrossGen = GetAssembliesToCrossGen();

View file

@ -339,10 +339,10 @@ namespace Microsoft.DotNet.Tools.Build
args.Add(_args.ArchValue); args.Add(_args.ArchValue);
} }
if (!string.IsNullOrWhiteSpace(_args.IlcArgsValue)) foreach (var ilcArg in _args.IlcArgsValue)
{ {
args.Add("--ilcargs"); args.Add("--ilcarg");
args.Add(_args.IlcArgsValue); args.Add(ilcArg);
} }
if (!string.IsNullOrWhiteSpace(_args.IlcPathValue)) if (!string.IsNullOrWhiteSpace(_args.IlcPathValue))

View file

@ -13,7 +13,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
public ArchitectureMode Architecture { get; set; } public ArchitectureMode Architecture { get; set; }
public NativeIntermediateMode? NativeMode { get; set; } public NativeIntermediateMode? NativeMode { get; set; }
public IEnumerable<string> ReferencePaths { get; set; } public IEnumerable<string> ReferencePaths { get; set; }
public string IlcArgs { get; set; } public IEnumerable<string> IlcArgs { get; set; }
public IEnumerable<string> LinkLibPaths { get; set; } public IEnumerable<string> LinkLibPaths { get; set; }
public string AppDepSDKPath { get; set; } public string AppDepSDKPath { get; set; }
public string IlcPath { get; set; } public string IlcPath { get; set; }
@ -88,7 +88,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
config.LogPath = LogPath; config.LogPath = LogPath;
} }
if (!string.IsNullOrEmpty(IlcArgs)) if (IlcArgs != null)
{ {
config.IlcArgs = IlcArgs; config.IlcArgs = IlcArgs;
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.CommandLine; using System.CommandLine;
using System.Linq;
namespace Microsoft.DotNet.Tools.Compiler.Native namespace Microsoft.DotNet.Tools.Compiler.Native
{ {
@ -15,7 +16,8 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
BuildConfiguration? buildConfiguration = null; BuildConfiguration? buildConfiguration = null;
string mode = null; string mode = null;
NativeIntermediateMode? nativeMode = null; NativeIntermediateMode? nativeMode = null;
string ilcArgs = null; IReadOnlyList<string> ilcArgs = Array.Empty<string>();
IEnumerable<string> unquotIlcArgs = Array.Empty<string>();
string ilcPath = null; string ilcPath = null;
string ilcSdkPath = null; string ilcSdkPath = null;
string appDepSdk = null; string appDepSdk = null;
@ -26,7 +28,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
string cppCompilerFlags = null; string cppCompilerFlags = null;
IReadOnlyList<string> references = Array.Empty<string>(); IReadOnlyList<string> references = Array.Empty<string>();
IReadOnlyList<string> linklib = Array.Empty<string>(); IReadOnlyList<string> linklib = Array.Empty<string>();
try try
{ {
@ -46,7 +48,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
"Use to specify Managed DLL references of the app."); "Use to specify Managed DLL references of the app.");
// Custom Extensibility Points to support CoreRT workflow TODO better descriptions // Custom Extensibility Points to support CoreRT workflow TODO better descriptions
syntax.DefineOption("ilcargs", ref ilcArgs, "Use to specify custom arguments for the IL Compiler."); syntax.DefineOptionList("ilcarg", ref ilcArgs, "Use to specify custom arguments for the IL Compiler.");
syntax.DefineOption("ilcpath", ref ilcPath, "Use to specify a custom build of IL Compiler."); syntax.DefineOption("ilcpath", ref ilcPath, "Use to specify a custom build of IL Compiler.");
syntax.DefineOption("ilcsdkpath", ref ilcSdkPath, "Use to specify a custom build of IL Compiler SDK"); syntax.DefineOption("ilcsdkpath", ref ilcSdkPath, "Use to specify a custom build of IL Compiler SDK");
@ -67,7 +69,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
"The managed input assembly to compile to native."); "The managed input assembly to compile to native.");
helpText = syntax.GetHelpText(); helpText = syntax.GetHelpText();
if (string.IsNullOrWhiteSpace(inputAssembly)) if (string.IsNullOrWhiteSpace(inputAssembly))
{ {
syntax.ReportError("Input Assembly is a required parameter."); syntax.ReportError("Input Assembly is a required parameter.");
@ -99,6 +101,15 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
help = true; help = true;
} }
} }
unquotIlcArgs = ilcArgs.Select(s =>
{
if (!s.StartsWith("\"") || !s.EndsWith("\""))
{
throw new ArgumentSyntaxException("--ilcarg must be specified in double quotes");
}
return s.Substring(1, s.Length - 2);
});
}); });
} }
catch (ArgumentSyntaxException exception) catch (ArgumentSyntaxException exception)
@ -130,7 +141,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
BuildConfiguration = buildConfiguration, BuildConfiguration = buildConfiguration,
NativeMode = nativeMode, NativeMode = nativeMode,
ReferencePaths = references, ReferencePaths = references,
IlcArgs = ilcArgs, IlcArgs = unquotIlcArgs,
IlcPath = ilcPath, IlcPath = ilcPath,
IlcSdkPath = ilcSdkPath, IlcSdkPath = ilcSdkPath,
LinkLibPaths = linklib, LinkLibPaths = linklib,

View file

@ -1,13 +1,15 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
namespace Microsoft.DotNet.Tools.Compiler.Native namespace Microsoft.DotNet.Tools.Compiler.Native
{ {
public class ILCompilerInvoker public class ILCompilerInvoker
{ {
private readonly string ExecutableName = "corerun" + Constants.ExeSuffix; private static readonly string HostExeName = "corerun" + Constants.ExeSuffix;
private readonly string ILCompiler = "ilc.exe"; private static readonly string ILCompiler = "ilc.exe";
private IEnumerable<string> Args; private IEnumerable<string> Args;
private NativeCompileSettings config; private NativeCompileSettings config;
@ -27,14 +29,6 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
{ {
var argsList = new List<string>(); var argsList = new List<string>();
var managedPath = Path.Combine(config.IlcPath, ILCompiler);
if (!File.Exists(managedPath))
{
throw new FileNotFoundException("Unable to find ILCompiler at " + managedPath);
}
argsList.Add($"{managedPath}");
// Input File // Input File
var inputFilePath = config.InputManagedAssemblyPath; var inputFilePath = config.InputManagedAssemblyPath;
argsList.Add($"{inputFilePath}"); argsList.Add($"{inputFilePath}");
@ -43,32 +37,29 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
var coreLibsPath = Path.Combine(config.IlcSdkPath, "sdk"); var coreLibsPath = Path.Combine(config.IlcSdkPath, "sdk");
foreach (var reference in Directory.EnumerateFiles(coreLibsPath, "*.dll")) foreach (var reference in Directory.EnumerateFiles(coreLibsPath, "*.dll"))
{ {
argsList.Add($"-r"); argsList.Add($"-r:{reference}");
argsList.Add($"{reference}");
} }
// AppDep References // AppDep References
foreach (var reference in config.ReferencePaths) foreach (var reference in config.ReferencePaths)
{ {
argsList.Add($"-r"); argsList.Add($"-r:{reference}");
argsList.Add($"{reference}");
} }
// Set Output DetermineOutFile // Set Output DetermineOutFile
var outFile = DetermineOutputFile(config); var outFile = DetermineOutputFile(config);
argsList.Add($"-out"); argsList.Add($"-o:{outFile}");
argsList.Add($"{outFile}");
// Add Mode Flag TODO // Add Mode Flag TODO
if (config.NativeMode == NativeIntermediateMode.cpp) if (config.NativeMode == NativeIntermediateMode.cpp)
{ {
argsList.Add("-cpp"); argsList.Add("--cpp");
} }
// Custom Ilc Args support // Custom Ilc Args support
if (! string.IsNullOrEmpty(config.IlcArgs)) foreach (var ilcArg in config.IlcArgs)
{ {
argsList.Add(config.IlcArgs); argsList.Add(ilcArg);
} }
Args = argsList; Args = argsList;
@ -76,9 +67,20 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
public int Invoke() public int Invoke()
{ {
var executablePath = Path.Combine(config.IlcPath, ExecutableName); // Check if ILCompiler is present
var ilcExePath = Path.Combine(config.IlcPath, ILCompiler);
var result = Command.Create(executablePath, Args) if (!File.Exists(ilcExePath))
{
throw new FileNotFoundException("Unable to find ILCompiler at " + ilcExePath);
}
// Write the response file
var intermediateDirectory = config.IntermediateDirectory;
var rsp = Path.Combine(intermediateDirectory, "dotnet-compile-native-ilc.rsp");
File.WriteAllLines(rsp, Args, Encoding.UTF8);
var hostPath = Path.Combine(config.IlcPath, HostExeName);
var result = Command.Create(hostPath, new string[] { ilcExePath, "@" + $"{rsp}" })
.ForwardStdErr() .ForwardStdErr()
.ForwardStdOut() .ForwardStdOut()
.Execute(); .Execute();

View file

@ -25,7 +25,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
private readonly string[] _appdeplibs = private readonly string[] _appdeplibs =
{ {
"libSystem.Native.a" "System.Native.a"
}; };
public LinuxCppCompileStep(NativeCompileSettings config) public LinuxCppCompileStep(NativeCompileSettings config)
@ -121,4 +121,4 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
return outfile; return outfile;
} }
} }
} }

View file

@ -24,7 +24,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
private readonly string[] _appdeplibs = private readonly string[] _appdeplibs =
{ {
"libSystem.Native.a" "System.Native.a"
}; };
public LinuxRyuJitCompileStep(NativeCompileSettings config) public LinuxRyuJitCompileStep(NativeCompileSettings config)

View file

@ -30,7 +30,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
private readonly string[] _appdeplibs = private readonly string[] _appdeplibs =
{ {
"libSystem.Native.a" "System.Native.a"
}; };

View file

@ -26,7 +26,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
private readonly string[] appdeplibs = private readonly string[] appdeplibs =
{ {
"libSystem.Native.a" "System.Native.a"
}; };
public MacRyuJitCompileStep(NativeCompileSettings config) public MacRyuJitCompileStep(NativeCompileSettings config)

View file

@ -19,8 +19,8 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
private string _outputDirectory; private string _outputDirectory;
private string _intermediateDirectory; private string _intermediateDirectory;
private string _logPath; private string _logPath;
private string _ilcArgs; private IEnumerable<string> _ilcArgs;
private readonly List<string> _referencePaths; private readonly Dictionary<string, string> _referencePaths;
private readonly List<string> _linkLibPaths; private readonly List<string> _linkLibPaths;
private string _cppCompilerFlags; private string _cppCompilerFlags;
@ -81,12 +81,12 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
{ {
get get
{ {
return _referencePaths; return _referencePaths.Values;
} }
} }
// Optional Customization Points (Can be null) // Optional Customization Points (Can be null)
public string IlcArgs public IEnumerable<string> IlcArgs
{ {
get { return _ilcArgs; } get { return _ilcArgs; }
set { _ilcArgs = value; } set { _ilcArgs = value; }
@ -168,8 +168,11 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
BuildType = DefaultBuiltType; BuildType = DefaultBuiltType;
NativeMode = DefaultNativeModel; NativeMode = DefaultNativeModel;
AppDepSDKPath = Path.Combine(AppContext.BaseDirectory, "appdepsdk"); AppDepSDKPath = Path.Combine(AppContext.BaseDirectory, "appdepsdk");
_referencePaths = new Dictionary<string, string>();
_referencePaths = new List<string>(Directory.EnumerateFiles(AppDepSDKPath, "*.dll")); foreach (var file in Directory.EnumerateFiles(AppDepSDKPath, "*.dll"))
{
_referencePaths.Add(Path.GetFileName(file), file);
}
} }
public static NativeCompileSettings Default public static NativeCompileSettings Default
@ -198,7 +201,12 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
public void AddReference(string reference) public void AddReference(string reference)
{ {
_referencePaths.Add(Path.GetFullPath(reference)); var path = Path.GetFullPath(reference);
var simpleName = Path.GetFileName(path);
if (!_referencePaths.ContainsKey(simpleName))
{
_referencePaths.Add(simpleName, path);
}
} }
public void AddLinkLibPath(string linkLibPath) public void AddLinkLibPath(string linkLibPath)

View file

@ -5,7 +5,7 @@
}, },
"dependencies": { "dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811", "NETStandard.Library": "1.0.0-rc2-23811",
"Microsoft.DotNet.AppDep":"1.0.5-prerelease-00001" "Microsoft.DotNet.AppDep":"1.0.6-prerelease-00001"
}, },
"frameworks": { "frameworks": {
"dnxcore50": { } "dnxcore50": { }

View file

@ -45,7 +45,7 @@ namespace Microsoft.DotNet.Tools.Compiler
public string ConfigValue { get; set; } public string ConfigValue { get; set; }
public bool IsNativeValue { get; set; } public bool IsNativeValue { get; set; }
public string ArchValue { get; set; } public string ArchValue { get; set; }
public string IlcArgsValue { get; set; } public IEnumerable<string> IlcArgsValue { get; set; }
public string IlcPathValue { get; set; } public string IlcPathValue { get; set; }
public string IlcSdkPathValue { get; set; } public string IlcSdkPathValue { get; set; }
public bool IsCppModeValue { get; set; } public bool IsCppModeValue { get; set; }
@ -83,7 +83,7 @@ namespace Microsoft.DotNet.Tools.Compiler
// Native Args // Native Args
_nativeOption = _app.Option("-n|--native", "Compiles source to native machine code.", CommandOptionType.NoValue); _nativeOption = _app.Option("-n|--native", "Compiles source to native machine code.", CommandOptionType.NoValue);
_archOption = _app.Option("-a|--arch <ARCH>", "The architecture for which to compile. x64 only currently supported.", CommandOptionType.SingleValue); _archOption = _app.Option("-a|--arch <ARCH>", "The architecture for which to compile. x64 only currently supported.", CommandOptionType.SingleValue);
_ilcArgsOption = _app.Option("--ilcargs <ARGS>", "Command line arguments to be passed directly to ILCompiler.", CommandOptionType.SingleValue); _ilcArgsOption = _app.Option("--ilcarg <ARG>", "Command line option to be passed directly to ILCompiler.", CommandOptionType.MultipleValue);
_ilcPathOption = _app.Option("--ilcpath <PATH>", "Path to the folder containing custom built ILCompiler.", CommandOptionType.SingleValue); _ilcPathOption = _app.Option("--ilcpath <PATH>", "Path to the folder containing custom built ILCompiler.", CommandOptionType.SingleValue);
_ilcSdkPathOption = _app.Option("--ilcsdkpath <PATH>", "Path to the folder containing ILCompiler application dependencies.", CommandOptionType.SingleValue); _ilcSdkPathOption = _app.Option("--ilcsdkpath <PATH>", "Path to the folder containing ILCompiler application dependencies.", CommandOptionType.SingleValue);
_appDepSdkPathOption = _app.Option("--appdepsdkpath <PATH>", "Path to the folder containing ILCompiler application dependencies.", CommandOptionType.SingleValue); _appDepSdkPathOption = _app.Option("--appdepsdkpath <PATH>", "Path to the folder containing ILCompiler application dependencies.", CommandOptionType.SingleValue);
@ -109,7 +109,7 @@ namespace Microsoft.DotNet.Tools.Compiler
IsNativeValue = _nativeOption.HasValue(); IsNativeValue = _nativeOption.HasValue();
ArchValue = _archOption.Value(); ArchValue = _archOption.Value();
IlcArgsValue = _ilcArgsOption.Value(); IlcArgsValue = _ilcArgsOption.HasValue() ? _ilcArgsOption.Values : Enumerable.Empty<string>();
IlcPathValue = _ilcPathOption.Value(); IlcPathValue = _ilcPathOption.Value();
IlcSdkPathValue = _ilcSdkPathOption.Value(); IlcSdkPathValue = _ilcSdkPathOption.Value();
AppDepSdkPathValue = _appDepSdkPathOption.Value(); AppDepSdkPathValue = _appDepSdkPathOption.Value();
@ -170,4 +170,4 @@ namespace Microsoft.DotNet.Tools.Compiler
return baseClassOptions.TryGetValue(optionTemplate, out option) && option.HasValue(); return baseClassOptions.TryGetValue(optionTemplate, out option) && option.HasValue();
} }
} }
} }

View file

@ -3,6 +3,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
namespace Microsoft.DotNet.Tools.Compiler namespace Microsoft.DotNet.Tools.Compiler
@ -22,16 +23,37 @@ namespace Microsoft.DotNet.Tools.Compiler
var managedOutput = outputPaths.CompilationFiles.Assembly; var managedOutput = outputPaths.CompilationFiles.Assembly;
// Create the library exporter
var exporter = context.CreateExporter(args.ConfigValue);
// Gather exports for the project
var exports = exporter.GetAllExports();
// Runtime assemblies.
// TODO: native assets/resources.
var references = exports
.SelectMany(export => export.RuntimeAssemblies)
.Select(r => r.ResolvedPath)
.ToList();
// Setup native args.
var nativeArgs = new List<string>(); var nativeArgs = new List<string>();
// Input Assembly // Input Assembly
nativeArgs.Add($"{managedOutput}"); nativeArgs.Add($"{managedOutput}");
// ILC Args // Add Resolved Assembly References
if (!string.IsNullOrWhiteSpace(args.IlcArgsValue)) foreach (var reference in references)
{ {
nativeArgs.Add("--ilcargs"); nativeArgs.Add("--reference");
nativeArgs.Add($"{args.IlcArgsValue}"); nativeArgs.Add(reference);
}
// ILC Args
foreach (var ilcArg in args.IlcArgsValue)
{
nativeArgs.Add("--ilcarg");
nativeArgs.Add($"\"{ilcArg}\"");
} }
// ILC Path // ILC Path

View file

@ -30,7 +30,7 @@
"Microsoft.DotNet.ProjectModel": "1.0.0-*", "Microsoft.DotNet.ProjectModel": "1.0.0-*",
"Microsoft.DotNet.Compiler.Common": "1.0.0-*", "Microsoft.DotNet.Compiler.Common": "1.0.0-*",
"Microsoft.DotNet.Cli.Utils": "1.0.0-*", "Microsoft.DotNet.Cli.Utils": "1.0.0-*",
"Microsoft.DotNet.ILCompiler.SDK": "1.0.5-prerelease-00002", "Microsoft.DotNet.ILCompiler.SDK": "1.0.6-prerelease-00003",
"Microsoft.Extensions.Logging": "1.0.0-rc2-16040", "Microsoft.Extensions.Logging": "1.0.0-rc2-16040",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc2-16040", "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-16040",

View file

@ -81,7 +81,6 @@ namespace Microsoft.DotNet.Tests.EndToEnd
} }
[Fact] [Fact]
[ActiveIssue(712, PlatformID.Windows | PlatformID.OSX | PlatformID.Linux)]
public void TestDotnetBuildNativeRyuJit() public void TestDotnetBuildNativeRyuJit()
{ {
if(IsCentOS()) if(IsCentOS())