diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index eea2860..acc066a 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -24,24 +24,33 @@ jobs: target: x86_64-pc-windows-msvc - os: ubuntu-latest target: x86_64-unknown-linux-gnu + - os: windows-11-arm + target: aarch64-pc-windows-msvc + extra_target: arm64ec-pc-windows-msvc runs-on: ${{ matrix.os }} - env: - CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse steps: - name: Checkout uses: actions/checkout@v3 - # no_global_oom_handling is currently broken in 1.69: https://github.com/rust-lang/rust/pull/110649 - # So use 1.68 until it gets fixed. - - name: Update Rust toolchain - run: rustup install 1.68 + # The toolchain version and required components are defined in rust-toolchain.toml, + # which rustup uses automatically when running cargo in this repository. + - name: Install Rust toolchain from rust-toolchain.toml + run: rustup show active-toolchain || rustup toolchain install - - name: Set 1.68 as the default - run: rustup default 1.68 - - - name: Add required components - run: rustup component add rust-src clippy rustfmt rust-docs --toolchain 1.68-${{ matrix.target }} + # Install the prebuilt standard library for the matrix target. This is a no-op when the + # target matches the host (e.g. x86_64 runners, or aarch64 on the windows-11-arm runner). + - name: Add target + run: rustup target add ${{ matrix.target }} - name: Run build script shell: pwsh - run: .\build.ps1 -BuildLocked + run: .\build.ps1 -BuildLocked -Target ${{ matrix.target }} + + - name: Add extra target + if: matrix.extra_target + run: rustup target add ${{ matrix.extra_target }} + + - name: Run build script (extra target) + if: matrix.extra_target + shell: pwsh + run: .\build.ps1 -BuildLocked -Target ${{ matrix.extra_target }} diff --git a/build.ps1 b/build.ps1 index 19c0370..b3f13f2 100644 --- a/build.ps1 +++ b/build.ps1 @@ -8,19 +8,29 @@ Builds the `fallible_vec` crate, runs tests, checks formatting, runs clippy. Adds `--locked` to the build commands to prevent the `Cargo.lock` file from being updated. This is useful for CI builds. +.PARAMETER Target +The target triple to build and test for (e.g. `aarch64-pc-windows-msvc`). When omitted, the host +target is used. The required `rust-std` for the target must already be installed (e.g. via +`rustup target add `). Tests are only executed when the target can run on the host. + .NOTES See README.md for details on the environment that this script expects. #> param ( [Parameter(Mandatory = $false)] [switch] - $BuildLocked + $BuildLocked, + + [Parameter(Mandatory = $false)] + [string] + $Target ) Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' $lockedArg = $BuildLocked ? '--locked' : $null +$targetArg = $Target ? @('--target', $Target) : @() function Invoke-CheckExitCode([string] $Description, [scriptblock]$ScriptBlock) { Write-Host "==== $Description ====" @@ -77,40 +87,42 @@ Invoke-WithEnvironment ` # # Check that enabling various feature combinations works. # - Invoke-CheckExitCode 'Build default' { cargo build $lockedArg } - Invoke-CheckExitCode 'Build allocator_api only' { cargo build $lockedArg --no-default-features --features allocator_api } - Invoke-CheckExitCode 'Build use_unstable_apis only' { cargo build $lockedArg --no-default-features --features use_unstable_apis } + Invoke-CheckExitCode 'Build default' { cargo build $lockedArg $targetArg } + Invoke-CheckExitCode 'Build allocator_api only' { cargo build $lockedArg $targetArg --no-default-features --features allocator_api } + Invoke-CheckExitCode 'Build use_unstable_apis only' { cargo build $lockedArg $targetArg --no-default-features --features use_unstable_apis } # # Run tests # - Invoke-CheckExitCode 'Test' { cargo test --locked } + Invoke-CheckExitCode 'Test' { cargo test --locked $targetArg } # # Lint and check formatting. # - Invoke-CheckExitCode 'Clippy' { cargo clippy --locked -- -D warnings } + Invoke-CheckExitCode 'Clippy' { cargo clippy --locked $targetArg -- -D warnings } Invoke-CheckExitCode 'Check format' { cargo fmt --check } # # Check docs # - Invoke-CheckExitCode 'Check docs' { cargo doc --locked } + Invoke-CheckExitCode 'Check docs' { cargo doc --locked $targetArg } # # Verify that we can build with #[cfg(no_global_oom_handling)] enabled. # # Find target (required for `build-std`). - [string] $target = '' - if ($Global:IsWindows) { - $target = 'x86_64-pc-windows-msvc' - } elseif ($Global:IsLinux) { - $target = 'x86_64-unknown-linux-gnu' - } elseif ($Global:IsMacOS) { - $target = 'x86_64-apple-darwin' - } else { - throw 'Unknown OS - Only Windows, Linux and MacOS are supported' + [string] $target = $Target + if (-not $target) { + if ($Global:IsWindows) { + $target = 'x86_64-pc-windows-msvc' + } elseif ($Global:IsLinux) { + $target = 'x86_64-unknown-linux-gnu' + } elseif ($Global:IsMacOS) { + $target = 'x86_64-apple-darwin' + } else { + throw 'Unknown OS - Only Windows, Linux and MacOS are supported' + } } Invoke-WithEnvironment ` -Environment @{ @@ -124,7 +136,7 @@ Invoke-WithEnvironment ` } # Build with no features enabled (should work on the non-nightly compiler). -Invoke-CheckExitCode 'Build no features' { cargo build $lockedArg --no-default-features } +Invoke-CheckExitCode 'Build no features' { cargo build $lockedArg $targetArg --no-default-features } # Run tests under miri Invoke-CheckExitCode 'Install miri' { rustup toolchain install nightly --component miri } diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..e9b4a7e --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.95" +components = ["rust-src", "rustfmt", "clippy"] diff --git a/src/collect.rs b/src/collect.rs index 766c926..eb12096 100644 --- a/src/collect.rs +++ b/src/collect.rs @@ -53,13 +53,13 @@ where #[cfg(feature = "allocator_api")] fn try_collect_in(self, alloc: A) -> Result, TryReserveError> { let mut vec = Vec::new_in(alloc); - vec.try_extend(self.into_iter())?; + vec.try_extend(self)?; Ok(vec) } fn try_collect(self) -> Result, TryReserveError> { let mut vec = Vec::new(); - vec.try_extend(self.into_iter())?; + vec.try_extend(self)?; Ok(vec) } }