Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Rust edition 2021 #4132

Merged
merged 3 commits into from
Nov 27, 2024
Merged

Conversation

eduardosm
Copy link
Contributor

@eduardosm eduardosm commented Nov 21, 2024

Description

Migrates the libc crate to Rust edition 2021 with an automated script (after some initial manual adjustments).

Since ctest2 does not support crate:: in paths, a hack has been implemented in libc-test/build.rs, which makes a copy of src replacing every crate:: with ::.

cc #3898

Sources

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI

@rustbot
Copy link
Collaborator

rustbot commented Nov 21, 2024

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@bors
Copy link
Contributor

bors commented Nov 21, 2024

☔ The latest upstream changes (presumably #4128) made this pull request unmergeable. Please resolve the merge conflicts.

@eduardosm
Copy link
Contributor Author

eduardosm commented Nov 21, 2024

  called `Result::unwrap()` on an `Err` value: Os { code: 30, kind: ReadOnlyFilesystem, message: "Read-only file system" }

Is the whole working copy read-only except target?

EDIT: It is.

libc/ci/run-docker.sh

Lines 50 to 51 in 01c7a63

--volume "$(pwd)":/checkout:ro \
--volume "$(pwd)"/target:/checkout/target \

std::fs::remove_dir_all("../target/src-hotfix").unwrap();
}

// ctest2 cannot parse `crate::` in paths, so replace them with `::`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this // FIXME(ctest): ... so it's greppable with the other ctest problems?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@tgross35
Copy link
Contributor

Thanks! It is pretty unfortunate that the hotfix is needed (ctest is quite limiting...) but I think that is okay for now.

Would it be possible to add popular imports to the top of these files and then drop the crate:: prefix? Not for everything of course, but it would be nice for the types that are used everywhere (all c_* types, Ioctl, size_t, ssize_t, anything else that is used somewhat commonly).

@tgross35
Copy link
Contributor

Alsocargo fix works with --target if you're up for just doing rustc --print target-list | xargs -ITARGET cargo fix --edition --target TARGET --allow-dirty (that's a bit too crude since some need build-std or downloaded targets and I don't expect every single target to actually work, but it should be possible to get everything that's in CI).

I'll also add a .git-blame-ignore-revs entry after this merges.

@eduardosm
Copy link
Contributor Author

I didn't know that sed -i was not portable. I replaced it with perl. Rebased and removed :: prefixes for Option, Copy and Clone.

Script
#!/usr/bin/env bash

git restore Cargo.toml src

# Handle leading `::` in common types

for file in $(find src -name "*.rs"); do
  perl -pi -077 -e 's/(?<!\w)::(Option|Copy|Clone)\b/$1/g' "$file"
done

implicit_c_long_ulong_char=(
  src/fuchsia/mod.rs
  src/solid/mod.rs
  src/unix/aix/mod.rs
  src/unix/bsd/apple/mod.rs
  src/unix/bsd/freebsdlike/freebsd/mod.rs
  src/unix/bsd/freebsdlike/mod.rs
  src/unix/bsd/netbsdlike/netbsd/mod.rs
  src/unix/bsd/netbsdlike/openbsd/mod.rs
  src/unix/bsd/netbsdlike/mod.rs
  src/unix/bsd/mod.rs
  src/unix/haiku/mod.rs
  src/unix/hurd/mod.rs
  src/unix/linux_like/android/b32/mod.rs
  src/unix/linux_like/android/b64/mod.rs
  src/unix/linux_like/android/mod.rs
  src/unix/linux_like/linux/gnu/b32/mod.rs
  src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs
  src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs
  src/unix/linux_like/linux/gnu/b64/mod.rs
  src/unix/linux_like/linux/gnu/mod.rs
  src/unix/linux_like/linux/musl/mod.rs
  src/unix/linux_like/linux/uclibc/mips/mod.rs
  src/unix/linux_like/linux/uclibc/mod.rs
  src/unix/linux_like/linux/mod.rs
  src/unix/linux_like/mod.rs
  src/unix/newlib/mod.rs
  src/unix/nto/mod.rs
  src/unix/mod.rs
  src/vxworks/mod.rs
)

for file in "${implicit_c_long_ulong_char[@]}"; do
  perl -pi -077 -e 's/(?<!\w)::(c_long|c_ulong|c_char)\b/$1/g' "$file"
done

implicit_off_t=(
  src/unix/linux_like/linux/gnu/mod.rs
  src/unix/linux_like/linux/mod.rs
  src/unix/linux_like/mod.rs
  src/unix/mod.rs
)

for file in "${implicit_off_t[@]}"; do
  perl -pi -077 -e 's/(?<!\w)::(off_t)\b/$1/g' "$file"
done

implicit_off64_t=(
  src/unix/linux_like/android/mod.rs
  src/unix/linux_like/mod.rs
)

for file in "${implicit_off64_t[@]}"; do
  perl -pi -077 -e 's/(?<!\w)::(off64_t)\b/$1/g' "$file"
done

implicit_Ioctl=(
  src/unix/linux_like/linux/mod.rs
)

for file in "${implicit_Ioctl[@]}"; do
  perl -pi -077 -e 's/(?<!\w)::(Ioctl)\b/$1/g' "$file"
done

perl -pi -077 -e 's/(?<!\w)::(__u8|__u16|__u32|__s16|__s32)\b/$1/g' src/unix/linux_like/linux/mod.rs

perl -pi -077 -e 's/(?<!\w)::(SIG[A-Z]+)\b/$1/g' src/unix/solarish/mod.rs

# These are used only in `cfg`ed items or comments, `use ::<type>;` would cause warnings on some targets
perl -pi -077 -e 's/(?<!\w)::c_ulong\b/crate::c_ulong/g' src/unix/newlib/generic.rs
perl -pi -077 -e 's/(?<!\w)::c_ulong\b/crate::c_ulong/g' src/unix/linux_like/linux/arch/generic/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_ulonglong\b/crate::c_ulonglong/g' src/unix/linux_like/linux/gnu/b64/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_ulonglong\b/crate::c_ulonglong/g' src/unix/linux_like/linux/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_ulonglong\b/crate::c_ulonglong/g' src/unix/linux_like/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_short\b/crate::c_short/g' src/unix/linux_like/linux/gnu/b32/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_short\b/crate::c_short/g' src/unix/newlib/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_float\b/c_float/g' src/unix/linux_like/linux/gnu/b64/s390x.rs
perl -pi -077 -e 's/(?<!\w)::c_float\b/c_float/g' src/unix/linux_like/linux/musl/b64/s390x.rs

function handle_type() {
  type="$1"
  uses_type="$(rg -l "[^\w]::$type\b" src)"
  has_type_def="$(rg -l "(type|struct) $type " src)"
  has_type_import="$(rg -l "use ([0-9a-zA-Z_]+::)*$type;" src)"

  add_import=($(comm -3 <(echo "$uses_type" | sort) <(printf "%s\n%s" "$has_type_def" "$has_type_import" | sort) | cut -f1))
  for file in "${add_import[@]}"; do
    # Split the file into two parts: module-level attributes and rest
    # Imports will be added after module-level attributes

    awk '/^#!|^\/\/!/ {found=NR} {lines[NR]=$0} END {for (i=1; i<=found; i++) print lines[i]}' \
      "$file" > "$file.attrs"
    awk '/^#!|^\/\/!/ {found=NR} END {if (found) {for (i=found+1; i<=NR; i++) print lines[i]} else {for (i=1; i<=NR; i++) print lines[i]}} {lines[NR]=$0}' \
      "$file" > "$file.rest"

    cat "$file.attrs" > "$file"
    echo >> "$file"
    echo 'use crate::'"$type"';' >> "$file"
    echo >> "$file"
    cat "$file.rest" >> "$file"

    rm "$file.attrs" "$file.rest"
  done

  for file in $uses_type; do
    perl -pi -077 -e 's/(?<!\w)::('"$type"')\b/$1/g' "$file"
  done
}

