Vendor dependencies

This commit is contained in:
2026-08-01 16:11:49 +03:00
parent 7f139a0241
commit 6b5e7f0f8b
29706 changed files with 9575646 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
#
# Copyright 2024 The Fuchsia Authors
#
# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.
set -eo pipefail
cd "$(dirname "$0")/.."
# Check whether the set of toolchains tested in this file (other than
# 'msrv', 'stable', and 'nightly') is equal to the set of toolchains
# listed in the 'package.metadata.build-rs' section of Cargo.toml.
#
# If the inputs to `diff` are not identical, `diff` exits with a
# non-zero error code, which causes this script to fail (thanks to
# `set -e`).
diff \
<(yq -r '.jobs.build_test.strategy.matrix.toolchain | .[]' ../.github/workflows/ci.yml | \
sort -u | grep -v '^\(msrv\|stable\|nightly\)$') \
<(cargo metadata -q --format-version 1 | \
jq -r ".packages[] | select(.name == \"zerocopy\").metadata.\"build-rs\" | keys | .[]" | \
sort -u) >&2
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
#
# Copyright 2024 The Fuchsia Authors
#
# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.
set -eo pipefail
cd "$(dirname "$0")/.."
if [[ "$1" == "--fix" ]]; then
FMT_FLAGS=""
else
FMT_FLAGS="--check"
fi
find . -iname '*.rs' -type f \
-not -path './target/*' \
-not -iname '*.expected.rs' \
-not -path './vendor/*' \
-print0 | xargs -0 --no-run-if-empty ./cargo.sh +nightly fmt $FMT_FLAGS -- >&2
+73
View File
@@ -0,0 +1,73 @@
#!/usr/bin/env bash
#
# Copyright 2025 The Fuchsia Authors
#
# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.
set -eo pipefail
cd "$(dirname "$0")/.."
read -r -d '' PYTHON_SCRIPT <<'EOF' || true
import sys
import json
def parse_version(v):
"""Converts a version string to a tuple of integers."""
return tuple(map(int, v.split(".")))
def main():
"""
Checks that the package's MSRV is strictly lower than any version
specified in `package.metadata.build-rs`.
"""
try:
data = json.load(sys.stdin)
except json.JSONDecodeError as e:
print(f"Error parsing JSON from cargo metadata: {e}", file=sys.stderr)
sys.exit(1)
# Find the zerocopy package
try:
pkg = next(p for p in data["packages"] if p["name"] == "zerocopy")
except StopIteration:
print("Error: zerocopy package not found in metadata", file=sys.stderr)
sys.exit(1)
msrv_str = pkg.get("rust_version")
if not msrv_str:
print("Error: rust-version not found in Cargo.toml", file=sys.stderr)
sys.exit(1)
try:
msrv = parse_version(msrv_str)
except ValueError:
print(f"Error: Invalid MSRV format: {msrv_str}", file=sys.stderr)
sys.exit(1)
build_rs_versions = (pkg.get("metadata") or {}).get("build-rs", {})
failed = False
for name, ver_str in build_rs_versions.items():
try:
ver = parse_version(ver_str)
except ValueError:
print(f"Warning: Skipping invalid version format for {name}: {ver_str}", file=sys.stderr)
continue
# Check that MSRV < Version (strictly lower)
if not (msrv < ver):
print(f"Error: MSRV ({msrv_str}) is not strictly lower than {name} ({ver_str})", file=sys.stderr)
failed = True
if failed:
sys.exit(1)
if __name__ == "__main__":
main()
EOF
cargo metadata --format-version 1 --no-deps | python3 -c "$PYTHON_SCRIPT"
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
#
# Copyright 2024 The Fuchsia Authors
#
# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.
set -eo pipefail
cd "$(dirname "$0")/.."
# Install again in case the installation failed during the
# `generate_cache` step. We treat that step as best-effort and
# suppress all errors from it.
(
cd ..
cargo install -q cargo-readme --version 3.2.0
)
diff <(cd .. && cargo -q run --manifest-path tools/Cargo.toml -p generate-readme) README.md >&2
exit $?
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
#
# Copyright 2026 The Fuchsia Authors
#
# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.
set -eo pipefail
cd "$(dirname "$0")/.."
# Directories to search
DIRS=("tests" "zerocopy-derive/tests")
EXIT_CODE=0
for dir in "${DIRS[@]}"; do
if [ ! -d "$dir" ]; then
echo "Warning: Directory $dir does not exist, skipping." >&2
continue
fi
# Find all .stderr files
while IFS= read -r -d '' stderr_file; do
# Strip .stderr extension
base="${stderr_file%.stderr}"
# Strip toolchain suffixes
base="${base%.msrv}"
base="${base%.stable}"
base="${base%.nightly}"
# Construct the corresponding .rs file path
rs_file="${stderr_file%.stderr}.rs"
rs_file="${base}.rs"
# Check if the .rs file exists. The `-e` flag checks if file exists:
# It returns true for regular files and valid symlinks, and false for
# broken symlinks or missing files.
if [ ! -e "$rs_file" ]; then
echo "Error: Orphaned stderr file found: $stderr_file" >&2
echo " Missing regular file or valid symlink: $rs_file" >&2
EXIT_CODE=1
fi
done < <(find "$dir" -name "*.stderr" -print0)
done
if [ "$EXIT_CODE" -eq 1 ]; then
echo "Found stale .stderr files. Please delete them." >&2
fi
exit "$EXIT_CODE"
+71
View File
@@ -0,0 +1,71 @@
#!/usr/bin/env bash
#
# Copyright 2024 The Fuchsia Authors
#
# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.
set -eo pipefail
cd "$(dirname "$0")/.."
# 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"
TARGET="$2"
cargo metadata -q --format-version 1 \
| jq -r ".packages[] | select(.name == \"zerocopy\").dependencies[] | select((.name == \"zerocopy-derive\") and .kind == $KIND and .target == $TARGET).req"
}
# The non-dev dependency version (kind `null` filters out the dev
# dependency, and target `null` filters out the targeted version).
zerocopy_derive_dep_ver=$(dependency-version null null)
# The non-dev dependency, targeted version (kind `null` filters out
# the dev dependency).
zerocopy_derive_targeted_ver=$(dependency-version null '"cfg(any())"')
# The dev dependency version (kind `"dev"` selects only the dev
# dependency).
zerocopy_derive_dev_dep_ver=$(dependency-version '"dev"' null)
function assert-match {
VER_A="$1"
VER_B="$2"
SUCCESS_MSG="$3"
FAILURE_MSG="$4"
if [[ "$VER_A" == "$VER_B" ]]; then
echo "$SUCCESS_MSG" | tee -a $GITHUB_STEP_SUMMARY
else
echo "$FAILURE_MSG" | tee -a $GITHUB_STEP_SUMMARY >&2
exit 1
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)." \
"zerocopy depends upon different version of zerocopy-derive ($zerocopy_derive_dep_ver) than the one in-tree ($ver_zerocopy_derive)."
# Note the leading `=` sign - the dependency needs to be an exact one.
assert-match "=$ver_zerocopy_derive" "$zerocopy_derive_dev_dep_ver" \
"In dev mode, zerocopy depends upon same version of zerocopy-derive in-tree ($zerocopy_derive_dev_dep_ver)." \
"In dev mode, zerocopy depends upon different version of zerocopy-derive ($zerocopy_derive_dev_dep_ver) than the one in-tree ($ver_zerocopy_derive)."
assert-match "$zerocopy_derive_dep_ver" "$zerocopy_derive_targeted_ver" \
"Same crate version ($zerocopy_derive_dep_ver) found for optional and targeted zerocopy-derive dependency." \
"Different crate versions found for optional ($zerocopy_derive_dep_ver) and targeted ($zerocopy_derive_targeted_ver) dependency."
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
#
# Copyright 2024 The Fuchsia Authors
#
# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.
set -e
cd "$(dirname "$0")/.."
if [ $# -ne 1 ]; then
echo "Usage: $0 <version>" >&2
exit 1
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
# Ensure that `Cargo.lock` is updated.
cargo generate-lockfile