The DarwinBuild project provides an integrated build environment for Darwin projects. There are many reasons why you should use DarwinBuild and although some parts of Darwin can be built without DarwinBuild, it is easier with it. This page describes some ways to use DarwinBuild in order to build Darwin projects.
It is a work in progess. Please post your comments below or edit this wiki page.
PrerequisitesHave a look at http://darwinbuild.macosforge.org/trac/browser/trunk/README. (to be determined)
If you are using svn from fink, you need to put it in your path by PATH=/sw/bin:$PATH # If you are using svn from fink
In case you use MacPorts, your path should already and probably be set to
TerminologySince the terminology used by DarwinBuild and PureDarwin is slightly different from what you might know from Linux, it makes sense to look at some commonly used terms now.
InstallationFrom SVNGo to the location where you want your DarwinBuild to live.
sudo su From MacPortsSimply run: The BuildRoot directoryThis place could also be called the BuildChroot directory, everything fetch or built by darwinbuild will reside inside this directory. Notes: The build version "9J61" (2009/05) used below is just an example. Create and select a BuildRoot location hierarchy in the current working directory: cd /<somewhere>/darwinbuildThe DarwinBuild ticket#1 workaround (DarwinBuild inherits a bug from Xcode that makes it impossible to use it on a HFS+ volume, the workaround(s) involve(s) setting up NFS locally or using an UFS disk image) is no longer needed since on the Darwinbuild website, we can read (news from 2009/04/17): "The latest revision of trunk has support for sparsebundles and NFS Loopback in order to avoid the problems with xcodebuild inside of chroots. If you do not change the way you use darwinbuild, you will start seeing the sparsebundle storage. Nothing else is needed and Xcode-based projects will build on whatever filesystem you have."darwinbuild -init 9J61 -nfs
If you get ".build/9F33.plist: No such file or directory", it can be necessary to repeat this step. As a result, you should now have inside the current working directory:
Whenever there are new Darwin projects or versions, you should do darwinbuild -init again in order to refresh the .plist files (think of it as "apt-get update" for Darwin source projects).Notes: Keep in mind that/etc/exports must be cleaned sometimes, since there is no concept of "uninitializing" (implicitly removing the added line from /etc/exports). An example of what is added: Logs folderLater on, if a project fails to build (and depending your tty), you will want to look into the entire history of build logs. So simply look into the "Logs/<project>/<project>-<version>~<build attempts>" folder for a detailled compilation loh. In this case the "CommonCrypto" project has been successfully built at the first attempt and its log can be found in [...]/9J61/Logs/CommonCrypto/CommonCrypto-32207.log~1. The entire content cannot be pasted here, but most the time, the end crowns with: [...] ** BUILD SUCCEEDED ** ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ BUILD TIME: Xh Ym Zs EXIT STATUS: 0 With a project which has failed to build, the end can looks like: [...] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ BUILD TIME: 0h 0m 0s EXIT STATUS: 2 Creating build root disk image ...
Adding build root to NFS exports file ... Ideally, one could transfer the contents of the BuildRoot to a volume, bless it, and boot a fully working Darwin system from it. In fact, it's not so simple. Whenever you build something using DarwinBuild and don't specifiy otherwise (using -nochroot), you will be building inside a chrooted environment using the DarwinBuild directory. Consequently, your build results, hence, will be "built on Darwin" as opposed to "built on Mac OS X".If during the process of downloading you get errors like "ERROR: could not find root: AppleUSBIrDA", this simply means that a binary root of the respective project has not been uploaded to the DarwinBuild server yet.The file xref.db contains the Darwin xref database. It keeps track of the Darwin projects installed in your BuildRoot and their files and version numbers (think of xref roughly as a package manager like "apt" for Darwin binary roots). The xref database has been filled by the darwinbuild -load command, and will be updated whenever you build something with DarwinBuild. To build a specific package, e.g., CF, type: darwinbuild CF
CF is a test case to build. On the first build in the new BuildRoot, DarwinBuild will do some initializations, e.g., copy some header files from the host OS. If it fails, then some prerequisites might be missing or you might need to use -nochroot (in case not all prerequisites are uploaded to DarwinBuild yet; this would then use the files from the currently running OS rather than from DarwinBuild). If the build succeeds, you should see a Roots/CF/CF-476.10.root~1 directory containing the files you just built. xnuA classic test case is xnu, the kernel. darwinbuild xnu If the build succeeds, you can see a xnu/xnu-1228.12.14.root~1 directory containing the built project. the ~1 stands for the number of time the project has been built. Then, in order to populate the BuildRoot dir with the freshly built project: darwinbuild -load xnu Inside BuildRoot, there should be a directory called XCD/ which contains Xcode and its dependencies (e.g., Xcode requires a proper CoreFoundation, not CF-Lite).
Anything under XCD should only link or refer to any other thing in XCD in order to "keep away" Xcode dependencies. If not, there's something wrong.
The contents of XCD/ are copied there from the host system by DarwinBuild's installXcode. This can be invoked manually as well: /usr/local/share/darwinbuild/installXcode /Developer/darwinbuild/9C31/BuildRoot/ Analyzing Xcode dependencies ...
Copying Xcode and dependencies ...
These need to be documented here
darwinxrefListing all the projects for a given branchdarwinxref -b 9G55 version '*'
Searching the project of a given filedarwinxref findFile launchctl
launchd:
/bin/launchctl
Building all the projects (brutus way)for X in $(darwinxref version '*' | cut -f 1 -d '-'); do darwinbuild $X; done Note: Of course, this doesn't mean all the projects will be compiled.
Package the built binariesTime to package them up! {DarwinBuild_Checkout_Dir}/packageRoots.sh{DarwinBuild_Checkout_Dir} is your working copy from SVN of DarwinBuild. If you followed the article as suggested at the beginning, it must be located in /Developer/darwinbuild/trunk/darwinbuild/ We now have a nice Darwin binary root archive in the Packages/ directory: ls Packages/Why doesn't it have a version number? ResourcesDeprecatedWorkaround DarwinBuild ticket #1 (no longer needed)The DarwinBuild ticket#1 workaround is no longer needed since on the Darwinbuild website, we can read (news from 2009/04/17): "The latest revision of trunk has support for sparsebundles and NFS Loopback in order to avoid the problems with xcodebuild inside of chroots. If you do not change the way you use darwinbuild, you will start seeing the sparsebundle storage. Nothing else is needed and Xcode-based projects will build on whatever filesystem you have." sudo su Populating the BuildRoot directory via the way below is no longer needed because the dependencies of a project are automatically retrieved and loaded in the BuildRoot.Theoretically you could begin building projects with DarwinBuild now. However, this would mean that you would have to build binaries using your host Mac OS X as the build environment (using -nochroot). This would clearly not be ideal, since the resulting binaries would not be guaranteed to run on Darwin. Hence, we want to build Darwin projects using Darwin itself as the build environment ("self-hosted").for X in `darwinxref version '*'` ; do darwinbuild -load ${X/-*/} ; doneThis downloads any Darwin components that are available in pre-compiled form (called "binary roots") to Roots/.DownloadCache and installs them into our BuildRoot directory. Since it downloads all available binary roots, it is obviously going to take some time, even on a fast Internet connection.Help and further reading
http://darwinbuild.macosforge.org/ The DarwinBuild Project Archives darwinbuild-dev mailing list at lists.macosforge.org CreditsCredits go to kvv and _wms for their work on DarwinBuild and for their excellent online support. |
The goal of this project is to make Darwin more usable by providing an installation ISO, documentation, and add-on software. You are welcome to join #puredarwin on irc.freenode.net if you would like to join PureDarwin development and to add to this site.