Skip to content

Commit

Permalink
Revert "Compiled all inlines into a single library thus decreasing th…
Browse files Browse the repository at this point in the history
…eir size from 58 to 4 MB."

This reverts commit e5a240a.

Signed-off-by: Dimitar Dobrev <[email protected]>
  • Loading branch information
ddobrev committed Oct 1, 2016
1 parent d91f99c commit 06dc367
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 127 deletions.
7 changes: 0 additions & 7 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
0.6.2 - 1.10.2016
BREAKING: The helping libraries with inlines are no longer separated per module.
Instead, there are just two of them, Qt-inlines for the LGPL modules and Qt-GPL-inlines for the rest.
Fixed:
- Removed all sealed overrides in the bindings;
- Removed the double name-space from QtDataVisualization.

0.6.1 - 17.9.2016
Fixed:
- Removed all mappings to C# structures because their empty constructors are not correctly wrapped yet.
Expand Down
3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ IMPORTANT: The Apache License below does not include the
following bindings:
- QtCharts.Sharp;
- QtDataVisualization.Sharp;
along with Qt-GPL-inlines. These are licensed under GPLv3 instead
as they link GPLv3 code.
They are licensed under GPLv3 instead as they link GPLv3 code.
You may obtain a copy of GPLv3 at

https://www.gnu.org/licenses/gpl-3.0.en.html
Expand Down
18 changes: 7 additions & 11 deletions QtSharp.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ static void ProcessGeneratedInlines ()
{
if (!Platform.IsWindows)
return;

#if DEBUG
if (File.Exists("../../../QtSharp.Tests/bin/Debug/Qt-inlines.dll"))
File.Delete("../../../QtSharp.Tests/bin/Debug/Qt-inlines.dll");
if (File.Exists("../../../QtSharp.Tests/bin/Debug/QtCore-inlines.dll"))
File.Delete("../../../QtSharp.Tests/bin/Debug/QtCore-inlines.dll");

File.Copy("release/Qt-inlines.dll", "../../../QtSharp.Tests/bin/Debug/Qt-inlines.dll");
File.Copy("release/QtCore-inlines.dll", "../../../QtSharp.Tests/bin/Debug/QtCore-inlines.dll");
#else
if (File.Exists("../../../QtSharp.Tests/bin/Release/QtCore-inlines.dll"))
File.Delete("../../../QtSharp.Tests/bin/Release/QtCore-inlines.dll");
Expand Down Expand Up @@ -233,16 +233,12 @@ public static int Main(string[] args)
{
foreach (var wrappedModule in wrappedModules)
{
zipArchive.CreateEntryFromFile(wrappedModule, wrappedModule);
var documentation = Path.ChangeExtension(wrappedModule, "xml");
zipArchive.CreateEntryFromFile(wrappedModule.Key, wrappedModule.Key);
var documentation = Path.ChangeExtension(wrappedModule.Key, "xml");
zipArchive.CreateEntryFromFile(documentation, documentation);
zipArchive.CreateEntryFromFile(wrappedModule.Value, Path.GetFileName(wrappedModule.Value));
}
zipArchive.CreateEntryFromFile("CppSharp.Runtime.dll", "CppSharp.Runtime.dll");
var extension = Platform.IsWindows ? "dll" : Platform.IsMacOS ? "dylib" : "so";
var inlines = string.Format("Qt-inlines.{0}", extension);
zipArchive.CreateEntryFromFile(string.Format("release/{0}", inlines), inlines);
var gplInlines = string.Format("Qt-GPL-inlines.{0}", extension);
zipArchive.CreateEntryFromFile(string.Format("release/{0}", gplInlines), gplInlines);
}
}
Console.WriteLine("Done in: " + s.Elapsed);
Expand Down
91 changes: 37 additions & 54 deletions QtSharp/CompileInlinesPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using CppSharp.Passes;
using CppSharp;
using CppSharp.Parser;
using System.Collections.Generic;

namespace QtSharp
{
Expand Down Expand Up @@ -34,79 +33,63 @@ public override bool VisitLibrary(ASTContext context)
File.WriteAllText(qtVersionFile, qtVersion);
qtVersionFileInfo = new FileInfo(qtVersionFile);
}
return CompileInlines(qtVersionFileInfo, "Qt-inlines") && CompileInlines(qtVersionFileInfo, "Qt-GPL-inlines", true);
}