handle_type c_void
handle_type c_int
handle_type c_uint
handle_type c_char
handle_type c_schar
handle_type c_uchar
handle_type c_short
handle_type c_ushort
handle_type c_long
handle_type c_ulong
handle_type c_longlong
handle_type c_ulonglong
handle_type c_float
handle_type c_double
handle_type size_t
handle_type ssize_t
handle_type intptr_t
handle_type ptrdiff_t
handle_type off_t
handle_type off64_t
#handle_type time_t # Produces deprecation warnings
handle_type Ioctl
handle_type cmsghdr # To avoid "line formatted, but exceeded maximum width"

# Commented targets failed to `cargo check -Zbuild-std=core`
targets=(
  aarch64-apple-darwin
  aarch64-apple-ios
  aarch64-apple-ios-macabi
  aarch64-apple-ios-sim
  aarch64-apple-tvos
  aarch64-apple-tvos-sim
  aarch64-apple-visionos
  aarch64-apple-visionos-sim
  aarch64-apple-watchos
  aarch64-apple-watchos-sim
  aarch64-kmc-solid_asp3
  aarch64-linux-android
  aarch64-nintendo-switch-freestanding
  aarch64-pc-windows-gnullvm
  aarch64-pc-windows-msvc
  aarch64-unknown-freebsd
  aarch64-unknown-fuchsia
  aarch64-unknown-hermit
  aarch64-unknown-illumos
  aarch64-unknown-linux-gnu
  aarch64-unknown-linux-gnu_ilp32
  aarch64-unknown-linux-musl
  aarch64-unknown-linux-ohos
  aarch64-unknown-netbsd
  aarch64-unknown-none
  aarch64-unknown-none-softfloat
  aarch64-unknown-nto-qnx700
  aarch64-unknown-nto-qnx710
  aarch64-unknown-openbsd
  aarch64-unknown-redox
  #aarch64-unknown-teeos
  aarch64-unknown-trusty
  aarch64-unknown-uefi
  aarch64-uwp-windows-msvc
  aarch64-wrs-vxworks
  aarch64_be-unknown-linux-gnu
  aarch64_be-unknown-linux-gnu_ilp32
  aarch64_be-unknown-netbsd
  arm-linux-androideabi
  arm-unknown-linux-gnueabi
  arm-unknown-linux-gnueabihf
  arm-unknown-linux-musleabi
  arm-unknown-linux-musleabihf
  arm64_32-apple-watchos
  arm64e-apple-darwin
  arm64e-apple-ios
  arm64e-apple-tvos
  arm64ec-pc-windows-msvc
  armeb-unknown-linux-gnueabi
  armebv7r-none-eabi
  armebv7r-none-eabihf
  armv4t-none-eabi
  armv4t-unknown-linux-gnueabi
  armv5te-none-eabi
  armv5te-unknown-linux-gnueabi
  armv5te-unknown-linux-musleabi
  armv5te-unknown-linux-uclibceabi
  armv6-unknown-freebsd
  armv6-unknown-netbsd-eabihf
  armv6k-nintendo-3ds
  armv7-linux-androideabi
  armv7-rtems-eabihf
  armv7-sony-vita-newlibeabihf
  armv7-unknown-freebsd
  armv7-unknown-linux-gnueabi
  armv7-unknown-linux-gnueabihf
  armv7-unknown-linux-musleabi
  armv7-unknown-linux-musleabihf
  armv7-unknown-linux-ohos
  armv7-unknown-linux-uclibceabi
  armv7-unknown-linux-uclibceabihf
  armv7-unknown-netbsd-eabihf
  armv7-unknown-trusty
  armv7-wrs-vxworks-eabihf
  armv7a-kmc-solid_asp3-eabi
  armv7a-kmc-solid_asp3-eabihf
  armv7a-none-eabi
  armv7a-none-eabihf
  armv7k-apple-watchos
  armv7r-none-eabi
  armv7r-none-eabihf
  armv7s-apple-ios
  armv8r-none-eabihf
  #avr-unknown-gnu-atmega328
  bpfeb-unknown-none
  bpfel-unknown-none
  csky-unknown-linux-gnuabiv2
  csky-unknown-linux-gnuabiv2hf
  hexagon-unknown-linux-musl
  #hexagon-unknown-none-elf
  i386-apple-ios
  #i586-pc-nto-qnx700
  i586-pc-windows-msvc
  i586-unknown-linux-gnu
  i586-unknown-linux-musl
  i586-unknown-netbsd
  i686-apple-darwin
  i686-linux-android
  i686-pc-windows-gnu
  i686-pc-windows-gnullvm
  i686-pc-windows-msvc
  i686-unknown-freebsd
  i686-unknown-haiku
  i686-unknown-hurd-gnu
  i686-unknown-linux-gnu
  i686-unknown-linux-musl
  i686-unknown-netbsd
  i686-unknown-openbsd
  i686-unknown-redox
  i686-unknown-uefi
  i686-uwp-windows-gnu
  i686-uwp-windows-msvc
  i686-win7-windows-msvc
  i686-wrs-vxworks
  loongarch64-unknown-linux-gnu
  loongarch64-unknown-linux-musl
  loongarch64-unknown-linux-ohos
  loongarch64-unknown-none
  loongarch64-unknown-none-softfloat
  #m68k-unknown-linux-gnu
  mips-unknown-linux-gnu
  mips-unknown-linux-musl
  mips-unknown-linux-uclibc
  mips64-openwrt-linux-musl
  mips64-unknown-linux-gnuabi64
  mips64-unknown-linux-muslabi64
  mips64el-unknown-linux-gnuabi64
  mips64el-unknown-linux-muslabi64
  mipsel-sony-psp
  mipsel-sony-psx
  mipsel-unknown-linux-gnu
  mipsel-unknown-linux-musl
  mipsel-unknown-linux-uclibc
  mipsel-unknown-netbsd
  mipsel-unknown-none
  mipsisa32r6-unknown-linux-gnu
  mipsisa32r6el-unknown-linux-gnu
  mipsisa64r6-unknown-linux-gnuabi64
  mipsisa64r6el-unknown-linux-gnuabi64
  msp430-none-elf
  nvptx64-nvidia-cuda
  powerpc-unknown-freebsd
  powerpc-unknown-linux-gnu
  powerpc-unknown-linux-gnuspe
  powerpc-unknown-linux-musl
  powerpc-unknown-linux-muslspe
  powerpc-unknown-netbsd
  powerpc-unknown-openbsd
  powerpc-wrs-vxworks
  powerpc-wrs-vxworks-spe
  powerpc64-ibm-aix
  powerpc64-unknown-freebsd
  powerpc64-unknown-linux-gnu
  powerpc64-unknown-linux-musl
  powerpc64-unknown-openbsd
  powerpc64-wrs-vxworks
  powerpc64le-unknown-freebsd
  powerpc64le-unknown-linux-gnu
  powerpc64le-unknown-linux-musl
  riscv32-wrs-vxworks
  riscv32e-unknown-none-elf
  riscv32em-unknown-none-elf
  riscv32emc-unknown-none-elf
  riscv32gc-unknown-linux-gnu
  riscv32gc-unknown-linux-musl
  riscv32i-unknown-none-elf
  riscv32im-risc0-zkvm-elf
  riscv32im-unknown-none-elf
  riscv32ima-unknown-none-elf
  riscv32imac-esp-espidf
  riscv32imac-unknown-none-elf
  riscv32imac-unknown-nuttx-elf
  riscv32imac-unknown-xous-elf
  riscv32imafc-esp-espidf
  riscv32imafc-unknown-none-elf
  riscv32imafc-unknown-nuttx-elf
  riscv32imc-esp-espidf
  riscv32imc-unknown-none-elf
  riscv32imc-unknown-nuttx-elf
  riscv64-linux-android
  riscv64-wrs-vxworks
  riscv64gc-unknown-freebsd
  riscv64gc-unknown-fuchsia
  riscv64gc-unknown-hermit
  riscv64gc-unknown-linux-gnu
  riscv64gc-unknown-linux-musl
  #riscv64gc-unknown-netbsd
  riscv64gc-unknown-none-elf
  riscv64gc-unknown-nuttx-elf
  riscv64gc-unknown-openbsd
  riscv64imac-unknown-none-elf
  riscv64imac-unknown-nuttx-elf
  s390x-unknown-linux-gnu
  s390x-unknown-linux-musl
  sparc-unknown-linux-gnu
  sparc-unknown-none-elf
  sparc64-unknown-linux-gnu
  sparc64-unknown-netbsd
  sparc64-unknown-openbsd
  sparcv9-sun-solaris
  thumbv4t-none-eabi
  thumbv5te-none-eabi
  thumbv6m-none-eabi
  thumbv6m-nuttx-eabi
  thumbv7a-pc-windows-msvc
  thumbv7a-uwp-windows-msvc
  thumbv7em-none-eabi
  thumbv7em-none-eabihf
  thumbv7em-nuttx-eabi
  thumbv7em-nuttx-eabihf
  thumbv7m-none-eabi
  thumbv7m-nuttx-eabi
  thumbv7neon-linux-androideabi
  thumbv7neon-unknown-linux-gnueabihf
  thumbv7neon-unknown-linux-musleabihf
  thumbv8m.base-none-eabi
  thumbv8m.base-nuttx-eabi
  thumbv8m.main-none-eabi
  thumbv8m.main-none-eabihf
  thumbv8m.main-nuttx-eabi
  thumbv8m.main-nuttx-eabihf
  wasm32-unknown-emscripten
  wasm32-unknown-unknown
  wasm32-wasip1
  wasm32-wasip1-threads
  wasm32-wasip2
  wasm32v1-none
  wasm64-unknown-unknown
  x86_64-apple-darwin
  x86_64-apple-ios
  x86_64-apple-ios-macabi
  x86_64-apple-tvos
  x86_64-apple-watchos-sim
  x86_64-fortanix-unknown-sgx
  x86_64-linux-android
  x86_64-pc-nto-qnx710
  x86_64-pc-solaris
  x86_64-pc-windows-gnu
  x86_64-pc-windows-gnullvm
  x86_64-pc-windows-msvc
  x86_64-unikraft-linux-musl
  x86_64-unknown-dragonfly
  x86_64-unknown-freebsd
  x86_64-unknown-fuchsia
  x86_64-unknown-haiku
  x86_64-unknown-hermit
  x86_64-unknown-hurd-gnu
  x86_64-unknown-illumos
  x86_64-unknown-l4re-uclibc
  x86_64-unknown-linux-gnu
  x86_64-unknown-linux-gnux32
  x86_64-unknown-linux-musl
  #x86_64-unknown-linux-none
  x86_64-unknown-linux-ohos
  x86_64-unknown-netbsd
  x86_64-unknown-none
  x86_64-unknown-openbsd
  x86_64-unknown-redox
  x86_64-unknown-trusty
  x86_64-unknown-uefi
  x86_64-uwp-windows-gnu
  x86_64-uwp-windows-msvc
  x86_64-win7-windows-msvc
  x86_64-wrs-vxworks
  x86_64h-apple-darwin
  #xtensa-esp32-espidf
  #xtensa-esp32-none-elf
  #xtensa-esp32s2-espidf
  #xtensa-esp32s2-none-elf
  #xtensa-esp32s3-espidf
  #xtensa-esp32s3-none-elf
)

