Skip to content

Commit 4b6471d

Browse files
yarshureclaude
andcommitted
CI: fix pthread_t in Thread.swift - exclude FreeBSD from canImport(Glibc)
pthread_t on FreeBSD is an opaque C pointer; _subprocess_pthread_create takes pthread_t* which Swift imports as UnsafeMutablePointer<pthread_t?>. Excluding FreeBSD from the canImport(Glibc) guard makes it use the #else branch (pthread_t?) which matches macOS and the expected function type. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0b67b0d commit 4b6471d

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

.github/workflows/pull_request.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,23 @@ jobs:
119119
mv /tmp/_th.swift "$SUBTHREAD"
120120
echo "Patched $SUBTHREAD (typealiases)"
121121
}
122-
grep -qF 'unsafeBitCast(0 as UInt' "$SUBTHREAD" || {
123-
awk '/^ var thread = pthread_t\(\)$/{
124-
print "#if os(FreeBSD) || os(OpenBSD)"
125-
print " var thread: pthread_t = unsafeBitCast(0 as UInt, to: pthread_t.self)"
126-
print "#else"
127-
print $0
128-
print "#endif"
129-
next}1' "$SUBTHREAD" > /tmp/_th.swift
122+
# Remove bad unsafeBitCast patch if it snuck in from a prior run
123+
grep -qF 'unsafeBitCast(0 as UInt' "$SUBTHREAD" && {
124+
awk '
125+
/^#if os\(FreeBSD\) \|\| os\(OpenBSD\)$/{ff=1; next}
126+
ff && /unsafeBitCast/{bad=1; next}
127+
ff && bad && /^#else$/{next}
128+
ff && bad && /^ var thread = pthread_t\(\)$/{print; ff=0; bad=0; next}
129+
ff && bad && /^#endif$/{ff=0; bad=0; next}
130+
ff{ff=0; print "#if os(FreeBSD) || os(OpenBSD)"}
131+
1' "$SUBTHREAD" > /tmp/_th.swift
130132
mv /tmp/_th.swift "$SUBTHREAD"
131-
echo "Patched $SUBTHREAD (pthread_t init)"
133+
}
134+
# pthread_t is also opaque on FreeBSD: exclude from canImport(Glibc)
135+
# so FreeBSD falls into #else branch and uses pthread_t? like macOS
136+
grep -qF '!os(FreeBSD) && !os(OpenBSD)) || canImport(Bionic)' "$SUBTHREAD" || {
137+
sed -i '' 's/#if canImport(Glibc) || canImport(Bionic)/#if (canImport(Glibc) \&\& !os(FreeBSD) \&\& !os(OpenBSD)) || canImport(Bionic)/g' "$SUBTHREAD"
138+
echo "Patched $SUBTHREAD (pthread_t? fix)"
132139
}
133140
fi
134141
swift build 2>&1

0 commit comments

Comments
 (0)