Browse Source

Ensured the C# gen correctly imports a native library with no target triple.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/778/merge
Dimitar Dobrev 9 years ago
parent
commit
fed72f5910
  1. 9
      src/CppParser/Parser.cpp
  2. 5
      src/Generator.Tests/GeneratorTest.cs
  3. 5
      src/Generator/Generators/CSharp/CSharpSources.cs
  4. 16
      src/Parser/TargetTriple.cs
  5. 3
      tests/NamespacesDerived/NamespacesDerived.cs

9
src/CppParser/Parser.cpp

@ -301,16 +301,17 @@ void Parser::SetupHeader() @@ -301,16 +301,17 @@ void Parser::SetupHeader()
auto& TO = Inv->TargetOpts;
targetABI = ConvertToClangTargetCXXABI(opts->abi);
TO->Triple = llvm::sys::getDefaultTargetTriple();
if (!opts->TargetTriple.empty())
TO->Triple = llvm::Triple::normalize(opts->TargetTriple);
if (opts->TargetTriple.empty())
opts->TargetTriple = llvm::sys::getDefaultTargetTriple();
TO->Triple = llvm::Triple::normalize(opts->TargetTriple);
TargetInfo* TI = TargetInfo::CreateTargetInfo(c->getDiagnostics(), TO);
if (!TI)
{
// We might have no target info due to an invalid user-provided triple.
// Try again with the default triple.
TO->Triple = llvm::sys::getDefaultTargetTriple();
opts->TargetTriple = llvm::sys::getDefaultTargetTriple();
TO->Triple = llvm::Triple::normalize(opts->TargetTriple);
TI = TargetInfo::CreateTargetInfo(c->getDiagnostics(), TO);
}

5
src/Generator.Tests/GeneratorTest.cs

@ -35,11 +35,6 @@ namespace CppSharp.Utils @@ -35,11 +35,6 @@ namespace CppSharp.Utils
Diagnostics.Message("Generating bindings for {0} ({1})",
testModule.LibraryName, options.GeneratorKind.ToString());
// Workaround for CLR which does not check for .dll if the
// name already has a dot.
if (!Platform.IsMono)
testModule.SharedLibraryName += ".dll";
var parserOptions = driver.ParserOptions;
if (Platform.IsMacOS)
parserOptions.TargetTriple = Environment.Is64BitProcess ? "x86_64-apple-darwin" : "i686-apple-darwin";

5
src/Generator/Generators/CSharp/CSharpSources.cs

@ -7,6 +7,7 @@ using System.Text; @@ -7,6 +7,7 @@ using System.Text;
using System.Text.RegularExpressions;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Parser;
using CppSharp.Types;
using CppSharp.Utils;
using Attribute = CppSharp.AST.Attribute;
@ -1893,8 +1894,6 @@ namespace CppSharp.Generators.CSharp @@ -1893,8 +1894,6 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.BeforeNextBlock);
}
var className = @class.IsAbstractImpl ? @class.BaseClass.Name : @class.Name;
var ctorCall = string.Format("{0}{1}", @class.Name, @class.IsAbstract ? "Internal" : "");
if (!@class.IsAbstractImpl)
{
@ -3046,7 +3045,7 @@ namespace CppSharp.Generators.CSharp @@ -3046,7 +3045,7 @@ namespace CppSharp.Generators.CSharp
var targetTriple = Context.ParserOptions.TargetTriple;
if (Options.GenerateInternalImports)
libName = "__Internal";
else if ((targetTriple.Contains("win32") || targetTriple.Contains("win64")) &&
else if (TargetTriple.IsWindows(targetTriple) &&
libName.Contains('.') && Path.GetExtension(libName) != ".dll")
libName += ".dll";

16
src/Parser/TargetTriple.cs

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
using System.Linq;
namespace CppSharp.Parser
{
// over time we should turn this into a real class
// like http://llvm.org/docs/doxygen/html/classllvm_1_1Triple.html
public static class TargetTriple
{
public static bool IsWindows(string targetTriple)
{
var parts = targetTriple.Split('-');
return parts.Contains("windows") ||
parts.Contains("win32") || parts.Contains("win64");
}
}
}

3
tests/NamespacesDerived/NamespacesDerived.cs

@ -24,9 +24,6 @@ namespace CppSharp.Tests @@ -24,9 +24,6 @@ namespace CppSharp.Tests
module.Headers.Add($"{@base}.h");
module.OutputNamespace = @base;
module.SharedLibraryName = $"{@base}.Native";
// Workaround for CLR which does not check for .dll if the name already has a dot
if (System.Type.GetType("Mono.Runtime") == null)
module.SharedLibraryName += ".dll";
driver.Options.Modules[1].Dependencies.Add(module);
}

Loading…
Cancel
Save