Files
smeng9andClaude Opus 5.5 6dc20ebe08 build(linux): install the kernel step toolchain on a Linux host
scripts/linux/setup-toolchain.py, run once as root, builds into
/opt/unixnu-linux (or PREFIX, or $UNIXNU_TOOLCHAIN):

- clang from llvm-project 58c46bae2118 with llvm-xnu-builtin-type.patch,
  which adds __builtin_xnu_type_signature, __builtin_xnu_type_summary,
  __builtin_xnu_types_compatible and xnu_usage_semantics; kalloc.h uses
  the builtins with no fallback;
- cctools-port 1030.6.3-ld64-956.6 (its master, ld64-609, corrupts the
  kernel link), with libdispatch for ld64;
- mig and migcom from bootstrap_cmds-138;
- iig-port, with iig-port-darwin-target.patch;
- xnu-host-cc, the host compiler for xnu's SETUP tools;
- lzfse for the kernelcache.

It installs the Command Line Tools shims (clang, clang++, cc, install,
gm4) under the prefix and xcrun, plutil and codesign in /usr/bin, where
xnu's makefiles call them. libmacho.a and libstuff.a go to /usr/lib and
libdispatch to /usr/local. Each step is skipped when its output exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 19:48:06 +08:00

35 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# clang in the CLT's usr/bin: the Darwin cross compiler xnu's makefiles get
# from `xcrun -find clang` (and through it LD = $(KC++) and MIGCC := $(CC)).
# It runs $CROSS_CLANG, the clang setup-toolchain.py builds with
# llvm-xnu-builtin-type.patch, with what Apple's clang does by itself for this
# target:
#
# -target $DARWIN_TRIPLE -arch alone does not switch clang off the Linux
# host triple, and xnu never passes -target for MacOSX
# (MakeInc.def uses -mmacosx-version-min).
# $CROSS_EXTRA_FLAGS -fptrauth-function-pointer-type-discrimination (on for
# -mkernel in Apple clang, opt-in upstream);
# -mllvm -disable-atexit-based-global-dtor-lowering, so C++
# static destructors land in __mod_term_func as the
# kernel expects; the __ARM_ARCH_8_2__..8_5__ Apple clang
# predefines for -mcpu=apple-a14.
# $XNU_CLANG_DROP_FLAGS removed: -mno-implicit-sme, Apple-only, which
# MakeInc.def passes; upstream never emits SME implicitly
# here, so dropping it is a no-op.
#
# The build driver (scripts/unixnu/kernel.py) sets CROSS_CLANG, DARWIN_TRIPLE
# and CROSS_EXTRA_FLAGS for UniXNU's plain arm64 iOS 17 kernel; the defaults are
# an arm64e macOS 26 target.
real="${CROSS_CLANG:-/opt/unixnu-linux/llvm/bin/clang}"
drop=(${XNU_CLANG_DROP_FLAGS--mno-implicit-sme})
args=()
for a in "$@"; do
skip=0
for d in "${drop[@]}"; do [ "$a" = "$d" ] && skip=1 && break; done
[ "$skip" = 1 ] || args+=("$a")
done
exec "${real}" -target "${DARWIN_TRIPLE:-arm64e-apple-macos26.0}" \
${CROSS_EXTRA_FLAGS--fptrauth-function-pointer-type-discrimination -mllvm -disable-atexit-based-global-dtor-lowering -D__ARM_ARCH_8_2__=1 -D__ARM_ARCH_8_3__=1 -D__ARM_ARCH_8_4__=1 -D__ARM_ARCH_8_5__=1} \
"${args[@]}"