private bool CompileInlines(FileInfo qtVersionFileInfo, string qtInlines, bool isGpl = false)
{
var dir = Platform.IsMacOS ? this.Context.Options.OutputDir : Path.Combine(this.Context.Options.OutputDir, "release");
var inlines = Path.GetFileName(string.Format("{0}{2}.{1}", Platform.IsWindows ? string.Empty : "lib",
Platform.IsWindows ? "dll" : Platform.IsMacOS ? "dylib" : "so", qtInlines));
var libFile = Path.Combine(dir, inlines);
var inlinesFileInfo = new FileInfo(libFile);
if (!inlinesFileInfo.Exists || qtVersionFileInfo.LastWriteTimeUtc > inlinesFileInfo.LastWriteTimeUtc)
foreach (var module in this.Context.Options.Modules)
{
if (!this.CompileInlines(qtInlines, isGpl))
var inlines = Path.GetFileName(string.Format("{0}{1}.{2}", Platform.IsWindows ? string.Empty : "lib",
module.InlinesLibraryName, Platform.IsMacOS ? "dylib" : "dll"));
var libFile = Path.Combine(dir, inlines);
var inlinesFileInfo = new FileInfo(libFile);
if (!inlinesFileInfo.Exists || qtVersionFileInfo.LastWriteTimeUtc > inlinesFileInfo.LastWriteTimeUtc)
{
return false;
if (!this.CompileInlines(module))
{
continue;
}
}
}
var parserOptions = new ParserOptions();
parserOptions.addLibraryDirs(dir);
parserOptions.LibraryFile = inlines;
using (var parserResult = CppSharp.Parser.ClangParser.ParseLibrary(parserOptions))
{
if (parserResult.Kind == ParserResultKind.Success)
var parserOptions = new ParserOptions();
parserOptions.addLibraryDirs(dir);
parserOptions.LibraryFile = inlines;
using (var parserResult = CppSharp.Parser.ClangParser.ParseLibrary(parserOptions))
{
var nativeLibrary = CppSharp.ClangParser.ConvertLibrary(parserResult.Library);
this.Context.Symbols.Libraries.Add(nativeLibrary);
this.Context.Symbols.IndexSymbols();
parserResult.Library.Dispose();
if (parserResult.Kind == ParserResultKind.Success)
{
var nativeLibrary = CppSharp.ClangParser.ConvertLibrary(parserResult.Library);
this.Context.Symbols.Libraries.Add(nativeLibrary);
this.Context.Symbols.IndexSymbols();
parserResult.Library.Dispose();
}
}
}
return true;
}

