Pickup headers from ILCompiler.SDK

Add support for --cppcompilerflags switch to enable passing custom native compiler arguments.
This commit is contained in:
Gaurav Khanna 2015-12-20 20:46:28 -08:00
parent 48facc6231
commit 0b2a6fee2e
13 changed files with 97 additions and 47 deletions

View file

@ -17,6 +17,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
public string AppDepSDKPath { get; set; } public string AppDepSDKPath { get; set; }
public string IlcPath { get; set; } public string IlcPath { get; set; }
public string IlcSdkPath { get; set; } public string IlcSdkPath { get; set; }
public string CppCompilerFlags { get; set; }
public bool IsHelp { get; set; } public bool IsHelp { get; set; }
public int ReturnCode { get; set; } public int ReturnCode { get; set; }
@ -56,12 +57,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
if (!string.IsNullOrEmpty(IlcPath)) if (!string.IsNullOrEmpty(IlcPath))
{ {
config.IlcPath = IlcPath; config.IlcPath = IlcPath;
config.IlcSdkPath = IlcPath;
// If ILCSdkPath is not specified, then default it to be the same as the overridden ILCPath
if (string.IsNullOrEmpty(IlcSdkPath))
{
IlcSdkPath = IlcPath;
}
} }
if (!string.IsNullOrEmpty(IlcSdkPath)) if (!string.IsNullOrEmpty(IlcSdkPath))
@ -79,6 +75,11 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
config.IlcArgs = IlcArgs; config.IlcArgs = IlcArgs;
} }
if (!string.IsNullOrWhiteSpace(CppCompilerFlags))
{
config.CppCompilerFlags = CppCompilerFlags;
}
foreach (var reference in ReferencePaths) foreach (var reference in ReferencePaths)
{ {
config.AddReference(reference); config.AddReference(reference);

View file

@ -23,6 +23,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
var help = false; var help = false;
string helpText = null; string helpText = null;
var returnCode = 0; var returnCode = 0;
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>();
@ -57,6 +58,9 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
// Optional Log Path // Optional Log Path
syntax.DefineOption("logpath", ref logPath, "Use to dump Native Compilation Logs to a file."); syntax.DefineOption("logpath", ref logPath, "Use to dump Native Compilation Logs to a file.");
// Optional flags to be passed to the native compiler
syntax.DefineOption("cppcompilerflags", ref cppCompilerFlags, "Additional flags to be passed to the native compiler.");
syntax.DefineOption("h|help", ref help, "Help for compile native."); syntax.DefineOption("h|help", ref help, "Help for compile native.");
syntax.DefineParameter("INPUT_ASSEMBLY", ref inputAssembly, syntax.DefineParameter("INPUT_ASSEMBLY", ref inputAssembly,
@ -131,7 +135,8 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
IlcSdkPath = ilcSdkPath, IlcSdkPath = ilcSdkPath,
LinkLibPaths = linklib, LinkLibPaths = linklib,
AppDepSDKPath = appDepSdk, AppDepSDKPath = appDepSdk,
LogPath = logPath LogPath = logPath,
CppCompilerFlags = cppCompilerFlags
}; };
} }
} }

View file

