Changing native out flag to output flag to match compiler. Also changing the rsp file spliting to handle both /r/n and /r

Fixing the input path to the native compiler. It was adding /native to it before.

Switching compile native to System.CommandLine for args parsing and removing quotes from -native.rsp.

Fixing build_appdeps.cmd: Removed the * from __ApPDepSDK as xcopy does not honor that. In order to stay independent of the version of appDep, we CD into the appDepSDK and then navigate to the first folder we find, which should always be one, as we clear the folder before restoring appDep, after that we xcopy
This commit is contained in:
Livar Cunha 2015-11-18 11:56:35 -08:00
parent 9fbf7a7995
commit d0100335da
4 changed files with 125 additions and 114 deletions

View file

@ -12,10 +12,20 @@ pushd %1
set __OutputPath=%CD%\bin
popd
rmdir /S /Q %AppDepsProjectDir%\packages
pushd %__AppDepsProjectDir%
dotnet restore --packages %AppDepsProjectDir%\packages
set __AppDepSDK=%AppDepsProjectDir%\packages\toolchain*\*\
set __AppDepSDK=%AppDepsProjectDir%\packages\toolchain*\
popd
mkdir %__OutputPath%\appdepsdk
xcopy /S/E/H/Y %__AppDepSDK% %__OutputPath%\appdepsdk
cd %__AppDepSDK%
FOR /D %%a IN (*) DO (
CD %%a
GOTO :Copy
)
:Copy
xcopy /S/E/H/Y * %__OutputPath%\appdepsdk

