Page MenuHomeWildfire Games

Adds FreeType support to the engine
Needs ReviewPublic

Authored by vladislavbelov on Jun 7 2021, 12:08 AM.

Details

Reviewers
None
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Summary

In any case of chosen library for text rendering (cairo, freetype, pango) they might depend on freetype to read such fonts.

Test Plan
  1. Apply the patch and compile the game
  2. Run the game with a user report and check that freetype version is correct

Event Timeline

vladislavbelov created this revision.Jun 7 2021, 12:08 AM

Binaries:

Put DLLs into the system folder, freetype folder into libraries/win32.

Build failure - The Moirai have given mortals hearts that can endure.

Debug: 
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

    13>e:\jenkins\workspace\vs2015-differential\source\ps\gamesetup\hwdetect.cpp(52): fatal error C1083: Cannot open include file: 'ft2build.h': No such file or directory [E:\Jenkins\workspace\vs2015-differential\build\workspaces\vs2017\engine.vcxproj]

Link to build: https://jenkins.wildfiregames.com/job/vs2015-differential/5686/display/redirect

Build failure - The Moirai have given mortals hearts that can endure.

builderr-debug-macos.txt
../../../source/ps/GameSetup/HWDetect.cpp:52:10: fatal error: 'ft2build.h' file not found
#include <ft2build.h>
         ^~~~~~~~~~~~
1 error generated.
make[1]: *** [obj/engine_Debug/HWDetect.o] Error 1
make: *** [engine] Error 2

Link to build: https://jenkins.wildfiregames.com/job/macos-differential/4592/display/redirect

Stan added a subscriber: Stan.Jun 7 2021, 12:24 AM

Works for me on windows.

"freetype": "2.10.4",
Vulcan added a comment.Jun 7 2021, 1:30 AM

Build failure - The Moirai have given mortals hearts that can endure.

builderr-debug-gcc7.txt
../../../source/ps/GameSetup/HWDetect.cpp:52:10: fatal error: ft2build.h: No such file or directory
 #include <ft2build.h>
          ^~~~~~~~~~~~
compilation terminated.
make[1]: *** [engine.make:342: obj/engine_Debug/HWDetect.o] Error 1
make: *** [Makefile:119: engine] Error 2

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/6310/display/redirect

vladislavbelov requested review of this revision.Jun 7 2021, 1:30 AM

With the suggested changes below applied on an ArchLinux system, userreport_hwdetect.txt reports:

"freetype": "2.10.4",

MacOS users will probably need a section adding to build-osx-libs.sh to acquire and build freetype2. (If it is installed on a base MacOS system, it doesn't seem to provide a .pc file - at least on our CI.)

build/premake/extern_libs5.lua
312–326

Suggested changes to get it to build on Linux (and hopefully, BSD) systems.

nani awarded a token.Jun 7 2021, 6:52 PM
nani rescinded a token.
nani awarded a token.
Imarok added a subscriber: Imarok.Jun 7 2021, 7:49 PM

With @s0600204's proposed changes and running apt install libfreetype6-dev it compiles on Ubuntu 20.04 and reports:

"freetype": "2.10.1",

That is the correct version.

I've managed to compile & run this on MacOS, but because freetype installs its header to include/freetype2/ instead of just include, we can't use the default include paths.
So I would suggest using png-config, but that requires D3611, ideally (could be done without by hardcoding the path). Alternatively, could hack in build-osx-libs.sh

Here's my diff-on-diff:

This comment was removed by wraitii.
Stan added inline comments.Aug 2 2021, 7:10 PM
source/ps/GameSetup/HWDetect.cpp
304

Maybe those strings could be constexpr

Build failure - The Moirai have given mortals hearts that can endure.

builderr-debug-macos.txt
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libsimulation2_dbg.a(precompiled.o) has no symbols
../../../source/ps/GameSetup/HWDetect.cpp:52:10: fatal error: 'ft2build.h' file not found
#include <ft2build.h>
         ^~~~~~~~~~~~
1 error generated.
make[1]: *** [obj/engine_Debug/HWDetect.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [engine] Error 2

Link to build: https://jenkins.wildfiregames.com/job/macos-differential/4942/display/redirect

Build failure - The Moirai have given mortals hearts that can endure.

Debug: 
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

    12>e:\jenkins\workspace\vs2015-differential\source\ps\gamesetup\hwdetect.cpp(52): fatal error C1083: Cannot open include file: 'ft2build.h': No such file or directory [E:\Jenkins\workspace\vs2015-differential\build\workspaces\vs2017\engine.vcxproj]

Link to build: https://jenkins.wildfiregames.com/job/vs2015-differential/6038/display/redirect

Stan added a comment.EditedSep 10 2021, 9:56 AM

Forgot the build-osx-libs.sh file :)
Need to update the dockerfile too

In D4108#181466, @Stan wrote:

Forgot the build-osx-libs.sh file :)

Thanks!

Need to update the dockerfile too

Which one?

Build failure - The Moirai have given mortals hearts that can endure.

Debug: 
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

    14>e:\jenkins\workspace\vs2015-differential\source\ps\gamesetup\hwdetect.cpp(52): fatal error C1083: Cannot open include file: 'ft2build.h': No such file or directory [E:\Jenkins\workspace\vs2015-differential\build\workspaces\vs2017\engine.vcxproj]

Link to build: https://jenkins.wildfiregames.com/job/vs2015-differential/6039/display/redirect

Build failure - The Moirai have given mortals hearts that can endure.