@ -65,20 +65,25 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
// Flags // Flags
argsList.Add(cflags); argsList.Add(cflags);
// Add Includes // TODO: Enable this when https://github.com/dotnet/cli/pull/469 goes through.
// var ilcSdkIncPath = Path.Combine(config.IlcSdkPath, "inc");
//
// Get the directory name to ensure there are no trailing slashes as they may conflict
// with the terminating " we suffix to account for paths with spaces in them.
var ilcSdkIncPath = Path.GetDirectoryName(config.IlcSdkPath);
argsList.Add("-I"); argsList.Add("-I");
argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk/ubuntu.14.04")); argsList.Add($"\"{ilcSdkIncPath}\"");
argsList.Add("-I");
argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk"));
// Input File // Input File
var inCppFile = DetermineInFile(config); var inCppFile = DetermineInFile(config);
argsList.Add(inCppFile); argsList.Add(inCppFile);
// Add Stubs // Pass the optional native compiler flags if specified
argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk/ubuntu.14.04/lxstubs.cpp")); if (!string.IsNullOrWhiteSpace(config.CppCompilerFlags))
{
argsList.Add(config.CppCompilerFlags);
}
// ILC SDK Libs // ILC SDK Libs
foreach (var lib in IlcSdkLibs) foreach (var lib in IlcSdkLibs)
{ {

View file

@ -70,6 +70,12 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
var inLibFile = DetermineInFile(config); var inLibFile = DetermineInFile(config);
argsList.Add(inLibFile); argsList.Add(inLibFile);
// Pass the optional native compiler flags if specified
if (!string.IsNullOrWhiteSpace(config.CppCompilerFlags))
{
argsList.Add(config.CppCompilerFlags);
}
// ILC SDK Libs // ILC SDK Libs
foreach (var lib in IlcSdkLibs) foreach (var lib in IlcSdkLibs)
{ {

View file

@ -67,23 +67,28 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
// Flags // Flags
argsList.Add(cflags); argsList.Add(cflags);
// Add Includes // TODO: Enable this when https://github.com/dotnet/cli/pull/469 goes through.
// var ilcSdkIncPath = Path.Combine(config.IlcSdkPath, "inc");
//
// Get the directory name to ensure there are no trailing slashes as they may conflict
// with the terminating " we suffix to account for paths with spaces in them.
var ilcSdkIncPath = Path.GetDirectoryName(config.IlcSdkPath);
argsList.Add("-I"); argsList.Add("-I");
argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk/osx.10.10")); argsList.Add($"\"{ilcSdkIncPath}\"");
argsList.Add("-I");
argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk"));
// 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/osx.10.10/osxstubs.cpp"));
// Lib flags // Lib flags
argsList.Add(libFlags); argsList.Add(libFlags);
// Pass the optional native compiler flags if specified
if (!string.IsNullOrWhiteSpace(config.CppCompilerFlags))
{
argsList.Add(config.CppCompilerFlags);
}
// ILC SDK Libs // ILC SDK Libs
foreach (var lib in IlcSdkLibs) foreach (var lib in IlcSdkLibs)
{ {

View file

@ -66,11 +66,12 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
// Flags // Flags
argsList.Add(cflags); argsList.Add(cflags);
// Add Stubs // Pass the optional native compiler flags if specified
argsList.Add("-I "+Path.Combine(config.AppDepSDKPath, "CPPSdk/osx.10.10")); if (!string.IsNullOrWhiteSpace(config.CppCompilerFlags))
argsList.Add("-I "+Path.Combine(config.AppDepSDKPath, "CPPSdk")); {
argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk/osx.10.10/osxstubs.cpp")); argsList.Add(config.CppCompilerFlags);
}
// Input File // Input File
var inLibFile = DetermineInFile(config); var inLibFile = DetermineInFile(config);
argsList.Add("-Xlinker "+inLibFile); argsList.Add("-Xlinker "+inLibFile);

View file

@ -22,7 +22,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
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 _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MD /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" }
}; };
@ -68,17 +68,26 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
argsList.Add("/c"); argsList.Add("/c");
// Add Includes // Add Includes
var win7CppSdkPath = Path.Combine(config.AppDepSDKPath, "CPPSdk\\win7"); //
// TODO: Enable this when https://github.com/dotnet/cli/pull/469 goes through.
// var ilcSdkIncPath = Path.Combine(config.IlcSdkPath, "inc");
//
// Get the directory name to ensure there are no trailing slashes as they may conflict
// with the terminating " we suffix to account for paths with spaces in them.
var ilcSdkIncPath = config.IlcSdkPath;
ilcSdkIncPath = ilcSdkIncPath.TrimEnd(new char[] {'\\'});
argsList.Add("/I"); argsList.Add("/I");
argsList.Add($"\"{win7CppSdkPath}\""); argsList.Add($"\"{ilcSdkIncPath}\"");
var cppSdkPath = Path.Combine(config.AppDepSDKPath, "CPPSdk");
argsList.Add("/I");
argsList.Add($"\"{cppSdkPath}\"");
// Configuration Based Compiler Options // Configuration Based Compiler Options
argsList.Add(ConfigurationCompilerOptionsMap[config.BuildType]); argsList.Add(ConfigurationCompilerOptionsMap[config.BuildType]);
// Pass the optional native compiler flags if specified
if (!string.IsNullOrWhiteSpace(config.CppCompilerFlags))
{
argsList.Add(config.CppCompilerFlags);
}
// Output // Output
var objOut = DetermineOutputFile(config); var objOut = DetermineOutputFile(config);
argsList.Add($"/Fo\"{objOut}\""); argsList.Add($"/Fo\"{objOut}\"");

View file

@ -46,9 +46,11 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
"odbccp32.lib" "odbccp32.lib"
}; };
// We will always link against msvcrt.lib since the runtime libraries are also built against msvcrt.lib as we are not interested in assertions
// from CRT code.
private static readonly Dictionary<BuildConfiguration, string[]> ConfigurationLinkLibMap = new Dictionary<BuildConfiguration, string[]>() private static readonly Dictionary<BuildConfiguration, string[]> ConfigurationLinkLibMap = new Dictionary<BuildConfiguration, string[]>()
{ {
{ BuildConfiguration.debug , new string[] { "msvcrtd.lib" } }, { BuildConfiguration.debug , new string[] { "msvcrt.lib" } },
{ BuildConfiguration.release , new string[] { "msvcrt.lib" } } { BuildConfiguration.release , new string[] { "msvcrt.lib" } }
}; };

View file

@ -21,6 +21,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
private string _ilcArgs; private string _ilcArgs;
private readonly List<string> _referencePaths; private readonly List<string> _referencePaths;
private readonly List<string> _linkLibPaths; private readonly List<string> _linkLibPaths;
private string _cppCompilerFlags;
public string LogPath public string LogPath
{ {
@ -147,6 +148,18 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
} }
} }
public string CppCompilerFlags
{
get
{
return _cppCompilerFlags;
}
set
{
_cppCompilerFlags = value;
}
}
private NativeCompileSettings() private NativeCompileSettings()
{ {
_linkLibPaths = new List<string>(); _linkLibPaths = new List<string>();

View file

@ -5,7 +5,7 @@
"emitEntryPoint": true "emitEntryPoint": true
}, },
"dependencies": { "dependencies": {
"Microsoft.DotNet.AppDep":"1.0.2-*" "Microsoft.DotNet.AppDep":"1.0.3-*"
}, },
"frameworks": { "frameworks": {
"dnxcore50": { } "dnxcore50": { }

View file

@ -15,8 +15,8 @@
"type": "build", "type": "build",
"version": "1.0.0-*" "version": "1.0.0-*"
}, },
"Microsoft.DotNet.ILCompiler": "1.0.3-*", "Microsoft.DotNet.ILCompiler": "1.0.4-*",
"Microsoft.DotNet.ILCompiler.SDK": "1.0.3-*", "Microsoft.DotNet.ILCompiler.SDK": "1.0.4-*",
"Microsoft.DotNet.Compiler.Common": "1.0.0-*" "Microsoft.DotNet.Compiler.Common": "1.0.0-*"
}, },
"frameworks": { "frameworks": {

View file

@ -48,6 +48,7 @@ namespace Microsoft.DotNet.Tools.Compiler
var ilcSdkPath = app.Option("--ilcsdkpath <PATH>", "Path to the folder containing custom built ILCompiler SDK.", CommandOptionType.SingleValue); var ilcSdkPath = app.Option("--ilcsdkpath <PATH>", "Path to the folder containing custom built ILCompiler SDK.", CommandOptionType.SingleValue);
var appDepSdkPath = app.Option("--appdepsdkpath <PATH>", "Path to the folder containing ILCompiler application dependencies.", CommandOptionType.SingleValue); var appDepSdkPath = app.Option("--appdepsdkpath <PATH>", "Path to the folder containing ILCompiler application dependencies.", CommandOptionType.SingleValue);
var cppMode = app.Option("--cpp", "Flag to do native compilation with C++ code generator.", CommandOptionType.NoValue); var cppMode = app.Option("--cpp", "Flag to do native compilation with C++ code generator.", CommandOptionType.NoValue);
var cppCompilerFlags = app.Option("--cppcompilerflags <flags>", "Additional flags to be passed to the native compiler.", CommandOptionType.SingleValue);
app.OnExecute(() => app.OnExecute(() =>
{ {
@ -69,6 +70,7 @@ namespace Microsoft.DotNet.Tools.Compiler
var configValue = configuration.Value() ?? Constants.DefaultConfiguration; var configValue = configuration.Value() ?? Constants.DefaultConfiguration;
var outputValue = output.Value(); var outputValue = output.Value();
var intermediateValue = intermediateOutput.Value(); var intermediateValue = intermediateOutput.Value();
var cppCompilerFlagsValue = cppCompilerFlags.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;
@ -80,7 +82,7 @@ namespace Microsoft.DotNet.Tools.Compiler
success &= Compile(context, configValue, outputValue, intermediateValue, buildProjectReferences, noHost.HasValue()); success &= Compile(context, configValue, outputValue, intermediateValue, buildProjectReferences, noHost.HasValue());
if (isNative && success) if (isNative && success)
{ {
success &= CompileNative(context, configValue, outputValue, buildProjectReferences, intermediateValue, archValue, ilcArgsValue, ilcPathValue, ilcSdkPathValue, appDepSdkPathValue, isCppMode); success &= CompileNative(context, configValue, outputValue, buildProjectReferences, intermediateValue, archValue, ilcArgsValue, ilcPathValue, ilcSdkPathValue, appDepSdkPathValue, isCppMode, cppCompilerFlagsValue);
} }
} }
@ -113,7 +115,8 @@ namespace Microsoft.DotNet.Tools.Compiler
string ilcPathValue, string ilcPathValue,
string ilcSdkPathValue, string ilcSdkPathValue,
string appDepSdkPathValue, string appDepSdkPathValue,
bool isCppMode) bool isCppMode,
string cppCompilerFlagsValue)
{ {
var outputPath = GetOutputPath(context, configuration, outputOptionValue); var outputPath = GetOutputPath(context, configuration, outputOptionValue);
var nativeOutputPath = Path.Combine(GetOutputPath(context, configuration, outputOptionValue), "native"); var nativeOutputPath = Path.Combine(GetOutputPath(context, configuration, outputOptionValue), "native");
@ -167,6 +170,12 @@ namespace Microsoft.DotNet.Tools.Compiler
nativeArgs.Add("cpp"); nativeArgs.Add("cpp");
} }
if (!string.IsNullOrWhiteSpace(cppCompilerFlagsValue))
{
nativeArgs.Add("--cppcompilerflags");
nativeArgs.Add(cppCompilerFlagsValue);
}
// Configuration // Configuration
if (configuration != null) if (configuration != null)
{ {

View file

@ -69,12 +69,6 @@ namespace ConsoleApplication
[Fact] [Fact]
public void TestDotnetCompileNativeCpp() public void TestDotnetCompileNativeCpp()
{ {
// Skip this test on windows
if(SkipForOS(OSPlatform.Windows, "https://github.com/dotnet/cli/issues/335"))
{
return;
}
TestSetup(); TestSetup();
TestRunCommand("dotnet", $"compile --native --cpp -o {OutputDirectory}"); TestRunCommand("dotnet", $"compile --native --cpp -o {OutputDirectory}");