Skip to content
150 changes: 150 additions & 0 deletions cherry-pick-stable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#!/bin/bash

set -e

# Parse arguments
DRY_RUN=false
while [[ $# -gt 0 ]]; do
case $1 in
--dry-run|-d)
DRY_RUN=true
shift
;;
--help|-h)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Cherry-pick commits from PRs labeled 'stable-nominated' to current branch"
echo ""
echo "Options:"
echo " -d, --dry-run Show what would be done without making changes"
echo " -h, --help Show this help message"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done

if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN MODE - No changes will be made]"
echo ""
fi

current_branch=$(git branch --show-current)
echo "Current branch: $current_branch"
echo "Fetching PRs with 'stable-nominated' label..."
echo ""

# Get PRs with stable-nominated label that are merged
# Sort by merge date (oldest first) to preserve merge order and avoid conflicts
# Format: PR number, title, merge commit SHA
prs=$(gh pr list --state merged --label stable-nominated --json number,title,mergeCommit,mergedAt --jq 'sort_by(.mergedAt) | .[] | "\(.number)|\(.title)|\(.mergeCommit.oid)"')

if [ -z "$prs" ]; then
echo "No PRs found with 'stable-nominated' label."
exit 0
fi

# Arrays to track results
declare -a successful
declare -a failed
declare -a skipped

echo "Found PRs to cherry-pick:"
echo ""

# Process each PR
while IFS='|' read -r pr_number title commit_sha; do
echo "----------------------------------------"
echo "PR #${pr_number}: ${title}"
echo "Commit: ${commit_sha}"

# Check if commit already exists in current branch
if git branch --contains "$commit_sha" 2>/dev/null | grep -q "^\*"; then
echo "⏭ Already cherry-picked, skipping"
skipped+=("PR #${pr_number}: ${title}")
echo ""
continue
fi

# Cherry-pick with -xe flags as specified
if [ "$DRY_RUN" = true ]; then
echo "Would cherry-pick with: git cherry-pick -xe $commit_sha"
echo "Would add backport note: (backport https://github.com/rust-lang/libc/pull/$pr_number)"
successful+=("PR #${pr_number}: ${title} (${commit_sha:0:8})")
else
if git cherry-pick -xe "$commit_sha" 2>&1; then
# Add backport note before the cherry-pick note as per CONTRIBUTING.md
current_msg=$(git log -1 --format=%B)
backport_line="(backport https://github.com/rust-lang/libc/pull/$pr_number)"

