Linux CPP Mode Working.
This commit is contained in:
parent
1952e6d972
commit
fd471025dc
5 changed files with 116 additions and 119 deletions
|
@ -46,7 +46,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
}
|
}
|
||||||
else if (config.OS == OSMode.Linux)
|
else if (config.OS == OSMode.Linux)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException("Linux Cpp not yet supported.");
|
stepList.Add(new LinuxCppCompileStep(config));
|
||||||
}
|
}
|
||||||
else if (config.OS == OSMode.Mac)
|
else if (config.OS == OSMode.Mac)
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,29 +10,27 @@ using Microsoft.DotNet.Tools.Common;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Compiler.Native
|
namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
{
|
{
|
||||||
public class LinuxCppCompiler : IPlatformNativeStep
|
public class LinuxCppCompileStep : IPlatformNativeStep
|
||||||
{
|
{
|
||||||
private readonly string CompilerName = "clang-3.5";
|
private readonly string CompilerName = "clang-3.5";
|
||||||
private readonly string InputExtension = ".cpp";
|
private readonly string InputExtension = ".cpp";
|
||||||
|
|
||||||
private readonly string CompilerOutputExtension = ".a";
|
|
||||||
|
|
||||||
// TODO: debug/release support
|
// TODO: debug/release support
|
||||||
private readonly string cLibsFlags = "-lm -ldl";
|
private readonly string cLibsFlags = "-lm -ldl";
|
||||||
private readonly string cflags = "-g -lstdc++ -lrt -Wno-invalid-offsetof -pthread";
|
private readonly string cflags = "-g -lstdc++ -lrt -Wno-invalid-offsetof -pthread";
|
||||||
|
|
||||||
private readonly string[] libs = new string[]
|
private readonly string[] libs = new string[]
|
||||||
{
|
{
|
||||||
"System.Native.so",
|
|
||||||
"libPortableRuntime.a",
|
|
||||||
"libbootstrappercpp.a",
|
"libbootstrappercpp.a",
|
||||||
|
"libPortableRuntime.a",
|
||||||
"libSystem.Private.CoreLib.Native.a",
|
"libSystem.Private.CoreLib.Native.a",
|
||||||
|
"System.Native.so"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
private string CompilerArgStr { get; set; }
|
private string CompilerArgStr { get; set; }
|
||||||
|
|
||||||
public LinuxCppCompiler(NativeCompileSettings config)
|
public LinuxCppCompileStep(NativeCompileSettings config)
|
||||||
{
|
{
|
||||||
InitializeArgs(config);
|
InitializeArgs(config);
|
||||||
}
|
}
|
||||||
|
@ -68,13 +66,15 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
argsList.Add("-I");
|
argsList.Add("-I");
|
||||||
argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk"));
|
argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk"));
|
||||||
|
|
||||||
// Add Stubs
|
|
||||||
argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk/ubuntu.14.04/lxstubs.cpp"));
|
|
||||||
|
|
||||||
// Input File
|
// Input File
|
||||||
var inCppFile = DetermineInFile(config);
|
var inCppFile = DetermineInFile(config);
|
||||||
argsList.Add(inCppFile);
|
argsList.Add(inCppFile);
|
||||||
|
|
||||||
|
// Add Stubs
|
||||||
|
argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk/ubuntu.14.04/lxstubs.cpp"));
|
||||||
|
|
||||||
|
|
||||||
// Libs
|
// Libs
|
||||||
foreach (var lib in libs)
|
foreach (var lib in libs)
|
||||||
{
|
{
|
||||||
|
@ -115,15 +115,13 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
|
|
||||||
public string DetermineOutputFile(NativeCompileSettings config)
|
public string DetermineOutputFile(NativeCompileSettings config)
|
||||||
{
|
{
|
||||||
var inputFile = DetermineInFile(config);
|
var intermediateDirectory = config.OutputDirectory;
|
||||||
|
|
||||||
return inputFile + CompilerOutputExtension;
|
var filename = Path.GetFileNameWithoutExtension(config.InputManagedAssemblyPath);
|
||||||
|
|
||||||
|
var outfile = Path.Combine(intermediateDirectory, filename);
|
||||||
|
|
||||||
|
return outfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool RequiresLinkStep()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,7 +24,6 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
{
|
{
|
||||||
"libbootstrapper.a",
|
"libbootstrapper.a",
|
||||||
"libRuntime.a",
|
"libRuntime.a",
|
||||||
"libPortableRuntime.a",
|
|
||||||
"libSystem.Private.CoreLib.Native.a",
|
"libSystem.Private.CoreLib.Native.a",
|
||||||
"System.Native.so"
|
"System.Native.so"
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,107 +10,107 @@ using Microsoft.DotNet.Tools.Common;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Compiler.Native
|
namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
{
|
{
|
||||||
public class WindowsCppCompileStep : IPlatformNativeStep
|
public class WindowsCppCompileStep : IPlatformNativeStep
|
||||||
{
|
{
|
||||||
//TODO support x86
|
//TODO support x86
|
||||||
private readonly string CompilerName = "cl.exe";
|
private readonly string CompilerName = "cl.exe";
|
||||||
|
|
||||||
private readonly string VSBin = "..\\..\\VC\\bin\\x86_amd64";
|
private readonly string VSBin = "..\\..\\VC\\bin\\amd64";
|
||||||
private readonly string InputExtension = ".cpp";
|
private readonly string InputExtension = ".cpp";
|
||||||
|
|
||||||
private readonly string CompilerOutputExtension = ".obj";
|
private readonly string CompilerOutputExtension = ".obj";
|
||||||
|
|
||||||
private static readonly Dictionary<BuildConfiguration, string> ConfigurationCompilerOptionsMap = new Dictionary<BuildConfiguration, string>
|
private static readonly Dictionary<BuildConfiguration, string> ConfigurationCompilerOptionsMap = new Dictionary<BuildConfiguration, string>
|
||||||
{
|
{
|
||||||
{ BuildConfiguration.debug, "/ZI /nologo /W3 /WX- /sdl /Od /D CPPCODEGEN /D WIN32 /D _DEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Gd /TP /wd4477 /errorReport:prompt" },
|
{ BuildConfiguration.debug, "/ZI /nologo /W3 /WX- /sdl /Od /D CPPCODEGEN /D WIN32 /D _DEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Gd /TP /wd4477 /errorReport:prompt" },
|
||||||
{ BuildConfiguration.release, "/Zi /nologo /W3 /WX- /sdl /O2 /Oi /GL /D CPPCODEGEN /D WIN32 /D NDEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Gd /TP /wd4477 /errorReport:prompt" }
|
{ BuildConfiguration.release, "/Zi /nologo /W3 /WX- /sdl /O2 /Oi /GL /D CPPCODEGEN /D WIN32 /D NDEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Gd /TP /wd4477 /errorReport:prompt" }
|
||||||
};
|
};
|
||||||
|
|
||||||
private string CompilerArgStr { get; set; }
|
private string CompilerArgStr { get; set; }
|
||||||
|
|
||||||
public WindowsCppCompileStep(NativeCompileSettings config)
|
public WindowsCppCompileStep(NativeCompileSettings config)
|
||||||
{
|
{
|
||||||
InitializeArgs(config);
|
InitializeArgs(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Invoke(NativeCompileSettings config)
|
public int Invoke(NativeCompileSettings config)
|
||||||
{
|
{
|
||||||
var result = WindowsCommon.SetVCVars();
|
var result = WindowsCommon.SetVCVars();
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
Reporter.Error.WriteLine("vcvarsall.bat invocation failed.");
|
Reporter.Error.WriteLine("vcvarsall.bat invocation failed.");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = InvokeCompiler(config);
|
result = InvokeCompiler(config);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
Reporter.Error.WriteLine("Compilation of intermediate files failed.");
|
Reporter.Error.WriteLine("Compilation of intermediate files failed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CheckPreReqs()
|
public bool CheckPreReqs()
|
||||||
{
|
{
|
||||||
var vcInstallDir = Environment.GetEnvironmentVariable("VS140COMNTOOLS");
|
var vcInstallDir = Environment.GetEnvironmentVariable("VS140COMNTOOLS");
|
||||||
return !string.IsNullOrEmpty(vcInstallDir);
|
return !string.IsNullOrEmpty(vcInstallDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeArgs(NativeCompileSettings config)
|
private void InitializeArgs(NativeCompileSettings config)
|
||||||
{
|
{
|
||||||
var argsList = new List<string>();
|
var argsList = new List<string>();
|
||||||
|
|
||||||
// Use a Custom Link Step
|
// Use a Custom Link Step
|
||||||
argsList.Add("/c");
|
argsList.Add("/c");
|
||||||
|
|
||||||
// Add Includes
|
// Add Includes
|
||||||
argsList.Add("/I");
|
argsList.Add("/I");
|
||||||
argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk\\Windows_NT"));
|
argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk\\Windows_NT"));
|
||||||
|
|
||||||
argsList.Add("/I");
|
argsList.Add("/I");
|
||||||
argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk"));
|
argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk"));
|
||||||
|
|
||||||
// Configuration Based Compiler Options
|
// Configuration Based Compiler Options
|
||||||
argsList.Add(ConfigurationCompilerOptionsMap[config.BuildType]);
|
argsList.Add(ConfigurationCompilerOptionsMap[config.BuildType]);
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
var objOut = DetermineOutputFile(config);
|
var objOut = DetermineOutputFile(config);
|
||||||
argsList.Add($"/Fo\"{objOut}\"");
|
argsList.Add($"/Fo\"{objOut}\"");
|
||||||
|
|
||||||
// Input File
|
// Input File
|
||||||
var inCppFile = DetermineInFile(config);
|
var inCppFile = DetermineInFile(config);
|
||||||
argsList.Add(inCppFile);
|
argsList.Add(inCppFile);
|
||||||
|
|
||||||
this.CompilerArgStr = string.Join(" ", argsList);
|
this.CompilerArgStr = string.Join(" ", argsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int InvokeCompiler(NativeCompileSettings config)
|
private int InvokeCompiler(NativeCompileSettings config)
|
||||||
{
|
{
|
||||||
var vcInstallDir = Environment.GetEnvironmentVariable("VS140COMNTOOLS");
|
var vcInstallDir = Environment.GetEnvironmentVariable("VS140COMNTOOLS");
|
||||||
var compilerPath = Path.Combine(vcInstallDir, VSBin, CompilerName);
|
var compilerPath = Path.Combine(vcInstallDir, VSBin, CompilerName);
|
||||||
|
|
||||||
var result = Command.Create(compilerPath, CompilerArgStr)
|
var result = Command.Create(compilerPath, CompilerArgStr)
|
||||||
.ForwardStdErr()
|
.ForwardStdErr()
|
||||||
.ForwardStdOut()
|
.ForwardStdOut()
|
||||||
.Execute();
|
.Execute();
|
||||||
|
|
||||||
return result.ExitCode;
|
return result.ExitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string DetermineInFile(NativeCompileSettings config)
|
private string DetermineInFile(NativeCompileSettings config)
|
||||||
{
|
{
|
||||||
var intermediateDirectory = config.IntermediateDirectory;
|
var intermediateDirectory = config.IntermediateDirectory;
|
||||||
|
|
||||||
var filename = Path.GetFileNameWithoutExtension(config.InputManagedAssemblyPath);
|
var filename = Path.GetFileNameWithoutExtension(config.InputManagedAssemblyPath);
|
||||||
|
|
||||||
var infile = Path.Combine(intermediateDirectory, filename + InputExtension);
|
var infile = Path.Combine(intermediateDirectory, filename + InputExtension);
|
||||||
|
|
||||||
return infile;
|
return infile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string DetermineOutputFile(NativeCompileSettings config)
|
public string DetermineOutputFile(NativeCompileSettings config)
|
||||||
{
|
{
|
||||||
var intermediateDirectory = config.IntermediateDirectory;
|
var intermediateDirectory = config.IntermediateDirectory;
|
||||||
|
|
||||||
var filename = Path.GetFileNameWithoutExtension(config.InputManagedAssemblyPath);
|
var filename = Path.GetFileNameWithoutExtension(config.InputManagedAssemblyPath);
|
||||||
|
@ -118,7 +118,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
var outfile = Path.Combine(intermediateDirectory, filename + CompilerOutputExtension);
|
var outfile = Path.Combine(intermediateDirectory, filename + CompilerOutputExtension);
|
||||||
|
|
||||||
return outfile;
|
return outfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
{
|
{
|
||||||
private readonly string LinkerName = "link.exe";
|
private readonly string LinkerName = "link.exe";
|
||||||
private readonly string LinkerOutputExtension = ".exe";
|
private readonly string LinkerOutputExtension = ".exe";
|
||||||
private readonly string VSBin = "..\\..\\VC\\bin\\x86_amd64";
|
private readonly string VSBin = "..\\..\\VC\\bin\\amd64";
|
||||||
|
|
||||||
private readonly string InputExtension = ".obj";
|
private readonly string InputExtension = ".obj";
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue