Add support --ilcsdkpath to allow ILCompiler to consume a custom build of ILCompiler.SDK

This commit is contained in:
Gaurav Khanna 2015-12-19 12:14:46 -08:00
parent 3395b43bd9
commit 57cbc119de
10 changed files with 67 additions and 27 deletions

View file

@ -16,6 +16,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
public IEnumerable<string> LinkLibPaths { get; set; } public IEnumerable<string> LinkLibPaths { get; set; }
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 bool IsHelp { get; set; } public bool IsHelp { get; set; }
public int ReturnCode { get; set; } public int ReturnCode { get; set; }
@ -57,6 +58,11 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
config.IlcPath = IlcPath; config.IlcPath = IlcPath;
} }
if (!string.IsNullOrEmpty(IlcSdkPath))
{
config.IlcSdkPath = IlcSdkPath;
}
if (!string.IsNullOrEmpty(LogPath)) if (!string.IsNullOrEmpty(LogPath))
{ {
config.LogPath = LogPath; config.LogPath = LogPath;

View file

@ -17,6 +17,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
NativeIntermediateMode? nativeMode = null; NativeIntermediateMode? nativeMode = null;
string ilcArgs = null; string ilcArgs = null;
string ilcPath = null; string ilcPath = null;
string ilcSdkPath = null;
string appDepSdk = null; string appDepSdk = null;
string logPath = null; string logPath = null;
var help = false; var help = false;
@ -45,7 +46,9 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
// Custom Extensibility Points to support CoreRT workflow TODO better descriptions // 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("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.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");
syntax.DefineOptionList("linklib", ref linklib, "Use to link in additional static libs"); syntax.DefineOptionList("linklib", ref linklib, "Use to link in additional static libs");
// TEMPORARY Hack until CoreRT compatible Framework Libs are available // TEMPORARY Hack until CoreRT compatible Framework Libs are available
@ -125,6 +128,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
ReferencePaths = references, ReferencePaths = references,
IlcArgs = ilcArgs, IlcArgs = ilcArgs,
IlcPath = ilcPath, IlcPath = ilcPath,
IlcSdkPath = ilcSdkPath,
LinkLibPaths = linklib, LinkLibPaths = linklib,
AppDepSDKPath = appDepSdk, AppDepSDKPath = appDepSdk,
LogPath = logPath LogPath = logPath

View file

@ -46,11 +46,10 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
argsList.Add($"\"{inputFilePath}\""); argsList.Add($"\"{inputFilePath}\"");
// System.Private.CoreLib Reference // System.Private.CoreLib Reference
String[] coreLibs = new String[] { "System.Private.CoreLib.dll", "System.Private.Corelib.dll" }; var coreLibPath = Path.Combine(config.IlcSdkPath, "System.Private.CoreLib.dll");
var coreLibPath = Path.Combine(config.IlcPath, Array.Find(coreLibs, lib => File.Exists(Path.Combine(config.IlcPath, lib))));
argsList.Add($"-r \"{coreLibPath}\""); argsList.Add($"-r \"{coreLibPath}\"");
// Dependency References // AppDep References
foreach (var reference in config.ReferencePaths) foreach (var reference in config.ReferencePaths)
{ {
argsList.Add($"-r \"{reference}\""); argsList.Add($"-r \"{reference}\"");

View file

@ -19,7 +19,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
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[] IlcSdkLibs = new string[]
{ {
"libbootstrappercpp.a", "libbootstrappercpp.a",
"libPortableRuntime.a", "libPortableRuntime.a",
@ -79,10 +79,10 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
// Add Stubs // Add Stubs
argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk/ubuntu.14.04/lxstubs.cpp")); argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk/ubuntu.14.04/lxstubs.cpp"));
// Libs // ILC SDK Libs
foreach (var lib in libs) foreach (var lib in IlcSdkLibs)
{ {
var libPath = Path.Combine(config.IlcPath, lib); var libPath = Path.Combine(config.IlcSdkPath, lib);
argsList.Add(libPath); argsList.Add(libPath);
} }

View file

@ -20,7 +20,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
// TODO: debug/release support // TODO: debug/release support
private readonly string cflags = "-lstdc++ -lpthread -ldl -lm -lrt"; private readonly string cflags = "-lstdc++ -lpthread -ldl -lm -lrt";
private readonly string[] libs = new string[] private readonly string[] IlcSdkLibs = new string[]
{ {
"libbootstrapper.a", "libbootstrapper.a",
"libRuntime.a", "libRuntime.a",
@ -70,10 +70,10 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
var inLibFile = DetermineInFile(config); var inLibFile = DetermineInFile(config);
argsList.Add(inLibFile); argsList.Add(inLibFile);
// Libs // ILC SDK Libs
foreach (var lib in libs) foreach (var lib in IlcSdkLibs)
{ {
var libPath = Path.Combine(config.IlcPath, lib); var libPath = Path.Combine(config.IlcSdkPath, lib);
argsList.Add(libPath); argsList.Add(libPath);
} }

View file

@ -21,7 +21,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
// Link to iconv APIs // Link to iconv APIs
private readonly string libFlags = "-liconv"; private readonly string libFlags = "-liconv";
private readonly string[] libs = new string[] private readonly string[] IlcSdkLibs = new string[]
{ {
"libbootstrappercpp.a", "libbootstrappercpp.a",
"libPortableRuntime.a", "libPortableRuntime.a",
@ -84,10 +84,10 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
// Lib flags // Lib flags
argsList.Add(libFlags); argsList.Add(libFlags);
// Libs // ILC SDK Libs
foreach (var lib in libs) foreach (var lib in IlcSdkLibs)
{ {
var libPath = Path.Combine(config.IlcPath, lib); var libPath = Path.Combine(config.IlcSdkPath, lib);
// Forward the library to linked to the linker // Forward the library to linked to the linker
argsList.Add("-Xlinker"); argsList.Add("-Xlinker");

View file

@ -20,7 +20,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
// TODO: debug/release support // TODO: debug/release support
private readonly string cflags = "-g -lstdc++ -Wno-invalid-offsetof -pthread -ldl -lm -liconv"; private readonly string cflags = "-g -lstdc++ -Wno-invalid-offsetof -pthread -ldl -lm -liconv";
private readonly string[] libs = new string[] private readonly string[] IlcSdkLibs = new string[]
{ {
"libbootstrapper.a", "libbootstrapper.a",
"libRuntime.a", "libRuntime.a",
@ -75,10 +75,10 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
var inLibFile = DetermineInFile(config); var inLibFile = DetermineInFile(config);
argsList.Add("-Xlinker "+inLibFile); argsList.Add("-Xlinker "+inLibFile);
// Libs // ILC SDK Libs
foreach (var lib in libs) foreach (var lib in IlcSdkLibs)
{ {
var libPath = Path.Combine(config.IlcPath, lib); var libPath = Path.Combine(config.IlcSdkPath, lib);
argsList.Add("-Xlinker "+libPath); argsList.Add("-Xlinker "+libPath);
} }

View file

@ -24,7 +24,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
{ BuildConfiguration.release, "/NOLOGO /ERRORREPORT:PROMPT /INCREMENTAL:NO /OPT:REF /OPT:ICF /LTCG:incremental /MANIFEST /MANIFESTUAC:\"level='asInvoker' uiAccess='false'\" /manifest:embed /Debug /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT" } { BuildConfiguration.release, "/NOLOGO /ERRORREPORT:PROMPT /INCREMENTAL:NO /OPT:REF /OPT:ICF /LTCG:incremental /MANIFEST /MANIFESTUAC:\"level='asInvoker' uiAccess='false'\" /manifest:embed /Debug /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT" }
}; };
private static readonly Dictionary<NativeIntermediateMode, string[]> ModeLibMap = new Dictionary<NativeIntermediateMode, string[]> private static readonly Dictionary<NativeIntermediateMode, string[]> IlcSdkLibMap = new Dictionary<NativeIntermediateMode, string[]>
{ {
{ NativeIntermediateMode.cpp, new string[] { "PortableRuntime.lib", "bootstrappercpp.lib" } }, { NativeIntermediateMode.cpp, new string[] { "PortableRuntime.lib", "bootstrappercpp.lib" } },
{ NativeIntermediateMode.ryujit, new string[] { "Runtime.lib", "bootstrapper.lib" } } { NativeIntermediateMode.ryujit, new string[] { "Runtime.lib", "bootstrapper.lib" } }
@ -98,11 +98,11 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
// Constant Libs // Constant Libs
argsList.Add(string.Join(" ", ConstantLinkLibs)); argsList.Add(string.Join(" ", ConstantLinkLibs));
// SDK Libs // ILC SDK Libs
var SDKLibs = ModeLibMap[config.NativeMode]; var SDKLibs = IlcSdkLibMap[config.NativeMode];
foreach (var lib in SDKLibs) foreach (var lib in SDKLibs)
{ {
var sdkLibPath = Path.Combine(config.IlcPath, lib); var sdkLibPath = Path.Combine(config.IlcSdkPath, lib);
argsList.Add($"\"{sdkLibPath}\""); argsList.Add($"\"{sdkLibPath}\"");
} }

View file

@ -14,6 +14,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
private string _inputManagedAssemblyPath; private string _inputManagedAssemblyPath;
private string _appDepSdkPath; private string _appDepSdkPath;
private string _ilcPath; private string _ilcPath;
private string _ilcSdkPath;
private string _outputDirectory; private string _outputDirectory;
private string _intermediateDirectory; private string _intermediateDirectory;
private string _logPath; private string _logPath;
@ -129,12 +130,32 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
} }
} }
public string IlcSdkPath
{
get
{
return _ilcSdkPath;
}
set
{
if (!Directory.Exists(value))
{
throw new Exception($"ILC SDK Directory does not exist: {value}.");
}
_ilcSdkPath = value;
}
}
private NativeCompileSettings() private NativeCompileSettings()
{ {
_linkLibPaths = new List<string>(); _linkLibPaths = new List<string>();
_referencePaths = new List<string>(); _referencePaths = new List<string>();
IlcPath = AppContext.BaseDirectory; IlcPath = AppContext.BaseDirectory;
// By default, ILC SDK Path is assumed to be the same folder as ILC path
IlcSdkPath = IlcPath;
Architecture = DefaultArchitectureMode; Architecture = DefaultArchitectureMode;
BuildType = DefaultBuiltType; BuildType = DefaultBuiltType;
NativeMode = DefaultNativeModel; NativeMode = DefaultNativeModel;

View file

@ -45,7 +45,8 @@ namespace Microsoft.DotNet.Tools.Compiler
var arch = app.Option("-a|--arch <ARCH>", "The architecture for which to compile. x64 only currently supported.", CommandOptionType.SingleValue); var arch = app.Option("-a|--arch <ARCH>", "The architecture for which to compile. x64 only currently supported.", CommandOptionType.SingleValue);
var ilcArgs = app.Option("--ilcargs <ARGS>", "Command line arguments to be passed directly to ILCompiler.", CommandOptionType.SingleValue); var ilcArgs = app.Option("--ilcargs <ARGS>", "Command line arguments to be passed directly to ILCompiler.", CommandOptionType.SingleValue);
var ilcPath = app.Option("--ilcpath <PATH>", "Path to the folder containing custom built ILCompiler.", CommandOptionType.SingleValue); var ilcPath = app.Option("--ilcpath <PATH>", "Path to the folder containing custom built ILCompiler.", CommandOptionType.SingleValue);
var ilcSdkPath = app.Option("--ilcsdkpath <PATH>", "Path to the folder containing ILCompiler application dependencies.", 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 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);
app.OnExecute(() => app.OnExecute(() =>
@ -64,6 +65,7 @@ namespace Microsoft.DotNet.Tools.Compiler
var ilcArgsValue = ilcArgs.Value(); var ilcArgsValue = ilcArgs.Value();
var ilcPathValue = ilcPath.Value(); var ilcPathValue = ilcPath.Value();
var ilcSdkPathValue = ilcSdkPath.Value(); var ilcSdkPathValue = ilcSdkPath.Value();
var appDepSdkPathValue = appDepSdkPath.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(); var intermediateValue = intermediateOutput.Value();
@ -78,7 +80,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, isCppMode); success &= CompileNative(context, configValue, outputValue, buildProjectReferences, intermediateValue, archValue, ilcArgsValue, ilcPathValue, ilcSdkPathValue, appDepSdkPathValue, isCppMode);
} }
} }
@ -110,6 +112,7 @@ namespace Microsoft.DotNet.Tools.Compiler
string ilcArgsValue, string ilcArgsValue,
string ilcPathValue, string ilcPathValue,
string ilcSdkPathValue, string ilcSdkPathValue,
string appDepSdkPathValue,
bool isCppMode) bool isCppMode)
{ {
var outputPath = GetOutputPath(context, configuration, outputOptionValue); var outputPath = GetOutputPath(context, configuration, outputOptionValue);
@ -146,10 +149,17 @@ namespace Microsoft.DotNet.Tools.Compiler
// ILC SDK Path // ILC SDK Path
if (!string.IsNullOrWhiteSpace(ilcSdkPathValue)) if (!string.IsNullOrWhiteSpace(ilcSdkPathValue))
{ {
nativeArgs.Add("--appdepsdk"); nativeArgs.Add("--ilcsdkpath");
nativeArgs.Add(ilcSdkPathValue); nativeArgs.Add(ilcSdkPathValue);
} }
// AppDep SDK Path
if (!string.IsNullOrWhiteSpace(appDepSdkPathValue))
{
nativeArgs.Add("--appdepsdk");
nativeArgs.Add(appDepSdkPathValue);
}
// CodeGen Mode // CodeGen Mode
if(isCppMode) if(isCppMode)
{ {