{"slug": "a-script-to-build-xnu-version-4570-1-46-macos-high-sierra-10-13", "title": "A script to build XNU version 4570.1.46 (macOS High Sierra 10.13).", "summary": "This article provides a shell script by Brandon Azad for building XNU version 4570.1.46, which corresponds to macOS High Sierra 10.13. The script downloads the necessary source code from Apple's open-source repository, installs required tools and headers, and modifies Xcode's SDK files to successfully compile the XNU kernel.", "body_md": "build-xnu-4570.1.46.sh\n\n      This file contains hidden or 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.\n      \nLearn more about bidirectional Unicode characters\n\n \n    Show hidden characters\n\n#! /bin/bash\n\n#\n\n# build-xnu-4570.1.46.sh\n\n# Brandon Azad\n\n#\n\n# A script showing how to build XNU version 4570.1.46 on MacOS High Sierra\n\n# 10.13 with Xcode 9.\n\n#\n\n# Note: This process will OVERWRITE files in Xcode's MacOSX10.13.sdk. Make a\n\n# backup of this directory first!\n\n#\n\n# Set the working directory.\n\nWORKDIR=\"${WORKDIR:-build-xnu-4570.1.46}\"\n\n# Set a permissive umask just in case.\n\numask 022\n\n# Print commands and exit on failure.\n\nset -ex\n\n# Get the SDK path and toolchain path.\n\nSDKPATH=\"$(xcrun --sdk macosx --show-sdk-path)\"\n\nTOOLCHAINPATH=\"$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain\"\n\n[ -d \"${SDKPATH}\" ] && [ -d \"${TOOLCHAINPATH}\" ]\n\n# Create the working directory.\n\nmkdir \"${WORKDIR}\"\n\ncd \"${WORKDIR}\"\n\n# Back up the SDK if that option is given.\n\nif [ -n \"${BACKUP_SDK}\" ]; then\n\n\tsudo ditto \"${SDKPATH}\" \"$(basename \"${SDKPATH}\")\"\n\nfi\n\n# Download XNU and some additional sources we will need to help build.\n\ncurl https://opensource.apple.com/tarballs/xnu/xnu-4570.1.46.tar.gz | tar -xf-\n\ncurl https://opensource.apple.com/tarballs/dtrace/dtrace-262.tar.gz | tar -xf-\n\ncurl https://opensource.apple.com/tarballs/AvailabilityVersions/AvailabilityVersions-32.tar.gz | tar -xf-\n\ncurl https://opensource.apple.com/tarballs/libplatform/libplatform-161.tar.gz | tar -xf-\n\ncurl https://opensource.apple.com/tarballs/libdispatch/libdispatch-913.1.6.tar.gz | tar -xf-\n\n# Build and install ctf utilities. This adds the ctf tools to\n\n# ${TOOLCHAINPATH}/usr/local/bin.\n\ncd dtrace-262\n\nmkdir -p obj dst sym\n\nxcodebuild install -target ctfconvert -target ctfdump -target ctfmerge ARCHS=\"x86_64\" SRCROOT=\"${PWD}\" OBJROOT=\"${PWD}/obj\" SYMROOT=\"${PWD}/sym\" DSTROOT=\"${PWD}/dst\"\n\n# TODO: Get the XcodeDefault.toolchain path programmatically.\n\nsudo ditto \"${PWD}/dst/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain\" \"${TOOLCHAINPATH}\"\n\ncd ..\n\n# Install AvailabilityVersions. This writes to ${SDKPATH}/usr/local/libexec.\n\ncd AvailabilityVersions-32\n\nmkdir -p dst\n\nmake install SRCROOT=\"${PWD}\" DSTROOT=\"${PWD}/dst\"\n\nsudo ditto \"${PWD}/dst/usr/local\" \"${SDKPATH}/usr/local\"\n\ncd ..\n\n# Install the XNU headers we'll need for libdispatch. This OVERWRITES files in\n\n# MacOSX10.13.sdk!\n\ncd xnu-4570.1.46\n\nmkdir -p BUILD.hdrs/obj BUILD.hdrs/sym BUILD.hdrs/dst\n\nmake installhdrs SDKROOT=macosx ARCH_CONFIGS=X86_64 SRCROOT=\"${PWD}\" OBJROOT=\"${PWD}/BUILD.hdrs/obj\" SYMROOT=\"${PWD}/BUILD.hdrs/sym\" DSTROOT=\"${PWD}/BUILD.hdrs/dst\"\n\n# HACK: The subsequent build command fails with a missing file error. We create\n\n# that file so that the build continues.\n\ntouch libsyscall/os/thread_self_restrict.h\n\nxcodebuild installhdrs -project libsyscall/Libsyscall.xcodeproj -sdk macosx ARCHS=\"x86_64 i386\" SRCROOT=\"${PWD}/libsyscall\" OBJROOT=\"${PWD}/BUILD.hdrs/obj\" SYMROOT=\"${PWD}/BUILD.hdrs/sym\" DSTROOT=\"${PWD}/BUILD.hdrs/dst\"\n\n# Set permissions correctly before dittoing over MacOSX10.13.sdk.\n\nsudo chown -R root:wheel BUILD.hdrs/dst/\n\nsudo ditto BUILD.hdrs/dst \"${SDKPATH}\"\n\ncd ..\n\n# Install libplatform headers to ${SDKPATH}/usr/local/include.\n\ncd libplatform-161\n\nsudo ditto \"${PWD}/include\" \"${SDKPATH}/usr/local/include\"\n\nsudo ditto \"${PWD}/private\"  \"${SDKPATH}/usr/local/include\"\n\ncd ..\n\n# Build and install libdispatch's libfirehose_kernel target to\n\n# ${SDKPATH}/usr/local.\n\ncd libdispatch-913.1.6\n\nmkdir -p obj sym dst\n\nxcodebuild install -project libdispatch.xcodeproj -target libfirehose_kernel -sdk macosx ARCHS=\"x86_64 i386\" SRCROOT=\"${PWD}\" OBJROOT=\"${PWD}/obj\" SYMROOT=\"${PWD}/sym\" DSTROOT=\"${PWD}/dst\"\n\nsudo ditto \"${PWD}/dst/usr/local\" \"${SDKPATH}/usr/local\"\n\ncd ..\n\n# Build XNU.\n\ncd xnu-4570.1.46\n\nmake SDKROOT=macosx ARCH_CONFIGS=X86_64 KERNEL_CONFIGS=\"RELEASE\"", "url": "https://wpnews.pro/news/a-script-to-build-xnu-version-4570-1-46-macos-high-sierra-10-13", "canonical_source": "https://gist.github.com/bazad/654959120a423b226dc564073b435453", "published_at": "2017-10-06 21:24:22+00:00", "updated_at": "2026-05-23 20:35:50.970360+00:00", "lang": "en", "topics": ["developer-tools", "open-source"], "entities": ["Brandon Azad", "XNU", "macOS High Sierra", "Xcode"], "alternates": {"html": "https://wpnews.pro/news/a-script-to-build-xnu-version-4570-1-46-macos-high-sierra-10-13", "markdown": "https://wpnews.pro/news/a-script-to-build-xnu-version-4570-1-46-macos-high-sierra-10-13.md", "text": "https://wpnews.pro/news/a-script-to-build-xnu-version-4570-1-46-macos-high-sierra-10-13.txt", "jsonld": "https://wpnews.pro/news/a-script-to-build-xnu-version-4570-1-46-macos-high-sierra-10-13.jsonld"}}