Dotnet compile --native integration with rsp file

This commit is contained in:
Bryan 2015-11-17 15:37:30 -08:00
parent 4141e1ec5b
commit 1576ffeb15
3 changed files with 70 additions and 7 deletions

View file

@ -96,6 +96,11 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
{ {
argsList.Add(Path.Combine(config.RuntimeLibPath, lib)); argsList.Add(Path.Combine(config.RuntimeLibPath, lib));
} }
// Link Libs
foreach(var path in config.LinkLibPaths){
argsList.Add($"\"{path}\"");
}
//arch //arch
argsList.Add($"/MACHINE:{config.Architecture}"); argsList.Add($"/MACHINE:{config.Architecture}");

View file

@ -72,7 +72,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
return null; return null;
} }
string[] nArgs = Helpers.SplitStringCommandLine(rspPath).ToArray(); string[] nArgs = content.Split('\n');
return nArgs; return nArgs;
} }
@ -298,7 +298,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
// Link Libs // Link Libs
foreach (var lib in args.LinkLibPaths) foreach (var lib in args.LinkLibPaths)
{ {
config.LinkLibPaths.Add(Path.GetFullPath(lib)); config.LinkLibPaths.Add(lib);
} }
// OS // OS

View file

@ -35,7 +35,12 @@ namespace Microsoft.DotNet.Tools.Compiler
var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue); var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
var noProjectDependencies = app.Option("--no-project-dependencies", "Skips building project references.", CommandOptionType.NoValue); var noProjectDependencies = app.Option("--no-project-dependencies", "Skips building project references.", CommandOptionType.NoValue);
var project = app.Argument("<PROJECT>", "The project to compile, defaults to the current directory. Can be a path to a project.json or a project directory"); var project = app.Argument("<PROJECT>", "The project to compile, defaults to the current directory. Can be a path to a project.json or a project directory");
// Native Args
var native = app.Option("-n|--native", "Compiles source to native machine code.", CommandOptionType.NoValue); var native = app.Option("-n|--native", "Compiles source to native machine code.", CommandOptionType.NoValue);
var arch = app.Option("-a|--arch <ARCH>", "The architecture for which to compile. x64 only currently supported.", CommandOptionType.SingleValue);
var ilcArgs = app.Option("--ilc-args <ARGS>", "String to pass directory to ilc in native compilation.", CommandOptionType.SingleValue);
var cppMode = app.Option("--cpp", "Flag to do native compilation with C++ code generator.", CommandOptionType.NoValue);
app.OnExecute(() => app.OnExecute(() =>
{ {
@ -48,8 +53,12 @@ namespace Microsoft.DotNet.Tools.Compiler
var buildProjectReferences = !noProjectDependencies.HasValue(); var buildProjectReferences = !noProjectDependencies.HasValue();
var isNative = native.HasValue(); var isNative = native.HasValue();
var isCppMode = cppMode.HasValue();
var archValue = arch.Value();
var ilcArgsValue = ilcArgs.Value();
var configValue = configuration.Value() ?? Constants.DefaultConfiguration; var configValue = configuration.Value() ?? Constants.DefaultConfiguration;
var outputValue = output.Value(); var outputValue = output.Value();
var intermediateValue = intermediateOutput.Value();
// Load project contexts for each framework and compile them // Load project contexts for each framework and compile them
bool success = true; bool success = true;
@ -61,7 +70,7 @@ namespace Microsoft.DotNet.Tools.Compiler
success &= Compile(context, configValue, outputValue, intermediateOutput.Value(), buildProjectReferences); success &= Compile(context, configValue, outputValue, intermediateOutput.Value(), buildProjectReferences);
if (isNative && success) if (isNative && success)
{ {
success &= CompileNative(context, configValue, outputValue, buildProjectReferences); success &= CompileNative(context, configValue, outputValue, buildProjectReferences, intermediateValue, archValue, ilcArgsValue, isCppMode);
} }
} }
@ -83,15 +92,64 @@ namespace Microsoft.DotNet.Tools.Compiler
} }
} }
private static bool CompileNative(ProjectContext context, string configuration, string outputOptionValue, bool buildProjectReferences) private static bool CompileNative(ProjectContext context, string configuration, string outputOptionValue, bool buildProjectReferences, string intermediateOutputValue, string archValue, string ilcArgsValue, bool isCppMode)
{ {
string outputPath = Path.Combine(GetOutputPath(context, configuration, outputOptionValue), "native"); var outputPath = Path.Combine(GetOutputPath(context, configuration, outputOptionValue), "native");
var intermediateOutputPath = GetIntermediateOutputPath(context, configuration, intermediateOutputValue, outputOptionValue);
Directory.CreateDirectory(outputPath);
Directory.CreateDirectory(intermediateOutputPath);
var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration); var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
var managedBinaryPath = Path.Combine(outputPath, context.ProjectFile.Name + (compilationOptions.EmitEntryPoint.GetValueOrDefault() ? ".exe" : ".dll")); var managedOutput = GetProjectOutput(context.ProjectFile, context.TargetFramework, configuration, outputPath);
var nativeArgs = new List<string>();
// Input Assembly
nativeArgs.Add($"\"{managedOutput}\"");
// ILC Args
nativeArgs.Add("--ilcargs");
nativeArgs.Add($"\"{ilcArgsValue}\"");
// CodeGen Mode
if(isCppMode)
{
nativeArgs.Add("--mode");
nativeArgs.Add("cpp");
}
// Configuration
if (configuration != null)
{
nativeArgs.Add("--configuration");
nativeArgs.Add(configuration);
}
// Architecture
if (archValue != null)
{
nativeArgs.Add("--arch");
nativeArgs.Add(archValue);
}
// Intermediate Path
nativeArgs.Add("--temp-output");
nativeArgs.Add($"\"{intermediateOutputPath}\"");
// Output Path
nativeArgs.Add("--output");
nativeArgs.Add($"\"{outputPath}\"");
// Write Response File
var rsp = Path.Combine(intermediateOutputPath, $"dotnet-compile-native.{context.ProjectFile.Name}.rsp");
File.WriteAllLines(rsp, nativeArgs);
// TODO Add -r assembly.dll for all Nuget References
// Need CoreRT Framework published to nuget
// Do Native Compilation // Do Native Compilation
var result = Command.Create($"dotnet-compile-native", $"\"{managedBinaryPath}\" \"{outputPath}\"") var result = Command.Create($"dotnet-compile-native", $"--rsp \"{rsp}\"")
.ForwardStdErr() .ForwardStdErr()
.ForwardStdOut() .ForwardStdOut()
.Execute(); .Execute();