# Migrate to 2018

for target in "${targets[@]}"; do
  echo "Migrating 2015 -> 2018 target $target"
  cargo fix --target "$target" -Zbuild-std=core --features extra_traits --allow-dirty --edition --broken-code 2> /dev/null
done

# Handle freebsd versions
freebsd_versions=(freebsd13 freebsd14 freebsd15)
for ver in "${freebsd_versions[@]}"; do
  echo "Migrating 2015 -> 2018 $ver"
  RUSTFLAGS="--cfg $ver" cargo fix --target i686-unknown-freebsd -Zbuild-std=core --features extra_traits --allow-dirty --edition --broken-code 2> /dev/null
  RUSTFLAGS="--cfg $ver" cargo fix --target x86_64-unknown-freebsd -Zbuild-std=core --features extra_traits --allow-dirty --edition --broken-code 2> /dev/null
done

perl -pi -077 -e 's/edition = "2015"/edition = "2018"/' Cargo.toml

# Migrate to 2021

for target in "${targets[@]}"; do
  echo "Migrating 2018 -> 2021 target $target"
  cargo fix --target "$target" -Zbuild-std=core --features extra_traits --allow-dirty --edition --broken-code 2> /dev/null
done

perl -pi -077 -e 's/edition = "2018"/edition = "2021"/' Cargo.toml

# Check
for target in "${targets[@]}"; do
  echo "Checking target $target"
  cargo check --target "$target" -Zbuild-std=core --features extra_traits || {
    echo "Failed for target $target"
    exit 1
  }
done

for ver in "${freebsd_versions[@]}"; do
  echo "Checking $ver"
  RUSTFLAGS="--cfg $ver" cargo check --target i686-unknown-freebsd -Zbuild-std=core --features extra_traits || {
    echo "Failed for i686 $freebsd_versions"
    exit 1
  }
  RUSTFLAGS="--cfg $ver" cargo check --target x86_64-unknown-freebsd -Zbuild-std=core --features extra_traits || {
    echo "Failed for x86_64 $freebsd_versions"
    exit 1
  }
done

# Fix formatting
ci/style.sh

