Merge pull request #122 from brthor/compilenative
Compile Native Option, first version
This commit is contained in:
commit
d5412f767e
6 changed files with 130 additions and 35 deletions
|
@ -9,7 +9,7 @@
|
||||||
"homepage": "https://dotnet.github.io/core",
|
"homepage": "https://dotnet.github.io/core",
|
||||||
|
|
||||||
"release":{
|
"release":{
|
||||||
"package_version":"0.3",
|
"package_version":"0.201",
|
||||||
"package_revision":"1",
|
"package_revision":"1",
|
||||||
"urgency" : "low",
|
"urgency" : "low",
|
||||||
"changelog_message" : "Bootstrap loop package"
|
"changelog_message" : "Bootstrap loop package"
|
||||||
|
|
|
@ -43,15 +43,20 @@ add_system_dir_placement(){
|
||||||
|
|
||||||
dir_files=( $(_get_files_in_dir_tree $PACKAGE_SOURCE_DIR/$in_package_dir) )
|
dir_files=( $(_get_files_in_dir_tree $PACKAGE_SOURCE_DIR/$in_package_dir) )
|
||||||
|
|
||||||
|
# If in_package_dir isn't empty include a slash
|
||||||
|
if [ ! -z "$in_package_dir" ]; then
|
||||||
|
in_package_dir="${in_package_dir}/"
|
||||||
|
fi
|
||||||
|
|
||||||
for rel_filepath in ${dir_files[@]}
|
for rel_filepath in ${dir_files[@]}
|
||||||
do
|
do
|
||||||
local parent_path=$(dirname $rel_filepath)
|
local parent_path=$(dirname $rel_filepath)
|
||||||
|
|
||||||
# If there is no parent, parent_path = "."
|
# If there is no parent, parent_path = "."
|
||||||
if [[ "$parent_path" == "." ]]; then
|
if [[ "$parent_path" == "." ]]; then
|
||||||
add_system_file_placement "${in_package_dir}/${rel_filepath}" "${abs_installation_dir}"
|
add_system_file_placement "${in_package_dir}${rel_filepath}" "${abs_installation_dir}"
|
||||||
else
|
else
|
||||||
add_system_file_placement "${in_package_dir}/${rel_filepath}" "${abs_installation_dir}/${parent_path}"
|
add_system_file_placement "${in_package_dir}${rel_filepath}" "${abs_installation_dir}/${parent_path}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
SOURCE="${BASH_SOURCE[0]}"
|
SOURCE="${BASH_SOURCE[0]}"
|
||||||
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
||||||
|
|
|
@ -68,7 +68,11 @@ create_or_start_vm(){
|
||||||
if [[ $(docker-machine ls | grep $VM_NAME) == "" ]]; then
|
if [[ $(docker-machine ls | grep $VM_NAME) == "" ]]; then
|
||||||
docker-machine create -d virtualbox $VM_NAME
|
docker-machine create -d virtualbox $VM_NAME
|
||||||
else
|
else
|
||||||
docker-machine start $VM_NAME
|
# This fails sometimes
|
||||||
|
if ! docker-machine start $VM_NAME; then
|
||||||
|
docker-machine rm -f $VM_NAME
|
||||||
|
docker-machine create -d virtualbox $VM_NAME
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,5 +13,10 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
public static readonly string DefaultConfiguration = "Debug";
|
public static readonly string DefaultConfiguration = "Debug";
|
||||||
public static readonly string BinDirectoryName = "bin";
|
public static readonly string BinDirectoryName = "bin";
|
||||||
public static readonly string ObjDirectoryName = "obj";
|
public static readonly string ObjDirectoryName = "obj";
|
||||||
|
|
||||||
|
public static readonly string DynamicLibSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".dll" :
|
||||||
|
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? ".dylib" : ".so";
|
||||||
|
|
||||||
|
public static readonly string StaticLibSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".lib" : ".a" ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ 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");
|
||||||
|
var native = app.Option("-n|--native", "Compiles source to native machine code.", CommandOptionType.NoValue);
|
||||||
|
|
||||||
app.OnExecute(() =>
|
app.OnExecute(() =>
|
||||||
{
|
{
|
||||||
|
@ -40,6 +41,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
}
|
}
|
||||||
|
|
||||||
var buildProjectReferences = !noProjectDependencies.HasValue();
|
var buildProjectReferences = !noProjectDependencies.HasValue();
|
||||||
|
var isNative = native.HasValue();
|
||||||
|
|
||||||
// Load project contexts for each framework and compile them
|
// Load project contexts for each framework and compile them
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
@ -48,6 +50,11 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
foreach (var context in framework.Values.Select(f => ProjectContext.Create(path, NuGetFramework.Parse(f))))
|
foreach (var context in framework.Values.Select(f => ProjectContext.Create(path, NuGetFramework.Parse(f))))
|
||||||
{
|
{
|
||||||
success &= Compile(context, configuration.Value() ?? Constants.DefaultConfiguration, output.Value(), buildProjectReferences);
|
success &= Compile(context, configuration.Value() ?? Constants.DefaultConfiguration, output.Value(), buildProjectReferences);
|
||||||
|
|
||||||
|
if (isNative)
|
||||||
|
{
|
||||||
|
success &= CompileNative(context, configuration.Value() ?? Constants.DefaultConfiguration, output.Value(), buildProjectReferences);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -55,6 +62,11 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
foreach (var context in ProjectContext.CreateContextForEachFramework(path))
|
foreach (var context in ProjectContext.CreateContextForEachFramework(path))
|
||||||
{
|
{
|
||||||
success &= Compile(context, configuration.Value() ?? Constants.DefaultConfiguration, output.Value(), buildProjectReferences);
|
success &= Compile(context, configuration.Value() ?? Constants.DefaultConfiguration, output.Value(), buildProjectReferences);
|
||||||
|
|
||||||
|
if (isNative)
|
||||||
|
{
|
||||||
|
success &= CompileNative(context, configuration.Value() ?? Constants.DefaultConfiguration, output.Value(), buildProjectReferences);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return success ? 0 : 1;
|
return success ? 0 : 1;
|
||||||
|
@ -75,10 +87,33 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool Compile(ProjectContext context, string configuration, string outputPath, bool buildProjectReferences)
|
private static bool CompileNative(ProjectContext context, string configuration, string outputOptionValue, bool buildProjectReferences)
|
||||||
|
{
|
||||||
|
string outputPath = Path.Combine(GetOutputPath(context, configuration, outputOptionValue), "native");
|
||||||
|
|
||||||
|
var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
|
||||||
|
var managedBinaryPath = Path.Combine(outputPath, context.ProjectFile.Name + (compilationOptions.EmitEntryPoint.GetValueOrDefault() ? ".exe" : ".dll"));
|
||||||
|
|
||||||
|
// Do Native Compilation
|
||||||
|
var result = Command.Create($"dotnet-compile-native", $"\"{managedBinaryPath}\" \"{outputPath}\"")
|
||||||
|
.ForwardStdErr()
|
||||||
|
.ForwardStdOut()
|
||||||
|
.Execute();
|
||||||
|
|
||||||
|
return result.ExitCode == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool Compile(ProjectContext context, string configuration, string outputOptionValue, bool buildProjectReferences)
|
||||||
{
|
{
|
||||||
Reporter.Output.WriteLine($"Compiling {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}");
|
Reporter.Output.WriteLine($"Compiling {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}");
|
||||||
|
|
||||||
|
//Set up Output Paths
|
||||||
|
string outputPath = GetOutputPath(context, configuration, outputOptionValue);
|
||||||
|
string intermediateOutputPath = GetIntermediateOutputPath(context, configuration, outputOptionValue);
|
||||||
|
|
||||||
|
CleanOrCreateDirectory(outputPath);
|
||||||
|
CleanOrCreateDirectory(intermediateOutputPath);
|
||||||
|
|
||||||
// Create the library exporter
|
// Create the library exporter
|
||||||
var exporter = context.CreateExporter(configuration);
|
var exporter = context.CreateExporter(configuration);
|
||||||
|
|
||||||
|
@ -127,35 +162,6 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
// file anyways
|
// file anyways
|
||||||
// ShowDependencyInfo(dependencies);
|
// ShowDependencyInfo(dependencies);
|
||||||
|
|
||||||
// Hackily generate the output path
|
|
||||||
if (string.IsNullOrEmpty(outputPath))
|
|
||||||
{
|
|
||||||
outputPath = Path.Combine(
|
|
||||||
context.ProjectFile.ProjectDirectory,
|
|
||||||
Constants.BinDirectoryName,
|
|
||||||
configuration,
|
|
||||||
context.TargetFramework.GetTwoDigitShortFolderName());
|
|
||||||
}
|
|
||||||
|
|
||||||
string intermediateOutputPath = Path.Combine(
|
|
||||||
context.ProjectFile.ProjectDirectory,
|
|
||||||
Constants.ObjDirectoryName,
|
|
||||||
configuration,
|
|
||||||
context.TargetFramework.GetTwoDigitShortFolderName());
|
|
||||||
|
|
||||||
if (Directory.Exists(outputPath))
|
|
||||||
{
|
|
||||||
Directory.Delete(outputPath, recursive: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Directory.Exists(intermediateOutputPath))
|
|
||||||
{
|
|
||||||
Directory.Delete(intermediateOutputPath, recursive: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
Directory.CreateDirectory(outputPath);
|
|
||||||
Directory.CreateDirectory(intermediateOutputPath);
|
|
||||||
|
|
||||||
// Get compilation options
|
// Get compilation options
|
||||||
var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
|
var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
|
||||||
var outputExtension = ".dll";
|
var outputExtension = ".dll";
|
||||||
|
@ -249,6 +255,82 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetOutputPath(ProjectContext context, string configuration, string outputOptionValue)
|
||||||
|
{
|
||||||
|
var outputPath = string.Empty;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(outputOptionValue))
|
||||||
|
{
|
||||||
|
outputPath = Path.Combine(
|
||||||
|
GetDefaultRootOutputPath(context, outputOptionValue),
|
||||||
|
Constants.BinDirectoryName,
|
||||||
|
configuration,
|
||||||
|
context.TargetFramework.GetTwoDigitShortFolderName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
outputPath = outputOptionValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputPath;
|
||||||
|
|
||||||
|
string intermediateOutputPath = Path.Combine(
|
||||||
|
context.ProjectFile.ProjectDirectory,
|
||||||
|
Constants.ObjDirectoryName,
|
||||||
|
configuration,
|
||||||
|
context.TargetFramework.GetTwoDigitShortFolderName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetIntermediateOutputPath(ProjectContext context, string configuration, string outputOptionValue)
|
||||||
|
{
|
||||||
|
var intermediateOutputPath = String.Empty;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(outputOptionValue))
|
||||||
|
{
|
||||||
|
intermediateOutputPath = Path.Combine(
|
||||||
|
GetDefaultRootOutputPath(context, outputOptionValue),
|
||||||
|
Constants.ObjDirectoryName,
|
||||||
|
configuration,
|
||||||
|
context.TargetFramework.GetTwoDigitShortFolderName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
intermediateOutputPath = outputOptionValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return intermediateOutputPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetDefaultRootOutputPath(ProjectContext context, string outputOptionValue)
|
||||||
|
{
|
||||||
|
string rootOutputPath = String.Empty;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(outputOptionValue))
|
||||||
|
{
|
||||||
|
rootOutputPath = context.ProjectFile.ProjectDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rootOutputPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CleanOrCreateDirectory(string path)
|
||||||
|
{
|
||||||
|
if (Directory.Exists(path))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.Delete(path, recursive: true);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Unable to remove directory: " + path);
|
||||||
|
Console.WriteLine(e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
}
|
||||||
|
|
||||||
private static void EmitHost(string outputPath, string projectName, LibraryExporter exporter)
|
private static void EmitHost(string outputPath, string projectName, LibraryExporter exporter)
|
||||||
{
|
{
|
||||||
// Write the Host information file (basically a simplified form of the lock file)
|
// Write the Host information file (basically a simplified form of the lock file)
|
||||||
|
|
Loading…
Reference in a new issue