@@ -47,12 +47,85 @@ if [[ -z "${!nss_dir_var}" ]]; then
4747fi
4848
4949# Use toolchain configuration from environment
50- eval " CC =\$ ${RUST_ANDROID_PREFIX} _CC"
50+ eval " BASE_CC =\$ ${RUST_ANDROID_PREFIX} _CC"
5151eval " AR=\$ ${RUST_ANDROID_PREFIX} _AR"
52+ eval " AS=\$ ${RUST_ANDROID_PREFIX} _AS"
5253eval " RANLIB=\$ ${RUST_ANDROID_PREFIX} _RANLIB"
54+ eval " LD=\$ ${RUST_ANDROID_PREFIX} _LD"
5355eval " STRIP=\$ ${RUST_ANDROID_PREFIX} _TOOLCHAIN_PREFIX/${NSS_TARGET} -strip"
56+ eval " TOOLCHAIN_BIN=\$ ${RUST_ANDROID_PREFIX} _TOOLCHAIN_PREFIX"
5457eval " CFLAGS=\$ ${RUST_ANDROID_PREFIX} _CFLAGS_${NSS_TARGET// -/ _} "
55- eval " LDFLAGS=\$ ${RUST_ANDROID_PREFIX} _LDFLAGS_${NSS_TARGET// -/ _} "
58+
59+ # Create a wrapper directory for fake tools and compiler wrappers
60+ WRAPPER_DIR=$( mktemp -d)
61+
62+ # Create compiler wrapper scripts that filter out incompatible Apple-specific flags
63+ # and add C++ standard library include paths for cross-compilation
64+ cat > " ${WRAPPER_DIR} /cc-wrapper" << 'EOF '
65+ #!/usr/bin/env bash
66+ # Filter out -fasm-blocks and -mpascal-strings which clang-20 doesn't support for cross-compilation
67+ args=()
68+ for arg in "$@"; do
69+ if [[ "$arg" != "-fasm-blocks" && "$arg" != "-mpascal-strings" ]]; then
70+ args+=("$arg")
71+ fi
72+ done
73+ # Add clang's C++ standard library include path
74+ args+=("-I/builds/worker/clang/include/c++/v1")
75+ exec "${REAL_CC}" "${args[@]}"
76+ EOF
77+ chmod +x " ${WRAPPER_DIR} /cc-wrapper"
78+
79+ # Set CC and CXX to use the wrapper with all flags baked in
80+ export REAL_CC=" ${BASE_CC} ${CFLAGS} "
81+ CC=" ${WRAPPER_DIR} /cc-wrapper"
82+ CXX=" ${WRAPPER_DIR} /cc-wrapper"
83+ export CC CXX
84+
85+ # Create a fake xcodebuild script and tool wrappers to allow gyp to use the mac flavor
86+ # This tricks gyp into thinking Xcode is installed so it generates macOS-style build rules
87+ cat > " ${WRAPPER_DIR} /xcodebuild" << 'EOF '
88+ #!/usr/bin/env bash
89+ # Fake xcodebuild that returns a version for gyp's mac flavor
90+ # Xcode 12.2 corresponds to macOS SDK 11.0 (Big Sur) and adds Apple Silicon support
91+ echo "Xcode 12.2"
92+ echo "Build version 12B45b"
93+ EOF
94+ chmod +x " ${WRAPPER_DIR} /xcodebuild"
95+
96+ # Create unprefixed symlinks to cctools binaries that gyp's mac flavor expects
97+ # The mac flavor expects tools like 'otool', 'libtool', 'lipo' without the target prefix
98+ ln -s " ${TOOLCHAIN_BIN} /${NSS_TARGET} -otool" " ${WRAPPER_DIR} /otool"
99+ ln -s " ${TOOLCHAIN_BIN} /${NSS_TARGET} -libtool" " ${WRAPPER_DIR} /libtool"
100+ ln -s " ${TOOLCHAIN_BIN} /${NSS_TARGET} -lipo" " ${WRAPPER_DIR} /lipo"
101+ ln -s " ${TOOLCHAIN_BIN} /${NSS_TARGET} -nm" " ${WRAPPER_DIR} /nm"
102+
103+ export PATH=" ${WRAPPER_DIR} :${PATH} "
104+
105+ # Work around Python 3 bug in Ubuntu 22.04 gyp package
106+ # Create a wrapper that monkey-patches GetStdoutQuiet to fix bytes/str handling
107+ GYP_WRAPPER=$( mktemp)
108+ cat > " ${GYP_WRAPPER} " << 'EOFGYP '
109+ #!/usr/bin/env python3
110+ import sys
111+ import gyp.xcode_emulation
112+
113+ # Monkey-patch GetStdoutQuiet to fix Python 3 bytes/str bug
114+ original_GetStdoutQuiet = gyp.xcode_emulation.GetStdoutQuiet
115+ def patched_GetStdoutQuiet(cmdlist):
116+ import subprocess
117+ job = subprocess.Popen(cmdlist, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
118+ out = job.communicate()[0]
119+ if job.returncode != 0:
120+ return None
121+ return out.rstrip(b'\n').decode('utf-8')
122+ gyp.xcode_emulation.GetStdoutQuiet = patched_GetStdoutQuiet
123+
124+ # Now run gyp normally
125+ import gyp
126+ sys.exit(gyp.script_main())
127+ EOFGYP
128+ chmod +x " ${GYP_WRAPPER} "
56129
57130# Build NSPR
58131NSPR_BUILD_DIR=$( mktemp -d)
@@ -61,12 +134,10 @@ pushd "${NSPR_BUILD_DIR}"
61134 STRIP=" ${STRIP} " \
62135 RANLIB=" ${RANLIB} " \
63136 AR=" ${AR} " \
64- AS=" ${AS:- ${AR} } " \
65- LD=" ${LD:- ${AR} } " \
137+ AS=" ${AS} " \
138+ LD=" ${LD} " \
66139 CC=" ${CC} " \
67140 CCC=" ${CC} " \
68- CFLAGS=" ${CFLAGS} " \
69- LDFLAGS=" ${LDFLAGS} " \
70141 --target=" ${NSS_TARGET} " \
71142 --enable-64bit \
72143 --disable-debug \
78149NSS_BUILD_DIR=$( mktemp -d)
79150rm -rf " ${NSS_SRC_DIR} /nss/out"
80151
81- gyp -f ninja " ${NSS_SRC_DIR} /nss/nss.gyp" \
152+ " ${GYP_WRAPPER} " -f ninja-mac " ${NSS_SRC_DIR} /nss/nss.gyp" \
82153 --depth " ${NSS_SRC_DIR} /nss/" \
83154 --generator-output=. \
84155 -DOS=mac \
@@ -97,6 +168,11 @@ gyp -f ninja "${NSS_SRC_DIR}/nss/nss.gyp" \
97168 -Dpython=python3
98169
99170GENERATED_DIR=" ${NSS_SRC_DIR} /nss/out/Release/"
171+ echo " === Dumping build.ninja for nss-macos-cross ==="
172+ cat " ${GENERATED_DIR} /build.ninja"
173+
174+ # With the mac flavor, we can build all targets including shared libraries
175+ # The generated ninja rules will use macOS-style linker flags (e.g., -install_name instead of -soname)
100176ninja -C " ${GENERATED_DIR} "
101177
102178# Assemble the DIST_DIR with relevant libraries and headers
@@ -112,3 +188,4 @@ ninja -C "${GENERATED_DIR}"
112188# Cleanup
113189rm -rf " ${NSS_BUILD_DIR} "
114190rm -rf " ${NSPR_BUILD_DIR} "
191+ rm -rf " ${WRAPPER_DIR} "
0 commit comments