@@ -145,11 +145,41 @@ fn main() {
// Avoid unnecessary re-building.
println!("cargo:rerun-if-changed=build.rs");

if std::fs::exists("../target/src-hotfix").unwrap() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I just noticed one more thing: I think these need to use CARGO_TARGET_DIR since if that is overridden then we shouldn't write to ../target.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used OUT_DIR instead, since I think it is more appropriate and Cargo won't set CARGO_TARGET_DIR if the user does not define it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, that's better 👍

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, git ls-tree --full-tree -r HEAD . | git hash-object --stdin reports 9bdf35a45c01d45498aa0bcaf8baaee3ce1d6d8a both when I run locally and when I check the latest commit here (bb8bbf2). For some reason I had to pass --lib to cargo fix and cargo check, otherwise it wanted to build std.

Anyway I think this should be good, let's get it merged.

… `crate::` with `::`

This is needed because ctest2 cannot parse `crate::` in paths
Migration script:

```sh
#!/usr/bin/env bash

git restore Cargo.toml src

# Handle leading `::` in common types

for file in $(find src -name "*.rs"); do
  perl -pi -077 -e 's/(?<!\w)::(Option|Copy|Clone)\b/$1/g' "$file"
done

implicit_c_long_ulong_char=(
  src/fuchsia/mod.rs
  src/solid/mod.rs
  src/unix/aix/mod.rs
  src/unix/bsd/apple/mod.rs
  src/unix/bsd/freebsdlike/freebsd/mod.rs
  src/unix/bsd/freebsdlike/mod.rs
  src/unix/bsd/netbsdlike/netbsd/mod.rs
  src/unix/bsd/netbsdlike/openbsd/mod.rs
  src/unix/bsd/netbsdlike/mod.rs
  src/unix/bsd/mod.rs
  src/unix/haiku/mod.rs
  src/unix/hurd/mod.rs
  src/unix/linux_like/android/b32/mod.rs
  src/unix/linux_like/android/b64/mod.rs
  src/unix/linux_like/android/mod.rs
  src/unix/linux_like/linux/gnu/b32/mod.rs
  src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs
  src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs
  src/unix/linux_like/linux/gnu/b64/mod.rs
  src/unix/linux_like/linux/gnu/mod.rs
  src/unix/linux_like/linux/musl/mod.rs
  src/unix/linux_like/linux/uclibc/mips/mod.rs
  src/unix/linux_like/linux/uclibc/mod.rs
  src/unix/linux_like/linux/mod.rs
  src/unix/linux_like/mod.rs
  src/unix/newlib/mod.rs
  src/unix/nto/mod.rs
  src/unix/mod.rs
  src/vxworks/mod.rs
)

for file in "${implicit_c_long_ulong_char[@]}"; do
  perl -pi -077 -e 's/(?<!\w)::(c_long|c_ulong|c_char)\b/$1/g' "$file"
done

implicit_off_t=(
  src/unix/linux_like/linux/gnu/mod.rs
  src/unix/linux_like/linux/mod.rs
  src/unix/linux_like/mod.rs
  src/unix/mod.rs
)

for file in "${implicit_off_t[@]}"; do
  perl -pi -077 -e 's/(?<!\w)::(off_t)\b/$1/g' "$file"
done

implicit_off64_t=(
  src/unix/linux_like/android/mod.rs
  src/unix/linux_like/mod.rs
)

for file in "${implicit_off64_t[@]}"; do
  perl -pi -077 -e 's/(?<!\w)::(off64_t)\b/$1/g' "$file"
done

implicit_Ioctl=(
  src/unix/linux_like/linux/mod.rs
)

for file in "${implicit_Ioctl[@]}"; do
  perl -pi -077 -e 's/(?<!\w)::(Ioctl)\b/$1/g' "$file"
done

perl -pi -077 -e 's/(?<!\w)::(__u8|__u16|__u32|__s16|__s32)\b/$1/g' src/unix/linux_like/linux/mod.rs

perl -pi -077 -e 's/(?<!\w)::(SIG[A-Z]+)\b/$1/g' src/unix/solarish/mod.rs

# These are used only in `cfg`ed items or comments, `use ::<type>;` would cause warnings on some targets
perl -pi -077 -e 's/(?<!\w)::c_ulong\b/crate::c_ulong/g' src/unix/newlib/generic.rs
perl -pi -077 -e 's/(?<!\w)::c_ulong\b/crate::c_ulong/g' src/unix/linux_like/linux/arch/generic/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_ulonglong\b/crate::c_ulonglong/g' src/unix/linux_like/linux/gnu/b64/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_ulonglong\b/crate::c_ulonglong/g' src/unix/linux_like/linux/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_ulonglong\b/crate::c_ulonglong/g' src/unix/linux_like/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_short\b/crate::c_short/g' src/unix/linux_like/linux/gnu/b32/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_short\b/crate::c_short/g' src/unix/newlib/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_float\b/c_float/g' src/unix/linux_like/linux/gnu/b64/s390x.rs
perl -pi -077 -e 's/(?<!\w)::c_float\b/c_float/g' src/unix/linux_like/linux/musl/b64/s390x.rs

function handle_type() {
  type="$1"
  uses_type="$(rg -l "[^\w]::$type\b" src)"
  has_type_def="$(rg -l "(type|struct) $type " src)"
  has_type_import="$(rg -l "use ([0-9a-zA-Z_]+::)*$type;" src)"

  add_import=($(comm -3 <(echo "$uses_type" | sort) <(printf "%s\n%s" "$has_type_def" "$has_type_import" | sort) | cut -f1))
  for file in "${add_import[@]}"; do
    # Split the file into two parts: module-level attributes and rest
    # Imports will be added after module-level attributes

    awk '/^#!|^\/\/!/ {found=NR} {lines[NR]=$0} END {for (i=1; i<=found; i++) print lines[i]}' \
      "$file" > "$file.attrs"
    awk '/^#!|^\/\/!/ {found=NR} END {if (found) {for (i=found+1; i<=NR; i++) print lines[i]} else {for (i=1; i<=NR; i++) print lines[i]}} {lines[NR]=$0}' \
      "$file" > "$file.rest"

    cat "$file.attrs" > "$file"
    echo >> "$file"
    echo 'use crate::'"$type"';' >> "$file"
    echo >> "$file"
    cat "$file.rest" >> "$file"

    rm "$file.attrs" "$file.rest"
  done

  for file in $uses_type; do
    perl -pi -077 -e 's/(?<!\w)::('"$type"')\b/$1/g' "$file"
  done
}

handle_type c_void
handle_type c_int
handle_type c_uint
handle_type c_char
handle_type c_schar
handle_type c_uchar
handle_type c_short
handle_type c_ushort
handle_type c_long
handle_type c_ulong
handle_type c_longlong
handle_type c_ulonglong
handle_type c_float
handle_type c_double
handle_type size_t
handle_type ssize_t
handle_type intptr_t
handle_type ptrdiff_t
handle_type off_t
handle_type off64_t
#handle_type time_t # Produces deprecation warnings
handle_type Ioctl
handle_type cmsghdr # To avoid "line formatted, but exceeded maximum width"

# Commented targets failed to `cargo check -Zbuild-std=core`
targets=(
  aarch64-apple-darwin
  aarch64-apple-ios
  aarch64-apple-ios-macabi
  aarch64-apple-ios-sim
  aarch64-apple-tvos
  aarch64-apple-tvos-sim
  aarch64-apple-visionos
  aarch64-apple-visionos-sim
  aarch64-apple-watchos
  aarch64-apple-watchos-sim
  aarch64-kmc-solid_asp3
  aarch64-linux-android
  aarch64-nintendo-switch-freestanding
  aarch64-pc-windows-gnullvm
  aarch64-pc-windows-msvc
  aarch64-unknown-freebsd
  aarch64-unknown-fuchsia
  aarch64-unknown-hermit
  aarch64-unknown-illumos
  aarch64-unknown-linux-gnu
  aarch64-unknown-linux-gnu_ilp32
  aarch64-unknown-linux-musl
  aarch64-unknown-linux-ohos
  aarch64-unknown-netbsd
  aarch64-unknown-none
  aarch64-unknown-none-softfloat
  aarch64-unknown-nto-qnx700
  aarch64-unknown-nto-qnx710
  aarch64-unknown-openbsd
  aarch64-unknown-redox
  #aarch64-unknown-teeos
  aarch64-unknown-trusty
  aarch64-unknown-uefi
  aarch64-uwp-windows-msvc
  aarch64-wrs-vxworks
  aarch64_be-unknown-linux-gnu
  aarch64_be-unknown-linux-gnu_ilp32
  aarch64_be-unknown-netbsd
  arm-linux-androideabi
  arm-unknown-linux-gnueabi
  arm-unknown-linux-gnueabihf
  arm-unknown-linux-musleabi
  arm-unknown-linux-musleabihf
  arm64_32-apple-watchos
  arm64e-apple-darwin
  arm64e-apple-ios
  arm64e-apple-tvos
  arm64ec-pc-windows-msvc
  armeb-unknown-linux-gnueabi
  armebv7r-none-eabi
  armebv7r-none-eabihf
  armv4t-none-eabi
  armv4t-unknown-linux-gnueabi
  armv5te-none-eabi
  armv5te-unknown-linux-gnueabi
  armv5te-unknown-linux-musleabi
  armv5te-unknown-linux-uclibceabi
  armv6-unknown-freebsd
  armv6-unknown-netbsd-eabihf
  armv6k-nintendo-3ds
  armv7-linux-androideabi
  armv7-rtems-eabihf
  armv7-sony-vita-newlibeabihf
  armv7-unknown-freebsd
  armv7-unknown-linux-gnueabi
  armv7-unknown-linux-gnueabihf
  armv7-unknown-linux-musleabi
  armv7-unknown-linux-musleabihf
  armv7-unknown-linux-ohos
  armv7-unknown-linux-uclibceabi
  armv7-unknown-linux-uclibceabihf
  armv7-unknown-netbsd-eabihf
  armv7-unknown-trusty
  armv7-wrs-vxworks-eabihf
  armv7a-kmc-solid_asp3-eabi
  armv7a-kmc-solid_asp3-eabihf
  armv7a-none-eabi
  armv7a-none-eabihf
  armv7k-apple-watchos
  armv7r-none-eabi
  armv7r-none-eabihf
  armv7s-apple-ios
  armv8r-none-eabihf
  #avr-unknown-gnu-atmega328
  bpfeb-unknown-none
  bpfel-unknown-none
  csky-unknown-linux-gnuabiv2
  csky-unknown-linux-gnuabiv2hf
  hexagon-unknown-linux-musl
  #hexagon-unknown-none-elf
  i386-apple-ios
  #i586-pc-nto-qnx700
  i586-pc-windows-msvc
  i586-unknown-linux-gnu
  i586-unknown-linux-musl
  i586-unknown-netbsd
  i686-apple-darwin
  i686-linux-android
  i686-pc-windows-gnu
  i686-pc-windows-gnullvm
  i686-pc-windows-msvc
  i686-unknown-freebsd
  i686-unknown-haiku
  i686-unknown-hurd-gnu
  i686-unknown-linux-gnu
  i686-unknown-linux-musl
  i686-unknown-netbsd
  i686-unknown-openbsd
  i686-unknown-redox
  i686-unknown-uefi
  i686-uwp-windows-gnu
  i686-uwp-windows-msvc
  i686-win7-windows-msvc
  i686-wrs-vxworks
  loongarch64-unknown-linux-gnu
  loongarch64-unknown-linux-musl
  loongarch64-unknown-linux-ohos
  loongarch64-unknown-none
  loongarch64-unknown-none-softfloat
  #m68k-unknown-linux-gnu
  mips-unknown-linux-gnu
  mips-unknown-linux-musl
  mips-unknown-linux-uclibc
  mips64-openwrt-linux-musl
  mips64-unknown-linux-gnuabi64
  mips64-unknown-linux-muslabi64
  mips64el-unknown-linux-gnuabi64
  mips64el-unknown-linux-muslabi64
  mipsel-sony-psp
  mipsel-sony-psx
  mipsel-unknown-linux-gnu
  mipsel-unknown-linux-musl
  mipsel-unknown-linux-uclibc
  mipsel-unknown-netbsd
  mipsel-unknown-none
  mipsisa32r6-unknown-linux-gnu
  mipsisa32r6el-unknown-linux-gnu
  mipsisa64r6-unknown-linux-gnuabi64
  mipsisa64r6el-unknown-linux-gnuabi64
  msp430-none-elf
  nvptx64-nvidia-cuda
  powerpc-unknown-freebsd
  powerpc-unknown-linux-gnu
  powerpc-unknown-linux-gnuspe
  powerpc-unknown-linux-musl
  powerpc-unknown-linux-muslspe
  powerpc-unknown-netbsd
  powerpc-unknown-openbsd
  powerpc-wrs-vxworks
  powerpc-wrs-vxworks-spe
  powerpc64-ibm-aix
  powerpc64-unknown-freebsd
  powerpc64-unknown-linux-gnu
  powerpc64-unknown-linux-musl
  powerpc64-unknown-openbsd
  powerpc64-wrs-vxworks
  powerpc64le-unknown-freebsd
  powerpc64le-unknown-linux-gnu
  powerpc64le-unknown-linux-musl
  riscv32-wrs-vxworks
  riscv32e-unknown-none-elf
  riscv32em-unknown-none-elf
  riscv32emc-unknown-none-elf
  riscv32gc-unknown-linux-gnu
  riscv32gc-unknown-linux-musl
  riscv32i-unknown-none-elf
  riscv32im-risc0-zkvm-elf
  riscv32im-unknown-none-elf
  riscv32ima-unknown-none-elf
  riscv32imac-esp-espidf
  riscv32imac-unknown-none-elf
  riscv32imac-unknown-nuttx-elf
  riscv32imac-unknown-xous-elf
  riscv32imafc-esp-espidf
  riscv32imafc-unknown-none-elf
  riscv32imafc-unknown-nuttx-elf
  riscv32imc-esp-espidf
  riscv32imc-unknown-none-elf
  riscv32imc-unknown-nuttx-elf
  riscv64-linux-android
  riscv64-wrs-vxworks
  riscv64gc-unknown-freebsd
  riscv64gc-unknown-fuchsia
  riscv64gc-unknown-hermit
  riscv64gc-unknown-linux-gnu
  riscv64gc-unknown-linux-musl
  #riscv64gc-unknown-netbsd
  riscv64gc-unknown-none-elf
  riscv64gc-unknown-nuttx-elf
  riscv64gc-unknown-openbsd
  riscv64imac-unknown-none-elf
  riscv64imac-unknown-nuttx-elf
  s390x-unknown-linux-gnu
  s390x-unknown-linux-musl
  sparc-unknown-linux-gnu
  sparc-unknown-none-elf
  sparc64-unknown-linux-gnu
  sparc64-unknown-netbsd
  sparc64-unknown-openbsd
  sparcv9-sun-solaris
  thumbv4t-none-eabi
  thumbv5te-none-eabi
  thumbv6m-none-eabi
  thumbv6m-nuttx-eabi
  thumbv7a-pc-windows-msvc
  thumbv7a-uwp-windows-msvc
  thumbv7em-none-eabi
  thumbv7em-none-eabihf
  thumbv7em-nuttx-eabi
  thumbv7em-nuttx-eabihf
  thumbv7m-none-eabi
  thumbv7m-nuttx-eabi
  thumbv7neon-linux-androideabi
  thumbv7neon-unknown-linux-gnueabihf
  thumbv7neon-unknown-linux-musleabihf
  thumbv8m.base-none-eabi
  thumbv8m.base-nuttx-eabi
  thumbv8m.main-none-eabi
  thumbv8m.main-none-eabihf
  thumbv8m.main-nuttx-eabi
  thumbv8m.main-nuttx-eabihf
  wasm32-unknown-emscripten
  wasm32-unknown-unknown
  wasm32-wasip1
  wasm32-wasip1-threads
  wasm32-wasip2
  wasm32v1-none
  wasm64-unknown-unknown
  x86_64-apple-darwin
  x86_64-apple-ios
  x86_64-apple-ios-macabi
  x86_64-apple-tvos
  x86_64-apple-watchos-sim
  x86_64-fortanix-unknown-sgx
  x86_64-linux-android
  x86_64-pc-nto-qnx710
  x86_64-pc-solaris
  x86_64-pc-windows-gnu
  x86_64-pc-windows-gnullvm
  x86_64-pc-windows-msvc
  x86_64-unikraft-linux-musl
  x86_64-unknown-dragonfly
  x86_64-unknown-freebsd
  x86_64-unknown-fuchsia
  x86_64-unknown-haiku
  x86_64-unknown-hermit
  x86_64-unknown-hurd-gnu
  x86_64-unknown-illumos
  x86_64-unknown-l4re-uclibc
  x86_64-unknown-linux-gnu
  x86_64-unknown-linux-gnux32
  x86_64-unknown-linux-musl
  #x86_64-unknown-linux-none
  x86_64-unknown-linux-ohos
  x86_64-unknown-netbsd
  x86_64-unknown-none
  x86_64-unknown-openbsd
  x86_64-unknown-redox
  x86_64-unknown-trusty
  x86_64-unknown-uefi
  x86_64-uwp-windows-gnu
  x86_64-uwp-windows-msvc
  x86_64-win7-windows-msvc
  x86_64-wrs-vxworks
  x86_64h-apple-darwin
  #xtensa-esp32-espidf
  #xtensa-esp32-none-elf
  #xtensa-esp32s2-espidf
  #xtensa-esp32s2-none-elf
  #xtensa-esp32s3-espidf
  #xtensa-esp32s3-none-elf
)

# Migrate to 2018

for target in "${targets[@]}"; do
  echo "Migrating 2015 -> 2018 target $target"
  cargo fix --target "$target" -Zbuild-std=core --features extra_traits --allow-dirty --edition --broken-code 2> /dev/null
done

# Handle freebsd versions
freebsd_versions=(freebsd13 freebsd14 freebsd15)
for ver in "${freebsd_versions[@]}"; do
  echo "Migrating 2015 -> 2018 $ver"
  RUSTFLAGS="--cfg $ver" cargo fix --target i686-unknown-freebsd -Zbuild-std=core --features extra_traits --allow-dirty --edition --broken-code 2> /dev/null
  RUSTFLAGS="--cfg $ver" cargo fix --target x86_64-unknown-freebsd -Zbuild-std=core --features extra_traits --allow-dirty --edition --broken-code 2> /dev/null
done

perl -pi -077 -e 's/edition = "2015"/edition = "2018"/' Cargo.toml

# Migrate to 2021

for target in "${targets[@]}"; do
  echo "Migrating 2018 -> 2021 target $target"
  cargo fix --target "$target" -Zbuild-std=core --features extra_traits --allow-dirty --edition --broken-code 2> /dev/null
done

perl -pi -077 -e 's/edition = "2018"/edition = "2021"/' Cargo.toml

# Check
for target in "${targets[@]}"; do
  echo "Checking target $target"
  cargo check --target "$target" -Zbuild-std=core --features extra_traits || {
    echo "Failed for target $target"
    exit 1
  }
done

for ver in "${freebsd_versions[@]}"; do
  echo "Checking $ver"
  RUSTFLAGS="--cfg $ver" cargo check --target i686-unknown-freebsd -Zbuild-std=core --features extra_traits || {
    echo "Failed for i686 $freebsd_versions"
    exit 1
  }
  RUSTFLAGS="--cfg $ver" cargo check --target x86_64-unknown-freebsd -Zbuild-std=core --features extra_traits || {
    echo "Failed for x86_64 $freebsd_versions"
    exit 1
  }
done

# Fix formatting
ci/style.sh
```
@tgross35
Copy link
Contributor

Thanks for all the work here! I'll backport this and add a .git-blame-ignore-revs entry for the third commit.

tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Nov 27, 2024
… `crate::` with `::`

This is needed because ctest2 cannot parse `crate::` in paths

(backport <rust-lang#4132>)
(cherry picked from commit fda6017)
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Nov 27, 2024
(backport <rust-lang#4132>)
(cherry picked from commit 65e7837)
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Nov 27, 2024
Migration script:

```sh
set -ex

git restore Cargo.toml src

for file in $(find src -name "*.rs"); do
  perl -pi -077 -e 's/(?<!\w)::(Option|Copy|Clone)\b/$1/g' "$file"
done

implicit_c_long_ulong_char=(
  src/fuchsia/mod.rs
  src/solid/mod.rs
  src/unix/aix/mod.rs
  src/unix/bsd/apple/mod.rs
  src/unix/bsd/freebsdlike/freebsd/mod.rs
  src/unix/bsd/freebsdlike/mod.rs
  src/unix/bsd/netbsdlike/netbsd/mod.rs
  src/unix/bsd/netbsdlike/openbsd/mod.rs
  src/unix/bsd/netbsdlike/mod.rs
  src/unix/bsd/mod.rs
  src/unix/haiku/mod.rs
  src/unix/hurd/mod.rs
  src/unix/linux_like/android/b32/mod.rs
  src/unix/linux_like/android/b64/mod.rs
  src/unix/linux_like/android/mod.rs
  src/unix/linux_like/linux/gnu/b32/mod.rs
  src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs
  src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs
  src/unix/linux_like/linux/gnu/b64/mod.rs
  src/unix/linux_like/linux/gnu/mod.rs
  src/unix/linux_like/linux/musl/mod.rs
  src/unix/linux_like/linux/uclibc/mips/mod.rs
  src/unix/linux_like/linux/uclibc/mod.rs
  src/unix/linux_like/linux/mod.rs
  src/unix/linux_like/mod.rs
  src/unix/newlib/mod.rs
  src/unix/nto/mod.rs
  src/unix/mod.rs
  src/vxworks/mod.rs
)

for file in "${implicit_c_long_ulong_char[@]}"; do
  perl -pi -077 -e 's/(?<!\w)::(c_long|c_ulong|c_char)\b/$1/g' "$file"
done

implicit_off_t=(
  src/unix/linux_like/linux/gnu/mod.rs
  src/unix/linux_like/linux/mod.rs
  src/unix/linux_like/mod.rs
  src/unix/mod.rs
)

for file in "${implicit_off_t[@]}"; do
  perl -pi -077 -e 's/(?<!\w)::(off_t)\b/$1/g' "$file"
done

implicit_off64_t=(
  src/unix/linux_like/android/mod.rs
  src/unix/linux_like/mod.rs
)

for file in "${implicit_off64_t[@]}"; do
  perl -pi -077 -e 's/(?<!\w)::(off64_t)\b/$1/g' "$file"
done

implicit_Ioctl=(
  src/unix/linux_like/linux/mod.rs
)

for file in "${implicit_Ioctl[@]}"; do
  perl -pi -077 -e 's/(?<!\w)::(Ioctl)\b/$1/g' "$file"
done

perl -pi -077 -e 's/(?<!\w)::(__u8|__u16|__u32|__s16|__s32)\b/$1/g' src/unix/linux_like/linux/mod.rs

perl -pi -077 -e 's/(?<!\w)::(SIG[A-Z]+)\b/$1/g' src/unix/solarish/mod.rs

perl -pi -077 -e 's/(?<!\w)::c_ulong\b/crate::c_ulong/g' src/unix/newlib/generic.rs
perl -pi -077 -e 's/(?<!\w)::c_ulong\b/crate::c_ulong/g' src/unix/linux_like/linux/arch/generic/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_ulonglong\b/crate::c_ulonglong/g' src/unix/linux_like/linux/gnu/b64/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_ulonglong\b/crate::c_ulonglong/g' src/unix/linux_like/linux/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_ulonglong\b/crate::c_ulonglong/g' src/unix/linux_like/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_short\b/crate::c_short/g' src/unix/linux_like/linux/gnu/b32/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_short\b/crate::c_short/g' src/unix/newlib/mod.rs
perl -pi -077 -e 's/(?<!\w)::c_float\b/c_float/g' src/unix/linux_like/linux/gnu/b64/s390x.rs
perl -pi -077 -e 's/(?<!\w)::c_float\b/c_float/g' src/unix/linux_like/linux/musl/b64/s390x.rs

function handle_type() {
  type="$1"
  uses_type="$(rg -l "[^\w]::$type\b" src || echo)"
  has_type_def="$(rg -l "(type|struct) $type " src || echo)"
  has_type_import="$(rg -l "use ([0-9a-zA-Z_]+::)*$type;" src || echo)"

  add_import=($(comm -3 <(echo "$uses_type" | sort) <(printf "%s\n%s" "$has_type_def" "$has_type_import" | sort) | cut -f1))
  for file in "${add_import[@]}"; do
    # Split the file into two parts: module-level attributes and rest
    # Imports will be added after module-level attributes

    awk '/^#!|^\/\/!/ {found=NR} {lines[NR]=$0} END {for (i=1; i<=found; i++) print lines[i]}' \
      "$file" > "$file.attrs"
    awk '/^#!|^\/\/!/ {found=NR} END {if (found) {for (i=found+1; i<=NR; i++) print lines[i]} else {for (i=1; i<=NR; i++) print lines[i]}} {lines[NR]=$0}' \
      "$file" > "$file.rest"

    cat "$file.attrs" > "$file"
    echo >> "$file"
    echo 'use crate::'"$type"';' >> "$file"
    echo >> "$file"
    cat "$file.rest" >> "$file"

    rm "$file.attrs" "$file.rest"
  done

  for file in $uses_type; do
    perl -pi -077 -e 's/(?<!\w)::('"$type"')\b/$1/g' "$file"
  done
}

handle_type c_void
handle_type c_int
handle_type c_uint
handle_type c_char
handle_type c_schar
handle_type c_uchar
handle_type c_short
handle_type c_ushort
handle_type c_long
handle_type c_ulong
handle_type c_longlong
handle_type c_ulonglong
handle_type c_float
handle_type c_double
handle_type size_t
handle_type ssize_t
handle_type intptr_t
handle_type ptrdiff_t
handle_type off_t
handle_type off64_t
handle_type Ioctl
handle_type cmsghdr # To avoid "line formatted, but exceeded maximum width"

targets=(
  aarch64-apple-darwin
  aarch64-apple-ios
  aarch64-apple-ios-macabi
  aarch64-apple-ios-sim
  aarch64-apple-tvos
  aarch64-apple-tvos-sim
  aarch64-apple-visionos
  aarch64-apple-visionos-sim
  aarch64-apple-watchos
  aarch64-apple-watchos-sim
  aarch64-kmc-solid_asp3
  aarch64-linux-android
  aarch64-nintendo-switch-freestanding
  aarch64-pc-windows-gnullvm
  aarch64-pc-windows-msvc
  aarch64-unknown-freebsd
  aarch64-unknown-fuchsia
  aarch64-unknown-hermit
  aarch64-unknown-illumos
  aarch64-unknown-linux-gnu
  aarch64-unknown-linux-gnu_ilp32
  aarch64-unknown-linux-musl
  aarch64-unknown-linux-ohos
  aarch64-unknown-netbsd
  aarch64-unknown-none
  aarch64-unknown-none-softfloat
  aarch64-unknown-nto-qnx700
  aarch64-unknown-nto-qnx710
  aarch64-unknown-openbsd
  aarch64-unknown-redox
  #aarch64-unknown-teeos
  aarch64-unknown-trusty
  aarch64-unknown-uefi
  aarch64-uwp-windows-msvc
  aarch64-wrs-vxworks
  aarch64_be-unknown-linux-gnu
  aarch64_be-unknown-linux-gnu_ilp32
  aarch64_be-unknown-netbsd
  arm-linux-androideabi
  arm-unknown-linux-gnueabi
  arm-unknown-linux-gnueabihf
  arm-unknown-linux-musleabi
  arm-unknown-linux-musleabihf
  arm64_32-apple-watchos
  arm64e-apple-darwin
  arm64e-apple-ios
  arm64e-apple-tvos
  arm64ec-pc-windows-msvc
  armeb-unknown-linux-gnueabi
  armebv7r-none-eabi
  armebv7r-none-eabihf
  armv4t-none-eabi
  armv4t-unknown-linux-gnueabi
  armv5te-none-eabi
  armv5te-unknown-linux-gnueabi
  armv5te-unknown-linux-musleabi
  armv5te-unknown-linux-uclibceabi
  armv6-unknown-freebsd
  armv6-unknown-netbsd-eabihf
  armv6k-nintendo-3ds
  armv7-linux-androideabi
  armv7-rtems-eabihf
  armv7-sony-vita-newlibeabihf
  armv7-unknown-freebsd
  armv7-unknown-linux-gnueabi
  armv7-unknown-linux-gnueabihf
  armv7-unknown-linux-musleabi
  armv7-unknown-linux-musleabihf
  armv7-unknown-linux-ohos
  armv7-unknown-linux-uclibceabi
  armv7-unknown-linux-uclibceabihf
  armv7-unknown-netbsd-eabihf
  armv7-unknown-trusty
  armv7-wrs-vxworks-eabihf
  armv7a-kmc-solid_asp3-eabi
  armv7a-kmc-solid_asp3-eabihf
  armv7a-none-eabi
  armv7a-none-eabihf
  armv7k-apple-watchos
  armv7r-none-eabi
  armv7r-none-eabihf
  armv7s-apple-ios
  armv8r-none-eabihf
  #avr-unknown-gnu-atmega328
  bpfeb-unknown-none
  bpfel-unknown-none
  csky-unknown-linux-gnuabiv2
  csky-unknown-linux-gnuabiv2hf
  hexagon-unknown-linux-musl
  #hexagon-unknown-none-elf
  i386-apple-ios
  #i586-pc-nto-qnx700
  i586-pc-windows-msvc
  i586-unknown-linux-gnu
  i586-unknown-linux-musl
  i586-unknown-netbsd
  i686-apple-darwin
  i686-linux-android
  i686-pc-windows-gnu
  i686-pc-windows-gnullvm
  i686-pc-windows-msvc
  i686-unknown-freebsd
  i686-unknown-haiku
  i686-unknown-hurd-gnu
  i686-unknown-linux-gnu
  i686-unknown-linux-musl
  i686-unknown-netbsd
  i686-unknown-openbsd
  i686-unknown-redox
  i686-unknown-uefi
  i686-uwp-windows-gnu
  i686-uwp-windows-msvc
  i686-win7-windows-msvc
  i686-wrs-vxworks
  loongarch64-unknown-linux-gnu
  loongarch64-unknown-linux-musl
  loongarch64-unknown-linux-ohos
  loongarch64-unknown-none
  loongarch64-unknown-none-softfloat
  #m68k-unknown-linux-gnu
  mips-unknown-linux-gnu
  mips-unknown-linux-musl
  mips-unknown-linux-uclibc
  mips64-openwrt-linux-musl
  mips64-unknown-linux-gnuabi64
  mips64-unknown-linux-muslabi64
  mips64el-unknown-linux-gnuabi64
  mips64el-unknown-linux-muslabi64
  mipsel-sony-psp
  mipsel-sony-psx
  mipsel-unknown-linux-gnu
  mipsel-unknown-linux-musl
  mipsel-unknown-linux-uclibc
  mipsel-unknown-netbsd
  mipsel-unknown-none
  mipsisa32r6-unknown-linux-gnu
  mipsisa32r6el-unknown-linux-gnu
  mipsisa64r6-unknown-linux-gnuabi64
  mipsisa64r6el-unknown-linux-gnuabi64
  msp430-none-elf
  nvptx64-nvidia-cuda
  powerpc-unknown-freebsd
  powerpc-unknown-linux-gnu
  powerpc-unknown-linux-gnuspe
  powerpc-unknown-linux-musl
  powerpc-unknown-linux-muslspe
  powerpc-unknown-netbsd
  powerpc-unknown-openbsd
  powerpc-wrs-vxworks
  powerpc-wrs-vxworks-spe
  powerpc64-ibm-aix
  powerpc64-unknown-freebsd
  powerpc64-unknown-linux-gnu
  powerpc64-unknown-linux-musl
  powerpc64-unknown-openbsd
  powerpc64-wrs-vxworks
  powerpc64le-unknown-freebsd
  powerpc64le-unknown-linux-gnu
  powerpc64le-unknown-linux-musl
  riscv32-wrs-vxworks
  riscv32e-unknown-none-elf
  riscv32em-unknown-none-elf
  riscv32emc-unknown-none-elf
  riscv32gc-unknown-linux-gnu
  riscv32gc-unknown-linux-musl
  riscv32i-unknown-none-elf
  riscv32im-risc0-zkvm-elf
  riscv32im-unknown-none-elf
  riscv32ima-unknown-none-elf
  riscv32imac-esp-espidf
  riscv32imac-unknown-none-elf
  riscv32imac-unknown-nuttx-elf
  riscv32imac-unknown-xous-elf
  riscv32imafc-esp-espidf
  riscv32imafc-unknown-none-elf
  riscv32imafc-unknown-nuttx-elf
  riscv32imc-esp-espidf
  riscv32imc-unknown-none-elf
  riscv32imc-unknown-nuttx-elf
  riscv64-linux-android
  riscv64-wrs-vxworks
  riscv64gc-unknown-freebsd
  riscv64gc-unknown-fuchsia
  riscv64gc-unknown-hermit
  riscv64gc-unknown-linux-gnu
  riscv64gc-unknown-linux-musl
  #riscv64gc-unknown-netbsd
  riscv64gc-unknown-none-elf
  riscv64gc-unknown-nuttx-elf
  riscv64gc-unknown-openbsd
  riscv64imac-unknown-none-elf
  riscv64imac-unknown-nuttx-elf
  s390x-unknown-linux-gnu
  s390x-unknown-linux-musl
  sparc-unknown-linux-gnu
  sparc-unknown-none-elf
  sparc64-unknown-linux-gnu
  sparc64-unknown-netbsd
  sparc64-unknown-openbsd
  sparcv9-sun-solaris
  thumbv4t-none-eabi
  thumbv5te-none-eabi
  thumbv6m-none-eabi
  thumbv6m-nuttx-eabi
  thumbv7a-pc-windows-msvc
  thumbv7a-uwp-windows-msvc
  thumbv7em-none-eabi
  thumbv7em-none-eabihf
  thumbv7em-nuttx-eabi
  thumbv7em-nuttx-eabihf
  thumbv7m-none-eabi
  thumbv7m-nuttx-eabi
  thumbv7neon-linux-androideabi
  thumbv7neon-unknown-linux-gnueabihf
  thumbv7neon-unknown-linux-musleabihf
  thumbv8m.base-none-eabi
  thumbv8m.base-nuttx-eabi
  thumbv8m.main-none-eabi
  thumbv8m.main-none-eabihf
  thumbv8m.main-nuttx-eabi
  thumbv8m.main-nuttx-eabihf
  wasm32-unknown-emscripten
  wasm32-unknown-unknown
  wasm32-wasip1
  wasm32-wasip1-threads
  wasm32-wasip2
  wasm32v1-none
  wasm64-unknown-unknown
  x86_64-apple-darwin
  x86_64-apple-ios
  x86_64-apple-ios-macabi
  x86_64-apple-tvos
  x86_64-apple-watchos-sim
  x86_64-fortanix-unknown-sgx
  x86_64-linux-android
  x86_64-pc-nto-qnx710
  x86_64-pc-solaris
  x86_64-pc-windows-gnu
  x86_64-pc-windows-gnullvm
  x86_64-pc-windows-msvc
  x86_64-unikraft-linux-musl
  x86_64-unknown-dragonfly
  x86_64-unknown-freebsd
  x86_64-unknown-fuchsia
  x86_64-unknown-haiku
  x86_64-unknown-hermit
  x86_64-unknown-hurd-gnu
  x86_64-unknown-illumos
  x86_64-unknown-l4re-uclibc
  x86_64-unknown-linux-gnu
  x86_64-unknown-linux-gnux32
  x86_64-unknown-linux-musl
  #x86_64-unknown-linux-none
  x86_64-unknown-linux-ohos
  x86_64-unknown-netbsd
  x86_64-unknown-none
  x86_64-unknown-openbsd
  x86_64-unknown-redox
  x86_64-unknown-trusty
  x86_64-unknown-uefi
  x86_64-uwp-windows-gnu
  x86_64-uwp-windows-msvc
  x86_64-win7-windows-msvc
  x86_64-wrs-vxworks
  x86_64h-apple-darwin
  #xtensa-esp32-espidf
  #xtensa-esp32-none-elf
  #xtensa-esp32s2-espidf
  #xtensa-esp32s2-none-elf
  #xtensa-esp32s3-espidf
  #xtensa-esp32s3-none-elf
)

for target in "${targets[@]}"; do
  echo "Migrating 2015 -> 2018 target $target"
  cargo fix --target "$target" -Zbuild-std=core --features extra_traits --allow-dirty --edition --broken-code --lib
done

freebsd_versions=(freebsd13 freebsd14 freebsd15)
for ver in "${freebsd_versions[@]}"; do
  echo "Migrating 2015 -> 2018 $ver"
  RUSTFLAGS="--cfg $ver" cargo fix --target i686-unknown-freebsd -Zbuild-std=core --features extra_traits --allow-dirty --edition --broken-code --lib
  RUSTFLAGS="--cfg $ver" cargo fix --target x86_64-unknown-freebsd -Zbuild-std=core --features extra_traits --allow-dirty --edition --broken-code --lib
done

perl -pi -077 -e 's/edition = "2015"/edition = "2018"/' Cargo.toml

for target in "${targets[@]}"; do
  echo "Migrating 2018 -> 2021 target $target"
  cargo fix --target "$target" -Zbuild-std=core --features extra_traits --allow-dirty --edition --broken-code --lib
done

perl -pi -077 -e 's/edition = "2018"/edition = "2021"/' Cargo.toml

for target in "${targets[@]}"; do
  echo "Checking target $target"
  cargo check --target "$target" -Zbuild-std=core --features extra_traits --lib || {
    echo "Failed for target $target"
    exit 1
  }
done

for ver in "${freebsd_versions[@]}"; do
  echo "Checking $ver"
  RUSTFLAGS="--cfg $ver" cargo check --target i686-unknown-freebsd -Zbuild-std=core --features extra_traits --lib || {
    echo "Failed for i686 $freebsd_versions"
    exit 1
  }
  RUSTFLAGS="--cfg $ver" cargo check --target x86_64-unknown-freebsd -Zbuild-std=core --features extra_traits || --lib {
    echo "Failed for x86_64 $freebsd_versions"
    exit 1
  }
done

ci/style.sh
```

(backport <rust-lang#4132>)
(cherry picked from commit 20f6aa4)

[ applied by rerunning the script rather than resolving conflicts. Also
  updated the script to fail on error and to pass `--lib` so `cargo fix`
  doesn't try to upgrade anything that requires `std`. -Trevor ]
@tgross35
Copy link
Contributor

tgross35 commented Nov 27, 2024

I think the older freebsd versions that we don't test in CI might have gotten skipped. I'll make sure everything gets synced up before this makes it to a release (fyi @asomers).

Edit: opened #4159

@tgross35
Copy link
Contributor

Backported in #4155 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants