diff --git a/binder/CLI.cs b/binder/CLI.cs index 7a2e1bd..fc40680 100644 --- a/binder/CLI.cs +++ b/binder/CLI.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -149,8 +149,8 @@ namespace MonoEmbeddinator4000 options.Verbose = Verbose; options.OutputDir = OutputDir; options.CompileCode = CompileCode; - options.Target = Target; - options.DebugMode = DebugMode; + options.Compilation.Target = Target; + options.Compilation.DebugMode = DebugMode; if (options.OutputDir == null) options.OutputDir = Directory.GetCurrentDirectory(); @@ -171,10 +171,10 @@ namespace MonoEmbeddinator4000 } var targetPlatform = ConvertToTargetPlatform(Platform); - options.Platform = targetPlatform; + options.Compilation.Platform = targetPlatform; var vsVersion = ConvertToVsVersion(VsVersion); - options.VsVersion = vsVersion; + options.Compilation.VsVersion = vsVersion; return true; } diff --git a/binder/Compilation.cs b/binder/Compilation.cs index cc72502..659e904 100644 --- a/binder/Compilation.cs +++ b/binder/Compilation.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -231,13 +231,13 @@ namespace MonoEmbeddinator4000 void AotAssemblies() { - switch (Options.Platform) + switch (Options.Compilation.Platform) { case TargetPlatform.iOS: case TargetPlatform.TVOS: case TargetPlatform.WatchOS: { - string aotCompiler = GetAppleAotCompiler(Options.Platform, + string aotCompiler = GetAppleAotCompiler(Options.Compilation.Platform, XamarinSdkRoot, is64bits: false); // Call the Mono AOT cross compiler for all input assemblies. @@ -255,7 +255,7 @@ namespace MonoEmbeddinator4000 case TargetPlatform.Android: throw new NotSupportedException(string.Format( "AOT cross compilation to target platform '{0}' is not supported.", - Options.Platform)); + Options.Compilation.Platform)); case TargetPlatform.MacOS: break; } @@ -266,7 +266,7 @@ namespace MonoEmbeddinator4000 get { var detectAppleSdks = new Xamarin.iOS.Tasks.DetectIPhoneSdks { - TargetFrameworkIdentifier = GetXamarinTargetFrameworkName(Options.Platform) + TargetFrameworkIdentifier = GetXamarinTargetFrameworkName(Options.Compilation.Platform) }; if (!detectAppleSdks.Execute()) @@ -300,13 +300,13 @@ namespace MonoEmbeddinator4000 { var appName = $"{OutputName}.app"; - switch (Options.Platform) + switch (Options.Compilation.Platform) { case TargetPlatform.iOS: case TargetPlatform.TVOS: case TargetPlatform.WatchOS: var sdkName = App.Abi.IsSimulator() ? "Simulator" : string.Empty; - return Path.Combine(Options.OutputDir, $"{Options.Platform}{sdkName}", + return Path.Combine(Options.OutputDir, $"{Options.Compilation.Platform}{sdkName}", appName); case TargetPlatform.Windows: case TargetPlatform.Android: @@ -314,7 +314,7 @@ namespace MonoEmbeddinator4000 break; } - return Path.Combine(Options.OutputDir, Options.Platform.ToString(), + return Path.Combine(Options.OutputDir, Options.Compilation.Platform.ToString(), App.Abi.ToString(), appName); } @@ -332,13 +332,13 @@ namespace MonoEmbeddinator4000 $"--assembly-build-target=@all=framework={OutputName}.framework" }; - if (Options.DebugMode) + if (Options.Compilation.DebugMode) args.Add("--debug"); var targetArg = App.Abi.IsSimulator() ? "--sim" : "--dev"; args.Add($"{targetArg} {GetOutputFolder()}"); - var xamarinAppleFramework = GetXamarinTargetFrameworkName(Options.Platform); + var xamarinAppleFramework = GetXamarinTargetFrameworkName(Options.Compilation.Platform); var references = new List { Path.Combine(MonoTouchSdk.LibDir, "mono", xamarinAppleFramework, $"{xamarinAppleFramework}.dll"), Path.Combine(MonoTouchSdk.LibDir, "mono", xamarinAppleFramework, "mscorlib.dll") @@ -408,7 +408,7 @@ namespace MonoEmbeddinator4000 string.Join(" ", files.Select(file => Path.GetFullPath(file))) }; - if (Options.DebugMode) + if (Options.Compilation.DebugMode) args.Add("-g"); var invocation = string.Join(" ", args); @@ -437,14 +437,14 @@ namespace MonoEmbeddinator4000 throw new Exception("Visual Studio SDK was not found on your system."); ToolchainVersion vsSdk; - if (Options.VsVersion == VisualStudioVersion.Latest) + if (Options.Compilation.VsVersion == VisualStudioVersion.Latest) vsSdk = vsSdks.LastOrDefault(); else { - var exactVersion = vsSdks.Where(vs => (int)vs.Version == (int)Options.VsVersion) + var exactVersion = vsSdks.Where(vs => (int)vs.Version == (int)Options.Compilation.VsVersion) .Cast().SingleOrDefault(); if (!exactVersion.HasValue) - throw new Exception($"Visual Studio SDK version {Options.VsVersion} was not found on your system."); + throw new Exception($"Visual Studio SDK version {Options.Compilation.VsVersion} was not found on your system."); vsSdk = exactVersion.Value; } @@ -462,7 +462,7 @@ namespace MonoEmbeddinator4000 $"-I\"{monoPath}\\include\\mono-2.0\"", string.Join(" ", files.Select(file => "\""+ Path.GetFullPath(file) + "\"")), $"\"{monoPath}\\lib\\monosgen-2.0.lib\"", - Options.CompileSharedLibrary ? "/LD" : string.Empty, + Options.Compilation.CompileSharedLibrary ? "/LD" : string.Empty, $"/Fe{output}" }; @@ -502,7 +502,7 @@ namespace MonoEmbeddinator4000 var sysroot = Path.Combine (XcodeToolchain.GetXcodeIncludesFolder (), "../.."); args.Add ($"-isysroot {sysroot}"); - if (Options.Target == CompilationTarget.SharedLibrary) + if (Options.Compilation.Target == CompilationTarget.SharedLibrary) { var name = Path.GetFileNameWithoutExtension(Project.Assemblies[0]); var libName = $"lib{name}.dylib"; @@ -535,7 +535,7 @@ namespace MonoEmbeddinator4000 } else if (Platform.IsMacOS) { - switch (Options.Platform) + switch (Options.Compilation.Platform) { case TargetPlatform.iOS: case TargetPlatform.TVOS: @@ -545,7 +545,7 @@ namespace MonoEmbeddinator4000 case TargetPlatform.Windows: case TargetPlatform.Android: throw new NotSupportedException( - $"Cross compilation to target platform '{Options.Platform}' is not supported."); + $"Cross compilation to target platform '{Options.Compilation.Platform}' is not supported."); case TargetPlatform.MacOS: CompileClang(files); break; diff --git a/binder/Generators/C/CGenerator.cs b/binder/Generators/C/CGenerator.cs index 4d295e4..c71b431 100644 --- a/binder/Generators/C/CGenerator.cs +++ b/binder/Generators/C/CGenerator.cs @@ -87,6 +87,8 @@ namespace MonoEmbeddinator4000.Generators { public TranslationUnit Unit; + Options EmbedOptions => Context.Options as Options; + public CCodeGenerator(BindingContext context, TranslationUnit unit) : base(context, unit) { @@ -113,7 +115,7 @@ namespace MonoEmbeddinator4000.Generators public void WriteInclude(string include) { - if (Options.GenerateSupportFiles) + if (EmbedOptions.GenerateSupportFiles) WriteLine("#include \"{0}\"", include); else WriteLine("#include <{0}>", include); diff --git a/binder/Options.cs b/binder/Options.cs index 275ef4f..e8233b6 100644 --- a/binder/Options.cs +++ b/binder/Options.cs @@ -4,5 +4,12 @@ namespace MonoEmbeddinator4000 { public class Options : DriverOptions { + // If true, will use unmanaged->managed thunks to call managed methods. + // In this mode the JIT will generate specialized wrappers for marshaling + // which will be faster but also lead to higher memory consumption. + public bool UseUnmanagedThunks; + + // If true, will generate support files alongside generated binding code. + public bool GenerateSupportFiles = true; } } diff --git a/build/projects/CppSharp.Generator.csproj b/build/projects/CppSharp.Generator.csproj index 1d68b72..6aa4c45 100644 --- a/build/projects/CppSharp.Generator.csproj +++ b/build/projects/CppSharp.Generator.csproj @@ -179,11 +179,8 @@ Passes/GenerateAnonymousDelegatesPass.cs - - Passes/GenerateInlinesPass.cs - - - Passes/GenerateTemplatesCodePass.cs + + Passes/GenerateSymbolsPass.cs Passes/GetterSetterToPropertyPass.cs @@ -194,9 +191,6 @@ Passes/IgnoreSystemDeclarationsPass.cs - - Passes/InlinesCodeGenerator.cs - Passes/MarkSupportedClassTemplateSpecializationsPass.cs @@ -236,6 +230,9 @@ Passes/StripUnusedSystemTypesPass.cs + + Passes/SymbolsCodeGenerator.cs + Passes/TrimSpecializationsPass.cs @@ -245,11 +242,14 @@ Types/Std/Stdlib.cs + + Types/TypeIgnoreChecker.cs + Types/TypeMap.cs - - Types/Types.cs + + Types/TypeMapDatabase.cs Utils/BlockGenerator.cs diff --git a/build/projects/CppSharp.Parser.CSharp.csproj b/build/projects/CppSharp.Parser.CSharp.csproj index 8863334..c007a94 100644 --- a/build/projects/CppSharp.Parser.CSharp.csproj +++ b/build/projects/CppSharp.Parser.CSharp.csproj @@ -41,15 +41,15 @@ - - i686-apple-darwin12.4.0/CppSharp.CppParser.cs - - - i686-apple-darwin12.4.0/Std.cs - premake5.lua + + x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs + + + x86_64-apple-darwin12.4.0/Std.cs + diff --git a/build/projects/CppSharp.csproj b/build/projects/CppSharp.csproj index b57a21c..aa64be0 100644 --- a/build/projects/CppSharp.csproj +++ b/build/projects/CppSharp.csproj @@ -41,8 +41,14 @@ + + ../../external/CppSharp/deps/vs2017/Microsoft.VisualStudio.Setup.Configuration.Interop.dll + + + Compilation.cs + Diagnostics.cs diff --git a/external/CppSharp b/external/CppSharp index df9666d..3ac96ac 160000 --- a/external/CppSharp +++ b/external/CppSharp @@ -1 +1 @@ -Subproject commit df9666d6c46800496e79286c9adfa681ffc16ce9 +Subproject commit 3ac96ac8f29bcbeec7126a5c8e98f9182a113935