diff --git a/scripts/build/build_appdeps.sh b/scripts/build/build_appdeps.sh index 7d72fee2d..d1f03d22a 100755 --- a/scripts/build/build_appdeps.sh +++ b/scripts/build/build_appdeps.sh @@ -7,11 +7,6 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source $SCRIPT_DIR/../_common.sh -# Dotnet-compile-native doesn't work for mac yet -if [[ "$(uname)" != "Linux" ]]; then - exit 0 -fi - REPO_ROOT="$SCRIPT_DIR/../.." APPDEPS_PROJECT_DIR=$REPO_ROOT/src/Microsoft.DotNet.Tools.Compiler.Native/appdep diff --git a/src/Microsoft.DotNet.Tools.Compiler.Native/ILCompilerInvoker.cs b/src/Microsoft.DotNet.Tools.Compiler.Native/ILCompilerInvoker.cs index 29e9ade71..93cd5bb0a 100644 --- a/src/Microsoft.DotNet.Tools.Compiler.Native/ILCompilerInvoker.cs +++ b/src/Microsoft.DotNet.Tools.Compiler.Native/ILCompilerInvoker.cs @@ -42,6 +42,11 @@ namespace Microsoft.DotNet.Tools.Compiler.Native var argsList = new List(); var managedPath = Path.Combine(config.IlcPath, ILCompiler); + if (!File.Exists(managedPath)) + { + throw new FileNotFoundException("Unable to find ILCompiler at " + managedPath); + } + argsList.Add($"\"{managedPath}\""); // Input File diff --git a/src/Microsoft.DotNet.Tools.Compiler.Native/IntermediateCompilation/IntermediateCompiler.cs b/src/Microsoft.DotNet.Tools.Compiler.Native/IntermediateCompilation/IntermediateCompiler.cs index 07e3ab39e..fdbe3515d 100644 --- a/src/Microsoft.DotNet.Tools.Compiler.Native/IntermediateCompilation/IntermediateCompiler.cs +++ b/src/Microsoft.DotNet.Tools.Compiler.Native/IntermediateCompilation/IntermediateCompiler.cs @@ -50,7 +50,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native } else if (config.OS == OSMode.Mac) { - throw new NotImplementedException("Mac not yet supported."); + stepList.Add(new MacCppCompileStep(config)); } else { diff --git a/src/Microsoft.DotNet.Tools.Compiler.Native/IntermediateCompilation/Linux/LinuxCppCompileStep.cs b/src/Microsoft.DotNet.Tools.Compiler.Native/IntermediateCompilation/Linux/LinuxCppCompileStep.cs index 4174c2008..4ebd39b87 100644 --- a/src/Microsoft.DotNet.Tools.Compiler.Native/IntermediateCompilation/Linux/LinuxCppCompileStep.cs +++ b/src/Microsoft.DotNet.Tools.Compiler.Native/IntermediateCompilation/Linux/LinuxCppCompileStep.cs @@ -87,10 +87,11 @@ namespace Microsoft.DotNet.Tools.Compiler.Native } // AppDep Libs + var baseAppDeplibPath = Path.Combine(config.AppDepSDKPath, "CPPSdk/ubuntu.14.04/x64"); foreach (var lib in appdeplibs) { - var libPath = Path.Combine(config.AppDepSDKPath, lib); - argsList.Add(libPath); + var appDeplibPath = Path.Combine(baseAppDeplibPath, lib); + argsList.Add(appDeplibPath); } argsList.Add(cLibsFlags); diff --git a/src/Microsoft.DotNet.Tools.Compiler.Native/IntermediateCompilation/Mac/MacCppCompileStep.cs b/src/Microsoft.DotNet.Tools.Compiler.Native/IntermediateCompilation/Mac/MacCppCompileStep.cs index 3731310c8..cd35f5b68 100644 --- a/src/Microsoft.DotNet.Tools.Compiler.Native/IntermediateCompilation/Mac/MacCppCompileStep.cs +++ b/src/Microsoft.DotNet.Tools.Compiler.Native/IntermediateCompilation/Mac/MacCppCompileStep.cs @@ -10,31 +10,136 @@ using Microsoft.DotNet.Tools.Common; namespace Microsoft.DotNet.Tools.Compiler.Native { - public class MacCppCompileStep : IPlatformNativeStep - { + public class MacCppCompileStep : IPlatformNativeStep + { + private readonly string CompilerName = "clang"; + private readonly string InputExtension = ".cpp"; + + // TODO: debug/release support + private readonly string cflags = "-g -lstdc++ -Wno-invalid-offsetof -pthread"; + + // Link to iconv APIs + private readonly string libFlags = "-liconv"; + + private readonly string[] libs = new string[] + { + "libbootstrappercpp.a", + "libPortableRuntime.a", + "libSystem.Private.CoreLib.Native.a" + }; + + private readonly string[] appdeplibs = new string[] + { + "libSystem.Native.a" + }; + + + private string CompilerArgStr { get; set; } + private NativeCompileSettings config; + public MacCppCompileStep(NativeCompileSettings config) { - throw new NotImplementedException("Mac Cpp Not Supported Yet"); + this.config = config; + InitializeArgs(config); } public int Invoke() - { - throw new NotImplementedException("mac cpp Not supported yet."); - } - - public bool CheckPreReqs() - { - throw new NotImplementedException("mac cpp Not supported yet."); - } - - public string DetermineOutputFile(NativeCompileSettings config) - { - throw new NotImplementedException("Mac cpp Not supported yet."); - } - - public bool RequiresLinkStep() { - return false; - } - } + var result = InvokeCompiler(); + if (result != 0) + { + Reporter.Error.WriteLine("Compilation of intermediate files failed."); + } + + return result; + } + + public bool CheckPreReqs() + { + // TODO check for clang + return true; + } + + private void InitializeArgs(NativeCompileSettings config) + { + var argsList = new List(); + + // Flags + argsList.Add(cflags); + + // Add Includes + argsList.Add("-I"); + argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk/osx.10.10")); + + argsList.Add("-I"); + argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk")); + + // Input File + var inCppFile = DetermineInFile(config); + argsList.Add(inCppFile); + + // Add Stubs + argsList.Add(Path.Combine(config.AppDepSDKPath, "CPPSdk/osx.10.10/osxstubs.cpp")); + + // Lib flags + argsList.Add(libFlags); + + // Libs + foreach (var lib in libs) + { + var libPath = Path.Combine(config.IlcPath, lib); + + // Forward the library to linked to the linker + argsList.Add("-Xlinker"); + argsList.Add(libPath); + } + + // AppDep Libs + var baseAppDeplibPath = Path.Combine(config.AppDepSDKPath, "CPPSdk/osx.10.10/x64"); + foreach (var lib in appdeplibs) + { + var appDeplibPath = Path.Combine(baseAppDeplibPath, lib); + argsList.Add("-Xlinker"); + argsList.Add(appDeplibPath); + } + + // Output + var libOut = DetermineOutputFile(config); + argsList.Add($"-o \"{libOut}\""); + + this.CompilerArgStr = string.Join(" ", argsList); + } + + private int InvokeCompiler() + { + var result = Command.Create(CompilerName, CompilerArgStr) + .ForwardStdErr() + .ForwardStdOut() + .Execute(); + + return result.ExitCode; + } + + private string DetermineInFile(NativeCompileSettings config) + { + var intermediateDirectory = config.IntermediateDirectory; + + var filename = Path.GetFileNameWithoutExtension(config.InputManagedAssemblyPath); + + var infile = Path.Combine(intermediateDirectory, filename + InputExtension); + + return infile; + } + + public string DetermineOutputFile(NativeCompileSettings config) + { + var intermediateDirectory = config.OutputDirectory; + + var filename = Path.GetFileNameWithoutExtension(config.InputManagedAssemblyPath); + + var outfile = Path.Combine(intermediateDirectory, filename); + + return outfile; + } + } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.Tools.Compiler.Native/appdep/project.json b/src/Microsoft.DotNet.Tools.Compiler.Native/appdep/project.json index 1c8141200..7f8eabbbf 100644 --- a/src/Microsoft.DotNet.Tools.Compiler.Native/appdep/project.json +++ b/src/Microsoft.DotNet.Tools.Compiler.Native/appdep/project.json @@ -5,7 +5,7 @@ "emitEntryPoint": true }, "dependencies": { - "Microsoft.DotNet.AppDep":"1.0.1-*" + "Microsoft.DotNet.AppDep":"1.0.2-*" }, "frameworks": { "dnxcore50": { } diff --git a/src/Microsoft.DotNet.Tools.Compiler.Native/project.json b/src/Microsoft.DotNet.Tools.Compiler.Native/project.json index 73a97a9a1..9bb5144c4 100644 --- a/src/Microsoft.DotNet.Tools.Compiler.Native/project.json +++ b/src/Microsoft.DotNet.Tools.Compiler.Native/project.json @@ -23,7 +23,7 @@ "type": "build", "version": "1.0.0-*" }, - "Microsoft.DotNet.ILCompiler": "1.0.1-*", + "Microsoft.DotNet.ILCompiler": "1.0.2-*", "Microsoft.DotNet.ObjectWriter": "1.0.2-*", "Microsoft.DotNet.RyuJit": "1.0.0-*", "Microsoft.DotNet.Compiler.Common": "1.0.0-*"