io-lifetimes and rustix and a few other crates I maintain have similar
build.rs scripts. Port some of the changes from rustix to io-lifetimes
to keep them in sync.
- Add `#![allow(stable_features)]` to the `has_feature` code to allow
it to detect features that have gotten stablized.
- Redirect feature-detection stderr to null, as it's confusing.
- Rename `test_program` to `can_compile`.
compiling rust programs in yocto uses a custom
target triple with a custom sysroot
not specifying the sysroot when executing rustc
can lead to errors like "can't find crate for `std`"
this patch forwards the sysroot for testing features
Add `#![cfg(any(unix, windows, target_os = "wasi"))]` to the top-level
lib.rs so that io-lifetimes can appear as a dependency on platforms even
when it doesn't have support for them.
* Remove use of `rustc_attrs`, which is no longer needed.
This io-lifetimes crate no longer needs this rustc_attrs code. On Rust
versions where io_safety is stabilized, we use the version in std (which
uses rustc_attrs internally). On Rust versions where it's not, rustc_attrs
isn't available to user code anyway, since it's not a stable language
feature.
This might fix#51.
* Rename `io_lifetimes_use_std` to `io_safety_is_in_std`.
This may also help fix#51.
* Disable async-std and other dependencies on WASI.
Move the async-std, tokio, socket2, and mio dependencies into a
`not(target_os = "wasi")` dependency section. This fixes the problem
that the default features in async-std, which we need, depend on
socket2, which doesn't work on WASI yet.
The tradeoff here is that WASI users won't be able to make use of
io-lifetimes' impls for these third-party crate types. But we are
working to add these traits upstream, which will eventually make
this unnecessary.
* Add testing on Rust 1.48.
* Add an MSRV note to README.md.
* Disable deprecation warnings in impls_std.rs.
* Update for io_safety being stabilized.
io_safety is now [stable in Rust 1.63]! This PR updates io-lifetimes to
use the standard library types and traits when available, and use its
own types and traits on older Rust versions.
The traits `FromFd` and `IntoFd` are now marked as deprecated. These are
replaced by `From<OwnedFd>` and `From<...> for OwnedFd` in the standard
library, and users should migrate accordingly.
[stable in Rust 1.63]: https://blog.rust-lang.org/2022/08/11/Rust-1.63.0.html#rust-ownership-for-raw-file-descriptorshandles-io-safety
* Disable deprecation warnings for our own uses of `FromFd` and `IntoFd`.
And, migrate the portability types and traits to use `From<OwnedFd>`
and `Into<OwnedFd>`.
* Deprecate the `from_fd` function, rather than the `FromFd` trait.
This allows the `from_into_fd` extension to continue working, for now.
The std implementation uses `From` impls instead of `FromFd`/`IntoFd`.
io-lifetimes continues to support `FromFd`/`IntoFd` so that it can add
impls for third-party types. But for users who don't need that, add
the same `From` impls that std has.
* Make views require dedicated `unsafe` marker traits.
Requiring `Into` and `From` conversions is not sufficient for
`FilelikeView` and `SocketlikeView`, becuase there's no guarantee
that the `Into` implementation will return the same handle as the `From`
implementation. If a type allows its handle to be reassigned, that
can lead to the old handle being freed twice, and the new handle being
leaked.
To fix this, introduce unsafe marker traits `FilelikeViewType` and
`SocketlikeViewType`, and have `FilelikeView` and `SocketlikeView`
require these traits.
* Fix io_lifetimes_use_std compilation.
* Remove the `DerefMut` from the view types.
* Add API tests for the `&*` idiom for using `Read` and `Write`.
* Add a debug check for views checking that they return the same handle.
* Use `ManuallyDrop` to avoid needing `Option` in the view types.
`ManuallyDrop::take` allows the view types to properly consume their temporary
objects without needing an `.unwrap()`.
* Clarify what values BorrowedHandle, OwnedHandle etc. can hold.
This ports the documentation updates from rust-lang/rust#96932.
* Relax the wording about the meaning of -1.
This corresponds to rust-lang/rust#96232.
Also, update the documentation and remove the assert from
`BorrowedHandle::borrow_raw` to match what's in std: `BorrowedHandle`
can hold NULL pointers.