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

[0.2] Backports #4166

Merged
merged 9 commits into from
Nov 28, 2024
Merged

Conversation

tgross35 and others added 8 commits November 27, 2024 20:19
The Android jobs seem to occasionally get stuck. Add a timeout of 10
minutes for simple jobs and 25 minutes for more complex jobs, which
should make sure that if anything gets stuck it will get stopped.

(backport <rust-lang#4164>)
(cherry picked from commit e1fe3d8)
Since we suport multiple versions and this is tier 2, we should make
sure that we can build with a couple versions. This does not run tests.

Additionally, introduce an environment variable for an easy way to
override the version for testing.

This includes an unrelated cleanup adjustment in `verify-build.sh`

(backport <rust-lang#4159>)
(cherry picked from commit 9c2f78e)
For versions 10, 11, 12, 13, 14, 15, and architectures aarch64, i686,
powerpc64, riscv64gc, and x86_64, I ran the following:

    RUST_LIBC_UNSTABLE_FREEBSD_VERSION=15 cargo fix \
        -Zbuild-std=core \
        --features extra_traits \
        --allow-dirty \
        --edition \
        --broken-code \
        --lib \
        --target aarch64-unknown-freebsd

(backport <rust-lang#4159>)
(cherry picked from commit 2e4ac8f)

Not an exact cherry pick, I just reran the command.
I looked for `[^\w]::` and fixed them manually.

(backport <rust-lang#4162>)
(cherry picked from commit 82d30c6)
Other platforms export these types, so update Trusty to do so as well.

(backport <rust-lang#4161>)
(cherry picked from commit 6bee30e)
When building with `rustc-dep-of-std`, we don't get the core types
imported by default (`Clone`, `Copy`, `Option`). In order to avoid
needing to import these individually, introduce a prelude that includes
them, along with commonly used C numeric types.

This allows cleaning up some of the `use` statements.

(backport <rust-lang#4161>)
(cherry picked from commit 30bc78b)
Automatically apply changes with the following:

    #!/bin/bash

    set -eux

    files=()

    # Types either defined in this crate or in `core`
    prelude_types=(
        c_char
        c_double
        c_float
        c_int
        c_longlong
        c_long
        c_short
        c_uchar
        c_uint
        c_ulonglong
        c_ulong
        c_ushort
        c_void
        intptr_t
        size_t
        ssize_t
        Clone
        Copy
        Option
        Send
        Sync
    )

    # Reexports from core
    prelude_modules=(
        fmt
        hash
        iter
        mem
    )

    # Everything in the prelude
    prelude=( "${prelude_types[@]}" "${prelude_modules[@]}" )

    # Generate a list of all files excluding `lib.rs` (since the prelude being
    # defined there makes string matching weird).
    while IFS= read -r -d '' file; do
        files+=("$file")
    done < <(find src -name '*.rs' -not -name '*lib.rs' -not -name '*macros.rs' -not -name 'fixed_width_ints.rs' -print0)

    for file in "${files[@]}"; do
        needs_prelude=0

        # If the file already has some sort of glob import, skip it
        if rg --pcre2 -q 'use (crate|super)::(?!prelude).*\*' "$file"; then
            continue
        fi

        # Core types always require the prelude to handle rustc-dep-of-std
        if rg --pcre2 -q '\b(?<!\.)(Option|Clone|Copy|Send|Sync|fmt|hash|iter|mem)\b' "$file"; then
            needs_prelude=1
        fi

        # If we use any types that are specified in the prelude then we will import it
        for ty in "${prelude[@]}"; do
            # If the type is defined in the current module, we don't need it from the prelude
            if rg -q "type $ty =" "$file"; then
                continue
            fi

            if rg -qU '((crate|super)::'"$ty"'|use (crate|super)::(\{\n){0,2}.*'"$ty)" "$file"; then
                needs_prelude=1
            fi
        done

        # Check if the prelude is needed and does not already exist; if so, add it
        if [ "$needs_prelude" = "1" ] && ! rg -q 'use crate::prelude::\*' "$file"; then
            # Split the file into two parts: module-level attributes and rest
            # Imports will be added after module-level attributes

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

            printf "%s\n" "$attrs" > "$file"
            printf "\n%s\n\n" "use crate::prelude::*;" >> "$file"
            printf "%s" "$rest" >> "$file"
        fi

        for ty in "${prelude[@]}"; do
            export TY="$ty" # env for perl to use

            # Remove simple imports `use crate::ty;`
            perl -pi -0777 -e 's/use ((crate|super)::)?($ENV{TY});//g' "$file"

            # Remove the type if it is part of a group import
            perl -pi -0777 -e 's/(use (crate|super)::\{?(.*|(\n.*){0,2}))\b$ENV{TY}\b,? ?/$1/g' "$file"

            # Replace pathed `crate::ty`
            perl -pi -0777 -e 's/(crate|super)::($ENV{TY})\b/$2/g' "$file"
        done

        # For some reason, rustfmt doesn't trim leading newlines. Do so manually here.
        perl -pi -0777 -e 's/\A\n+//' "$file"

        rustfmt "$file"
    done

    ./ci/style.sh

(backport <rust-lang#4161>)
(cherry picked from commit f8a018a)

Applied by rerunning the script rather than resolving conflicts
manually.
@rustbot
Copy link
Collaborator

rustbot commented Nov 28, 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

Ignore 108310d ("Make use of the crate's prelude...") since this was
an automated refactoring that updated type paths in most files.

This is the `main` version of 744fce2 ("Add a .git-blame-ignore-revs
entry for adding the prelude").
@rustbot
Copy link
Collaborator

rustbot commented Nov 28, 2024

Some changes occurred in OpenBSD module

cc @semarie

Some changes occurred in OpenBSD module

cc @semarie

Some changes occurred in solarish module

cc @jclulow, @pfmooney

@tgross35 tgross35 enabled auto-merge November 28, 2024 01:42
@tgross35 tgross35 added this pull request to the merge queue Nov 28, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 28, 2024
@tgross35 tgross35 added this pull request to the merge queue Nov 28, 2024
Merged via the queue into rust-lang:libc-0.2 with commit 0acb8d6 Nov 28, 2024
45 checks passed
@tgross35 tgross35 deleted the backport-crate-prelude branch November 28, 2024 03:14
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