# Insert backport line before "(cherry picked from commit" line
new_msg=$(echo "$current_msg" | sed "/^(cherry picked from commit/i\\
$backport_line\\
")

# Amend the commit with the new message
git commit --amend -m "$new_msg"

echo "✓ Successfully cherry-picked with backport note"
successful+=("PR #${pr_number}: ${title} (${commit_sha:0:8})")
else
echo "✗ Failed to cherry-pick"
failed+=("PR #${pr_number}: ${title} (${commit_sha:0:8})")
# Abort the failed cherry-pick
git cherry-pick --abort 2>/dev/null || true
fi
fi
echo ""
done <<< "$prs"

# Print summary
echo "========================================"
if [ "$DRY_RUN" = true ]; then
echo "SUMMARY (DRY RUN)"
else
echo "SUMMARY"
fi
echo "========================================"
echo ""

if [ ${#successful[@]} -gt 0 ]; then
if [ "$DRY_RUN" = true ]; then
echo "Would cherry-pick (${#successful[@]}):"
else
echo "Successfully cherry-picked (${#successful[@]}):"
fi
for item in "${successful[@]}"; do
echo " ✓ $item"
done
echo ""
fi

if [ ${#skipped[@]} -gt 0 ]; then
echo "Skipped (${#skipped[@]}):"
for item in "${skipped[@]}"; do
echo " ⏭ $item"
done
echo ""
fi

if [ ${#failed[@]} -gt 0 ]; then
echo "Failed (${#failed[@]}):"
for item in "${failed[@]}"; do
echo " ✗ $item"
done
echo ""
if [ "$DRY_RUN" = false ]; then
echo "Please resolve conflicts manually and re-run if needed."
fi
exit 1
fi

if [ "$DRY_RUN" = true ]; then
echo "Dry run complete! Run without --dry-run to apply changes."
else
echo "All done!"
fi
1 change: 1 addition & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ fn test_openbsd(target: &str) {
"sys/syscall.h",
"sys/shm.h",
"sys/param.h",
"sys/auxv.h",
}

cfg.rename_type(|ty| match ty {
Expand Down
5 changes: 5 additions & 0 deletions libc-test/semver/apple.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,7 @@ TIOCEXCL
TIOCEXT
TIOCFLUSH
TIOCGDRAINWAIT
TIOCGETA
TIOCGETD
TIOCGPGRP
TIOCIXOFF
Expand Down Expand Up @@ -1495,6 +1496,9 @@ TIOCSCONS
TIOCSCTTY
TIOCSDRAINWAIT
TIOCSDTR
TIOCSETA
TIOCSETAF
TIOCSETAW
TIOCSETD
TIOCSIG
TIOCSPGRP
Expand Down Expand Up @@ -2198,6 +2202,7 @@ pthread_attr_setschedpolicy
pthread_attr_setscope
pthread_attr_setstackaddr
pthread_cancel
pthread_cond_timedwait_relative_np
pthread_condattr_getpshared
pthread_condattr_setpshared
pthread_cpu_number_np
Expand Down
1 change: 1 addition & 0 deletions libc-test/semver/dragonfly.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,7 @@ WTRAPPED
XUCRED_VERSION
YESEXPR
YESSTR
_CS_PATH
_IOFBF
_IOLBF
_IONBF
Expand Down
1 change: 1 addition & 0 deletions libc-test/semver/freebsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,7 @@ XUCRED_VERSION
XU_NGROUPS
YESEXPR
YESSTR
_CS_PATH
_IOFBF
_IOLBF
_IONBF
Expand Down
1 change: 1 addition & 0 deletions libc-test/semver/linux-mips.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ PTRACE_GETREGS
PTRACE_SETFPREGS
PTRACE_SETFPXREGS
PTRACE_SETREGS
SIGEMT
SO_PRIORITY
SO_PROTOCOL
SYS__sysctl
Expand Down
1 change: 1 addition & 0 deletions libc-test/semver/linux-sparc64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ MAP_SYNC
PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
SIGEMT
SYS__llseek
SYS__newselect
SYS__sysctl
Expand Down
1 change: 1 addition & 0 deletions libc-test/semver/netbsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,7 @@ XATTR_CREATE
XATTR_REPLACE
YESEXPR
YESSTR
_CS_PATH
_IO
_IOC
_IOFBF
Expand Down
7 changes: 7 additions & 0 deletions libc-test/semver/openbsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ ATF_PUBL
ATF_USETRAILERS
AT_EACCESS
AT_FDCWD
AT_HWCAP
AT_HWCAP2
AT_IGNORE
AT_NULL
AT_PAGESZ
AT_REMOVEDIR
AT_SYMLINK_FOLLOW
AT_SYMLINK_NOFOLLOW
Expand Down Expand Up @@ -921,6 +926,7 @@ WSTOPPED
WTRAPPED
YESEXPR
YESSTR
_CS_PATH
_IO
_IOC
_IOFBF
Expand Down Expand Up @@ -1094,6 +1100,7 @@ dl_phdr_info
drand48
dup3
duplocale
elf_aux_info
endgrent
endpwent
endservent
Expand Down
19 changes: 19 additions & 0 deletions libc-test/semver/redox.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,27 @@ _PC_SOCK_MAXBUF
_PC_SYMLINK_MAX
_PC_SYNC_IO
_POSIX_VDISABLE
_SC_ARG_MAX
_SC_CHILD_MAX
_SC_CLK_TCK
_SC_GETGR_R_SIZE_MAX
_SC_GETPW_R_SIZE_MAX
_SC_HOST_NAME_MAX
_SC_LOGIN_NAME_MAX
_SC_NGROUPS_MAX
_SC_NPROCESSORS_CONF
_SC_NPROCESSORS_ONLN
_SC_OPEN_MAX
_SC_PAGESIZE
_SC_PAGE_SIZE
_SC_REALTIME_SIGNALS
_SC_RE_DUP_MAX
_SC_SIGQUEUE_MAX
_SC_STREAM_MAX
_SC_SYMLOOP_MAX
_SC_TTY_NAME_MAX
_SC_TZNAME_MAX
_SC_VERSION
__WALL
__WCLONE
__WNOTHREAD
Expand Down
1 change: 1 addition & 0 deletions libc-test/semver/windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ utimbuf
wchar_t
wchmod
wcslen
wcsnlen
wcstombs
wexecl
wexecle
Expand Down
9 changes: 9 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3341,6 +3341,10 @@ pub const TIOCDSIMICROCODE: c_uint = 0x20007455;
pub const TIOCPTYGRANT: c_uint = 0x20007454;
pub const TIOCPTYGNAME: c_uint = 0x40807453;
pub const TIOCPTYUNLK: c_uint = 0x20007452;
pub const TIOCGETA: c_ulong = 0x40487413;
pub const TIOCSETA: c_ulong = 0x80487414;
pub const TIOCSETAW: c_ulong = 0x80487415;
pub const TIOCSETAF: c_ulong = 0x80487416;

pub const BIOCGRSIG: c_ulong = 0x40044272;
pub const BIOCSRSIG: c_ulong = 0x80044273;
Expand Down Expand Up @@ -5380,6 +5384,11 @@ extern "C" {
pub fn mach_host_self() -> mach_port_t;
#[deprecated(since = "0.2.55", note = "Use the `mach2` crate instead")]
pub fn mach_thread_self() -> mach_port_t;
pub fn pthread_cond_timedwait_relative_np(
cond: *mut pthread_cond_t,
lock: *mut pthread_mutex_t,
timeout: *const crate::timespec,
) -> c_int;
pub fn pthread_once(
once_control: *mut crate::pthread_once_t,
init_routine: Option<unsafe extern "C" fn()>,
Expand Down
2 changes: 2 additions & 0 deletions src/unix/bsd/freebsdlike/dragonfly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,8 @@ pub const VCHECKPT: usize = 19;
pub const _PC_2_SYMLINKS: c_int = 22;
pub const _PC_TIMESTAMP_RESOLUTION: c_int = 23;

pub const _CS_PATH: c_int = 1;

pub const _SC_V7_ILP32_OFF32: c_int = 122;
pub const _SC_V7_ILP32_OFFBIG: c_int = 123;
pub const _SC_V7_LP64_OFF64: c_int = 124;
Expand Down
2 changes: 2 additions & 0 deletions src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,8 @@ pub const _SC_RAW_SOCKETS: c_int = 119;
pub const _SC_SYMLOOP_MAX: c_int = 120;
pub const _SC_PHYS_PAGES: c_int = 121;

pub const _CS_PATH: c_int = 1;

pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = ptr::null_mut();
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = ptr::null_mut();
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = ptr::null_mut();
Expand Down
2 changes: 2 additions & 0 deletions src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,8 @@ pub const _PC_2_SYMLINKS: c_int = 13;
pub const _PC_ACL_EXTENDED: c_int = 14;
pub const _PC_MIN_HOLE_SIZE: c_int = 15;

pub const _CS_PATH: c_int = 1;

pub const _SC_SYNCHRONIZED_IO: c_int = 31;
pub const _SC_IOV_MAX: c_int = 32;
pub const _SC_MAPPED_FILES: c_int = 33;
Expand Down
10 changes: 10 additions & 0 deletions src/unix/bsd/netbsdlike/openbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,12 @@ pub const AT_SYMLINK_NOFOLLOW: c_int = 0x02;
pub const AT_SYMLINK_FOLLOW: c_int = 0x04;
pub const AT_REMOVEDIR: c_int = 0x08;

pub const AT_NULL: c_int = 0;
pub const AT_IGNORE: c_int = 1;
pub const AT_PAGESZ: c_int = 6;
pub const AT_HWCAP: c_int = 25;
pub const AT_HWCAP2: c_int = 26;

#[deprecated(since = "0.2.64", note = "Not stable across OS versions")]
pub const RLIM_NLIMITS: c_int = 9;

Expand Down Expand Up @@ -1219,6 +1225,8 @@ pub const _PC_SYMLINK_MAX: c_int = 19;
pub const _PC_SYNC_IO: c_int = 20;
pub const _PC_TIMESTAMP_RESOLUTION: c_int = 21;

pub const _CS_PATH: c_int = 1;

pub const _SC_CLK_TCK: c_int = 3;
pub const _SC_SEM_NSEMS_MAX: c_int = 31;
pub const _SC_SEM_VALUE_MAX: c_int = 32;
Expand Down Expand Up @@ -2091,6 +2099,8 @@ extern "C" {
pub fn fstatfs(fd: c_int, buf: *mut statfs) -> c_int;
pub fn getmntinfo(mntbufp: *mut *mut crate::statfs, flags: c_int) -> c_int;
pub fn getfsstat(buf: *mut statfs, bufsize: size_t, flags: c_int) -> c_int;

pub fn elf_aux_info(aux: c_int, buf: *mut c_void, buflen: c_int) -> c_int;
}

#[link(name = "execinfo")]
Expand Down
1 change: 1 addition & 0 deletions src/unix/linux_like/linux/gnu/b32/mips/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ pub const SOCK_DGRAM: c_int = 1;
pub const SA_SIGINFO: c_int = 0x00000008;
pub const SA_NOCLDWAIT: c_int = 0x00010000;

pub const SIGEMT: c_int = 7;
pub const SIGCHLD: c_int = 18;
pub const SIGBUS: c_int = 10;
pub const SIGTTIN: c_int = 26;
Expand Down
1 change: 1 addition & 0 deletions src/unix/linux_like/linux/gnu/b32/sparc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ pub const SOCK_DGRAM: c_int = 2;
pub const SA_SIGINFO: c_int = 0x200;
pub const SA_NOCLDWAIT: c_int = 0x100;

pub const SIGEMT: c_int = 7;
pub const SIGTTIN: c_int = 21;
pub const SIGTTOU: c_int = 22;
pub const SIGXCPU: c_int = 24;
Expand Down
1 change: 1 addition & 0 deletions src/unix/linux_like/linux/gnu/b64/mips64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ pub const SA_ONSTACK: c_int = 0x08000000;
pub const SA_SIGINFO: c_int = 0x00000008;
pub const SA_NOCLDWAIT: c_int = 0x00010000;

pub const SIGEMT: c_int = 7;
pub const SIGCHLD: c_int = 18;
pub const SIGBUS: c_int = 10;
pub const SIGTTIN: c_int = 26;
Expand Down
Loading
Loading