Skip to content

Commit b9d3df8

Browse files
committed
Merge #15176: docs: Get rid of badly named readme
f24ed6d Delete README_osx.md and move its contents into build-osx.md (Martin Erlandsson) Pull request description: With its current name, the file `doc/README_osx.md` looks like an entry point README for OSX users, but it only contains specific instructions on how to build a DMG. This PR deletes the file and moves the contents of the file into `doc/build-osx.md`. Tree-SHA512: 2636b9da967f2a4c0d68cb9a157fb3db137bdb8fbff5d9d004f28b5d816e9c27fddc5c403e6b0c363d1dc9ddc7cac8b295efa01fc691126c0e36e21bb9b3cbd3
2 parents 37d09b2 + f24ed6d commit b9d3df8

File tree

3 files changed

+101
-98
lines changed

3 files changed

+101
-98
lines changed

doc/README_osx.md

Lines changed: 0 additions & 97 deletions
This file was deleted.

doc/build-osx.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,103 @@ Notes
105105
* Tested on OS X 10.10 Yosemite through macOS 10.13 High Sierra on 64-bit Intel processors only.
106106

107107
* Building with downloaded Qt binaries is not officially supported. See the notes in [#7714](https://github.com/bitcoin/bitcoin/issues/7714)
108+
109+
Deterministic macOS DMG Notes
110+
-----------------------------
111+
112+
Working macOS DMGs are created in Linux by combining a recent clang,
113+
the Apple binutils (ld, ar, etc) and DMG authoring tools.
114+
115+
Apple uses clang extensively for development and has upstreamed the necessary
116+
functionality so that a vanilla clang can take advantage. It supports the use
117+
of -F, -target, -mmacosx-version-min, and --sysroot, which are all necessary
118+
when building for macOS.
119+
120+
Apple's version of binutils (called cctools) contains lots of functionality
121+
missing in the FSF's binutils. In addition to extra linker options for
122+
frameworks and sysroots, several other tools are needed as well such as
123+
install_name_tool, lipo, and nmedit. These do not build under linux, so they
124+
have been patched to do so. The work here was used as a starting point:
125+
[mingwandroid/toolchain4](https://github.com/mingwandroid/toolchain4).
126+
127+
In order to build a working toolchain, the following source packages are needed
128+
from Apple: cctools, dyld, and ld64.
129+
130+
These tools inject timestamps by default, which produce non-deterministic
131+
binaries. The ZERO_AR_DATE environment variable is used to disable that.
132+
133+
This version of cctools has been patched to use the current version of clang's
134+
headers and its libLTO.so rather than those from llvmgcc, as it was
135+
originally done in toolchain4.
136+
137+
To complicate things further, all builds must target an Apple SDK. These SDKs
138+
are free to download, but not redistributable.
139+
To obtain it, register for a developer account, then download the [Xcode 7.3.1 dmg](https://developer.apple.com/devcenter/download.action?path=/Developer_Tools/Xcode_7.3.1/Xcode_7.3.1.dmg).
140+
141+
This file is several gigabytes in size, but only a single directory inside is
142+
needed:
143+
```
144+
Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
145+
```
146+
147+
Unfortunately, the usual linux tools (7zip, hpmount, loopback mount) are incapable of opening this file.
148+
To create a tarball suitable for Gitian input, there are two options:
149+
150+
Using macOS, you can mount the dmg, and then create it with:
151+
```
152+
$ hdiutil attach Xcode_7.3.1.dmg
153+
$ tar -C /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ -czf MacOSX10.11.sdk.tar.gz MacOSX10.11.sdk
154+
```
155+
156+
Alternatively, you can use 7zip and SleuthKit to extract the files one by one.
157+
The script contrib/macdeploy/extract-osx-sdk.sh automates this. First ensure
158+
the dmg file is in the current directory, and then run the script. You may wish
159+
to delete the intermediate 5.hfs file and MacOSX10.11.sdk (the directory) when
160+
you've confirmed the extraction succeeded.
161+
162+
```bash
163+
apt-get install p7zip-full sleuthkit
164+
contrib/macdeploy/extract-osx-sdk.sh
165+
rm -rf 5.hfs MacOSX10.11.sdk
166+
```
167+
168+
The Gitian descriptors build 2 sets of files: Linux tools, then Apple binaries
169+
which are created using these tools. The build process has been designed to
170+
avoid including the SDK's files in Gitian's outputs. All interim tarballs are
171+
fully deterministic and may be freely redistributed.
172+
173+
genisoimage is used to create the initial DMG. It is not deterministic as-is,
174+
so it has been patched. A system genisoimage will work fine, but it will not
175+
be deterministic because the file-order will change between invocations.
176+
The patch can be seen here: [theuni/osx-cross-depends](https://raw.githubusercontent.com/theuni/osx-cross-depends/master/patches/cdrtools/genisoimage.diff).
177+
No effort was made to fix this cleanly, so it likely leaks memory badly. But
178+
it's only used for a single invocation, so that's no real concern.
179+
180+
genisoimage cannot compress DMGs, so afterwards, the 'dmg' tool from the
181+
libdmg-hfsplus project is used to compress it. There are several bugs in this
182+
tool and its maintainer has seemingly abandoned the project. It has been forked
183+
and is available (with fixes) here: [theuni/libdmg-hfsplus](https://github.com/theuni/libdmg-hfsplus).
184+
185+
The 'dmg' tool has the ability to create DMGs from scratch as well, but this
186+
functionality is broken. Only the compression feature is currently used.
187+
Ideally, the creation could be fixed and genisoimage would no longer be necessary.
188+
189+
Background images and other features can be added to DMG files by inserting a
190+
.DS_Store before creation. This is generated by the script
191+
contrib/macdeploy/custom_dsstore.py.
192+
193+
As of OS X 10.9 Mavericks, using an Apple-blessed key to sign binaries is a
194+
requirement in order to satisfy the new Gatekeeper requirements. Because this
195+
private key cannot be shared, we'll have to be a bit creative in order for the
196+
build process to remain somewhat deterministic. Here's how it works:
197+
198+
- Builders use Gitian to create an unsigned release. This outputs an unsigned
199+
dmg which users may choose to bless and run. It also outputs an unsigned app
200+
structure in the form of a tarball, which also contains all of the tools
201+
that have been previously (deterministically) built in order to create a
202+
final dmg.
203+
- The Apple keyholder uses this unsigned app to create a detached signature,
204+
using the script that is also included there. Detached signatures are available from this [repository](https://github.com/bitcoin-core/bitcoin-detached-sigs).
205+
- Builders feed the unsigned app + detached signature back into Gitian. It
206+
uses the pre-built tools to recombine the pieces into a deterministic dmg.
207+

doc/release-process.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Ensure gitian-builder is up-to-date:
9292
echo 'f9a8cdb38b9c309326764ebc937cba1523a3a751a7ab05df3ecc99d18ae466c9 inputs/osslsigncode-1.7.1.tar.gz' | sha256sum -c
9393
popd
9494

95-
Create the macOS SDK tarball, see the [macOS readme](README_osx.md) for details, and copy it into the inputs directory.
95+
Create the macOS SDK tarball, see the [macOS build instructions](build-osx.md#deterministic-macos-dmg-notes) for details, and copy it into the inputs directory.
9696

9797
### Optional: Seed the Gitian sources cache and offline git repositories
9898

0 commit comments

Comments
 (0)