builderr-debug-macos.txt
../../../source/ps/GameSetup/HWDetect.cpp:52:10: fatal error: 'ft2build.h' file not found
#include <ft2build.h>
         ^~~~~~~~~~~~
1 error generated.
make[1]: *** [obj/engine_Debug/HWDetect.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [engine] Error 2

Link to build: https://jenkins.wildfiregames.com/job/macos-differential/4943/display/redirect

Stan added a comment.Sep 10 2021, 12:35 PM

Okay so as @wraitii said build fails on macos because path is

libraries/osx/freetype/include/freetype2
libraries/osx/freetype/include
libraries/osx/freetype/include
\---include
    \---freetype2
        |   ft2build.h
        |
        \---freetype
            |   freetype.h
            |   ftadvanc.h
            |   ftbbox.h
            |   ftbdf.h
            |   ftbitmap.h
            |   ftbzip2.h
            |   ftcache.h
            |   ftchapters.h
            |   ftcid.h
            |   ftcolor.h
            |   ftdriver.h
            |   fterrdef.h
            |   fterrors.h
            |   ftfntfmt.h
            |   ftgasp.h
            |   ftglyph.h
            |   ftgxval.h
            |   ftgzip.h
            |   ftimage.h
            |   ftincrem.h
            |   ftlcdfil.h
            |   ftlist.h
            |   ftlzw.h
            |   ftmac.h
            |   ftmm.h
            |   ftmodapi.h
            |   ftmoderr.h
            |   ftotval.h
            |   ftoutln.h
            |   ftparams.h
            |   ftpfr.h
            |   ftrender.h
            |   ftsizes.h
            |   ftsnames.h
            |   ftstroke.h
            |   ftsynth.h
            |   ftsystem.h
            |   fttrigon.h
            |   fttypes.h
            |   ftwinfnt.h
            |   t1tables.h
            |   ttnameid.h
            |   tttables.h
            |   tttags.h
            |
            \---config
                |    ftconfig.h
                |    ftconfig.h
                |    ftheader.h
                |    ftmodule.h
                |    ftoption.h
                |    ftstdlib.h
                |    integer-types.h
                |    mac-support.h
                |    public-macros.h

It seems to be also possible to use the version installed by XCode, but that seems like asking for trouble https://stackoverflow.com/questions/18887445/does-freetype-comes-pre-installed-on-mac
Don't seem to have it on the VM;

println "ls -lah /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/".execute().text
println "ls -lah /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/".execute().text
println "ls -lah /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/".execute().text
libraries/osx/build-osx-libs.sh
513

A solution could be to add

Stan added a comment.Sep 10 2021, 3:33 PM

Another solution would be to #ifdef the usages of freetype. Up to you;

For the docker it's this file https://trac.wildfiregames.com/browser/ps/trunk/build/jenkins/dockerfiles/build-base.Dockerfile

Langbart added a subscriber: Langbart.EditedSep 16 2021, 3:21 PM

Apply the patch and compile the game

Yes, macOS 10.15.7 with rP25923.

Run the game with a user report and check that freetype version is correct

userreport_hwdetect.txt in my /Users/picus/Library/Application Support/0ad/logs folder says:

...
"sdl_runtime_version": "2.0.12",
"sdl_video_backend": "Cocoa",
"freetype": "2.11.0",
"vulkan": "cantload",
"GL_VERSION": "2.1 NVIDIA-14.0.32 355.11.11.10.10.143",
...

My library folder says freetype-2.10.4

Stan added a comment.Sep 16 2021, 4:05 PM

You probably have a version somewhere @Langbart see if you can find it in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/

In D4108#181951, @Stan wrote:

You probably have a version somewhere @Langbart see if you can find it in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/

I don't have the Xcode.app, but I have it installed via Homebrew.

picus@Picus ~ % brew info freetype
freetype: stable 2.11.0 (bottled)
Software library to render fonts
https://www.freetype.org/
/usr/local/Cellar/freetype/2.11.0 (66 files, 2.5MB) *
Stan added a comment.Sep 16 2021, 4:12 PM

Interesting so it picked the homebrew version instead of the local one. It's a bit strange the game compiled with no header change though.

In D4108#181953, @Stan wrote:

Interesting so it picked the homebrew version instead of the local one. It's a bit strange the game compiled with no header change though.

I uninstalled freetype 2.11.0 by running brew uninstall --ignore-dependencies freetype and I did a clean install SVN (with D4108) run, and .... I can not compile.

Stan added a comment.Sep 16 2021, 4:27 PM

Yeah it's because freetype ft2build.h is named freenode2/ft2build.h only on macOS

Stan added a comment.Fri, Sep 24, 5:41 PM

@s0600204 any idea what we could do for macos and pkg config ?

In D4108#182476, @Stan wrote:

@s0600204 any idea what we could do for macos and pkg config ?

Rebase to take into account recent changes, then add the below suggested line so that the generated .pc file is in the correct place for our scripts to find it. (There's no need to relocate the header files.)

libraries/osx/build-osx-libs.sh
514–515
In D4108#182476, @Stan wrote:

@s0600204 any idea what we could do for macos and pkg config ?

Rebase to take into account recent changes, then add the below suggested line so that the generated .pc file is in the correct place for our scripts to find it. (There's no need to relocate the header files.)

Yes, this worked for me. I could compile and the userreport_hwdetect.txt now says:

"freetype": "2.10.4",

PS: I still have the Homebrew version freetype 2.11.0 installed.