View file

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.IO;
using Microsoft.Dnx.Runtime.Common.CommandLine;
using System.Linq;
using Microsoft.DotNet.Cli.Utils;
namespace Microsoft.DotNet.Tools.Compiler.Native
@ -10,13 +12,76 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
public static int Main(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);
var app = SetupApp();
return ExecuteApp(app, args);
return ExecuteApp(args);
}
private static int ExecuteApp(CommandLineApplication app, string[] args)
private static ArgValues GetArgs(string[] args)
{
string inputAssembly = null;
string outputDirectory = null;
string temporaryOutputDirectory = null;
string configuration = null;
string mode = null;
string ilcArgs = null;
string ilcPath = null;
string appDepSdk = null;
string logPath = null;
IReadOnlyList<string> references = Array.Empty<string>();
IReadOnlyList<string> linklib = Array.Empty<string>();
try
{
ArgumentSyntax.Parse(args, syntax =>
{
syntax.DefineOption("output", ref outputDirectory, "Output Directory for native executable.");
syntax.DefineOption("temp-output", ref temporaryOutputDirectory, "Directory for intermediate files.");
syntax.DefineOption("configuration", ref configuration, "debug/release build configuration. Defaults to debug.");
syntax.DefineOption("mode", ref mode, "Code Generation mode. Defaults to ryujit.");
syntax.DefineOptionList("reference", ref references, "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.DefineOption("ilcpath", ref ilcPath, "Use to plug in a custom built ilc.exe");
syntax.DefineOptionList("linklib", ref linklib, "Use to link in additional static libs");
// TEMPORARY Hack until CoreRT compatible Framework Libs are available
syntax.DefineOption("appdepsdk", ref appDepSdk, "Use to plug in custom appdepsdk path");
// Optional Log Path
syntax.DefineOption("logpath", ref logPath, "Use to dump Native Compilation Logs to a file.");
syntax.DefineParameter("INPUT_ASSEMBLY", ref inputAssembly, "The managed input assembly to compile to native.");
});
}
catch (ArgumentSyntaxException)
{
//return ExitFailed;
}
Console.WriteLine($"Input Assembly: {inputAssembly}");
return new ArgValues()
{
InputManagedAssemblyPath = inputAssembly,
OutputDirectory = outputDirectory,
IntermediateDirectory = temporaryOutputDirectory,
Architecture = "x64",
BuildConfiguration = configuration,
NativeMode = mode,
ReferencePaths = references.ToList(),
IlcArgs = ilcArgs,
IlcPath = ilcPath,
LinkLibPaths = linklib.ToList(),
AppDepSDKPath = appDepSdk,
LogPath = logPath
};
}
private static int ExecuteApp(string[] args)
{
// Support Response File
foreach(var arg in args)
@ -34,7 +99,17 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
try
{
return app.Execute(args);
var cmdLineArgs = GetArgs(args);
var config = ParseAndValidateArgs(cmdLineArgs);
DirectoryExtensions.CleanOrCreateDirectory(config.OutputDirectory);
DirectoryExtensions.CleanOrCreateDirectory(config.IntermediateDirectory);
var nativeCompiler = NativeCompiler.Create(config);
var result = nativeCompiler.CompileToNative(config);
return result ? 0 : 1;
}
catch (Exception ex)
{
@ -66,72 +141,9 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
return null;
}
string[] nArgs = content.Split('\n');
string[] nArgs = content.Split(new [] {"\r\n", "\n"}, StringSplitOptions.RemoveEmptyEntries);
return nArgs;
}
private static CommandLineApplication SetupApp()
{
var app = new CommandLineApplication
{
Name = "dotnet compile native",
FullName = "IL to Native compiler",
Description = "IL to Native compiler Compiler for the .NET Platform"
};
app.HelpOption("-h|--help");
var managedInputArg = app.Argument("<INPUT_ASSEMBLY>", "The managed input assembly to compile to native.");
var outputArg = app.Option("-o|--out <OUTPUT_DIR>", "Output Directory for native executable.", CommandOptionType.SingleValue);
var intermediateArg = app.Option("-t|--temp-output <OUTPUT_DIR>", "Directory for intermediate files.", CommandOptionType.SingleValue);
var buildConfigArg = app.Option("-c|--configuration <TYPE>", "debug/release build configuration. Defaults to debug.", CommandOptionType.SingleValue);
var modeArg = app.Option("-m|--mode <MODE>", "Code Generation mode. Defaults to ryujit. ", CommandOptionType.SingleValue);
var referencesArg = app.Option("-r|--reference <REF_PATH>", "Use to specify Managed DLL references of the app.", CommandOptionType.MultipleValue);
// Custom Extensibility Points to support CoreRT workflow TODO better descriptions
var ilcArgs = app.Option("--ilcargs <CODEGEN>", "Use to specify custom arguments for the IL Compiler.", CommandOptionType.SingleValue);
var ilcPathArg = app.Option("--ilcpath <ILC_PATH>", "Use to plug in a custom built ilc.exe", CommandOptionType.SingleValue);
var linklibArg = app.Option("--linklib <LINKLIB>", "Use to link in additional static libs", CommandOptionType.MultipleValue);
// TEMPORARY Hack until CoreRT compatible Framework Libs are available
var appdepSdkPathArg = app.Option("--appdepsdk <SDK>", "Use to plug in custom appdepsdk path", CommandOptionType.SingleValue);
// Optional Log Path
var logpathArg = app.Option("--logpath <LOG_PATH>", "Use to dump Native Compilation Logs to a file.", CommandOptionType.SingleValue);
app.OnExecute(() =>
{
var cmdLineArgs = new ArgValues()
{
InputManagedAssemblyPath = managedInputArg.Value,
OutputDirectory = outputArg.Value(),
IntermediateDirectory = intermediateArg.Value(),
Architecture = "x64",
BuildConfiguration = buildConfigArg.Value(),
NativeMode = modeArg.Value(),
ReferencePaths = referencesArg.Values,
IlcArgs = ilcArgs.Value(),
IlcPath = ilcPathArg.Value(),
LinkLibPaths = linklibArg.Values,
AppDepSDKPath = appdepSdkPathArg.Value(),
LogPath = logpathArg.Value()
};
var config = ParseAndValidateArgs(cmdLineArgs);
DirectoryExtensions.CleanOrCreateDirectory(config.OutputDirectory);
DirectoryExtensions.CleanOrCreateDirectory(config.IntermediateDirectory);
var nativeCompiler = NativeCompiler.Create(config);
var result = nativeCompiler.CompileToNative(config);
return result ? 0 : 1;
});
return app;
}
private static NativeCompileSettings ParseAndValidateArgs(ArgValues args)
{

View file

@ -23,9 +23,10 @@
"type": "build",
"version": "1.0.0-*"
},
"Microsoft.DotNet.ILCompiler": "1.0.1-*",
"Microsoft.DotNet.ObjectWriter": "1.0.2-*",
"Microsoft.DotNet.RyuJit": "1.0.0-*"
"Microsoft.DotNet.ILCompiler": "1.0.1-*",
"Microsoft.DotNet.ObjectWriter": "1.0.2-*",
"Microsoft.DotNet.RyuJit": "1.0.0-*",
"Microsoft.DotNet.Compiler.Common": "1.0.0-*"
},
"frameworks": {
"dnxcore50": { }

View file

@ -92,25 +92,39 @@ namespace Microsoft.DotNet.Tools.Compiler
}
}
private static bool CompileNative(ProjectContext context, string configuration, string outputOptionValue, bool buildProjectReferences, string intermediateOutputValue, string archValue, string ilcArgsValue, bool isCppMode)
private static bool CompileNative(
ProjectContext context,
string configuration,
string outputOptionValue,
bool buildProjectReferences,
string intermediateOutputValue,
string archValue,
string ilcArgsValue,
bool isCppMode)
{
var outputPath = Path.Combine(GetOutputPath(context, configuration, outputOptionValue), "native");
var intermediateOutputPath = GetIntermediateOutputPath(context, configuration, intermediateOutputValue, outputOptionValue);
var outputPath = GetOutputPath(context, configuration, outputOptionValue);
var nativeOutputPath = Path.Combine(GetOutputPath(context, configuration, outputOptionValue), "native");
var intermediateOutputPath =
GetIntermediateOutputPath(context, configuration, intermediateOutputValue, outputOptionValue);
Directory.CreateDirectory(outputPath);
Directory.CreateDirectory(nativeOutputPath);
Directory.CreateDirectory(intermediateOutputPath);
var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
var managedOutput = GetProjectOutput(context.ProjectFile, context.TargetFramework, configuration, outputPath);
var managedOutput =
GetProjectOutput(context.ProjectFile, context.TargetFramework, configuration, outputPath);
var nativeArgs = new List<string>();
// Input Assembly
nativeArgs.Add($"\"{managedOutput}\"");
nativeArgs.Add($"{managedOutput}");
// ILC Args
nativeArgs.Add("--ilcargs");
nativeArgs.Add($"\"{ilcArgsValue}\"");
if (!string.IsNullOrWhiteSpace(ilcArgsValue))
{
nativeArgs.Add("--ilcargs");
nativeArgs.Add($"{ilcArgsValue}");
}
// CodeGen Mode
if(isCppMode)
@ -135,37 +149,11 @@ namespace Microsoft.DotNet.Tools.Compiler
// Intermediate Path
nativeArgs.Add("--temp-output");
nativeArgs.Add($"\"{intermediateOutputPath}\"");
nativeArgs.Add($"{intermediateOutputPath}");
// Output Path
nativeArgs.Add("--output");
nativeArgs.Add($"\"{outputPath}\"");
// Dependencies
var exporter = context.CreateExporter(configuration);
var dependencies = exporter.GetDependencies().ToList();
foreach (var dependency in dependencies)
{
var projectDependency = dependency.Library as ProjectDescription;
if (projectDependency != null)
{
if (projectDependency.Project.Files.SourceFiles.Any())
{
var projectOutputPath = GetProjectOutput(projectDependency.Project, projectDependency.Framework, configuration, outputPath);
nativeArgs.Add("-r");
nativeArgs.Add($"\"{projectOutputPath}\"");
}
}
else
{
foreach(var dep in dependency.RuntimeAssemblies)
{
nativeArgs.Add("-r");
nativeArgs.Add($"\"{dep.ResolvedPath}\"");
}
}
}
nativeArgs.Add($"{nativeOutputPath}");
// Write Response File
var rsp = Path.Combine(intermediateOutputPath, $"dotnet-compile-native.{context.ProjectFile.Name}.rsp");
@ -175,7 +163,7 @@ namespace Microsoft.DotNet.Tools.Compiler
// Need CoreRT Framework published to nuget
// Do Native Compilation
var result = Command.Create($"dotnet-compile-native", $"--rsp \"{rsp}\"")
var result = Command.Create("dotnet-compile-native", $"--rsp \"{rsp}\"")
.ForwardStdErr()
.ForwardStdOut()
.Execute();