HinTak / Font-Validator

Font Validator is a tool for testing fonts prior to release. This testing ensures that fonts meet Microsoft's high quality standards and perform exceptionally well on Microsoft's platform.
Other
146 stars 12 forks source link

How do you build for MacOS? #35

Closed camertron closed 6 years ago

camertron commented 6 years ago

The documentation says running make will generate the correct executables, but the only one I see in bin/ is FontValidator.exe, which refuses to run on MacOS. I've looked through the Makefile and it doesn't look like there's any code to build for MacOS, yet a binary package exists for Mac. How do I re-generate the package? Note: I'm talking about the command-line tool only, I don't care about the GUI at the moment.

HinTak commented 6 years ago

According to my notes, the 2.1.1 binary was built with something like this:

MONO_PATH=. mkbundle -v --i18n all --cross mono-4.8.0-osx-10.7-x64.zip \
-o FontVal-2.1.1-py-osx-10.7-x64/FontValidator-clang FontValidator.exe  \
IronPython.Modules.dll --library libfreetype.6.dylib,Darwin/libfreetype.6-clang.dylib --library \
libfreetype6.dylib,Darwin/libfreetype.6-clang.dylib

You'll need to consult the documentation of mkbundle. Also, you must use exactly mono 4.8.x - mono 5.x+ is buggy (bug already filed at Xamarin - look for bugs I filed), and 4.6.x or below does not have the required enhancement. This (that the mac os x binary needs mono 4.8.x to build) was mentioned in the 2.1.x release notes.

Since this is using experimental technology from mono, I will not answer further questions on this. You'll have to consult the mono's source (as I did) to figure out how it works. I filed about 6(?) bugs at mono and fixed most of them myself and sent them the fix while I was building the Mac OS X binary.

camertron commented 6 years ago

Great, thanks @HinTak. Since Mac support is experimental I understand why the build instructions aren't in the README or wiki.

I ended up running make and then using the mono command to run FontValidator.exe. Initially I didn't know that was possible, being fairly new to the Mono community. May I suggest mentioning that somewhere in the documentation for n00bs like me?

thundernixon commented 6 years ago

Just chiming in to say that I would also appreciate some macOS build instructions. :) Thanks for the help here, though!

HinTak commented 6 years ago

I have not looked at mono 5 at all (see issue under upstream on "mono 5"). FV 2.1.2 was built with a late mono 5 but haven't really been tested thoroughly. So I'd say get the last of mono 4 (4.8) from https://www.mono-project.com .

The "first stage binary" is built by doing "make" with GNU make and mono. (GNU make is part of xcode's "commandline tool", I think).

The first binary still needs the runtime.

To build the all-in-one binary (without mono), you use the "mkbundle" tool which is part of mono. Unfortunately the needed functionality was introduced in 4.8, so basically you should not use anything earlier, and the early mono 5.x are buggy... So 4.8 or a very late 5.x .

That's the main idea. The first stage binary is platform independent so in principle you can build on windows and run on Mac. However the more usual way of building the first stage, via visual studio, was removed by Microsoft and has not been re-implement yet. This is one of the top priority tasks at the moment: make it easy for windows developers to build/improve Fontval.

schriftgestalt commented 4 years ago

Can you elaborate on the build process for mac?

camertron commented 4 years ago

@schriftgestalt I got it working a while ago, but I believe these are the steps I followed:

  1. Install Xcode, then run xcode-select --install to install the command-tools. This will give you the make executable.
  2. Install mono via Homebrew, i.e. brew install mono.
  3. Clone this repo and change directory into it.
  4. Run make. This will create an executable at bin/FontValidator.exe.
  5. Run the executable. For example, mono bin/FontValidator.exe -file input.ttf -report-dir ./results

That's how to build the command-line executable. I'm not sure how to build the native MacOS app that's also in this repo, but I think you can do it with Xcode.

schriftgestalt commented 4 years ago

The current mac binary contains the mono runtime as it can be called directly. That is what I need to build. The Mac UI is just a wrapper around that command line tool. So the last time I just copied the binary form the mac release.

HinTak commented 4 years ago

The two urls I wrote in https://github.com/HinTak/Font-Validator/issues/53 , i.e. https://xamarin.github.io/bugzilla-archives/52/52443/bug.html , and https://github.com/mono/mono/issues/17881 are basically the issue.

I'll try to write it here briefly also:

Around the time of mono 4.8.0, Apple announced that they would stop people playing with LD_LIBRARY_PATH and friends, i.e. overriding the default library look-up locations for applications.

FontVal has a private copy of a heavily customised freetype for hinting instruction checking; this is not a FontVal-only requirement, but affect other software, not necessarily mono-related either.

The mono people came up with the interesting way of coping, by making the main mono executable "self-aware", and being able to read extra stuff from the end of itself, and unpack the individual pieces to a temporary directory, and explicitly dl-open the pieces.

So the mac OS X FonVali executable is basically a mono executable with extra bits and bytes at the end. This, as reported in both of those urls, is what Mac OS X's codesign does not like: an executable file for which the actual "executable" part with machine instructions, etc, is a lot smaller than the file itself.

I think it is possible for the mono people to make the bundling process codesign-compatible, but they haven't done it yet.

Specifically, the mono people need to do what the pyinstaller people do: https://github.com/pyinstaller/pyinstaller/wiki/Recipe-OSX-Code-Signing

I haven't had a look at the other fix in qt yet. https://bugreports.qt.io/browse/QTIFW-153

HinTak commented 4 years ago

I have written a python script using macholib, based on the advice at the bottom of https://github.com/pyinstaller/pyinstaller/wiki/Recipe-OSX-Code-Signing .