Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
46 changes: 29 additions & 17 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 <target>`). 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 ===="
Expand Down Expand Up @@ -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 @{
Expand All @@ -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 }
Expand Down
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.95"
components = ["rust-src", "rustfmt", "clippy"]
4 changes: 2 additions & 2 deletions src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ where
#[cfg(feature = "allocator_api")]
fn try_collect_in<A: Allocator>(self, alloc: A) -> Result<Vec<T, A>, 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<Vec<T>, TryReserveError> {
let mut vec = Vec::new();
vec.try_extend(self.into_iter())?;
vec.try_extend(self)?;
Ok(vec)
}
}
Loading