private bool CompileInlines(string qtInlines, bool isGpl = false)
private bool CompileInlines(Module module)
{
var pro = string.Format("{0}.pro", qtInlines);
var pro = string.Format("{0}.pro", module.InlinesLibraryName);
var path = Path.Combine(this.Context.Options.OutputDir, pro);
var proBuilder = new StringBuilder();
string qtModules;
if (isGpl)
{
qtModules = "charts datavisualization";
}
else
{
qtModules = string.Join(" ", from module in this.Context.Options.Modules
from header in module.Headers
where header != "QtCharts" && header != "QtDataVisualization" &&
!header.EndsWith(".h", StringComparison.Ordinal)
var qtModules = string.Join(" ", from header in module.Headers
where !header.EndsWith(".h", StringComparison.Ordinal)
select header.Substring("Qt".Length).ToLowerInvariant());
switch (qtModules)
{
// QtTest is only library which has a "lib" suffix to its module alias for qmake
case "test":
qtModules += "lib";
break;
// HACK: work around https://bugreports.qt.io/browse/QTBUG-54030
case "bluetooth":
qtModules += " network";
break;
}
// QtTest is only library which has a "lib" suffix to its module alias for qmake
qtModules = qtModules.Replace(" test ", " testlib ");

proBuilder.AppendFormat("QT += {0}\n", qtModules);
proBuilder.Append("CONFIG += c++11\n");
proBuilder.Append("QMAKE_CXXFLAGS += -fkeep-inline-functions\n");
proBuilder.AppendFormat("TARGET = {0}\n", qtInlines);
proBuilder.AppendFormat("TARGET = {0}\n", module.InlinesLibraryName);
proBuilder.Append("TEMPLATE = lib\n");
IEnumerable<string> sources;
if (isGpl)
{
sources = from module in this.Context.Options.Modules
where module.Headers.Contains("QtCharts") || module.Headers.Contains("QtDataVisualization")
select module.InlinesLibraryName + ".cpp";
}
else
{
sources = from module in this.Context.Options.Modules
where !module.Headers.Contains("QtCharts") && ! module.Headers.Contains("QtDataVisualization")
select module.InlinesLibraryName + ".cpp";
}
proBuilder.AppendFormat("SOURCES += {0}\n", string.Join(" ", sources));
proBuilder.AppendFormat("SOURCES += {0}\n", Path.ChangeExtension(pro, "cpp"));
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
proBuilder.Append("LIBS += -loleaut32 -lole32");
Expand Down
47 changes: 1 addition & 46 deletions QtSharp/ProcessHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Diagnostics;
using System.Text;
using System.Threading;

namespace QtSharp
{
Expand All @@ -21,50 +19,7 @@ public static string Run(string path, string args, out string error, bool readOu
process.Start();
if (waitForExit)
{
using (var outputWaitHandle = new AutoResetEvent(false))
{
using (var errorWaitHandle = new AutoResetEvent(false))
{
var outputBuilder = new StringBuilder();
process.OutputDataReceived += (sender, e) =>
{
if (e.Data == null)
{
outputWaitHandle.Set();
}
else
{
outputBuilder.AppendLine(e.Data);
}
};
var errorBuilder = new StringBuilder();
process.ErrorDataReceived += (sender, e) =>
{
if (e.Data == null)
{
errorWaitHandle.Set();
}
else
{
errorBuilder.AppendLine(e.Data);
}
};
process.BeginErrorReadLine();
process.BeginOutputReadLine();
if (process.WaitForExit(Timeout.Infinite) && outputWaitHandle.WaitOne() &&
errorWaitHandle.WaitOne())
{
error = errorBuilder.ToString();
if (process.ExitCode != 0)
{
return string.Empty;
}
return readOutputByLines ? string.Empty : outputBuilder.ToString().Trim().Replace(@"\\", @"\");
}
error = string.Empty;
return string.Empty;
}
}
process.WaitForExit();
}
while (readOutputByLines && !process.StandardOutput.EndOfStream)
{
Expand Down
10 changes: 6 additions & 4 deletions QtSharp/QtSharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public QtSharp(QtInfo qtInfo)
this.qtInfo = qtInfo;
}

public ICollection<string> GetVerifiedWrappedModules()
public ICollection<KeyValuePair<string, string>> GetVerifiedWrappedModules()
{
for (int i = this.wrappedModules.Count - 1; i >= 0; i--)
{
var wrappedModule = this.wrappedModules[i];
if (!File.Exists(wrappedModule))
if (!File.Exists(wrappedModule.Key) || !File.Exists(wrappedModule.Value))
{
this.wrappedModules.RemoveAt(i);
}
Expand Down Expand Up @@ -215,7 +215,9 @@ public void Postprocess(Driver driver, ASTContext lib)
{
var prefix = Platform.IsWindows ? string.Empty : "lib";
var extension = Platform.IsWindows ? ".dll" : Platform.IsMacOS ? ".dylib" : ".so";
this.wrappedModules.Add(module.LibraryName + ".dll");
var inlinesLibraryFile = string.Format("{0}{1}{2}", prefix, module.InlinesLibraryName, extension);
var inlinesLibraryPath = Path.Combine(driver.Options.OutputDir, Platform.IsWindows ? "release" : string.Empty, inlinesLibraryFile);
this.wrappedModules.Add(new KeyValuePair<string, string>(module.LibraryName + ".dll", inlinesLibraryPath));
}
}

Expand Down Expand Up @@ -337,6 +339,6 @@ public void SetupPasses(Driver driver)
}

private readonly QtInfo qtInfo;
private List<string> wrappedModules = new List<string>();
private List<KeyValuePair<string, string>> wrappedModules = new List<KeyValuePair<string, string>>();
}
}
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ Qt for OS X and Linux are planned, Qt for VC++ has not been planned for now.
The source code is separated into a library that contains the settings and passes the generator needs, and a command-line client.
In the future a GUI client, constructed with Qt# itself, is planned as well.

There are binary releases for Windows and Qt MinGW at https://github.com/ddobrev/QtSharp/releases. They are in an alpha stage.
The are binary releases for Windows and Qt MinGW at https://github.com/ddobrev/QtSharp/releases. They are in an alpha stage.
As they get more stable, binaries for other operating systems will be added as well.

## Getting started

You need to deploy Qt itself by following http://doc.qt.io/qt-5/windows-deployment.html#application-dependencies .
In addition, you need to deploy Qt-inlines alongside your executable. If you use QtCharts or QtDataVisualization,
you also need Qt-GPL-inlines.
In addition, for each Qt module you use you also need Qt<module>-inlines.dll deployed alongside your executable.
You can use QtSharp with any C# IDE, including Visual Studio, but make sure your executable is 32-bit by either using the
x86 configuration or AnyCPU with "Prefer 32-bit" checked.

Expand Down

0 comments on commit 06dc367

Please sign in to comment.