This post (once again) re-presents a comprehensive way to compile Google’s woff2_compress and woff2_decompress tools on Windows using MSYS, CURL (which comes with several MSYS distros), GIT and some version of mingw32-w64.
- 20150824 — updated
- May 6 2015 — PATCHING IS NO LONGER REQUIRED on Windows using mingw32-w64. The project(s) compile quite easily now in
mingw32-w64-i686
andmingw32-w64-x86_64
. - April 15 2015 — woff2 sha1:7375be53fc0c7c9c1f1bb62a29d94650fa7448b7 is now supported only for mingw32-w64 (posix) compiler version(s).
- prior — (oh forget it)
After translating my efforts to DIFF patches (for compiling this project on Windows)—I couldn’t resist attempting to spread my MSYS/MSYS2/MINGW-W64 joy 😉
WOFF2 Observed
From Jyrki Alakuijala on stackoverflow: “WOFF 2.0, based on the Brotli compression algorithm and other improvements over WOFF 1.0 giving more than 30 % reduction in file size, is supported in Chrome, Opera, and Firefox (pending in upcoming version 35).”
Lets MAKE this simple
I did some scripting so you can pretty much load up MSYS bash, COPY/PASTE and execute one of the following snippets. However lacking prior revisions of this post was misleading garbage ;( is better now 😉
be aware: This script is designed to abstract the process of downloading, patching and compiling Google’s woff2 C source-code project(s) to binary executables to copy/pasting the code/snip-it below.
Compile on Windows
YOU NEED MSYS, MSYS2 or CYGWIN
[20171107] for those new to compilers and bash
I’ve added a bit here highlighting or recommending GCC compiler newbs to use msys2 rather than my MSYS Helper setup, and also added a few pointers on getting started with msys2 in attempt to keep the process of setting up a bash/dev-environment as quick and accessible as possible—even if you don’t intend to code c++ er whatever and just need to build some useful tool such as this.
I truly recommend msys2 with increasing reason as it is a much more adequate emulation ofbash
, compared to using cygwin for example.
Further, there is quite a variety of options out in the wild as well as the original MSYS project which has made several changes over the years, so many that I’ve been hesitant towards implementing its use of late (such as in this context)—Though it has its advantages also and has evolved as well, over the years.
- MSYS (options)
- MSYS the older no BS bare-bones MSYS (msys+7za+wget+svn+git+mercurial+cvs-rev13.7z) can be good for compiling c/cpp programs with GCC. I would recommend this or msys2 if you’re new to compiling.
See: MSYS Helper post for instruction on how to ‘mount’ your chosen version of mingw-w64 if you are completely new to and interested in getting started in MSYS. - MSYS2 is highly recommended. It absolutely ROCKS, containing a forked version of arch-linux’s package-manager, pacman. Learn to use pacman 😉 msys2 appears to use posix threading model once you use pacman to install mingw (and friends). (skip to the bottom of the msys-helper post for some tips for getting started with msys2-pacman usage as well as how to use it with Visual Studio Code)
If you go the msys2 route, you only need to install GCC via a very simple command-line explained in msys2-quickie. - (not explained here) The official MSYS project can supply you with the things you need however to my experience its semantic has changed too often over the years for me to want to adapt. They have their instructions.
- MSYS the older no BS bare-bones MSYS (msys+7za+wget+svn+git+mercurial+cvs-rev13.7z) can be good for compiling c/cpp programs with GCC. I would recommend this or msys2 if you’re new to compiling.
- To setup a build-environment on top of the MSYS Helper instructions you still need…
- GIT (on your PATH)
- MSYS (as featured in the helper post [not msys2]) seems to have a version of GIT but I hadn’t tested it and tend to rely on installing downloading and installing GIT) and tortoise-git.
- if using msys2, I’m fairly sure installs GIT and CURL by default (do correct me if I’m wrong) — which works. Once installed, you probably just need to call (for mingw32)
pacman -S mingw64/mingw-w64-x86_64-gcc
or for mingw64:pacman -S mingw32/mingw-w64-i686-gcc
. There are a few more pointers towards the end of the msys-helper post.
- mingw-w64-mingw32 — versions >= 4.8.0 seem to work
- GCC-4.9.2 32 bit: mingw-w64/mingw-builds GCC-4.9.2
- GCC-4.9.2 64 bit: mingw-w64/mingw-builds GCC-4.9.2
- [edit:20170430] GCC-4.9.2 was current when I’d written. Now GCC-6.3.0.
See: mingw-builds GCC toolchains Targeting Win32 or Win64 for concurrent releases.
If you’ve got a working, compatible msys+curl+git+mingw32-w64
configuration you can copy paste the following into your bash console.
OPTION#1
# download curl -L https://gist.githubusercontent.com/tfwio/14f106070625d142f00a/raw/c2968d783151f2ed3281e4e94f7ac0d38c2171d1/get-woff2 -oget-woff2 # execute ./get-woff2 #
OPTION#2: HEAD REVISION (still working in msys2 on 20150824 and 20170430/GCC-6.3.0)
# download script curl -L https://gist.githubusercontent.com/tfwio/14f106070625d142f00a/raw/8d45d09dbfa017ec0b76e9bbb5f55204fdee6d2e/get-woff2-head -oget-woff2-head # run it ./get-woff2-head #
GIST:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
function boo () { | |
# vars | |
local WORK_PATH=${PWD} | |
local WOFF2_GIT=https://github.com/google/woff2.git | |
local WOFF2_SHA=2855ee7b8bf6a46ec3a10f773f358c8c0f808b74 | |
# BROTLISHA=f8bfe06821904a8e009577e938682d6522998792 | |
# if you notice a differnt brotli SHA1 when cloning, | |
# you now know why my old scripts broke down. | |
local WOFF2_NAM=woff2-${WOFF2_SHA::9} | |
local WOFF2_DIR=${WORK_PATH}/${WOFF2_NAM} | |
# clone | |
git clone ${WOFF2_GIT} ${WOFF2_NAM} | |
# step into the directory you just cloned | |
pushd ${WOFF2_DIR} | |
# pushd brotli > /dev/null | |
git checkout ${WOFF2_SHA} | |
git submodule init | |
git submodule update | |
# popd > /dev/null | |
# build! | |
CC=gcc.exe LFLAGS="–static -s" make | |
# return to start-path | |
popd > /dev/null | |
# why not | |
unset WORK_PATH | |
unset WOFF2_GIT | |
unset WOFF2_SHA | |
unset WOFF2_NAM | |
unset WOFF2_DIR | |
} | |
boo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
function boo () { | |
# vars | |
local WORK_PATH=${PWD} | |
local WOFF2_GIT=https://github.com/google/woff2.git | |
local WOFF2_NAM=woff2 | |
local WOFF2_DIR=${WORK_PATH}/${WOFF2_NAM} | |
## remove existing directory | |
rm -fdr ${WOFF2_DIR} | |
# clone | |
# we don't do recursive to checkout a specific revision (including the submodule) | |
git clone ${WOFF2_GIT} ${WOFF2_NAM} | |
# step into the directory you just cloned | |
pushd ${WOFF2_DIR} | |
# pushd brotli > /dev/null | |
# git checkout ${WOFF2_SHA} | |
git submodule init | |
git submodule update | |
# popd > /dev/null | |
# build! | |
CC=gcc.exe LFLAGS="–static -s" CXXFLAGS="-D__STDC_FORMAT_MACROS" make clean all | |
# return to start-path | |
popd > /dev/null | |
# why not | |
unset WORK_PATH | |
unset WOFF2_GIT | |
unset WOFF2_SHA | |
unset WOFF2_NAM | |
unset WOFF2_DIR | |
} | |
boo |
How embarassing ;/
My last edit broke down rather quickly. Apparently I was referencing an undefined (renamed)$(variable)
, so it was checking out the latest revision and not the SHA1/revision specified—oops ;\
Apologies to those whom this may have a/effected. In any case, I hope those of you who encountered this were able to figure it out!
REFERENCE
- http://www.w3.org/TR/WOFF2
- http://code.google.com/p/ttf2eot
- http://stackoverflow.com/questions/22958700/woff2-conversion-from-standard-woff
- http://people.mozilla.org/~jkew/woff/ (woff2sfnt/sfnt2woff)
- http://code.google.com/p/ttf2eot
- https://code.google.com/p/font-compression-reference
MSYS2 (POSIX-LIKE WINDOWS DEVELOPMENT ENVIRONMENT)
- MSYS2 Installation
- github.com/Alexpux/MSYS2-pacman , github.com/Alexpux/MINGW-packages, github.com/Alexpux/MSYS2-packages
- wiki.allegro.com/…/Building with msys2
MINGW/MSYS HELPER
- mingw-w64/wiki/MSYS
- http://sourceforge.net/p/mingw-w64/wiki2/GeneralUsageInstructions/
- Setting up a MinGW-w64 build environment
- threading model / mingw-w64 notes — http://qt-project.org/wiki/MinGW-64-bit
GRUNT WEBFONT
LIKE BUILD SCRIPTS?
The (OLD) Gist
is dead now 😉