Skip to content

Commit

Permalink
Make it so you don't need to copy libsqlite3 on Linux anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Jul 3, 2024
1 parent f427e1d commit 3c2d98c
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion MCGalaxy/MCGalaxy_.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@
<Compile Include="Server\Maintenance\ZipWriter.cs" />
<Compile Include="util\Formatting\Wildcard.cs" />
<Compile Include="util\ImageUtils.cs" />
<Compile Include="util\NetBackend.cs" />
<Compile Include="util\DotnetBackend.cs" />
<Compile Include="util\NumberUtils.cs" />
<Compile Include="util\OperatingSystem.cs" />
<Compile Include="Server\Server.cs" />
Expand Down
3 changes: 2 additions & 1 deletion MCGalaxy/MCGalaxy_dotnet.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<DefineConstants>$(DefineConstants);MCG_DOTNET</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MySql.Data" Version="8.1.0" />
Expand Down
4 changes: 2 additions & 2 deletions MCGalaxy/MCGalaxy_standalone.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<DefineConstants>$(DefineConstants);MCG_STANDALONE</DefineConstants>
<DefineConstants>$(DefineConstants);MCG_DOTNET;MCG_STANDALONE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.8" />
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Modules/Compiling/CompilerBackends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

namespace MCGalaxy.Modules.Compiling
{
#if !NETSTANDARD
#if !MCG_DOTNET
/// <summary> Compiles source code files from a particular language, using a CodeDomProvider for the compiler </summary>
public static class ICodeDomCompiler
{
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Modules/Compiling/CompilerFrontends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed class CSCompiler : ICompiler
public override string ShortName { get { return "C#"; } }
public override string FullName { get { return "CSharp"; } }

#if !NETSTANDARD
#if !MCG_DOTNET
CodeDomProvider compiler;

protected override ICompilerErrors DoCompile(string[] srcPaths, string dstPath) {
Expand Down
1 change: 1 addition & 0 deletions MCGalaxy/Server/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public sealed partial class Server
levelConfig = ConfigElement.GetAll(typeof(LevelConfig));
zoneConfig = ConfigElement.GetAll(typeof(ZoneConfig));

DotNetBackend.Init();
IOperatingSystem.DetectOS().Init();

StartTime = DateTime.UtcNow;
Expand Down
14 changes: 10 additions & 4 deletions MCGalaxy/util/NetBackend.cs → MCGalaxy/util/DotnetBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace MCGalaxy.Platform
{
#if !NETSTANDARD
#if !MCG_DOTNET
public static class DotNetBackend
{
public static void Init() { }
Expand All @@ -44,7 +44,13 @@ public static class DotNetBackend
}

static IntPtr ImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath) {
return IntPtr.Zero;
IntPtr libHandle = IntPtr.Zero;

// Since otherwise it's not always found on Linux
if (libraryName == "sqlite3") {
NativeLibrary.TryLoad("libsqlite3.so.0", assembly, DllImportSearchPath.System32, out libHandle);
}
return libHandle;
}


Expand All @@ -63,8 +69,8 @@ public static class DotNetBackend
// https://learn.microsoft.com/en-us/dotnet/core/dependency-loading/default-probing?source=recommendations#how-are-the-properties-populated

try {
AssemblyName name = new AssemblyName(name);
string path = name.Name + ".dll";
AssemblyName assemName = new AssemblyName(name);
string path = assemName.Name + ".dll";
if (File.Exists(path)) return Assembly.LoadFrom(path);
} catch (Exception ex) {
Logger.LogError("Resolving plugin DLL reference", ex);
Expand Down
6 changes: 3 additions & 3 deletions MCGalaxy/util/ImageUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
permissions and limitations under the Licenses.
*/
using System;
#if !NETSTANDARD
#if !MCG_DOTNET
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
Expand Down Expand Up @@ -55,7 +55,7 @@ public abstract class IBitmap2D : IDisposable

public abstract void Dispose();

#if !NETSTANDARD
#if !MCG_DOTNET
public static IBitmap2D Create() { return new GDIPlusBitmap(); }
#else
public static IBitmap2D Create() { return new ImageSharpBitmap(); }
Expand Down Expand Up @@ -94,7 +94,7 @@ public static class ImageUtils
}


#if !NETSTANDARD
#if !MCG_DOTNET
unsafe sealed class GDIPlusBitmap : IBitmap2D
{
Image img;
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/util/OperatingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class UnixOS : IOperatingSystem
execvp(exe, new string[] { exe, Server.RestartPath, null });
Console.WriteLine("execvp {0} failed: {1}", exe, Marshal.GetLastWin32Error());

#if !NETSTANDARD
#if !MCG_DOTNET
// .. and fallback to mono if that doesn't work for some reason
execvp("mono", new string[] { "mono", Server.RestartPath, null });
Console.WriteLine("execvp mono failed: {0}", Marshal.GetLastWin32Error());
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ Compiling - .NET 6 / .NET 7 / .NET 8
* Compiling for .NET 7: Navigate into `CLI` directory, and then run `dotnet build MCGalaxyCLI_dotnet7.csproj`
* Compiling for .NET 8: Navigate into `CLI` directory, and then run `dotnet build MCGalaxyCLI_dotnet8.csproj`

Linux notes:
**You will also need to copy `libsqlite3.so.0` from system libraries to `libsqlite3.so` in the server folder**

Copyright/License
-----------------
See LICENSE for MCGalaxy license, and license.txt for code used from other software.
Expand Down

0 comments on commit 3c2d98c

Please sign in to comment.