Finish backporting Freetype from in development quik.

This commit is contained in:
H. Utku Maden 2023-11-10 20:57:33 +03:00
parent 6240f5921b
commit cea243a3b8
Signed by: themixedupstuff
GPG Key ID: 25A001B636F17843
8 changed files with 82 additions and 18 deletions

1
.gitignore vendored

@ -4,6 +4,7 @@ obj/
riderModule.iml
/_ReSharper.Caches/
.idea
.vs
.vscode
nuget_repo
**/out

@ -5,6 +5,9 @@
FROM debian:stable-slim
WORKDIR /root
# Set host name.
RUN echo quik_docker_env > /etc/hostname
# Download and Install dependencies.
# Install WGET
RUN apt-get update
@ -28,6 +31,8 @@ WORKDIR /root
gcc-aarch64-linux-gnu \
gcc-i686-linux-gnu \
git \
libharfbuzz-dev \
libpng-dev \
libssl-dev \
libxml2-dev \
lzma-dev \

@ -1,4 +1,5 @@
using System;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Quik.FreeType
@ -7,6 +8,42 @@ namespace Quik.FreeType
{
private const string freetype2 = "freetype";
private static readonly string[] LibraryNames = new string[]
{
//FIXME: This is wrong on so many levels, but, i need to do this
// in order to get a change of this running.
"runtimes/win-x64/native/libfreetype.dll",
"runtimes/win-x86/native/libfreetype.dll",
"runtimes/linux-arm/native/libfreetype.so",
"runtimes/linux-arm64/native/libfreetype.so",
"runtimes/linux-x64/native/libfreetype.so",
"runtimes/native/libfreetype.dylib",
"libfreetype.dll",
"libfreetype.so",
"libfreetype.dylib",
};
static FT()
{
NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), Resolver);
}
private static IntPtr Resolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
{
if (libraryName != freetype2)
return IntPtr.Zero;
foreach (string name in LibraryNames)
{
if (NativeLibrary.TryLoad(name, assembly, searchPath, out IntPtr handle))
{
return handle;
}
}
return NativeLibrary.Load(libraryName);
}
[DllImport(freetype2, EntryPoint = "FT_Init_FreeType")]
public static extern FTError InitFreeType(out FTLibrary library);

@ -4,10 +4,25 @@
<TargetFramework>net6.0</TargetFramework>
<LangVersion>7.3</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RuntimeIdentifiers>linux-arm;linux-arm64;linux-x64;win-x86;win-x64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup>
<!-- Nuget Properties. -->
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>Quik.FreeType</PackageId>
<Version>1.0.0</Version>
<Authors>FreeType Authors, H. Utku Maden</Authors>
<Description>
A C# wrapper for the FreeType font loading library.
</Description>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Quik\Quik.csproj" />
<Content Include="runtimes/**">
<PackagePath>runtimes</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

@ -0,0 +1,8 @@
#!/bin/bash
cd $(dirname "$0")
# Apply the patch file that makes it easier to build freetype.
# Note that this doesn't work all that well on windows.
cat ../lib/freetype_patch.diff | git -C ../lib/freetype apply
QUIK_ADDITIONAL_CMAKE=-DBUILD_SHARED_LIBS\=true DST=$PWD ../sh/quik_build_native.sh ../lib/freetype

@ -4,10 +4,4 @@ services:
user: quik
working_dir: /home/quik
volumes:
- src:/home/quik/src
volumes:
src:
driver_opts:
type: none
device: ${PWD}
o: bind
- .:/home/quik/src

@ -11,5 +11,3 @@ export QNUGET_LOCAL_PATH=$QUIK_SRC/nuget_repo
# Create nuget repository.
mkdir -p $QUIK_SRC/nuget_repo
nuget sources Add -Name $QNUGET_LOCAL -Source $QNUGET_LOCAL_PATH -NonInteractive
source sh/quik_build_native.sh

@ -2,9 +2,9 @@
# $1 Source path of the project.
# $2 Target architecture list.
# DST is the destination directory.
SRC=$1
NAME=$(dirname $SRC)
ARCHS=$2
if [ -z "$SRC" ]
@ -18,24 +18,30 @@ then
ARCHS="linux-arm linux-arm64 linux-x64 win-x64 win-x86"
fi
cd $SRC
if [ -z "$DST" ]
then
DST=$PWD
fi
for ARCH in $ARCHS; do
# Output directory.
PREFIX=runtimes/$ARCH/native
PREFIX=$DST/runtimes/$ARCH/native
# Build directory.
BUILD=out/$ARCH
BUILD=$DST/out/$ARCH
# Cmake toolchain file.
TOOLCHAIN=../cmake/$ARCH.cmake
TOOLCHAIN=$DST/../cmake/$ARCH.cmake
# Create directories.
mkdir -p $PREFIX $BUILD
# Configure CMAKE.
cmake -B $BUILD -S . \
cmake -B $BUILD -S $SRC \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS=-static-libgcc \
-DCMAKE_CXX_FLAGS=-static-libgcc \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN
-DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN \
$QUIK_ADDITIONAL_CMAKE
# Build and install.
ninja -C $BUILD all