diff -Nru rust-peg-0.8.1/Cargo.lock rust-peg-0.8.2/Cargo.lock --- rust-peg-0.8.1/Cargo.lock 2022-09-25 23:48:31.000000000 +0000 +++ rust-peg-0.8.2/Cargo.lock 2023-10-10 01:18:35.000000000 +0000 @@ -3,6 +3,15 @@ version = 3 [[package]] +name = "basic-toml" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c0de75129aa8d0cceaf750b89013f0e08804d6ec61416da787b35ad0d7cddf1" +dependencies = [ + "serde", +] + +[[package]] name = "glob" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -15,23 +24,24 @@ checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" [[package]] -name = "lazy_static" -version = "1.4.0" +name = "once_cell" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] name = "peg" -version = "0.8.1" +version = "0.8.2" dependencies = [ "peg-macros", "peg-runtime", "trybuild", + "version_check", ] [[package]] name = "peg-macros" -version = "0.8.1" +version = "0.8.2" dependencies = [ "peg-runtime", "proc-macro2", @@ -40,22 +50,22 @@ [[package]] name = "peg-runtime" -version = "0.8.1" +version = "0.8.2" [[package]] name = "proc-macro2" -version = "1.0.24" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.7" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] @@ -68,18 +78,15 @@ [[package]] name = "serde" -version = "1.0.115" +version = "1.0.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5" -dependencies = [ - "serde_derive", -] +checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" [[package]] name = "serde_derive" -version = "1.0.115" +version = "1.0.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" +checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" dependencies = [ "proc-macro2", "quote", @@ -99,13 +106,13 @@ [[package]] name = "syn" -version = "1.0.39" +version = "2.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891d8d6567fe7c7f8835a3a98af4208f3846fba258c1bc3c31d6e506239f11f9" +checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] @@ -118,33 +125,31 @@ ] [[package]] -name = "toml" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a" -dependencies = [ - "serde", -] - -[[package]] name = "trybuild" -version = "1.0.33" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48105a4deaf74163c017939b45ef7322fba46e8b17281528039b0beb04235e92" +checksum = "501dbdbb99861e4ab6b60eb6a7493956a9defb644fd034bc4a5ef27c693c8a3a" dependencies = [ + "basic-toml", "glob", - "lazy_static", + "once_cell", "serde", + "serde_derive", "serde_json", "termcolor", - "toml", ] [[package]] -name = "unicode-xid" -version = "0.2.1" +name = "unicode-ident" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" + +[[package]] +name = "version_check" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "winapi" diff -Nru rust-peg-0.8.1/Cargo.toml rust-peg-0.8.2/Cargo.toml --- rust-peg-0.8.1/Cargo.toml 2022-09-25 23:48:31.000000000 +0000 +++ rust-peg-0.8.2/Cargo.toml 2023-10-10 01:18:35.000000000 +0000 @@ -3,7 +3,7 @@ [package] name = "peg" -version = "0.8.1" +version = "0.8.2" authors = [ "Kevin Mehall " ] license = "MIT" repository = "https://github.com/kevinmehall/rust-peg" @@ -12,13 +12,15 @@ categories = ["parsing"] readme = "README.md" edition = "2018" +rust-version = "1.68.0" # if changed, also update .github/workflows/rust.yml [dependencies] -peg-macros = { path = "./peg-macros", version = "= 0.8.1" } -peg-runtime = { path = "./peg-runtime", version = "= 0.8.1" } +peg-macros = { path = "./peg-macros", version = "= 0.8.2" } +peg-runtime = { path = "./peg-runtime", version = "= 0.8.2" } [dev-dependencies] -trybuild = "1.0" +trybuild = "1.0.80" +version_check = "0.9" [[test]] name = "trybuild" @@ -26,4 +28,7 @@ harness = false [features] +default = ["std"] trace = ["peg-macros/trace"] +std = ["peg-runtime/std"] +unstable = ["peg-runtime/unstable"] \ No newline at end of file diff -Nru rust-peg-0.8.1/debian/changelog rust-peg-0.8.2/debian/changelog --- rust-peg-0.8.1/debian/changelog 2023-06-28 12:35:12.000000000 +0000 +++ rust-peg-0.8.2/debian/changelog 2023-10-16 16:10:34.000000000 +0000 @@ -1,3 +1,26 @@ +rust-peg (0.8.2-1) unstable; urgency=medium + + [ upstream ] + * new release + + [ Jonas Smedegaard ] + * bump project version in virtual packages and autopkgtests + * add patch 2001 to avoid feature unstable + * build- and autopkgtest-depend on package for crate version_check + * autopkgtest-depend on feature-specific packages + * provide and autopkgtest features std trace + * update dh-cargo fork + * update copyright info: update coverage + + -- Jonas Smedegaard Mon, 16 Oct 2023 18:10:34 +0200 + +rust-peg (0.8.1-4) unstable; urgency=medium + + * update dh-cargo fork; + closes: bug#1047410, thanks to Lucas Nussbaum + + -- Jonas Smedegaard Sat, 19 Aug 2023 23:28:42 +0200 + rust-peg (0.8.1-3) unstable; urgency=medium * add patch 1001 to drop tests using unstable syntax now gone diff -Nru rust-peg-0.8.1/debian/control rust-peg-0.8.2/debian/control --- rust-peg-0.8.1/debian/control 2023-05-27 07:17:47.000000000 +0000 +++ rust-peg-0.8.2/debian/control 2023-10-16 15:47:20.000000000 +0000 @@ -7,6 +7,7 @@ librust-quote-1+default-dev , librust-proc-macro2-1+default-dev (>= 1.0.24) , librust-trybuild-1+default-dev , + librust-version-check-0.9+default-dev , libstring-shellquote-perl, Maintainer: Jonas Smedegaard Standards-Version: 4.6.2 @@ -25,9 +26,10 @@ Provides: librust-peg-0-dev (= ${binary:Version}), librust-peg-0.8+default-dev (= ${binary:Version}), + librust-peg-0.8+std-dev (= ${binary:Version}), librust-peg-0.8+trace-dev (= ${binary:Version}), librust-peg-0.8-dev (= ${binary:Version}), - librust-peg-0.8.1-dev (= ${binary:Version}), + librust-peg-0.8.2-dev (= ${binary:Version}), Description: simple Parsing Expression Grammar (PEG) parser generator rust-peg is a simple yet flexible parser generator that makes it easy to write robust parsers. @@ -51,8 +53,9 @@ Provides: librust-peg-macros-0-dev (= ${binary:Version}), librust-peg-macros-0.8+default-dev (= ${binary:Version}), + librust-peg-macros-0.8+trace-dev (= ${binary:Version}), librust-peg-macros-0.8-dev (= ${binary:Version}), - librust-peg-macros-0.8.1-dev (= ${binary:Version}), + librust-peg-macros-0.8.2-dev (= ${binary:Version}), Description: simple Parsing Expression Grammar (PEG) parser generator - macros rust-peg is a simple yet flexible parser generator that makes it easy to write robust parsers. @@ -73,8 +76,9 @@ Provides: librust-peg-runtime-0-dev (= ${binary:Version}), librust-peg-runtime-0.8+default-dev (= ${binary:Version}), + librust-peg-runtime-0.8+std-dev (= ${binary:Version}), librust-peg-runtime-0.8-dev (= ${binary:Version}), - librust-peg-runtime-0.8.1-dev (= ${binary:Version}), + librust-peg-runtime-0.8.2-dev (= ${binary:Version}), Description: simple Parsing Expression Grammar (PEG) parser generator - runtime rust-peg is a simple yet flexible parser generator that makes it easy to write robust parsers. diff -Nru rust-peg-0.8.1/debian/copyright rust-peg-0.8.2/debian/copyright --- rust-peg-0.8.1/debian/copyright 2023-05-27 07:06:48.000000000 +0000 +++ rust-peg-0.8.2/debian/copyright 2023-10-16 16:10:03.000000000 +0000 @@ -31,7 +31,7 @@ Reference: debian/copyright Files: - debian/debcargo/bin/cargo + debian/dh-cargo/bin/cargo Copyright: 2022 Jonas Smedegaard 2015-2016 Luca Bruno @@ -40,11 +40,13 @@ License: Apache-2.0 or Expat Files: + debian/dh-cargo/bin/dh-cargo-built-using debian/debcargo/lib/* Copyright: 2022-2023 Jonas Smedegaard 2016 Josh Triplett - 2018 Ximin Luo + 2019-2021 Sylvestre Ledru + 2018-2021 Ximin Luo License: Expat License: Apache-2.0 diff -Nru rust-peg-0.8.1/debian/copyright_hints rust-peg-0.8.2/debian/copyright_hints --- rust-peg-0.8.1/debian/copyright_hints 2023-06-28 12:21:02.000000000 +0000 +++ rust-peg-0.8.2/debian/copyright_hints 2023-10-16 16:10:14.000000000 +0000 @@ -15,6 +15,8 @@ debian/dh-cargo/README.md debian/gbp.conf debian/patches/1001_unstable_gone_syntax.patch + debian/patches/1002_failure_tests.patch + debian/patches/2001_no_feature_unstable.patch debian/patches/README debian/patches/series debian/rules @@ -79,9 +81,11 @@ tests/run-pass/position.rs tests/run-pass/renamed_imports.rs tests/run-pass/repeats.rs + tests/run-pass/return_type.rs tests/run-pass/rule_args.rs tests/run-pass/test-hygiene.rs tests/run-pass/tokens.rs + tests/run-pass/tokens_struct.rs tests/run-pass/utf8.rs tests/trybuild.rs Copyright: NONE @@ -92,16 +96,25 @@ Copyright: 2015-2016, Luca Bruno 2016-2019, Ximin Luo 2017-2019, Vasudeva Kamath + 2022, Jonas Smedegaard License: Apache-2.0 FIXME Files: debian/dh-cargo/lib/Debian/Debhelper/Buildsystem/cargo.pm Copyright: 2016, Josh Triplett - 2018, Ximin Luo + 2018-2021, Ximin Luo + 2019-2021, Sylvestre Ledru 2022-2023, Jonas Smedegaard License: Expat FIXME +Files: debian/dh-cargo/bin/dh-cargo-built-using +Copyright: 2018-2021, Ximin Luo + 2023, Jonas Smedegaard + file +License: Expat + FIXME + Files: LICENSE Copyright: 2013, Kevin Mehall License: Expat diff -Nru rust-peg-0.8.1/debian/dh-cargo/bin/cargo rust-peg-0.8.2/debian/dh-cargo/bin/cargo --- rust-peg-0.8.1/debian/dh-cargo/bin/cargo 2023-01-25 15:45:55.000000000 +0000 +++ rust-peg-0.8.2/debian/dh-cargo/bin/cargo 2023-09-21 13:43:46.000000000 +0000 @@ -2,9 +2,10 @@ """ Wrapper around cargo to have it build using Debian settings. +SPDX-FileCopyrightText: 2022 Jonas Smedegaard SPDX-FileCopyrightText: 2015-2016 Luca Bruno -SPDX-FileCopyrightText: 2016-2019 Ximin Luo SPDX-FileCopyrightText: 2017-2019 Vasudeva Kamath +SPDX-FileCopyrightText: 2016-2019 Ximin Luo SPDX-License-Identifier: Apache-2.0 or MIT @@ -175,9 +176,20 @@ build_profiles = os.getenv("DEB_BUILD_PROFILES", "").split() parallel = [] + lto = 0 for o in build_options: if o.startswith("parallel="): parallel = ["-j" + o[9:]] + elif o.startswith("optimize="): + opt_arg = o[9:] + for arg in opt_arg.split(","): + if opt_arg == "-lto": + lto = -1 + elif opt_arg == "+lto": + lto = 1 + else: + log(f"WARNING: unhandled optimization flag: {opt_arg}") + nodoc = "nodoc" in build_options or "nodoc" in build_profiles nocheck = "nocheck" in build_options or "nocheck" in build_profiles noopt = "noopt" in build_options @@ -190,7 +202,7 @@ host_rust_type = os.getenv("DEB_HOST_RUST_TYPE", "") host_gnu_type = os.getenv("DEB_HOST_GNU_TYPE", "") - log("options, profiles, parallel:", build_options, build_profiles, parallel) + log("options, profiles, parallel, lto:", build_options, build_profiles, parallel, lto) log("rust_type, gnu_type:", ", ".join([host_rust_type, host_gnu_type])) if "RUSTFLAGS" in os.environ: @@ -222,11 +234,14 @@ newargs.append("--release") elif noopt and subcmd == "install": newargs.append("--debug") - elif (subcmd is None) and (a in ("check", "clean", "run")): + elif (subcmd is None) and (a in ("check", "run")): subcmd = a newargs.extend([a] + verbose) if not noopt: newargs.append("--release") + elif (subcmd is None) and (a == "clean"): + subcmd = a + newargs.extend([a] + verbose) else: newargs.append(a) @@ -238,6 +253,11 @@ if nocheck and subcmd in ("test", "bench"): return 0 + if lto == 1: + newargs.append("--config profile.release.lto = \"thin\"") + elif lto == -1: + newargs.append("--config profile.release.lto = false") + if subcmd == "clean": logrun(["env", "RUST_BACKTRACE=1", "/usr/bin/cargo"] + list(newargs), check=True) if os.path.exists(cargo_home): diff -Nru rust-peg-0.8.1/debian/dh-cargo/bin/dh-cargo-built-using rust-peg-0.8.2/debian/dh-cargo/bin/dh-cargo-built-using --- rust-peg-0.8.1/debian/dh-cargo/bin/dh-cargo-built-using 1970-01-01 00:00:00.000000000 +0000 +++ rust-peg-0.8.2/debian/dh-cargo/bin/dh-cargo-built-using 2023-09-21 13:43:46.000000000 +0000 @@ -0,0 +1,179 @@ +#!/bin/sh +# Generates Built-Using after a successful cargo build. +# Run this in the package top-level directory where debian/ is. +# +# SPDX-FileCopyrightText: 2023 Jonas Smedegaard +# SPDX-FileCopyrightText: 2018-2021 Ximin Luo +# +# SPDX-License-Identifier: MIT + +set -e + +CARGO_MANIFEST_DIR="${CARGO_MANIFEST_DIR:-.}" +DEB_HOST_RUST_TYPE="${DEB_HOST_RUST_TYPE:-$(printf "include /usr/share/rustc/architecture.mk\nall:\n\techo \$(DEB_HOST_RUST_TYPE)\n" | make --no-print-directory -sf -)}" +CARGO_REGISTRY="${CARGO_REGISTRY:-debian/cargo_registry}" +CARGO_CHANNEL="${CARGO_CHANNEL:-release}" +# useful for testing: +# CARGO_REGISTRY="$HOME/.cargo/registry/src/github.com-1ecc6299db9ec823" DEB_HOST_RUST_TYPE="." CARGO_CHANNEL=debug + +CARGO_TARGET_DIR="$CARGO_MANIFEST_DIR/target/$DEB_HOST_RUST_TYPE/$CARGO_CHANNEL" +CARGO_TARGET_DIR_ABS="$(readlink -f "$CARGO_TARGET_DIR")" + +CPRIGHT_FORMAT="https://www.debian.org/doc/packaging-manuals/copyright-format/1.0" +SRCLEFT_LICENSES="$(echo GPL LGPL AGPL GFDL MPL CDDL CPL Artistic Perl QPL | tr ' ' '\n')" +pkg_has_srcleft_license() { + local pkg="$1" + local ver="$2" + local f="/usr/share/doc/$pkg/copyright" + if ! sed -nre 's ^Format: (.*) \1 gp' "$f" | grep -qiw "$CPRIGHT_FORMAT"; then + echo >&2 "$0: abort: Not in machine-readable format: $f" + echo 2 + elif sed -nre 's ^X-Binary-Requires-Source: (.*) \1 gp' "$f" | grep -qiw yes; then + echo 1 + elif sed -nre 's ^License: (.*) \1 gp' "$f" | grep -qiwF "$SRCLEFT_LICENSES"; then + echo 1 + else + echo 0 + fi +} + +dep_files_to_pkgs() { + xargs -r dpkg -S \ + | sed -nre 's (.*): .* \1 gp' \ + | xargs -r dpkg-query --show \ + | while read pkg ver; do echo "$pkg $ver $(pkg_has_srcleft_license "${pkg%:*}" "$ver")"; done + # pkg_has_srcleft_license should be accurate for all rust crates, no need to give a $containing_crate + # this is due to nature of crate copyright info, and the debian rust packaging policy +} + +rust_dep_files() { + cat "$CARGO_TARGET_DIR/deps"/*.d \ + | sed -nre 's ^\S*/('"$CARGO_REGISTRY"'/[^/]*)/.* '"$(readlink -f "$PWD")/"'\1 gp' \ + | sort -u \ + | xargs -r readlink -f +} + +rust_libs() { + { which rustc; rust_dep_files; } | dep_files_to_pkgs +} + +gcc_default_searchdirs() { + gcc -print-search-dirs \ + | sed -nre 's ^libraries: (.*) \1 gp' \ + | tr ':' '\n' \ + | sed -e 's ^= '"$(gcc -print-sysroot)"' g' \ + | xargs readlink -m 2>/dev/null # suppress errors caused by early pipe closure +} + +rust_search_lib() { + local lib="$1" + { + cat + # rust does not actually search normal paths when linking static libs + # - see https://github.com/rust-lang/rust/issues/43118 + # - see also `fn link_rlib` in back/link.rs which calls + # `pub fn find_library` in back/archive.rs which generates the error message + #gcc_default_searchdirs + } | while read searchdir; do + #echo >&2 "searching $searchdir for static lib $lib" + local f="$(readlink -m "$searchdir/lib${lib}.a")" + if test -f "$f"; then + printf "%s\n" "$f" + break + fi + done +} + +native_libs() { + ls -1d "$CARGO_TARGET_DIR/build"/*/output 2>/dev/null | while read output; do + sed -nre 's ^cargo:rustc-link-lib=static=(.*) \1 '"$output"' gp' "$output" + done | while read lib output; do + local containing_crate="$(basename "$(dirname "$output")")" + test -n "$lib" || continue + local libfile="$(sed -nre 's ^cargo:rustc-link-search=native=(.*) \1 gp' "$output" | rust_search_lib "$lib")" + local srcleft="" + test -n "$libfile" || { echo >&2 "$0: abort: could not find static lib '$lib'; rustc should have failed already?"; exit 1; } + echo >&2 "$0: found static lib $lib at $libfile" + if [ "${libfile#$CARGO_TARGET_DIR_ABS/}" != "$libfile" ]; then + # static library source code embedded in crate + local srcstat="$(sed -nre 's ^dh-cargo:deb-built-using='"$lib"'=([01]=.*) \1 gp' "$output")" + case "$srcstat" in + 0=*|1=*) + srcleft="${srcstat%%=*}" + libfile="${srcstat#*=}" + if [ "$(readlink -f "$libfile")" = "$(readlink -f "$PWD")" ]; then + # Note that this exception only applies in the case that where you are building + # the Debian package for $containing_crate itself. In the case where you are + # building a Debian package for crate X depending on $containing_crate, the + # latter still has to output the dh-cargo:deb-built-using in their build.rs so + # that the Debian package for crate X can correctly set Built-Using themselves. + echo >&2 "$0: static library derived from $libfile which is the top-level crate being built, no need to add Built-Using" + continue + fi + ;; + *) + echo >&2 "$0: abort: could not determine source-distribution conditions of ${libfile#$CARGO_TARGET_DIR_ABS/}." + echo >&2 "You must patch build.rs of ${containing_crate%-*} to output 'println!(\"dh-cargo:deb-built-using=$lib=\$s={}\", env::var(\"CARGO_MANIFEST_DIR\").unwrap());' where:" + echo >&2 "- \$s is 1 if the license(s) of the included static libs require source distribution alongside binaries, otherwise 0" + exit 1 + ;; + esac + fi + local wpkg="$(dpkg -S "$(readlink -f "$libfile")")" + test -n "$wpkg" || { echo >&2 "$0: abort: could not find Debian package for file $libfile"; exit 1; } + local pkgstat="$(echo "$wpkg" | sed -nre 's (.*): .* \1 gp' | xargs -r dpkg-query --show)" + local pkg="$(echo "$pkgstat" | cut -f1)" + local ver="$(echo "$pkgstat" | cut -f2)" + # static library source code embedded in crate (from earlier) + if [ -n "$srcleft" ]; then + echo "$pkg $ver $srcleft" + # static libraries from another Debian package + elif sed -nre 's ^dh-cargo:deb-built-using='"$lib"'=0~=(.*) \1 gp' "$output" | { echo "${pkg%:*} $ver" | grep -qExf /dev/fd/3; } 3<&0; then + echo "$pkg $ver 0" + elif sed -nre 's ^dh-cargo:deb-built-using='"$lib"'=1~=(.*) \1 gp' "$output" | { echo "${pkg%:*} $ver" | grep -qExf /dev/fd/3; } 3<&0; then + echo "$pkg $ver 1" + else + # guess the conditions based on the whole d/copyright file + # this loses granularity, e.g. gcc is mostly distributed as GPL-3 but the libbacktrace portion is BSD-3 + # to retain granularity the crate package maintainer should patch build.rs as suggested + echo >&2 "$0: warning: guessing source-distribution conditions of $libfile, this may be inaccurate." + echo >&2 "$0: warning: patch build.rs to suppress the above warning" + srcleft="$(pkg_has_srcleft_license "${pkg%:*}" "$ver")" + if [ "$srcleft" -gt 1 ]; then + echo >&2 "You must patch build.rs of ${containing_crate%-*} to output 'dh-cargo:deb-built-using=$lib=\$s~=\$PAT' where:" + echo >&2 "- \$s is 1 if the license(s) of the included static libs require source distribution alongside binaries, otherwise 0" + echo >&2 "- \$PAT is an egrep pattern matching the \"\$pkg \$ver\" combinations that satisfy \$s" + echo >&2 " for example '$pkg .*' matches the currently-relevant package, $pkg $ver" + exit 1 + fi + echo "$pkg $ver $srcleft" + fi + done +} + +output() { + local binpkg="$1" + if [ -z "$binpkg" ]; then + cat + else + local built_using="" + local built_using_x="" + while read pkg ver srcleft; do + local src="$(dpkg-query -f '${source:Package}' --show "$pkg")" + local srcver="$(dpkg-query -f '${source:Version}' --show "$pkg")" + case "$srcleft" in + 2) exit 1;; + 1) built_using="${built_using}$src (= $srcver), ";; + esac + built_using_x="${built_using_x}$src (= $srcver), " + done + echo "cargo:Built-Using=${built_using%, }" >> "debian/$binpkg.substvars" + echo "cargo:X-Cargo-Built-Using=${built_using_x%, }" >> "debian/$binpkg.substvars" + fi +} + +native_libs="$(native_libs)" # capture output outside of pipe so set -e works +{ +rust_libs +test -z "$native_libs" || echo "$native_libs" +} | LC_ALL=C.utf-8 sort -u | output "$@" diff -Nru rust-peg-0.8.1/debian/dh-cargo/lib/Debian/Debhelper/Buildsystem/cargo.pm rust-peg-0.8.2/debian/dh-cargo/lib/Debian/Debhelper/Buildsystem/cargo.pm --- rust-peg-0.8.1/debian/dh-cargo/lib/Debian/Debhelper/Buildsystem/cargo.pm 2023-01-25 15:45:55.000000000 +0000 +++ rust-peg-0.8.2/debian/dh-cargo/lib/Debian/Debhelper/Buildsystem/cargo.pm 2023-09-21 13:43:46.000000000 +0000 @@ -1,8 +1,9 @@ # debhelper buildsystem for Rust crates using Cargo # -# SPDX-FileCopyrightText: 2016 Josh Triplett -# SPDX-FileCopyrightText: 2018 Ximin Luo # SPDX-FileCopyrightText: 2022-2023 Jonas Smedegaard +# SPDX-FileCopyrightText: 2016 Josh Triplett +# SPDX-FileCopyrightText: 2019-2021 Sylvestre Ledru +# SPDX-FileCopyrightText: 2018-2021 Ximin Luo # # SPDX-License-Identifier: MIT # @@ -37,7 +38,7 @@ use String::ShellQuote qw( shell_quote ); use base 'Debian::Debhelper::Buildsystem'; -use constant CARGO_SYSTEM_REGISTRY => '/usr/share/cargo/registry/'; +use constant CARGO_SYSTEM_REGISTRY => '/usr/share/cargo/registry'; sub DESCRIPTION { "Rust Cargo" @@ -50,24 +51,35 @@ my $json = JSON::PP->new; my $manifest = $json->decode(); my %crates; - for ( @{ $manifest->{packages} } ) { - my $pkg_longstem = "$_->{name}-$_->{version}" =~ s/_/-/gr; + for my $key ( @{ $manifest->{packages} } ) { my %object = ( - cratespec => "$_->{name}_$_->{version}", - systempath => CARGO_SYSTEM_REGISTRY . "/$_->{name}-$_->{version}", - sourcepath => File::Spec->abs2rel( $_->{manifest_path} =~ s{/Cargo\.toml$}{}r, $root ), + cratename => join( '-', $key->{name}, $key->{version} ), + cratespec => join( '_', $key->{name}, $key->{version} ), + pkgid => join( '@', $key->{name}, $key->{version} ), ); + $object{sourcepath} = File::Spec->abs2rel( + $key->{manifest_path} =~ s{/Cargo\.toml$}{}r, + $root, + ); + $object{packagepath} = 'target/package/' . $object{cratename} . '.crate'; + $object{systempath} = CARGO_SYSTEM_REGISTRY . '/' . $object{cratename}; # resolve crate from dh-cargo cratespec $crates{ $object{cratespec} } = \%object; # resolve topmost declared crate from package stems + my $pkg_longstem = $object{cratename} =~ tr/_/-/r; $crates{$_} //= \%object for ( $pkg_longstem =~ /^(((([^+]+?)-[^+.-]+)?\.[^+.]+)?\.[^+]+)?$/ ); # resolve topmost declared crate from crate name $crates{_default} //= \%object - if $_->{name} eq $default; + if $key->{name} eq $default; + } + # resolve amount of local dependencies + # TODO: use Graph to compute an always reliable order instead + for my $key ( @{ $manifest->{packages} } ) { + $crates{ $key->{name} =~ tr/_/-/r }{depcount} = grep { exists $crates{ $_->{name} =~ tr/_/-/r } } @{ $key->{dependencies} }; } return \%crates; } @@ -227,14 +239,6 @@ $this->SUPER::pre_building_step($step); } -sub get_sources { - my ( $this, $sourcedir ) = @_; - opendir(my $dirhandle, $sourcedir); - my @sources = grep { !/^(\.(\.|git.*|pc)?|debian|Cargo\.lock|COPYING.*|LICENSE.*)$/ } readdir($dirhandle); - closedir($dirhandle); - @sources -} - sub configure { my $this=shift; # use Cargo.lock if it exists, or debian/Cargo.lock if that also exists @@ -250,17 +254,21 @@ "--remap-path-prefix", "$_->{cratespec}=$_->{systempath}", )} map { @{ $this->{libpkg}{$_}{crates} } } sort keys %{ $this->{libpkg} }; - push @rustflags, "--remap-path-prefix", "$registry_path=" . CARGO_SYSTEM_REGISTRY; + push @rustflags, "--remap-path-prefix", "$registry_path=" . CARGO_SYSTEM_REGISTRY . '/'; + my $rustflags = shell_quote(@rustflags); + $rustflags .= " $ENV{RUSTFLAGS}" + if $ENV{RUSTFLAGS}; $this->doit_in_sourcedir( - "env", 'RUSTFLAGS=' . shell_quote(@rustflags), + "env", "RUSTFLAGS=$rustflags", $this->{cargo_command}, "prepare-debian", $registry_path, "--link-from-system"); if ( -d 'debian/vendorlibs' ) { complex_doit( qw(find debian/cargo_registry -lname '../vendorlibs/*' -delete)); + # force to favor this crate over a dependency pulled from system complex_doit( - qw(ln --symbolic --relative --target-directory=debian/cargo_registry debian/vendorlibs/*)); + qw(ln --symbolic --force --relative --target-directory=debian/cargo_registry debian/vendorlibs/*)); } $this->doit_in_sourcedir(qw(cargo update)) if -f $cargo_lock; } @@ -281,30 +289,40 @@ # this additional information to debcargo. $this->doit_in_sourcedir($this->{cargo_command}, "test", @_); # test generating Built-Using fields - doit("env", "CARGO_CHANNEL=debug", "/usr/share/cargo/bin/dh-cargo-built-using"); + my $channel = get_buildoption("noopt") ? 'debug' : 'release'; + doit("env", + "CARGO_MANIFEST_DIR=" . $this->get_sourcedir(), + "CARGO_CHANNEL=$channel", + "debian/dh-cargo/bin/dh-cargo-built-using"); } sub install { my $this=shift; my $destdir=shift; - foreach my $crate ( map { @{ $_->{crates} } } sort values %{ $this->{libpkg} } ) { + foreach my $crate ( sort { $a->{depcount} cmp $b->{depcount} } map { @{ $_->{crates} } } sort values %{ $this->{libpkg} } ) { my $target = tmpdir( $crate->{libpkg}{name} ) . $crate->{systempath}; - my @sources = $this->get_sources( $crate->{sourcepath} ); install_dir($target); $this->doit_in_somedir( $crate->{sourcepath}, - "env", "DEB_CARGO_CRATE=$crate->{cratespec}", - "cp", "--parents", - "-at", $this->_rel2rel($target, $crate->{sourcepath}), - @sources); - doit("rm", "-rf", "$target/target"); + qw(cargo package --offline --allow-dirty --no-verify), + '--target-dir', cwd . '/target', '--package', $crate->{pkgid} ); + $this->doit_in_somedir( + "$target/..", + 'tar', map( { ( '--exclude', $_ ) } qw(debian/* debian Cargo.toml.orig Cargo.lock COPYING* LICENSE*) ), '-xvf', + $this->_rel2rel( $crate->{packagepath}, "$target/.." ), + $crate->{cratename} ); complex_doit( qw(perl -MDigest::SHA=sha256_hex -0777 -nE 'say sprintf), 'q<{"package":"%s","files":{}}>,', "sha256_hex($_)'", - "<", "$crate->{sourcepath}/Cargo.toml", + "<", "$target/Cargo.toml", ">", "$target/.cargo-checksum.json"); # prevent an ftpmaster auto-reject regarding files with old dates. doit("touch", "-d@" . $ENV{SOURCE_DATE_EPOCH}, "$target/Cargo.toml"); + # add crate to local registry, needed by some multi-crate workspaces + # maybe related: + # force to favor this crate over a dependency pulled from system + complex_doit( + qw(ln --symbolic --force --relative --target-directory=debian/cargo_registry), $target ); } foreach my $featurepkg (@{$this->{featurepkg}}) { my $target = tmpdir( $featurepkg->{name} ) . "/usr/share/doc"; @@ -318,7 +336,9 @@ $this->doit_in_sourcedir("env", "DESTDIR=$destdir", "DEB_CARGO_CRATE=$crate->{cratespec}", $this->{cargo_command}, "install", @path_opts, @_); # generate Built-Using fields - doit("env", "/usr/share/cargo/bin/dh-cargo-built-using", $crate->{binpkg}{name}); + doit("env", + "CARGO_MANIFEST_DIR=" . $this->get_sourcedir(), + "debian/dh-cargo/bin/dh-cargo-built-using", $crate->{binpkg}{name}); } } diff -Nru rust-peg-0.8.1/debian/dh-cargo/README.md rust-peg-0.8.2/debian/dh-cargo/README.md --- rust-peg-0.8.1/debian/dh-cargo/README.md 2023-01-25 15:45:55.000000000 +0000 +++ rust-peg-0.8.2/debian/dh-cargo/README.md 2023-09-21 13:43:46.000000000 +0000 @@ -15,23 +15,21 @@ * generate cargo-checksum during install * pass cargo --remap-path-prefix option sets in RUSTFLAGS * allow overriding CARGO_HOME - * use regex (not strings) for matching files to omit from install - * omit installing crate metadata in binary library packages: - * omit any .git* files or directories - * omit license files - * omit debian/patches - (see bug#880689) - * use debian/Cargo.lock or Cargo.lock (in that order), + * install crate contents using "cargo package" + * omit license files, Cargo.toml.orig, and debian/patches + (see bug#880689) + * use debian/Cargo.lock or Cargo.lock (in that order) during build, if Cargo.lock exists * use crates below debian/vendorlibs when available * use dh_auto_build (not confusingly only dh_auto_test) Also included is a slight fork of related [cargo] wrapper script, -based on git commit e4072cb -(included with version 0.63.1-1 released 2022-11-16), +based on git commit bac0ad2d +(expected to be included with the version succeeding 0.66.0+ds1-1), with these functional changes: + * support CARGO_MANIFEST_DIR=${debhelper_sourcedirectory} * support --remap-path-prefix option sets in RUSTFLAGS by omitting that (not fail) when DEB_CARGO_CRATE is not set * support documented shorter CARGO_HOME path @@ -65,4 +63,4 @@ ``` - -- Jonas Smedegaard Wed, 25 Jan 2023 16:45:34 +0100 + -- Jonas Smedegaard Sun, 17 Sep 2023 07:36:27 +0200 diff -Nru rust-peg-0.8.1/debian/patches/2001_no_feature_unstable.patch rust-peg-0.8.2/debian/patches/2001_no_feature_unstable.patch --- rust-peg-0.8.1/debian/patches/2001_no_feature_unstable.patch 1970-01-01 00:00:00.000000000 +0000 +++ rust-peg-0.8.2/debian/patches/2001_no_feature_unstable.patch 2023-10-16 15:37:13.000000000 +0000 @@ -0,0 +1,21 @@ +Description: avoid feature unstable +Author: Jonas Smedegaard +Last-Update: 2023-10-16 +--- +This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ +--- a/Cargo.toml ++++ b/Cargo.toml +@@ -31,4 +31,3 @@ + default = ["std"] + trace = ["peg-macros/trace"] + std = ["peg-runtime/std"] +-unstable = ["peg-runtime/unstable"] +\ No newline at end of file +--- a/peg-runtime/Cargo.toml ++++ b/peg-runtime/Cargo.toml +@@ -12,4 +12,3 @@ + + [features] + std = [] +-unstable = [] +\ No newline at end of file diff -Nru rust-peg-0.8.1/debian/patches/series rust-peg-0.8.2/debian/patches/series --- rust-peg-0.8.1/debian/patches/series 2023-06-28 12:34:06.000000000 +0000 +++ rust-peg-0.8.2/debian/patches/series 2023-10-16 15:35:10.000000000 +0000 @@ -1,2 +1,3 @@ 1001_unstable_gone_syntax.patch 1002_failure_tests.patch +2001_no_feature_unstable.patch diff -Nru rust-peg-0.8.1/debian/rules rust-peg-0.8.2/debian/rules --- rust-peg-0.8.1/debian/rules 2023-06-27 12:28:33.000000000 +0000 +++ rust-peg-0.8.2/debian/rules 2023-07-30 00:38:46.000000000 +0000 @@ -7,9 +7,3 @@ %: dh $@ --buildsystem cargo - -# TODO: teach dh-cargo to mangle Cargo.toml to strip same-workspace path -execute_after_dh_auto_install: - perl -p -i \ - -e 's!(?=, )?path= " \./peg-\w+"(?= ,)?!!;' \ - debian/librust-*-dev/usr/share/cargo/registry/*/Cargo.toml diff -Nru rust-peg-0.8.1/debian/tests/control rust-peg-0.8.2/debian/tests/control --- rust-peg-0.8.1/debian/tests/control 2023-06-27 12:28:33.000000000 +0000 +++ rust-peg-0.8.2/debian/tests/control 2023-10-16 16:07:36.000000000 +0000 @@ -1,35 +1,49 @@ -Test-Command: /usr/share/cargo/bin/cargo-auto-test peg 0.8.1 +Test-Command: /usr/share/cargo/bin/cargo-auto-test peg 0.8.2 --all-targets --all-features Features: test-name=rust-peg-0.8:@ Depends: dh-cargo (>= 18), librust-peg-0.8-dev, librust-trybuild-1+default-dev, + librust-version-check-0.9+default-dev, Restrictions: allow-stderr -Test-Command: /usr/share/cargo/bin/cargo-auto-test peg 0.8.1 +Test-Command: /usr/share/cargo/bin/cargo-auto-test peg 0.8.2 --all-targets --no-default-features Features: test-name=rust-peg-0.8: Depends: dh-cargo (>= 18), librust-peg-0.8-dev, librust-trybuild-1+default-dev, + librust-version-check-0.9+default-dev, Restrictions: allow-stderr -Test-Command: /usr/share/cargo/bin/cargo-auto-test peg 0.8.1 - --all-targets --no-default-features --features trace -Features: test-name=rust-peg-0.8:trace +Test-Command: /usr/share/cargo/bin/cargo-auto-test peg 0.8.2 + --all-targets +Features: test-name=rust-peg-0.8:default Depends: dh-cargo (>= 18), - librust-peg-0.8-dev, + librust-peg-0.8+default-dev, librust-trybuild-1+default-dev, + librust-version-check-0.9+default-dev, Restrictions: allow-stderr -Test-Command: /usr/share/cargo/bin/cargo-auto-test peg 0.8.1 - --all-targets -Features: test-name=rust-peg-0.8:default +Test-Command: /usr/share/cargo/bin/cargo-auto-test peg 0.8.2 + --all-targets --no-default-features --features std +Features: test-name=rust-peg-0.8:std Depends: dh-cargo (>= 18), - librust-peg-0.8+default-dev, + librust-peg-0.8+std-dev, + librust-trybuild-1+default-dev, + librust-version-check-0.9+default-dev, +Restrictions: allow-stderr + +Test-Command: /usr/share/cargo/bin/cargo-auto-test peg 0.8.2 + --all-targets --no-default-features --features trace +Features: test-name=rust-peg-0.8:trace +Depends: + dh-cargo (>= 18), + librust-peg-0.8+trace-dev, librust-trybuild-1+default-dev, + librust-version-check-0.9+default-dev, Restrictions: allow-stderr diff -Nru rust-peg-0.8.1/.github/workflows/rust.yml rust-peg-0.8.2/.github/workflows/rust.yml --- rust-peg-0.8.1/.github/workflows/rust.yml 2022-09-25 23:48:31.000000000 +0000 +++ rust-peg-0.8.2/.github/workflows/rust.yml 2023-10-10 01:18:35.000000000 +0000 @@ -9,14 +9,23 @@ jobs: build: + name: Rust ${{matrix.rust}} + strategy: + fail-fast: false + matrix: + rust: [stable, 1.68.0] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{matrix.rust}} + components: rustfmt - name: Check bootstrap run: ./bootstrap.sh && git diff --exit-code - name: Run tests run: cargo test --all - - name: Run tests with all features - run: cargo test --all --all-features + - name: Run tests with trace feature + run: cargo test --all --features trace diff -Nru rust-peg-0.8.1/peg-macros/ast.rs rust-peg-0.8.2/peg-macros/ast.rs --- rust-peg-0.8.1/peg-macros/ast.rs 2022-09-25 23:48:31.000000000 +0000 +++ rust-peg-0.8.2/peg-macros/ast.rs 2023-10-10 01:18:35.000000000 +0000 @@ -84,7 +84,7 @@ MatchStrExpr(Box), PositionExpr, QuietExpr(Box), - FailExpr(Literal), + FailExpr(Group), PrecedenceExpr { levels: Vec, }, diff -Nru rust-peg-0.8.1/peg-macros/Cargo.toml rust-peg-0.8.2/peg-macros/Cargo.toml --- rust-peg-0.8.1/peg-macros/Cargo.toml 2022-09-25 23:48:31.000000000 +0000 +++ rust-peg-0.8.2/peg-macros/Cargo.toml 2023-10-10 01:18:35.000000000 +0000 @@ -1,6 +1,6 @@ [package] name = "peg-macros" -version = "0.8.1" +version = "0.8.2" authors = [ "Kevin Mehall " ] license = "MIT" repository = "https://github.com/kevinmehall/rust-peg" @@ -10,7 +10,7 @@ [dependencies] quote = "1.0" proc-macro2 = "1.0.24" -peg-runtime = { version = "= 0.8.1", path = "../peg-runtime" } +peg-runtime = { version = "= 0.8.2", path = "../peg-runtime" } [features] trace = [] diff -Nru rust-peg-0.8.1/peg-macros/grammar.rs rust-peg-0.8.2/peg-macros/grammar.rs --- rust-peg-0.8.1/peg-macros/grammar.rs 2022-09-25 23:48:31.000000000 +0000 +++ rust-peg-0.8.2/peg-macros/grammar.rs 2023-10-10 01:18:35.000000000 +0000 @@ -6,13 +6,13 @@ type PositionRepr = ::PositionRepr; #[allow(unused_parens)] struct ParseState<'input> { - _phantom: ::std::marker::PhantomData<(&'input ())>, + _phantom: ::core::marker::PhantomData<(&'input ())>, primary_cache: ::std::collections::HashMap>, } impl<'input> ParseState<'input> { fn new() -> ParseState<'input> { ParseState { - _phantom: ::std::marker::PhantomData, + _phantom: ::core::marker::PhantomData, primary_cache: ::std::collections::HashMap::new(), } } @@ -23,7 +23,7 @@ use proc_macro2::{Delimiter, Group, Ident, Literal, Span, TokenStream}; pub fn peg_grammar<'input>( __input: &'input Input, - ) -> ::std::result::Result> { + ) -> ::core::result::Result> { #![allow(non_snake_case, unused)] let mut __err_state = ::peg::error::ErrorState::new(::peg::Parse::start(__input)); let mut __state = ParseState::new(); @@ -50,11 +50,12 @@ &mut __err_state, ::peg::Parse::start(__input), ) { - ::peg::RuleResult::::Matched(__pos, __value) => { + ::peg::RuleResult::Matched(__pos, __value) => { if ::peg::Parse::is_eof(__input, __pos) { panic!( "Parser is nondeterministic: succeeded when reparsing for error position" ); + return Ok(__value); } else { __err_state.mark_failure(__pos, "EOF"); } @@ -2777,7 +2778,7 @@ let __choice_res = { let __seq_res = __parse_sp(__input, __state, __err_state, __pos); - match __seq_res { :: peg :: RuleResult :: Matched (__pos , sp) => { match :: peg :: ParseLiteral :: parse_string_literal (__input , __pos , "expected") { :: peg :: RuleResult :: Matched (__pos , __val) => { match :: peg :: ParseLiteral :: parse_string_literal (__input , __pos , "!") { :: peg :: RuleResult :: Matched (__pos , __val) => { match :: peg :: ParseLiteral :: parse_string_literal (__input , __pos , "(") { :: peg :: RuleResult :: Matched (__pos , __val) => { { let __seq_res = __parse_LITERAL (__input , __state , __err_state , __pos) ; match __seq_res { :: peg :: RuleResult :: Matched (__pos , s) => { match :: peg :: ParseLiteral :: parse_string_literal (__input , __pos , ")") { :: peg :: RuleResult :: Matched (__pos , __val) => { :: peg :: RuleResult :: Matched (__pos , (|| { FailExpr (s) . at (sp) }) ()) } :: peg :: RuleResult :: Failed => { __err_state . mark_failure (__pos , "\")\"") ; :: peg :: RuleResult :: Failed } } } :: peg :: RuleResult :: Failed => :: peg :: RuleResult :: Failed , } } } :: peg :: RuleResult :: Failed => { __err_state . mark_failure (__pos , "\"(\"") ; :: peg :: RuleResult :: Failed } } } :: peg :: RuleResult :: Failed => { __err_state . mark_failure (__pos , "\"!\"") ; :: peg :: RuleResult :: Failed } } } :: peg :: RuleResult :: Failed => { __err_state . mark_failure (__pos , "\"expected\"") ; :: peg :: RuleResult :: Failed } } } :: peg :: RuleResult :: Failed => :: peg :: RuleResult :: Failed , } + match __seq_res { :: peg :: RuleResult :: Matched (__pos , sp) => { match :: peg :: ParseLiteral :: parse_string_literal (__input , __pos , "expected") { :: peg :: RuleResult :: Matched (__pos , __val) => { match :: peg :: ParseLiteral :: parse_string_literal (__input , __pos , "!") { :: peg :: RuleResult :: Matched (__pos , __val) => { { let __seq_res = __parse_PAREN_GROUP (__input , __state , __err_state , __pos) ; match __seq_res { :: peg :: RuleResult :: Matched (__pos , s) => { :: peg :: RuleResult :: Matched (__pos , (|| { FailExpr (s) . at (sp) }) ()) } :: peg :: RuleResult :: Failed => :: peg :: RuleResult :: Failed , } } } :: peg :: RuleResult :: Failed => { __err_state . mark_failure (__pos , "\"!\"") ; :: peg :: RuleResult :: Failed } } } :: peg :: RuleResult :: Failed => { __err_state . mark_failure (__pos , "\"expected\"") ; :: peg :: RuleResult :: Failed } } } :: peg :: RuleResult :: Failed => :: peg :: RuleResult :: Failed , } }; match __choice_res { ::peg::RuleResult::Matched(__pos, __value) => { diff -Nru rust-peg-0.8.1/peg-macros/grammar.rustpeg rust-peg-0.8.2/peg-macros/grammar.rustpeg --- rust-peg-0.8.1/peg-macros/grammar.rustpeg 2022-09-25 23:48:31.000000000 +0000 +++ rust-peg-0.8.2/peg-macros/grammar.rustpeg 2023-10-10 01:18:35.000000000 +0000 @@ -124,7 +124,7 @@ = sp:sp() "precedence" "!" "{" levels:precedence_level()**"--" "}" { PrecedenceExpr{ levels:levels }.at(sp) } / sp:sp() "position" "!" "(" ")" { PositionExpr.at(sp) } / sp:sp() "quiet" "!" "{" e:expression() "}" { QuietExpr(Box::new(e)).at(sp) } - / sp:sp() "expected" "!" "(" s:LITERAL() ")" { FailExpr(s).at(sp) } + / sp:sp() "expected" "!" s:PAREN_GROUP() { FailExpr(s).at(sp) } / &("_" / "__" / "___") sp:sp() name:IDENT() { RuleExpr(name, Vec::new()).at(sp) } / sp:sp() name:IDENT() "(" args:(rule_arg() ** ",") ")" { RuleExpr(name, args).at(sp) } / sp:sp() l:LITERAL() { LiteralExpr(l).at(sp) } diff -Nru rust-peg-0.8.1/peg-macros/translate.rs rust-peg-0.8.2/peg-macros/translate.rs --- rust-peg-0.8.1/peg-macros/translate.rs 2022-09-25 23:48:31.000000000 +0000 +++ rust-peg-0.8.2/peg-macros/translate.rs 2023-10-10 01:18:35.000000000 +0000 @@ -171,14 +171,14 @@ quote_spanned! { span => #[allow(unused_parens)] struct ParseState<'input #(, #grammar_lifetime_params)*> { - _phantom: ::std::marker::PhantomData<(&'input () #(, &#grammar_lifetime_params ())*)>, + _phantom: ::core::marker::PhantomData<(&'input () #(, &#grammar_lifetime_params ())*)>, #(#cache_fields_def),* } impl<'input #(, #grammar_lifetime_params)*> ParseState<'input #(, #grammar_lifetime_params)*> { fn new() -> ParseState<'input #(, #grammar_lifetime_params)*> { ParseState { - _phantom: ::std::marker::PhantomData, + _phantom: ::core::marker::PhantomData, #(#cache_fields: ::std::collections::HashMap::new()),* } } @@ -369,7 +369,7 @@ quote_spanned! { span => #doc - #visibility fn #name<'input #(, #grammar_lifetime_params)* #(, #ty_params)*>(__input: #input_ty #extra_args_def #(, #rule_params)*) -> ::std::result::Result<#ret_ty, ::peg::error::ParseError>> { + #visibility fn #name<'input #(, #grammar_lifetime_params)* #(, #ty_params)*>(__input: #input_ty #extra_args_def #(, #rule_params)*) -> ::core::result::Result<#ret_ty, ::peg::error::ParseError>> { #![allow(non_snake_case, unused)] let mut __err_state = ::peg::error::ErrorState::new(::peg::Parse::start(__input)); @@ -389,9 +389,10 @@ __err_state.reparse_for_error(); match #parse_fn(__input, &mut __state, &mut __err_state, ::peg::Parse::start(__input) #extra_args_call #(, #rule_params_call)*) { - ::peg::RuleResult::<#ret_ty>::Matched(__pos, __value) => { + ::peg::RuleResult::Matched(__pos, __value) => { if #eof_check { panic!("Parser is nondeterministic: succeeded when reparsing for error position"); + return Ok(__value); // dead code, but needed for type inference } else { __err_state.mark_failure(__pos, "EOF"); } diff -Nru rust-peg-0.8.1/peg-runtime/Cargo.toml rust-peg-0.8.2/peg-runtime/Cargo.toml --- rust-peg-0.8.1/peg-runtime/Cargo.toml 2022-09-25 23:48:31.000000000 +0000 +++ rust-peg-0.8.2/peg-runtime/Cargo.toml 2023-10-10 01:18:35.000000000 +0000 @@ -1,6 +1,6 @@ [package] name = "peg-runtime" -version = "0.8.1" +version = "0.8.2" authors = [ "Kevin Mehall " ] license = "MIT" repository = "https://github.com/kevinmehall/rust-peg" @@ -8,4 +8,8 @@ edition = "2018" [lib] -path = "lib.rs" \ No newline at end of file +path = "lib.rs" + +[features] +std = [] +unstable = [] \ No newline at end of file diff -Nru rust-peg-0.8.1/peg-runtime/error.rs rust-peg-0.8.2/peg-runtime/error.rs --- rust-peg-0.8.1/peg-runtime/error.rs 2022-09-25 23:48:31.000000000 +0000 +++ rust-peg-0.8.2/peg-runtime/error.rs 2023-10-10 01:18:35.000000000 +0000 @@ -1,13 +1,18 @@ //! Parse error reporting use crate::{Parse, RuleResult}; -use std::collections::HashSet; use std::fmt::{self, Debug, Display}; +#[cfg(feature = "std")] +use std::collections::BTreeSet; + +#[cfg(not(feature = "std"))] +use {alloc::collections::BTreeSet, alloc::vec::Vec}; + /// A set of literals or names that failed to match #[derive(PartialEq, Eq, Debug, Clone)] pub struct ExpectedSet { - expected: HashSet<&'static str>, + expected: BTreeSet<&'static str>, } impl ExpectedSet { @@ -58,6 +63,7 @@ } } +#[cfg(any(feature = "std", feature = "unstable"))] impl ::std::error::Error for ParseError { fn description(&self) -> &str { "parse error" @@ -88,7 +94,7 @@ suppress_fail: 0, reparsing_on_error: false, expected: ExpectedSet { - expected: HashSet::new(), + expected: BTreeSet::new(), }, } } diff -Nru rust-peg-0.8.1/peg-runtime/lib.rs rust-peg-0.8.2/peg-runtime/lib.rs --- rust-peg-0.8.1/peg-runtime/lib.rs 2022-09-25 23:48:31.000000000 +0000 +++ rust-peg-0.8.2/peg-runtime/lib.rs 2023-10-10 01:18:35.000000000 +0000 @@ -1,3 +1,6 @@ +#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(feature = "unstable", feature(error_in_core))] + use std::fmt::Display; pub mod error; @@ -50,3 +53,8 @@ /// Get a slice of input. fn parse_slice(&'input self, p1: usize, p2: usize) -> Self::Slice; } + +#[cfg(not(feature = "std"))] +extern crate alloc; +#[cfg(not(feature = "std"))] +extern crate core as std; diff -Nru rust-peg-0.8.1/README.md rust-peg-0.8.2/README.md --- rust-peg-0.8.1/README.md 2022-09-25 23:48:31.000000000 +0000 +++ rust-peg-0.8.2/README.md 2023-10-10 01:18:35.000000000 +0000 @@ -60,11 +60,13 @@ [annotate-snippets]: https://crates.io/crates/annotate-snippets [codespan-reporting]: https://crates.io/crates/codespan-reporting [codemap-diagnostic]: https://crates.io/crates/codemap-diagnostic + ## Development The `rust-peg` grammar is written in `rust-peg`: `peg-macros/grammar.rustpeg`. To avoid the circular dependency, a precompiled grammar is checked in as `peg-macros/grammar.rs`. To regenerate this, run the `./bootstrap.sh` script. -There is a large test suite which uses [`trybuild`](https://crates.io/crates/trybuild) to support testing for compilation failure errors. +There is a large test suite which uses [`trybuild`](https://crates.io/crates/trybuild) to test both functionality (`tests/run-pass`) and error messages for incorrect grammars (`tests/compile-fail`). Because `rustc` error messages change, the `compile-fail` tests are only run on the minimum supported Rust version to avoid spurious failures. + Use `cargo test` to run the entire suite, or `cargo test -- trybuild trybuild=lifetimes.rs` to test just the indicated file. Add `--features trace` to trace these tests. diff -Nru rust-peg-0.8.1/src/lib.rs rust-peg-0.8.2/src/lib.rs --- rust-peg-0.8.1/src/lib.rs 2022-09-25 23:48:31.000000000 +0000 +++ rust-peg-0.8.2/src/lib.rs 2023-10-10 01:18:35.000000000 +0000 @@ -151,7 +151,7 @@ //! ### Repeat ranges //! //! The repeat operators `*` and `**` can be followed by an optional range specification of the -//! form `` (exact), `` (min), `<,m>` (max) or `` (range), where `n` and `m` are either +//! form `` (exact), `` (min-inclusive), `<,m>` (max-inclusive) or `` (range-inclusive), where `n` and `m` are either //! integers, or a Rust `usize` expression enclosed in `{}`. //! //! ### Precedence climbing @@ -256,7 +256,7 @@ //! ```rust,no_run //! # peg::parser!{grammar doc() for str { //! rule identifier() -//! = quiet!{[ 'a'..='z' | 'A'..='Z']['a'..='z' | 'A'..='Z' | '0'..='9' ]+} +//! = quiet!{[ 'a'..='z' | 'A'..='Z']['a'..='z' | 'A'..='Z' | '0'..='9' ]*} //! / expected!("identifier") //! # }} //! # fn main() {} diff -Nru rust-peg-0.8.1/tests/compile-fail/rust_action_type_error.stderr rust-peg-0.8.2/tests/compile-fail/rust_action_type_error.stderr --- rust-peg-0.8.1/tests/compile-fail/rust_action_type_error.stderr 2022-09-25 23:48:31.000000000 +0000 +++ rust-peg-0.8.2/tests/compile-fail/rust_action_type_error.stderr 2023-10-10 01:18:35.000000000 +0000 @@ -1,15 +1,20 @@ error[E0308]: mismatched types - --> $DIR/rust_action_type_error.rs:7:27 + --> tests/compile-fail/rust_action_type_error.rs:7:27 + | +7 | rule foo() -> X = "a" { Y } //~ ERROR + | ^^^^^ + | | + | expected struct `X`, found struct `Y` + | arguments to this enum variant are incorrect + | +help: the type constructed contains `Y` due to the type of the argument passed + --> tests/compile-fail/rust_action_type_error.rs:7:27 | 7 | rule foo() -> X = "a" { Y } //~ ERROR - | ^^^^^ - | | - | expected struct `X`, found struct `Y` - | arguments to this enum variant are incorrect - | + | ^^^^^ this argument influences the type of `{{root}}` note: tuple variant defined here - --> $DIR/lib.rs:14:5 + --> peg-runtime/lib.rs | -14 | Matched(usize, T), + | Matched(usize, T), | ^^^^^^^ = note: this error originates in the macro `peg::parser` (in Nightly builds, run with -Z macro-backtrace for more info) diff -Nru rust-peg-0.8.1/tests/run-pass/errors.rs rust-peg-0.8.2/tests/run-pass/errors.rs --- rust-peg-0.8.1/tests/run-pass/errors.rs 2022-09-25 23:48:31.000000000 +0000 +++ rust-peg-0.8.2/tests/run-pass/errors.rs 2023-10-10 01:18:35.000000000 +0000 @@ -11,6 +11,8 @@ pub rule q() = (quiet!{ ("a" / "b" / "c") ("1" / "2") } / expected!("letter followed by number"))+ + + pub rule var(s: &'static str) = expected!(s) }} fn main() { @@ -59,4 +61,8 @@ let err = parser::q("a1bb").unwrap_err(); assert_eq!(err.location.offset, 2); assert_eq!(err.expected.to_string(), "one of EOF, letter followed by number"); + + let err = parser::var("", "asdf").unwrap_err(); + assert_eq!(err.expected.to_string(), "asdf"); + } diff -Nru rust-peg-0.8.1/tests/run-pass/return_type.rs rust-peg-0.8.2/tests/run-pass/return_type.rs --- rust-peg-0.8.1/tests/run-pass/return_type.rs 1970-01-01 00:00:00.000000000 +0000 +++ rust-peg-0.8.2/tests/run-pass/return_type.rs 2023-10-10 01:18:35.000000000 +0000 @@ -0,0 +1,15 @@ +use std::fmt::Debug; + +// `--features trace` code names the return type, so doesn't work with `impl Trait` +#[cfg(not(feature = "trace"))] +peg::parser!{ + grammar g() for str { + pub rule returns_impl_trait() -> impl Debug + = "" { Box::new(5) } + } +} + +fn main() { + #[cfg(not(feature = "trace"))] + assert_eq!(format!("{:?}", g::returns_impl_trait("")), "Ok(5)"); +} diff -Nru rust-peg-0.8.1/tests/run-pass/tokens_struct.rs rust-peg-0.8.2/tests/run-pass/tokens_struct.rs --- rust-peg-0.8.1/tests/run-pass/tokens_struct.rs 1970-01-01 00:00:00.000000000 +0000 +++ rust-peg-0.8.2/tests/run-pass/tokens_struct.rs 2023-10-10 01:18:35.000000000 +0000 @@ -0,0 +1,73 @@ +use peg::{Parse, ParseElem, RuleResult}; + +/// The default implementation of the parsing traits for `[T]` expects `T` to be +/// `Copy`, as in the `[u8]` or simple enum cases. This wrapper exposes the +/// elements by `&T` reference, which is `Copy`. +pub struct SliceByRef<'a, T>(pub &'a [T]); + +impl<'a , T> Parse for SliceByRef<'a, T> { + type PositionRepr = usize; + fn start(&self) -> usize { + 0 + } + + fn is_eof(&self, pos: usize) -> bool { + pos >= self.0.len() + } + + fn position_repr(&self, pos: usize) -> usize { + pos + } +} + +impl<'a, T: 'a> ParseElem<'a> for SliceByRef<'a, T> { + type Element = &'a T; + + fn parse_elem(&'a self, pos: usize) -> RuleResult<&'a T> { + match self.0[pos..].first() { + Some(c) => RuleResult::Matched(pos + 1, c), + None => RuleResult::Failed, + } + } +} + +#[derive(PartialEq)] +pub enum TokenType { + Word, + Number, +} + +pub struct Token { + pub token_type: TokenType, + pub term: String, +} + +peg::parser!{ + grammar tokenparser<'a>() for SliceByRef<'a, Token> { + // The [] syntax works just like (and expands into) an arm of a match + // in regular Rust, so you can use a pattern that matches one field + // and ignores the rest + pub rule word_by_field() = [ Token { token_type: TokenType::Word, .. } ] + + // Or capture the token as a variable and then test it with an if guard. + pub rule word_by_eq() = [t if t.token_type == TokenType::Word] + + // You could wrap this in a rule that accepts the TokenType as an argument + rule tok(ty: TokenType) -> &'input Token = [t if t.token_type == ty] + pub rule number() = tok(TokenType::Number) + } +} + +fn main() { + let word_tok = vec![ + Token { token_type: TokenType::Word, term: "foo".into() } + ]; + + let number_tok = vec![ + Token { token_type: TokenType::Number, term: "123".into() } + ]; + + assert!(tokenparser::word_by_field(&SliceByRef(&word_tok[..])).is_ok()); + assert!(tokenparser::word_by_eq(&SliceByRef(&word_tok[..])).is_ok()); + assert!(tokenparser::number(&SliceByRef(&number_tok[..])).is_ok()); +} diff -Nru rust-peg-0.8.1/tests/trybuild.rs rust-peg-0.8.2/tests/trybuild.rs --- rust-peg-0.8.1/tests/trybuild.rs 2022-09-25 23:48:31.000000000 +0000 +++ rust-peg-0.8.2/tests/trybuild.rs 2023-10-10 01:18:35.000000000 +0000 @@ -1,20 +1,26 @@ -extern crate trybuild; - fn main() { + let args: Vec<_> = std::env::args().collect(); let t = trybuild::TestCases::new(); - let rust_ver = option_env!("TRAVIS_RUST_VERSION"); - if rust_ver.is_none() { - println!( - "Note: compile-fail tests are normally only tested on the stable rust compiler in CI." - ); - } + t.pass("tests/run-pass/*.rs"); + + let expected_rust_ver = env!("CARGO_PKG_RUST_VERSION"); + let run_anyway = args.iter().any(|a| a == "--compile-fail"); - if rust_ver.is_none() || rust_ver == Some("stable") { + let run_compile_fail = run_anyway || version_check::is_exact_version(expected_rust_ver).unwrap_or(true); + if run_compile_fail { t.compile_fail("tests/compile-fail/*.rs"); - } else { - println!("Skipping compile-fail tests."); } - t.pass("tests/run-pass/*.rs"); + // Trybuild runs the configured tests on drop + drop(t); + + if !run_compile_fail { + eprintln!("!!! Skipped compile-fail tests !!!"); + eprintln!("These tests are only checked on rust version {expected_rust_ver} because"); + eprintln!("the error message text may change between compiler versions."); + eprintln!(""); + eprintln!("Run `cargo +{expected_rust_ver} test` to run these tests."); + eprintln!(""); + } }