Closed Bug 2095405 Opened 2 days ago Closed 2 days ago

Allow `build.sh` to cross-compile NSS for macOS from a non-macOS host

Categories

(NSS :: Build, enhancement)

enhancement

Tracking

(nss 3.135)

RESOLVED FIXED
Tracking Status
nss --- 3.135

People

(Reporter: RyanVM, Assigned: RyanVM)

Details

Attachments

(1 external file)

build.sh --target-os supports android and ios, but building NSS for macOS still requires a Mac. application-services builds its NSS on Linux for every other platform, and for macOS it downloads NSS CI's mac opt-static build instead. That download has to be repinned by hand on every NSS update, and it targets the CI runner's macOS version rather than the consumer's deployment target. NSS CI itself builds macOS on macOS workers too.

This adds --target-os=macos, with --macos-sdk=<dir> pointing at an unpacked MacOSX.sdk and --macos-version-min defaulting to 11.0. NSPR and NSS build with clang, the LLVM tools and lld through gyp's ninja-mac generator. That generator runs libtool, xcodebuild and xcrun by name, so coreconf/macos.sh puts stand-ins for them on the PATH:

  • libtool is llvm-libtool-darwin;
  • xcodebuild -version reports a fixed Xcode version;
  • xcrun fails, so gyp treats the host as a Command Line Tools install and takes the SDK from -isysroot.

I tested this with the macOS 27.2 SDK and Gecko's clang 22 toolchain. Both x64 and arm64 build. The x64 static archives export the same symbols as NSS CI's mac build, and application-services' CI links them into its x86_64 macOS library. It needs gyp-next: the old Chromium gyp fails to detect the Xcode version under Python 3.

NSS CI could build its gyp macOS targets on Linux the same way, with a cross build feeding the macOS test workers, as Windows AArch64 builds already feed the native ARM64 pools. That would free Mac workers, and it would make an arm64 mac build cheap to add.

--target-os=macos builds NSPR and NSS with clang, lld and the LLVM tools against the unpacked SDK given by
--macos-sdk, through gyp's ninja-mac generator. That generator runs libtool, nm, otool, xcodebuild and xcrun
by name, so coreconf/macos.sh puts stand-ins for them from coreconf/macos-tools on the PATH: libtool, nm and
otool are the LLVM tools, xcodebuild -version reports a fixed Xcode version, and xcrun fails, so gyp treats
the host as a Command Line Tools install and takes the SDK from -isysroot. Library signing is turned off
because shlibsign would have to run the target's binaries on the build host.

The target flags go in CFLAGS, CXXFLAGS and LDFLAGS rather than CC, because werror.py and check_cc.py run CC
as a single program name.

gyp copies CPPFLAGS, CFLAGS, CXXFLAGS and LDFLAGS from the environment into the ninja files it generates, so
build.sh now records them in out/gyp_config and reruns gyp when they change. Without that, a new --macos-sdk
or --macos-version-min reconfigures NSPR but leaves NSS on the old flags.

NSPR's configure only defines HAS_CONNECTX when the build host is Darwin 15 or later, so macos.sh passes it to
NSPR to match a native build.

Pushed by rvandermeulen@mozilla.com:
https://hg.mozilla.org/projects/nss/rev/36a8c0e58ed7
Allow build.sh to cross-compile NSS for macOS from a non-macOS host. r=nss-reviewers,jschanck

Status: NEW → RESOLVED
Closed: 2 days ago
Resolution: --- → FIXED
status-nss: --- → 3.135
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: