Merge pull request #1363 from schellap/noappdepsdk
Include project.json dependencies and use response files
This commit is contained in:
commit
ade2fa8b9b
15 changed files with 98 additions and 56 deletions
|
@ -13,7 +13,7 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
public class CompileTargets
|
||||
{
|
||||
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();
|
||||
|
||||
|
|
|
@ -339,10 +339,10 @@ namespace Microsoft.DotNet.Tools.Build
|
|||
args.Add(_args.ArchValue);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(_args.IlcArgsValue))
|
||||
foreach (var ilcArg in _args.IlcArgsValue)
|
||||
{
|
||||
args.Add("--ilcargs");
|
||||
args.Add(_args.IlcArgsValue);
|
||||
args.Add("--ilcarg");
|
||||
args.Add(ilcArg);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(_args.IlcPathValue))
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
public ArchitectureMode Architecture { get; set; }
|
||||
public NativeIntermediateMode? NativeMode { 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 string AppDepSDKPath { get; set; }
|
||||
public string IlcPath { get; set; }
|
||||
|
@ -88,7 +88,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
config.LogPath = LogPath;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(IlcArgs))
|
||||
if (IlcArgs != null)
|
||||
{
|
||||
config.IlcArgs = IlcArgs;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.CommandLine;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||
{
|
||||
|
@ -15,7 +16,8 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
BuildConfiguration? buildConfiguration = null;
|
||||
string mode = null;
|
||||
NativeIntermediateMode? nativeMode = null;
|
||||
string ilcArgs = null;
|
||||
IReadOnlyList<string> ilcArgs = Array.Empty<string>();
|
||||
IEnumerable<string> unquotIlcArgs = Array.Empty<string>();
|
||||
string ilcPath = null;
|
||||
string ilcSdkPath = null;
|
||||
string appDepSdk = null;
|
||||
|
@ -26,7 +28,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
string cppCompilerFlags = null;
|
||||
|
||||
IReadOnlyList<string> references = Array.Empty<string>();
|
||||
IReadOnlyList<string> linklib = Array.Empty<string>();
|
||||
IReadOnlyList<string> linklib = Array.Empty<string>();
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -46,7 +48,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
"Use to specify Managed DLL references of the app.");
|
||||
|
||||
// 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("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.");
|
||||
|
||||
helpText = syntax.GetHelpText();
|
||||
|
||||
|
||||
if (string.IsNullOrWhiteSpace(inputAssembly))
|
||||
{
|
||||
syntax.ReportError("Input Assembly is a required parameter.");
|
||||
|
@ -99,6 +101,15 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
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)
|
||||
|
@ -130,7 +141,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
BuildConfiguration = buildConfiguration,
|
||||
NativeMode = nativeMode,
|
||||
ReferencePaths = references,
|
||||
IlcArgs = ilcArgs,
|
||||
IlcArgs = unquotIlcArgs,
|
||||
IlcPath = ilcPath,
|
||||
IlcSdkPath = ilcSdkPath,
|
||||
LinkLibPaths = linklib,
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||
{
|
||||
public class ILCompilerInvoker
|
||||
{
|
||||
private readonly string ExecutableName = "corerun" + Constants.ExeSuffix;
|
||||
private readonly string ILCompiler = "ilc.exe";
|
||||
private static readonly string HostExeName = "corerun" + Constants.ExeSuffix;
|
||||
private static readonly string ILCompiler = "ilc.exe";
|
||||
|
||||
private IEnumerable<string> Args;
|
||||
private NativeCompileSettings config;
|
||||
|
||||
|
@ -27,14 +29,6 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
{
|
||||
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
|
||||
var inputFilePath = config.InputManagedAssemblyPath;
|
||||
argsList.Add($"{inputFilePath}");
|
||||
|
@ -43,32 +37,29 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
var coreLibsPath = Path.Combine(config.IlcSdkPath, "sdk");
|
||||
foreach (var reference in Directory.EnumerateFiles(coreLibsPath, "*.dll"))
|
||||
{
|
||||
argsList.Add($"-r");
|
||||
argsList.Add($"{reference}");
|
||||
argsList.Add($"-r:{reference}");
|
||||
}
|
||||
|
||||
// AppDep References
|
||||
foreach (var reference in config.ReferencePaths)
|
||||
{
|
||||
argsList.Add($"-r");
|
||||
argsList.Add($"{reference}");
|
||||
argsList.Add($"-r:{reference}");
|
||||
}
|
||||
|
||||
// Set Output DetermineOutFile
|
||||
var outFile = DetermineOutputFile(config);
|
||||
argsList.Add($"-out");
|
||||
argsList.Add($"{outFile}");
|
||||
argsList.Add($"-o:{outFile}");
|
||||
|
||||
// Add Mode Flag TODO
|
||||
if (config.NativeMode == NativeIntermediateMode.cpp)
|
||||
{
|
||||
argsList.Add("-cpp");
|
||||
argsList.Add("--cpp");
|
||||
}
|
||||
|
||||
// Custom Ilc Args support
|
||||
if (! string.IsNullOrEmpty(config.IlcArgs))
|
||||
foreach (var ilcArg in config.IlcArgs)
|
||||
{
|
||||
argsList.Add(config.IlcArgs);
|
||||
argsList.Add(ilcArg);
|
||||
}
|
||||
|
||||
Args = argsList;
|
||||
|
@ -76,9 +67,20 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
|
||||
public int Invoke()
|
||||
{
|
||||
var executablePath = Path.Combine(config.IlcPath, ExecutableName);
|
||||
|
||||
var result = Command.Create(executablePath, Args)
|
||||
// Check if ILCompiler is present
|
||||
var ilcExePath = Path.Combine(config.IlcPath, ILCompiler);
|
||||
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()
|
||||
.ForwardStdOut()
|
||||
.Execute();
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
|
||||
private readonly string[] _appdeplibs =
|
||||
{
|
||||
"libSystem.Native.a"
|
||||
"System.Native.a"
|
||||
};
|
||||
|
||||
public LinuxCppCompileStep(NativeCompileSettings config)
|
||||
|
@ -121,4 +121,4 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
return outfile;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
|
||||
private readonly string[] _appdeplibs =
|
||||
{
|
||||
"libSystem.Native.a"
|
||||
"System.Native.a"
|
||||
};
|
||||
|
||||
public LinuxRyuJitCompileStep(NativeCompileSettings config)
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
|
||||
private readonly string[] _appdeplibs =
|
||||
{
|
||||
"libSystem.Native.a"
|
||||
"System.Native.a"
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
|
||||
private readonly string[] appdeplibs =
|
||||
{
|
||||
"libSystem.Native.a"
|
||||
"System.Native.a"
|
||||
};
|
||||
|
||||
public MacRyuJitCompileStep(NativeCompileSettings config)
|
||||
|
|
|
@ -19,8 +19,8 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
private string _outputDirectory;
|
||||
private string _intermediateDirectory;
|
||||
private string _logPath;
|
||||
private string _ilcArgs;
|
||||
private readonly List<string> _referencePaths;
|
||||
private IEnumerable<string> _ilcArgs;
|
||||
private readonly Dictionary<string, string> _referencePaths;
|
||||
private readonly List<string> _linkLibPaths;
|
||||
private string _cppCompilerFlags;
|
||||
|
||||
|
@ -81,12 +81,12 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
{
|
||||
get
|
||||
{
|
||||
return _referencePaths;
|
||||
return _referencePaths.Values;
|
||||
}
|
||||
}
|
||||
|
||||
// Optional Customization Points (Can be null)
|
||||
public string IlcArgs
|
||||
public IEnumerable<string> IlcArgs
|
||||
{
|
||||
get { return _ilcArgs; }
|
||||
set { _ilcArgs = value; }
|
||||
|
@ -168,8 +168,11 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
BuildType = DefaultBuiltType;
|
||||
NativeMode = DefaultNativeModel;
|
||||
AppDepSDKPath = Path.Combine(AppContext.BaseDirectory, "appdepsdk");
|
||||
|
||||
_referencePaths = new List<string>(Directory.EnumerateFiles(AppDepSDKPath, "*.dll"));
|
||||
_referencePaths = new Dictionary<string, string>();
|
||||
foreach (var file in Directory.EnumerateFiles(AppDepSDKPath, "*.dll"))
|
||||
{
|
||||
_referencePaths.Add(Path.GetFileName(file), file);
|
||||
}
|
||||
}
|
||||
|
||||
public static NativeCompileSettings Default
|
||||
|
@ -198,7 +201,12 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
|
||||
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)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.0.0-rc2-23811",
|
||||
"Microsoft.DotNet.AppDep":"1.0.5-prerelease-00001"
|
||||
"Microsoft.DotNet.AppDep":"1.0.6-prerelease-00001"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnxcore50": { }
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
public string ConfigValue { get; set; }
|
||||
public bool IsNativeValue { 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 IlcSdkPathValue { get; set; }
|
||||
public bool IsCppModeValue { get; set; }
|
||||
|
@ -83,7 +83,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
// Native Args
|
||||
_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);
|
||||
_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);
|
||||
_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);
|
||||
|
@ -109,7 +109,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
|
||||
IsNativeValue = _nativeOption.HasValue();
|
||||
ArchValue = _archOption.Value();
|
||||
IlcArgsValue = _ilcArgsOption.Value();
|
||||
IlcArgsValue = _ilcArgsOption.HasValue() ? _ilcArgsOption.Values : Enumerable.Empty<string>();
|
||||
IlcPathValue = _ilcPathOption.Value();
|
||||
IlcSdkPathValue = _ilcSdkPathOption.Value();
|
||||
AppDepSdkPathValue = _appDepSdkPathOption.Value();
|
||||
|
@ -170,4 +170,4 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
return baseClassOptions.TryGetValue(optionTemplate, out option) && option.HasValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Compiler
|
||||
|
@ -22,16 +23,37 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
|
||||
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>();
|
||||
|
||||
// Input Assembly
|
||||
nativeArgs.Add($"{managedOutput}");
|
||||
|
||||
// ILC Args
|
||||
if (!string.IsNullOrWhiteSpace(args.IlcArgsValue))
|
||||
// Add Resolved Assembly References
|
||||
foreach (var reference in references)
|
||||
{
|
||||
nativeArgs.Add("--ilcargs");
|
||||
nativeArgs.Add($"{args.IlcArgsValue}");
|
||||
nativeArgs.Add("--reference");
|
||||
nativeArgs.Add(reference);
|
||||
}
|
||||
|
||||
// ILC Args
|
||||
foreach (var ilcArg in args.IlcArgsValue)
|
||||
{
|
||||
nativeArgs.Add("--ilcarg");
|
||||
nativeArgs.Add($"\"{ilcArg}\"");
|
||||
}
|
||||
|
||||
// ILC Path
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
|
||||
"Microsoft.DotNet.Compiler.Common": "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.Console": "1.0.0-rc2-16040",
|
||||
|
|
|
@ -81,7 +81,6 @@ namespace Microsoft.DotNet.Tests.EndToEnd
|
|||
}
|
||||
|
||||
[Fact]
|
||||
[ActiveIssue(712, PlatformID.Windows | PlatformID.OSX | PlatformID.Linux)]
|
||||
public void TestDotnetBuildNativeRyuJit()
|
||||
{
|
||||
if(IsCentOS())
|
||||
|
|
Loading…
Reference in a new issue