|
| 1 | +# build tectonic with vcpkg on macOS |
| 2 | + |
| 3 | +This tutorial will walk you through how to build a _mostly_ staticly linked |
| 4 | +`tectonic` binary on macOS. Why does this matter? Static binaries are more |
| 5 | +portable and so free you from having to support complex user environments. |
| 6 | +Thanks to |
| 7 | +[mcgoo's work](https://github.com/tectonic-typesetting/tectonic/pull/420) we can |
| 8 | +use `vcpkg`. [vcpkg](https://vcpkg.readthedocs.io/en/latest/) is a C/C++ package |
| 9 | +manager from Microsoft. |
| 10 | + |
| 11 | +## prerequisites |
| 12 | + |
| 13 | +This guide assumes you have [git](https://git-scm.com/) installed and are |
| 14 | +comfortable using the command-line. You'll also need to install |
| 15 | +[homebrew](https://brew.sh/) to install for `vcpkg`'s gcc dependency. Package |
| 16 | +management is _fun_. |
| 17 | + |
| 18 | +1. install `gcc`: |
| 19 | + |
| 20 | +```sh |
| 21 | +brew install gcc |
| 22 | +``` |
| 23 | + |
| 24 | +## setting up your environment |
| 25 | + |
| 26 | +1. Install vcpkg |
| 27 | + |
| 28 | + 1. Clone the vcpkg repository: |
| 29 | + ```sh |
| 30 | + git clone https://github.com/Microsoft/vcpkg |
| 31 | + ``` |
| 32 | + 2. Install it for your system: |
| 33 | + ```sh |
| 34 | + ./bootstrap-vcpkg.sh |
| 35 | + ``` |
| 36 | + |
| 37 | +2. Install `tectonic` dependencies using vcpkg. \* Run the following command in |
| 38 | + your checkout of the `vcpkg` repository |
| 39 | + `sh ./vcpkg install freetype harfbuzz\[icu,graphite2\]` It should print |
| 40 | + something like the following: |
| 41 | + |
| 42 | + ```sh |
| 43 | + $ ./vcpkg install freetype harfbuzz\[icu,graphite2\] |
| 44 | + The following packages will be built and installed: |
| 45 | + * bzip2[core]:x64-osx |
| 46 | + freetype[core]:x64-osx |
| 47 | + * gettext[core]:x64-osx |
| 48 | + * graphite2[core]:x64-osx |
| 49 | + harfbuzz[core,graphite2,icu,ucdn]:x64-osx |
| 50 | + * icu[core]:x64-osx |
| 51 | + * libiconv[core]:x64-osx |
| 52 | + * libpng[core]:x64-osx |
| 53 | + * ragel[core]:x64-osx |
| 54 | + * zlib[core]:x64-osx |
| 55 | + Additional packages (*) will be modified to complete this operation. |
| 56 | + Starting package 1/10: graphite2:x64-osx |
| 57 | + Building package graphite2[core]:x64-osx... |
| 58 | + ``` |
| 59 | + |
| 60 | +## build tectonic |
| 61 | + |
| 62 | +Now we only need to configure tectonic so it knows we are using `vcpkg` to build |
| 63 | +the binary. |
| 64 | + |
| 65 | +1. Run `cargo build` with the appropriate environment variables: |
| 66 | + ```sh |
| 67 | + TECTONIC_DEP_BACKEND="vcpkg" VCPKG_ROOT=/Users/me/vcpkg/ cargo build --release |
| 68 | + ``` |
| 69 | + |
| 70 | +You'll need to set `VCPKG_ROOT` to the full path of your vcpkg checkout. |
| 71 | +`TECTONIC_DEP_BACKEND="vcpkg"` tells `tectonic` to use `vcpkg` instead of trying |
| 72 | +to resolve the libraries using `pkgconfig`. `VCPKG_ROOT=/Users/me/vcpkg/` is the |
| 73 | +root of the `vcpkg` tree where we just installed the required libraries. |
| 74 | +
|
| 75 | +This will take a couple minutes but should eventually print something like: |
| 76 | +
|
| 77 | +```sh |
| 78 | + Finished release [optimized] target(s) in 3m 39s |
| 79 | +``` |
| 80 | +
|
| 81 | +Congratulations! You should now have a mostly staticly linked binary in |
| 82 | +`target/release` suitable for sharing with users or whatever your needs are. |
| 83 | +
|
| 84 | +## caveats |
| 85 | +
|
| 86 | +I say _mostly_ staticly linked because the binary itself presumes system |
| 87 | +libraries. You can observe those links by executing `otool` on a given binary: |
| 88 | +
|
| 89 | +```sh |
| 90 | +otool -L target/release/tectonic |
| 91 | +``` |
| 92 | +
|
| 93 | +In my case it printed the following: |
| 94 | +
|
| 95 | +```sh |
| 96 | +target/release/tectonic: |
| 97 | + /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1454.98.0) |
| 98 | + /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1454.98.0) |
| 99 | + /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 1161.21.2) |
| 100 | + /System/Library/Frameworks/CoreText.framework/Versions/A/CoreText (compatibility version 1.0.0, current version 1.0.0) |
| 101 | + /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1561.60.100) |
| 102 | + /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.0) |
| 103 | + /System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 58286.70.14) |
| 104 | + /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.50.4) |
| 105 | + /usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 1.0.0) |
| 106 | + /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0) |
| 107 | +``` |
0 commit comments