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

Use Cargo manifest workspace keys #1884

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
64 changes: 0 additions & 64 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ jobs:
# which a particular feature is supported.
"zerocopy-core-error",
"zerocopy-diagnostic-on-unimplemented",
"zerocopy-generic-bounds-in-const-fn",
"zerocopy-target-has-atomics",
"zerocopy-aarch64-simd",
"zerocopy-panic-in-const-and-vec-try-reserve"
]
target: [
"i686-unknown-linux-gnu",
Expand Down Expand Up @@ -93,14 +89,6 @@ jobs:
features: "--all-features"
- toolchain: "zerocopy-diagnostic-on-unimplemented"
features: "--all-features"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
features: "--all-features"
- toolchain: "zerocopy-target-has-atomics"
features: "--all-features"
- toolchain: "zerocopy-aarch64-simd"
features: "--all-features"
- toolchain: "zerocopy-panic-in-const-and-vec-try-reserve"
features: "--all-features"
# Exclude any combination for the zerocopy-derive crate which
# uses zerocopy features.
- crate: "zerocopy-derive"
Expand All @@ -117,36 +105,6 @@ jobs:
toolchain: "zerocopy-core-error"
- crate: "zerocopy-derive"
toolchain: "zerocopy-diagnostic-on-unimplemented"
- crate: "zerocopy-derive"
toolchain: "zerocopy-generic-bounds-in-const-fn"
- crate: "zerocopy-derive"
toolchain: "zerocopy-target-has-atomics"
- crate: "zerocopy-derive"
toolchain: "zerocopy-aarch64-simd"
- crate: "zerocopy-derive"
toolchain: "zerocopy-panic-in-const-and-vec-try-reserve"
# Exclude non-aarch64 targets from the `zerocopy-aarch64-simd`
# toolchain.
- toolchain: "zerocopy-aarch64-simd"
target: "i686-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "x86_64-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "arm-unknown-linux-gnueabi"
- toolchain: "zerocopy-aarch64-simd"
target: "powerpc-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "powerpc64-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "riscv64gc-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "s390x-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "x86_64-pc-windows-msvc"
- toolchain: "zerocopy-aarch64-simd"
target: "thumbv6m-none-eabi"
- toolchain: "zerocopy-aarch64-simd"
target: "wasm32-wasi"
# Exclude most targets targets from the `zerocopy-core-error`
# toolchain since the `zerocopy-core-error` feature is unrelated to
# compilation target. This only leaves i686 and x86_64 targets.
Expand Down Expand Up @@ -190,28 +148,6 @@ jobs:
target: "thumbv6m-none-eabi"
- toolchain: "zerocopy-diagnostic-on-unimplemented"
target: "wasm32-wasi"
# Exclude most targets targets from the
# `zerocopy-generic-bounds-in-const-fn` toolchain since the
# `zerocopy-generic-bounds-in-const-fn` feature is unrelated to
# compilation target. This only leaves i686 and x86_64 targets.
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "arm-unknown-linux-gnueabi"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "aarch64-unknown-linux-gnu"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "powerpc-unknown-linux-gnu"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "powerpc64-unknown-linux-gnu"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "riscv64gc-unknown-linux-gnu"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "s390x-unknown-linux-gnu"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "x86_64-pc-windows-msvc"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "thumbv6m-none-eabi"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "wasm32-wasi"
# Exclude `thumbv6m-none-eabi` combined with any feature that implies
# the `std` feature since `thumbv6m-none-eabi` does not include a
# pre-compiled std.
Expand Down
43 changes: 17 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@
# paths that are stable regardless of the path to the repository root. This
# avoids issues like:
# https://github.com/dtolnay/trybuild/issues/207#issuecomment-131227.594
[workspace]

[package]
[workspace.package]
edition = "2021"
name = "zerocopy"
version = "0.8.5"
authors = ["Joshua Liebow-Feeser <[email protected]>"]
description = "Zerocopy makes zero-cost memory manipulation effortless. We write \"unsafe\" so you don't have to."
version = "0.9.0-alpha.0"
categories = ["embedded", "encoding", "no-std::no-alloc", "parsing", "rust-patterns"]
keywords = ["cast", "convert", "transmute", "transmutation", "type-punning"]
license = "BSD-2-Clause OR Apache-2.0 OR MIT"
repository = "https://github.com/google/zerocopy"
rust-version = "1.56.0"

[package]
name = "zerocopy"
description = "Zerocopy makes zero-cost memory manipulation effortless. We write \"unsafe\" so you don't have to."
rust-version = "1.65.0"

edition.workspace = true
version.workspace = true
categories.workspace = true
keywords.workspace = true
license.workspace = true
repository.workspace = true

exclude = [".*"]

Expand All @@ -38,21 +44,6 @@ zerocopy-core-error = "1.81.0"
# From 1.78.0, Rust supports the `#[diagnostic::on_unimplemented]` attribute.
zerocopy-diagnostic-on-unimplemented = "1.78.0"

# From 1.61.0, Rust supports generic types with trait bounds in `const fn`.
zerocopy-generic-bounds-in-const-fn = "1.61.0"

# From 1.60.0, Rust supports `cfg(target_has_atomics)`, which allows us to
# detect whether a target supports particular sets of atomics.
zerocopy-target-has-atomics = "1.60.0"

# When the "simd" feature is enabled, include SIMD types from the
# `core::arch::aarch64` module, which was stabilized in 1.59.0. On earlier Rust
# versions, these types require the "simd-nightly" feature.
zerocopy-aarch64-simd = "1.59.0"

# Permit panicking in `const fn`s and calling `Vec::try_reserve`.
zerocopy-panic-in-const-and-vec-try-reserve = "1.57.0"

[package.metadata.ci]
# The versions of the stable and nightly compiler toolchains to use in CI.
pinned-stable = "1.81.0"
Expand All @@ -77,13 +68,13 @@ std = ["alloc"]
__internal_use_only_features_that_work_on_stable = ["alloc", "derive", "simd", "std"]

[dependencies]
zerocopy-derive = { version = "=0.8.5", path = "zerocopy-derive", optional = true }
zerocopy-derive = { version = "=0.9.0-alpha.0", path = "zerocopy-derive", optional = true }

# The "associated proc macro pattern" ensures that the versions of zerocopy and
# zerocopy-derive remain equal, even if the 'derive' feature isn't used.
# See: https://github.com/matklad/macro-dep-test
[target.'cfg(any())'.dependencies]
zerocopy-derive = { version = "=0.8.5", path = "zerocopy-derive" }
zerocopy-derive = { version = "=0.9.0-alpha.0", path = "zerocopy-derive" }

[dev-dependencies]
itertools = "0.11"
Expand All @@ -97,6 +88,6 @@ testutil = { path = "testutil" }
# CI test failures.
trybuild = { version = "=1.0.89", features = ["diff"] }
# In tests, unlike in production, zerocopy-derive is not optional
zerocopy-derive = { version = "=0.8.5", path = "zerocopy-derive" }
zerocopy-derive = { version = "=0.9.0-alpha.0", path = "zerocopy-derive" }
# TODO(#381) Remove this dependency once we have our own layout gadgets.
elain = "0.3.0"
12 changes: 0 additions & 12 deletions ci/check_versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@

set -eo pipefail

# Usage: version <crate-name>
function version {
cargo metadata -q --format-version 1 | jq -r ".packages[] | select(.name == \"$1\").version"
}

ver_zerocopy=$(version zerocopy)
ver_zerocopy_derive=$(version zerocopy-derive)

# Usage: dependency-version <kind> <target>
function dependency-version {
KIND="$1"
Expand Down Expand Up @@ -51,10 +43,6 @@ function assert-match {
fi
}

assert-match "$ver_zerocopy" "$ver_zerocopy_derive" \
"Same crate version ($ver_zerocopy) found for zerocopy and zerocopy-derive." \
"Different crate versions found for zerocopy ($ver_zerocopy) and zerocopy-derive ($ver_zerocopy_derive)."

# Note the leading `=` sign - the dependency needs to be an exact one.
assert-match "=$ver_zerocopy_derive" "$zerocopy_derive_dep_ver" \
"zerocopy depends upon same version of zerocopy-derive in-tree ($zerocopy_derive_dep_ver)." \
Expand Down
2 changes: 1 addition & 1 deletion ci/release_crate_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ fi
VERSION="$1"

sed -i -e "s/^zerocopy-derive = { version = \"=[0-9a-zA-Z\.-]*\"/zerocopy-derive = { version = \"=$VERSION\"/" Cargo.toml
sed -i -e "s/^version = \"[0-9a-zA-Z\.-]*\"/version = \"$VERSION\"/" Cargo.toml zerocopy-derive/Cargo.toml
sed -i -e "s/^version = \"[0-9a-zA-Z\.-]*\"/version = \"$VERSION\"/" Cargo.toml
59 changes: 28 additions & 31 deletions src/byteorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,33 +539,29 @@ example of how it can be used for parsing UDP packets.
}

impl<O: ByteOrder> $name<O> {
maybe_const_trait_bounded_fn! {
/// Constructs a new value, possibly performing an endianness
/// swap to guarantee that the returned value has endianness
/// `O`.
#[must_use = "has no side effects"]
#[inline(always)]
pub const fn new(n: $native) -> $name<O> {
let bytes = match O::ORDER {
Order::BigEndian => $to_be_fn(n),
Order::LittleEndian => $to_le_fn(n),
};
/// Constructs a new value, possibly performing an endianness
/// swap to guarantee that the returned value has endianness
/// `O`.
#[must_use = "has no side effects"]
#[inline(always)]
pub const fn new(n: $native) -> $name<O> {
let bytes = match O::ORDER {
Order::BigEndian => $to_be_fn(n),
Order::LittleEndian => $to_le_fn(n),
};

$name(bytes, PhantomData)
}
$name(bytes, PhantomData)
}

maybe_const_trait_bounded_fn! {
/// Returns the value as a primitive type, possibly performing
/// an endianness swap to guarantee that the return value has
/// the endianness of the native platform.
#[must_use = "has no side effects"]
#[inline(always)]
pub const fn get(self) -> $native {
match O::ORDER {
Order::BigEndian => $from_be_fn(self.0),
Order::LittleEndian => $from_le_fn(self.0),
}
/// Returns the value as a primitive type, possibly performing
/// an endianness swap to guarantee that the return value has
/// the endianness of the native platform.
#[must_use = "has no side effects"]
#[inline(always)]
pub const fn get(self) -> $native {
match O::ORDER {
Order::BigEndian => $from_be_fn(self.0),
Order::LittleEndian => $from_le_fn(self.0),
}
}

Expand Down Expand Up @@ -971,6 +967,7 @@ module!(network_endian, NetworkEndian, "network-endian");
module!(native_endian, NativeEndian, "native-endian");

#[cfg(any(test, kani))]
#[allow(clippy::missing_const_for_fn)]
mod tests {
use super::*;

Expand Down Expand Up @@ -1057,8 +1054,8 @@ mod tests {
/// themselves. This method is like `assert_eq!`, but it treats NaN
/// values as equal.
fn assert_eq_or_nan(self, other: Self) {
let slf = (!self.is_nan()).then(|| self);
let other = (!other.is_nan()).then(|| other);
let slf = (!self.is_nan()).then_some(self);
let other = (!other.is_nan()).then_some(other);
assert_eq!(slf, other);
}
}
Expand Down Expand Up @@ -1088,8 +1085,8 @@ mod tests {
/// themselves. This method is like `assert_eq!`, but it treats NaN
/// values as equal.
fn assert_eq_or_nan(self, other: Self) {
let slf = (!self.get().is_nan()).then(|| self);
let other = (!other.get().is_nan()).then(|| other);
let slf = (!self.get().is_nan()).then_some(self);
let other = (!other.get().is_nan()).then_some(other);
assert_eq!(slf, other);
}
}
Expand Down Expand Up @@ -1396,11 +1393,11 @@ mod tests {
// For `f32` and `f64`, NaN values are not considered equal to
// themselves. We store `Option<f32>`/`Option<f64>` and store
// NaN as `None` so they can still be compared.
let val_or_none = |t: T| (!T::Native::is_nan(t.get())).then(|| t.get());
let val_or_none = |t: T| (!T::Native::is_nan(t.get())).then_some(t.get());
let t_t_res = val_or_none(t_t_res);
let t_n_res = val_or_none(t_n_res);
let n_t_res = val_or_none(n_t_res);
let n_n_res = (!T::Native::is_nan(n_n_res)).then(|| n_n_res);
let n_n_res = (!T::Native::is_nan(n_n_res)).then_some(n_n_res);
assert_eq!(t_t_res, n_n_res);
assert_eq!(t_n_res, n_n_res);
assert_eq!(n_t_res, n_n_res);
Expand All @@ -1418,7 +1415,7 @@ mod tests {
// NaN as `None` so they can still be compared.
let t_t_res = val_or_none(t_t_res);
let t_n_res = val_or_none(t_n_res);
let n_t_res = (!T::Native::is_nan(n_t_res)).then(|| n_t_res);
let n_t_res = (!T::Native::is_nan(n_t_res)).then_some(n_t_res);
assert_eq!(t_t_res, n_n_res);
assert_eq!(t_n_res, n_n_res);
assert_eq!(n_t_res, n_n_res);
Expand Down
7 changes: 4 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl<Src, Dst: ?Sized> AlignmentError<Src, Dst> {
AlignmentError { src: f(self.src), dst: SendSyncPhantomData::default() }
}

pub(crate) fn into<S, V>(self) -> ConvertError<Self, S, V> {
pub(crate) const fn into<S, V>(self) -> ConvertError<Self, S, V> {
ConvertError::Alignment(self)
}

Expand Down Expand Up @@ -463,7 +463,7 @@ impl<Src, Dst: ?Sized> SizeError<Src, Dst> {
}

/// Converts the error into a general [`ConvertError`].
pub(crate) fn into<A, V>(self) -> ConvertError<A, Self, V> {
pub(crate) const fn into<A, V>(self) -> ConvertError<A, Self, V> {
ConvertError::Size(self)
}

Expand Down Expand Up @@ -595,7 +595,7 @@ impl<Src, Dst: ?Sized + TryFromBytes> ValidityError<Src, Dst> {
}

/// Converts the error into a general [`ConvertError`].
pub(crate) fn into<A, S>(self) -> ConvertError<A, S, Self> {
pub(crate) const fn into<A, S>(self) -> ConvertError<A, S, Self> {
ConvertError::Validity(self)
}

Expand Down Expand Up @@ -957,6 +957,7 @@ pub type AlignedTryCastError<Src, Dst: ?Sized + TryFromBytes> =
pub struct AllocError;

#[cfg(test)]
#[allow(clippy::missing_const_for_fn)]
mod tests {
use super::*;

Expand Down
18 changes: 7 additions & 11 deletions src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,12 @@ safety_comment! {
unsafe_impl_for_power_set!(A, B, C, D, E, F, G, H, I, J, K, L -> M => Immutable for opt_extern_c_fn!(...));
}

#[cfg(all(
zerocopy_target_has_atomics,
any(
target_has_atomic = "8",
target_has_atomic = "16",
target_has_atomic = "32",
target_has_atomic = "64",
target_has_atomic = "ptr"
)
#[cfg(any(
target_has_atomic = "8",
target_has_atomic = "16",
target_has_atomic = "32",
target_has_atomic = "64",
target_has_atomic = "ptr"
))]
mod atomics {
use super::*;
Expand Down Expand Up @@ -933,7 +930,6 @@ mod simd {
#[cfg(all(feature = "simd-nightly", target_arch = "powerpc64"))]
powerpc64, powerpc64, vector_bool_long, vector_double, vector_signed_long, vector_unsigned_long
);
#[cfg(zerocopy_aarch64_simd)]
simd_arch_mod!(
// NOTE(https://github.com/rust-lang/stdarch/issues/1484): NEON intrinsics are currently
// broken on big-endian platforms.
Expand Down Expand Up @@ -1882,7 +1878,7 @@ mod tests {
vector_signed_long,
vector_unsigned_long
);
#[cfg(all(target_arch = "aarch64", zerocopy_aarch64_simd))]
#[cfg(target_arch = "aarch64")]
#[rustfmt::skip]
test_simd_arch_mod!(
aarch64, float32x2_t, float32x4_t, float64x1_t, float64x2_t, int8x8_t, int8x8x2_t,
Expand Down
Loading