diff --git a/Cargo.lock b/Cargo.lock index ff3431b..7d04ec1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,9 +35,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.0.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -59,51 +59,51 @@ dependencies = [ [[package]] name = "anstream" -version = "0.3.2" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", - "is-terminal", + "is_terminal_polyfill", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.1" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" [[package]] name = "anstyle-parse" -version = "0.2.1" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" dependencies = [ - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "1.0.1" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" dependencies = [ "anstyle", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -118,16 +118,16 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi 0.1.19", + "hermit-abi", "libc", "winapi", ] [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "base16" @@ -158,9 +158,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.3.3" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "block-buffer" @@ -173,9 +173,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.13.0" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "cbor_event" @@ -185,9 +185,9 @@ checksum = "089a0261d1bc59e54e8e11860031efd88593f0e61b921172c474f1f38c2f2d3c" [[package]] name = "cc" -version = "1.0.79" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" [[package]] name = "cddl" @@ -228,13 +228,13 @@ version = "0.1.0" dependencies = [ "cbor_event", "cddl", - "clap 4.3.19", + "clap 4.5.4", "codegen", "nom", "once_cell", "pathdiff", "quote", - "syn 2.0.28", + "syn 2.0.66", "which", ] @@ -246,24 +246,23 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.26" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", "js-sys", "num-traits", - "time", "wasm-bindgen", - "winapi", + "windows-targets 0.52.5", ] [[package]] name = "ciborium" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "effd91f6c78e5a4ace8a5d3c0b6bfaec9e2baaef55f3efc00e45fb2e477ee926" +checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" dependencies = [ "ciborium-io", "ciborium-ll", @@ -272,15 +271,15 @@ dependencies = [ [[package]] name = "ciborium-io" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdf919175532b369853f5d5e20b26b43112613fd6fe7aee757e35f7a44642656" +checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" [[package]] name = "ciborium-ll" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "defaa24ecc093c77630e6c15e17c51f5e187bf35ee514f4e2d67baaa96dae22b" +checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" dependencies = [ "ciborium-io", "half", @@ -298,32 +297,31 @@ dependencies = [ "clap_lex 0.2.4", "indexmap", "once_cell", - "strsim", + "strsim 0.10.0", "termcolor", "textwrap", ] [[package]] name = "clap" -version = "4.3.19" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fd304a20bff958a57f04c4e96a2e7594cc4490a0e809cbd48bb6437edaa452d" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ "clap_builder", - "clap_derive 4.3.12", - "once_cell", + "clap_derive 4.5.4", ] [[package]] name = "clap_builder" -version = "4.3.19" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01c6a3f08f1fe5662a35cfe393aec09c4df95f60ee93b7556505260f75eee9e1" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" dependencies = [ "anstream", "anstyle", - "clap_lex 0.5.0", - "strsim", + "clap_lex 0.7.0", + "strsim 0.11.1", ] [[package]] @@ -332,7 +330,7 @@ version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro-error", "proc-macro2", "quote", @@ -341,14 +339,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.3.12" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.66", ] [[package]] @@ -362,9 +360,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "codegen" @@ -388,9 +386,9 @@ dependencies = [ [[package]] name = "colorchoice" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" [[package]] name = "console_error_panic_hook" @@ -404,15 +402,15 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] @@ -442,6 +440,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + [[package]] name = "crypto-common" version = "0.1.6" @@ -470,34 +474,23 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.66", ] [[package]] name = "either" -version = "1.9.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" [[package]] name = "errno" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" -dependencies = [ - "errno-dragonfly", - "libc", - "windows-sys", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ - "cc", "libc", + "windows-sys 0.52.0", ] [[package]] @@ -518,9 +511,13 @@ dependencies = [ [[package]] name = "half" -version = "1.8.2" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" +checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" +dependencies = [ + "cfg-if", + "crunchy", +] [[package]] name = "hashbrown" @@ -534,6 +531,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -543,30 +546,33 @@ dependencies = [ "libc", ] -[[package]] -name = "hermit-abi" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" - [[package]] name = "hexf-parse" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "iana-time-zone" -version = "0.1.57" +version = "0.1.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows", + "windows-core", ] [[package]] @@ -589,15 +595,10 @@ dependencies = [ ] [[package]] -name = "is-terminal" -version = "0.4.9" +name = "is_terminal_polyfill" +version = "1.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" -dependencies = [ - "hermit-abi 0.3.2", - "rustix", - "windows-sys", -] +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" [[package]] name = "itertools" @@ -610,15 +611,15 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" -version = "0.3.64" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] @@ -695,21 +696,21 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.147" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "linux-raw-sys" -version = "0.4.5" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" -version = "0.4.10" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -717,15 +718,15 @@ dependencies = [ [[package]] name = "log" -version = "0.4.19" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "memchr" -version = "2.5.0" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "minimal-lexical" @@ -735,14 +736,14 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "mio" -version = "0.8.8" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "wasi", + "windows-sys 0.48.0", ] [[package]] @@ -757,30 +758,30 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.16" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "os_str_bytes" -version = "6.5.1" +version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", @@ -788,15 +789,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.8" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.52.5", ] [[package]] @@ -807,19 +808,20 @@ checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" [[package]] name = "pest" -version = "2.7.2" +version = "2.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1acb4a4365a13f749a93f1a094a7805e5cfa0955373a9de860d962eaa3a5fe5a" +checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" dependencies = [ + "memchr", "thiserror", "ucd-trie", ] [[package]] name = "pest_meta" -version = "2.7.2" +version = "2.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56af0a30af74d0445c0bf6d9d051c979b516a1a5af790d251daee76005420a48" +checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd" dependencies = [ "once_cell", "pest", @@ -828,9 +830,9 @@ dependencies = [ [[package]] name = "pest_vm" -version = "2.7.2" +version = "2.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a7f5568b27841af86452b4b44c8c73bacc8523fed343e9604d1daf14834a4e6" +checksum = "36985db609c630fd9cb74e1808e553a221a9658fbcc94446b3c252e7e32b8b11" dependencies = [ "pest", "pest_meta", @@ -874,52 +876,52 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.32" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] [[package]] name = "redox_syscall" -version = "0.3.5" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", ] [[package]] name = "regex" -version = "1.9.1" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", "regex-automata", - "regex-syntax 0.7.4", + "regex-syntax 0.8.3", ] [[package]] name = "regex-automata" -version = "0.3.4" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7b6d6190b7594385f61bd3911cd1be99dfddcfc365a4160cc2ab5bff4aed294" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.4", + "regex-syntax 0.8.3", ] [[package]] @@ -930,28 +932,28 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.4" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "rustix" -version = "0.38.4" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags 2.3.3", + "bitflags 2.5.0", "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "ryu" -version = "1.0.15" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "scopeguard" @@ -961,9 +963,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.180" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea67f183f058fe88a4e3ec6e2788e003840893b91bac4559cabedd00863b3ed" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] @@ -981,20 +983,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.180" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24e744d7782b686ab3b73267ef05697159cc0e5abbed3f47f9933165e5219036" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.66", ] [[package]] name = "serde_json" -version = "1.0.104" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "itoa", "ryu", @@ -1003,9 +1005,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.7" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", @@ -1035,9 +1037,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] @@ -1055,9 +1057,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.0" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "static_assertions" @@ -1071,6 +1073,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "syn" version = "1.0.109" @@ -1084,9 +1092,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.28" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", @@ -1104,39 +1112,28 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.16.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" +checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" [[package]] name = "thiserror" -version = "1.0.44" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.44" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", -] - -[[package]] -name = "time" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", + "syn 2.0.66", ] [[package]] @@ -1147,9 +1144,9 @@ checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "ucd-trie" @@ -1159,21 +1156,21 @@ checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-segmentation" -version = "1.10.1" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" [[package]] name = "unicode-width" -version = "0.1.10" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" [[package]] name = "uriparse" @@ -1197,12 +1194,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1211,9 +1202,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1221,24 +1212,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.66", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1246,32 +1237,33 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.66", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "which" -version = "4.4.0" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" dependencies = [ "either", - "libc", + "home", "once_cell", + "rustix", ] [[package]] @@ -1292,11 +1284,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ - "winapi", + "windows-sys 0.52.0", ] [[package]] @@ -1306,12 +1298,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "windows" -version = "0.48.0" +name = "windows-core" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets", + "windows-targets 0.52.5", ] [[package]] @@ -1320,62 +1312,135 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", ] [[package]] name = "windows-targets" -version = "0.48.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/Cargo.toml b/Cargo.toml index 9afce00..6fe95f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,8 @@ which-rustfmt = ["which"] [dependencies] cbor_event = "2.4.0" -cddl = "0.9.1" +# we don't update due to https://github.com/anweiss/cddl/issues/222 +cddl = "=0.9.1" clap = { version = "4.3.12", features = ["derive"] } codegen = { git = "https://github.com/dcSpark/codegen", branch = "master" } once_cell = "1.18.0" diff --git a/docs/docs/integration-other.mdx b/docs/docs/integration-other.mdx index d8efe87..08b4eb6 100644 --- a/docs/docs/integration-other.mdx +++ b/docs/docs/integration-other.mdx @@ -25,8 +25,9 @@ There are two ways to have explicitly externally-defined types in cddl-codegen: ### Import pathing -In order to make imports easier it's recommended to make a directory corresponding to the dependency and put the `_CDDL_CODEGEN_RAW_BYTES_TYPE_` and `_CDDL_CODEGEN_EXTERN_TYPE_` external types inside of there and then later delete the output directories containing those modules. For an example see the `cml_chain` directory inside of the [`specs/multiera`](https://github.com/dcSpark/cardano-multiplatform-lib/tree/develop/specs/multiera). +If your input directory includes a `/_CDDL_CODEGEN_EXTERN_DEPS_DIR_/` directory, everything inside will be treated as an external dependency. This allows users to specify the import tree of any dependency CDDL structures. +You can define these types as `_CDDL_CODEGEN_EXTERN_TYPE_` if it is entirely self-contained or `_CDDL_CODEGEN_RAW_BYTES_TYPE_` if it is CBOR bytes. For an example see the `_CDDL_CODEGEN_EXTERN_DEPS_DIR_` directory inside of the [`specs/multiera`](https://github.com/dcSpark/cardano-multiplatform-lib/tree/develop/specs/multiera). Each folder within the directory will be treated as a separate dependency. Nothing will be generated by any definitions inside this folder. You will still need to specify the dependency inside the `Cargo.toml` file afterwards. ### Non-black-box types -Another important detail, demonstrated in the above `multiera` CDDL spec, is that when using external types that aren't 100% self-contained (i.e. can't be treated as a black box that implements `Serialize` + `Deserialize`, nor as CBOR bytes implementing `RawBytesEncoding`) like `uint` aliases should be explicitly defined and then removed afterwards. Using the above directory/pathing tip makes this trivial to remove after. +Another important detail, demonstrated in the above `multiera` CDDL spec, is that when using external types that aren't 100% self-contained (i.e. can't be treated as a black box that implements `Serialize` + `Deserialize`, nor as CBOR bytes implementing `RawBytesEncoding`) like `uint` aliases should be explicitly defined and then removed afterwards. Use the above directory/pathing tip. diff --git a/src/generation.rs b/src/generation.rs index 111f555..f08219a 100644 --- a/src/generation.rs +++ b/src/generation.rs @@ -424,6 +424,7 @@ impl From for DeserializationCode { /// * {x = Some(}{}{);} - variable assignment (could be nested in function call, etc, too) /// * {}{}{} - for last-expression eval in blocks /// * etc +/// /// We also keep track of if it expects a result and can adjust the generated code based on that /// to avoid warnings (e.g. avoid Ok(foo?) and directly do foo instead) struct DeserializeBeforeAfter<'a> { @@ -532,7 +533,7 @@ impl GenerationScope { FixedValue::Text(s) => ("String", format!("\"{s}\".to_owned()")), }; self.wasm(types, ident) - .new_fn(&convert_to_snake_case(ident.as_ref())) + .new_fn(convert_to_snake_case(ident.as_ref())) .attr("wasm_bindgen") .vis("pub") .ret(ty) @@ -809,7 +810,13 @@ impl GenerationScope { .collect::>(); for scope in scope_names .iter() - .filter_map(|s| s.components().first()) + .filter_map(|s| { + if s.export() { + s.components().first() + } else { + None + } + }) .collect::>() { self.rust_lib().raw(&format!("pub mod {scope};")); @@ -895,7 +902,7 @@ impl GenerationScope { for (import_scope, idents) in scope_imports.iter() { let import_scope = if *import_scope == *ROOT_SCOPE { Cow::from("crate") - } else if *scope == *ROOT_SCOPE { + } else if *scope == *ROOT_SCOPE || !import_scope.export() { Cow::from(import_scope.to_string()) } else { Cow::from(format!("crate::{import_scope}")) @@ -974,15 +981,7 @@ impl GenerationScope { // declare submodules // we do this after the rest to avoid declaring serialization mod/cbor encodings/etc // for these modules when they only exist to support modules nested deeper - for scope in scope_names.iter() { - let comps = scope.components(); - for i in 1..comps.len() { - self.rust_scopes - .entry(ModuleScope::new(comps.as_slice()[0..i].to_vec())) - .or_insert(codegen::Scope::new()) - .raw(&format!("pub mod {};", comps[i])); - } - } + declare_modules(&mut self.rust_scopes, &scope_names); // wasm if cli.wasm { @@ -998,7 +997,13 @@ impl GenerationScope { .collect::>(); for scope in wasm_scope_names .iter() - .filter_map(|s| s.components().first()) + .filter_map(|s| { + if s.export() { + s.components().first() + } else { + None + } + }) .collect::>() { self.wasm_lib().raw(&format!("pub mod {scope};")); @@ -1039,15 +1044,7 @@ impl GenerationScope { // declare submodules // we do this after the rest to avoid declaring serialization mod/cbor encodings/etc // for these modules when they only exist to support modules nested deeper - for scope in wasm_scope_names.iter() { - let comps = scope.components(); - for i in 1..comps.len() { - self.wasm_scopes - .entry(ModuleScope::new(comps.as_slice()[0..i].to_vec())) - .or_insert(codegen::Scope::new()) - .raw(&format!("pub mod {};", comps[i])); - } - } + declare_modules(&mut self.wasm_scopes, &wasm_scope_names); } } @@ -1099,8 +1096,9 @@ impl GenerationScope { std::fs::create_dir_all(&src_dir)?; for (scope, content) in other_scopes { if *scope == *ROOT_SCOPE { + assert!(scope.export()); merged_scope.append(&content.clone()); - } else { + } else if scope.export() { let mod_dir = scope .components() .iter() @@ -1167,18 +1165,20 @@ impl GenerationScope { // cbor_encodings.rs / {module}/cbor_encodings.rs (if input is a directory) if cli.preserve_encodings { for (scope, contents) in self.cbor_encodings_scopes.iter() { - let path = if *scope == *ROOT_SCOPE { - Cow::from("rust/src/cbor_encodings.rs") - } else { - Cow::from(format!( - "rust/src/{}/cbor_encodings.rs", - scope.components().join("/") - )) - }; - std::fs::write( - rust_dir.join(path.as_ref()), - rustfmt_generated_string(&contents.to_string())?.as_ref(), - )?; + if scope.export() { + let path = if *scope == *ROOT_SCOPE { + Cow::from("rust/src/cbor_encodings.rs") + } else { + Cow::from(format!( + "rust/src/{}/cbor_encodings.rs", + scope.components().join("/") + )) + }; + std::fs::write( + rust_dir.join(path.as_ref()), + rustfmt_generated_string(&contents.to_string())?.as_ref(), + )?; + } } } @@ -2442,7 +2442,7 @@ impl GenerationScope { )); } } - type_check.after(&before_after.after_str(false)); + type_check.after(before_after.after_str(false)); deser_code.content.push_block(type_check); deser_code.throws = true; } @@ -2783,7 +2783,7 @@ impl GenerationScope { } else { none_block.line("None"); } - deser_block.after(&before_after.after_str(false)); + deser_block.after(before_after.after_str(false)); deser_block.push_block(none_block); deser_code.content.push_block(deser_block); deser_code.throws = true; @@ -3346,7 +3346,7 @@ impl GenerationScope { new_func.vis("pub"); let can_fail = variant.rust_type().needs_bounds_check_if_inlined(types); if !variant.rust_type().is_fixed_value() { - new_func.arg(&variant_arg, &variant.rust_type().for_wasm_param(types)); + new_func.arg(&variant_arg, variant.rust_type().for_wasm_param(types)); } let ctor = if variant.rust_type().is_fixed_value() { format!( @@ -3412,7 +3412,7 @@ impl GenerationScope { .s_impl .new_fn("get") .vis("pub") - .ret(&element_type.for_wasm_return(types)) + .ret(element_type.for_wasm_return(types)) .arg_ref_self() .arg("index", "usize") .line(element_type.to_wasm_boundary(types, "self.0[index]", false)); @@ -3644,6 +3644,23 @@ fn bounds_check_if_block( ) } +fn declare_modules( + gen_scopes: &mut BTreeMap, + module_scopes: &[ModuleScope], +) { + for module_scope in module_scopes.iter() { + if module_scope.export() { + let components = module_scope.components(); + for (i, component) in components.iter().enumerate().skip(1) { + gen_scopes + .entry(module_scope.parents(i)) + .or_insert(codegen::Scope::new()) + .raw(&format!("pub mod {};", component)); + } + } + } +} + #[derive(Debug, Clone)] enum BlockOrLine { Line(String), @@ -5153,7 +5170,7 @@ fn codegen_struct( let mut setter = codegen::Function::new(&format!("set_{}", field.name)); setter .arg_mut_self() - .arg(&field.name, &field.rust_type.for_wasm_param(types)) + .arg(&field.name, field.rust_type.for_wasm_param(types)) .vis("pub"); // don't call needs_bounds_check_if_inlined() since if it's a RustType it's checked during that ctor if let Some(bounds) = field.rust_type.config.bounds.as_ref() { @@ -6824,7 +6841,7 @@ fn generate_enum( let mut kind = codegen::Enum::new(format!("{name}Kind")); kind.vis("pub"); for variant in variants.iter() { - kind.new_variant(&variant.name.to_string()); + kind.new_variant(variant.name.to_string()); } kind.attr("wasm_bindgen"); gen_scope.wasm(types, name).push_enum(kind); @@ -6927,7 +6944,7 @@ fn generate_enum( for variant in variants.iter() { let enum_gen_info = EnumVariantInRust::new(types, variant, rep, cli); let variant_var_name = variant.name_as_var(); - let mut v = codegen::Variant::new(&variant.name.to_string()); + let mut v = codegen::Variant::new(variant.name.to_string()); match enum_gen_info.names.len() { 0 => {} 1 if enum_gen_info.enc_fields.is_empty() => { diff --git a/src/intermediate.rs b/src/intermediate.rs index a9590f3..a10fb1e 100644 --- a/src/intermediate.rs +++ b/src/intermediate.rs @@ -16,27 +16,47 @@ use once_cell::sync::Lazy; pub static ROOT_SCOPE: Lazy = Lazy::new(|| vec![String::from("lib")].into()); #[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)] -pub struct ModuleScope(Vec); +pub struct ModuleScope { + export: bool, + scope: Vec, +} impl ModuleScope { pub fn new(scope: Vec) -> Self { Self::from(scope) } + /// Make a new ModuleScope using only the first [depth] components + pub fn parents(&self, depth: usize) -> Self { + Self { + export: self.export, + scope: self.scope.as_slice()[0..depth].to_vec(), + } + } + + pub fn export(&self) -> bool { + self.export + } + pub fn components(&self) -> &Vec { - &self.0 + &self.scope } } impl From> for ModuleScope { - fn from(scope: Vec) -> Self { - Self(scope) + fn from(mut scope: Vec) -> Self { + let export = match scope.first() { + Some(first_scope) => first_scope != crate::parsing::EXTERN_DEPS_DIR, + None => true, + }; + let scope = if export { scope } else { scope.split_off(1) }; + Self { export, scope } } } impl std::fmt::Display for ModuleScope { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.0.join("::")) + write!(f, "{}", self.scope.join("::")) } } @@ -87,6 +107,7 @@ pub struct IntermediateTypes<'a> { generic_instances: BTreeMap, news_can_fail: BTreeSet, used_as_key: BTreeSet, + // which scope an ident is declared in scopes: BTreeMap, // for scope() to work we keep this here. // Returning a reference to the const ROOT_SCOPE complains of returning a temporary @@ -986,8 +1007,6 @@ mod idents { // except for defining new cddl rules, since those should not be reserved identifiers pub fn new(cddl_ident: CDDLIdent) -> Self { // int is special here since it refers to our own rust struct, not a primitive - println!("{}", cddl_ident.0); - assert!( !STD_TYPES.contains(&&super::convert_to_camel_case(&cddl_ident.0)[..]), "Cannot use reserved Rust type name: \"{}\"", @@ -1502,7 +1521,6 @@ impl ConceptualRustType { } pub fn directly_wasm_exposable(&self, types: &IntermediateTypes) -> bool { - println!("{self:?}.directly_wasm_exposable()"); match self { Self::Fixed(_) => false, Self::Primitive(_) => true, diff --git a/src/main.rs b/src/main.rs index ad58865..7c36177 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ use parsing::{parse_rule, rule_ident, rule_is_scope_marker}; pub static CLI_ARGS: Lazy = Lazy::new(Cli::parse); -use crate::intermediate::{ModuleScope, ROOT_SCOPE}; +use crate::intermediate::ROOT_SCOPE; fn cddl_paths( output: &mut Vec, @@ -78,9 +78,9 @@ fn main() -> Result<(), Box> { components.pop(); } } - ModuleScope::new(components) + components.join("::") } else { - ROOT_SCOPE.clone() + ROOT_SCOPE.to_string() }; std::fs::read_to_string(input_file).map(|raw| { format!( diff --git a/src/parsing.rs b/src/parsing.rs index 814ee8d..62c8fbf 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -23,6 +23,7 @@ enum ControlOperator { } pub const SCOPE_MARKER: &str = "_CDDL_CODEGEN_SCOPE_MARKER_"; +pub const EXTERN_DEPS_DIR: &str = "_CDDL_CODEGEN_EXTERN_DEPS_DIR_"; pub const EXTERN_MARKER: &str = "_CDDL_CODEGEN_EXTERN_TYPE_"; pub const RAW_BYTES_MARKER: &str = "_CDDL_CODEGEN_RAW_BYTES_TYPE_"; diff --git a/src/test.rs b/src/test.rs index 375ce2c..8107dfe 100644 --- a/src/test.rs +++ b/src/test.rs @@ -72,14 +72,24 @@ fn run_test( lib_rs.write_all(test_rs.as_bytes()).unwrap(); std::mem::drop(lib_rs); // add extra deps used within tests - let mut cargo_toml = std::fs::OpenOptions::new() - .append(true) - .open(test_path.join(format!("{export_path}/rust/Cargo.toml"))) - .unwrap(); - for dep in test_deps { - cargo_toml.write_all(dep.as_bytes()).unwrap(); + if !test_deps.is_empty() { + let mut cargo_toml = std::fs::OpenOptions::new() + .append(true) + .open(test_path.join(format!("{export_path}/rust/Cargo.toml"))) + .unwrap(); + for dep in test_deps { + cargo_toml.write_all(dep.as_bytes()).unwrap(); + } + // copy test deps to wasm too in case they're used (e.g. extern deps dir crates) + if let Ok(mut cargo_toml_wasm) = std::fs::OpenOptions::new() + .append(true) + .open(test_path.join(format!("{export_path}/wasm/Cargo.toml"))) + { + for dep in test_deps { + cargo_toml_wasm.write_all(dep.as_bytes()).unwrap(); + } + } } - std::mem::drop(cargo_toml); // run tests in generated code println!(" ------ testing ------"); let cargo_test = std::process::Command::new("cargo") @@ -391,3 +401,19 @@ fn json_preserve() { &[], ); } + +#[test] +fn extern_deps() { + run_test( + "extern-deps", + &[ + "--preserve-encodings=true", + "--common-import-override=extern_dep_crate", + ], + None, + &[], + &[], + true, + &["extern-dep-crate = { path = \"../../../extern-dep-crate\" }"], + ); +} diff --git a/static/serialization_preserve.rs b/static/serialization_preserve.rs index 0e18d4a..a71d14f 100644 --- a/static/serialization_preserve.rs +++ b/static/serialization_preserve.rs @@ -54,7 +54,7 @@ pub trait DeserializeEmbeddedGroup { } #[inline] -pub(crate) fn sz_max(sz: cbor_event::Sz) -> u64 { +pub fn sz_max(sz: cbor_event::Sz) -> u64 { match sz { cbor_event::Sz::Inline => 23u64, cbor_event::Sz::One => u8::MAX as u64, diff --git a/static/serialization_preserve_force_canonical.rs b/static/serialization_preserve_force_canonical.rs index 465c9c0..53d7a65 100644 --- a/static/serialization_preserve_force_canonical.rs +++ b/static/serialization_preserve_force_canonical.rs @@ -1,5 +1,5 @@ #[inline] -pub(crate) fn fit_sz(len: u64, sz: Option, force_canonical: bool) -> cbor_event::Sz { +pub fn fit_sz(len: u64, sz: Option, force_canonical: bool) -> cbor_event::Sz { match sz { Some(sz) => if !force_canonical && len <= sz_max(sz) { sz diff --git a/static/serialization_preserve_non_force_canonical.rs b/static/serialization_preserve_non_force_canonical.rs index d9a1bb2..b72536a 100644 --- a/static/serialization_preserve_non_force_canonical.rs +++ b/static/serialization_preserve_non_force_canonical.rs @@ -1,5 +1,5 @@ #[inline] -pub(crate) fn fit_sz(len: u64, sz: Option) -> cbor_event::Sz { +pub fn fit_sz(len: u64, sz: Option) -> cbor_event::Sz { match sz { Some(sz) => if len <= sz_max(sz) { sz diff --git a/tests/extern-dep-crate/Cargo.toml b/tests/extern-dep-crate/Cargo.toml new file mode 100644 index 0000000..de67b80 --- /dev/null +++ b/tests/extern-dep-crate/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "extern-dep-crate" +version = "0.1.0" +edition = "2018" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +cbor_event = "2.4.0" +wasm-bindgen = "0.2" +linked-hash-map = "0.5.3" diff --git a/tests/extern-dep-crate/README.md b/tests/extern-dep-crate/README.md new file mode 100644 index 0000000..0b8745d --- /dev/null +++ b/tests/extern-dep-crate/README.md @@ -0,0 +1,3 @@ +This is a simple crate to test out the `_CDDL_CODEGEN_EXTERN_DEPS_DIR_` feature. + +It is not a test but is instead used by other tests. \ No newline at end of file diff --git a/tests/extern-dep-crate/src/cbor_encodings.rs b/tests/extern-dep-crate/src/cbor_encodings.rs new file mode 100644 index 0000000..ef179d4 --- /dev/null +++ b/tests/extern-dep-crate/src/cbor_encodings.rs @@ -0,0 +1,10 @@ +use crate::serialization::{LenEncoding, StringEncoding}; + +#[derive(Clone, Debug, Default)] +pub struct ExternCrateFooEncoding { + pub len_encoding: LenEncoding, + pub tag_encoding: Option, + pub index_0_encoding: Option, + pub index_1_encoding: StringEncoding, + pub index_2_encoding: StringEncoding, +} diff --git a/tests/extern-dep-crate/src/error.rs b/tests/extern-dep-crate/src/error.rs new file mode 100644 index 0000000..6818af2 --- /dev/null +++ b/tests/extern-dep-crate/src/error.rs @@ -0,0 +1,146 @@ +use cbor_event::{self, de::Deserializer}; +use std::io::{BufRead, Seek}; + +#[derive(Debug)] +pub enum Key { + Str(String), + Uint(u64), + Float(f64), +} + +impl std::fmt::Display for Key { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Key::Str(x) => write!(f, "\"{}\"", x), + Key::Uint(x) => write!(f, "{}", x), + Key::Float(x) => write!(f, "{}", x), + } + } +} + +#[derive(Debug)] +pub enum DeserializeFailure { + BreakInDefiniteLen, + CBOR(cbor_event::Error), + DefiniteLenMismatch(u64, Option), + DuplicateKey(Key), + EndingBreakMissing, + ExpectedNull, + FixedValueMismatch{ + found: Key, + expected: Key, + }, + /// Invalid internal structure imposed on top of the CBOR format + InvalidStructure(Box), + MandatoryFieldMissing(Key), + NoVariantMatched, + NoVariantMatchedWithCauses(Vec), + RangeCheck{ + found: isize, + min: Option, + max: Option, + }, + TagMismatch{ + found: u64, + expected: u64, + }, + UnknownKey(Key), + UnexpectedKeyType(cbor_event::Type), +} + +// we might want to add more info like which field, +#[derive(Debug)] +pub struct DeserializeError { + location: Option, + failure: DeserializeFailure, +} + +impl DeserializeError { + pub fn new>(location: T, failure: DeserializeFailure) -> Self { + Self { + location: Some(location.into()), + failure, + } + } + + pub fn annotate>(self, location: T) -> Self { + match self.location { + Some(loc) => Self::new(format!("{}.{}", location.into(), loc), self.failure), + None => Self::new(location, self.failure), + } + } + + fn fmt_indent(&self, f: &mut std::fmt::Formatter<'_>, indent: u32) -> std::fmt::Result { + use std::fmt::Display; + for _ in 0..indent { + write!(f, "\t")?; + } + match &self.location { + Some(loc) => write!(f, "Deserialization failed in {} because: ", loc), + None => write!(f, "Deserialization: "), + }?; + match &self.failure { + DeserializeFailure::BreakInDefiniteLen => write!(f, "Encountered CBOR Break while reading definite length sequence"), + DeserializeFailure::CBOR(e) => e.fmt(f), + DeserializeFailure::DefiniteLenMismatch(found, expected) => { + write!(f, "Definite length mismatch: found {}", found)?; + if let Some(expected_elems) = expected { + write!(f, ", expected: {}", expected_elems)?; + } + Ok(()) + }, + DeserializeFailure::DuplicateKey(key) => write!(f, "Duplicate key: {}", key), + DeserializeFailure::EndingBreakMissing => write!(f, "Missing ending CBOR Break"), + DeserializeFailure::ExpectedNull => write!(f, "Expected null, found other type"), + DeserializeFailure::FixedValueMismatch{ found, expected } => write!(f, "Expected fixed value {} found {}", expected, found), + DeserializeFailure::InvalidStructure(e) => { + write!(f, "Invalid internal structure: {}", e) + } + DeserializeFailure::MandatoryFieldMissing(key) => write!(f, "Mandatory field {} not found", key), + DeserializeFailure::NoVariantMatched => write!(f, "No variant matched"), + DeserializeFailure::NoVariantMatchedWithCauses(errs) => { + write!(f, "No variant matched. Failures:\n")?; + for e in errs { + e.fmt_indent(f, indent + 1)?; + write!(f, "\n")?; + } + Ok(()) + }, + DeserializeFailure::RangeCheck{ found, min, max } => match (min, max) { + (Some(min), Some(max)) => write!(f, "{} not in range {} - {}", found, min, max), + (Some(min), None) => write!(f, "{} not at least {}", found, min), + (None, Some(max)) => write!(f, "{} not at most {}", found, max), + (None, None) => write!(f, "invalid range (no min nor max specified)"), + }, + DeserializeFailure::TagMismatch{ found, expected } => write!(f, "Expected tag {}, found {}", expected, found), + DeserializeFailure::UnknownKey(key) => write!(f, "Found unexpected key {}", key), + DeserializeFailure::UnexpectedKeyType(ty) => write!(f, "Found unexpected key of CBOR type {:?}", ty), + } + } +} + +impl std::error::Error for DeserializeError {} + +impl std::fmt::Display for DeserializeError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.fmt_indent(f, 0) + } +} + +impl From for DeserializeError { + fn from(failure: DeserializeFailure) -> DeserializeError { + DeserializeError { + location: None, + failure, + } + } +} + +impl From for DeserializeError { + fn from(err: cbor_event::Error) -> DeserializeError { + DeserializeError { + location: None, + failure: DeserializeFailure::CBOR(err), + } + } +} diff --git a/tests/extern-dep-crate/src/lib.rs b/tests/extern-dep-crate/src/lib.rs new file mode 100644 index 0000000..6c8b329 --- /dev/null +++ b/tests/extern-dep-crate/src/lib.rs @@ -0,0 +1,51 @@ +use std::collections::BTreeMap; +use wasm_bindgen::prelude::{wasm_bindgen, JsError}; +use cbor_encodings::ExternCrateFooEncoding; + +pub mod cbor_encodings; +pub mod error; +pub mod ordered_hash_map; +pub mod serialization; +pub mod sub; + +#[wasm_bindgen] +#[derive(Clone, Debug)] +pub struct ExternCrateFoo { + index_0: u64, + index_1: String, + index_2: Vec, + encodings: Option, +} + +#[wasm_bindgen] +impl ExternCrateFoo { + pub fn new(index_0: u64, index_1: String, index_2: Vec) -> Self { + Self { + index_0, + index_1, + index_2, + encodings: None, + } + } + + pub fn to_cbor_bytes(&self) -> Vec { + serialization::ToCBORBytes::to_cbor_bytes(&self) + } + + pub fn from_cbor_bytes(cbor_bytes: &[u8]) -> Result { + serialization::Deserialize::from_cbor_bytes(cbor_bytes) + .map_err(|e| JsError::new(&format!("from_bytes: {}", e))) + } + + pub fn index_0(&self) -> u64 { + self.index_0 + } + + pub fn index_1(&self) -> String { + self.index_1.clone() + } + + pub fn index_2(&self) -> Vec { + self.index_2.clone() + } +} diff --git a/tests/extern-dep-crate/src/ordered_hash_map.rs b/tests/extern-dep-crate/src/ordered_hash_map.rs new file mode 100644 index 0000000..e4d561d --- /dev/null +++ b/tests/extern-dep-crate/src/ordered_hash_map.rs @@ -0,0 +1,35 @@ +use core::hash::Hash; + +#[derive(Clone, Debug, Default, Hash, Ord, Eq, PartialEq, PartialOrd)] +pub struct OrderedHashMap(linked_hash_map::LinkedHashMap) +where + K: Hash + Eq + Ord; + +impl std::ops::Deref for OrderedHashMap +where + K: Hash + Eq + Ord, +{ + type Target = linked_hash_map::LinkedHashMap; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl std::ops::DerefMut for OrderedHashMap +where + K: Hash + Eq + Ord, +{ + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl OrderedHashMap +where + K: Hash + Eq + Ord, +{ + pub fn new() -> Self { + Self(linked_hash_map::LinkedHashMap::new()) + } +} diff --git a/tests/extern-dep-crate/src/serialization.rs b/tests/extern-dep-crate/src/serialization.rs new file mode 100644 index 0000000..e33435b --- /dev/null +++ b/tests/extern-dep-crate/src/serialization.rs @@ -0,0 +1,333 @@ +// same as cbor_event::de::Deserialize but with our DeserializeError +pub trait Deserialize { + fn from_cbor_bytes(data: &[u8]) -> Result + where + Self: Sized, + { + let mut raw = Deserializer::from(std::io::Cursor::new(data)); + Self::deserialize(&mut raw) + } + + fn deserialize(raw: &mut Deserializer) -> Result + where + Self: Sized; +} + +impl Deserialize for T { + fn deserialize(raw: &mut Deserializer) -> Result { + T::deserialize(raw).map_err(DeserializeError::from) + } +} +pub struct CBORReadLen { + deser_len: cbor_event::LenSz, + read: u64, +} + +impl CBORReadLen { + pub fn new(len: cbor_event::LenSz) -> Self { + Self { + deser_len: len, + read: 0, + } + } + + pub fn read(&self) -> u64 { + self.read + } + + // Marks {n} values as being read, and if we go past the available definite length + // given by the CBOR, we return an error. + pub fn read_elems(&mut self, count: usize) -> Result<(), DeserializeFailure> { + match self.deser_len { + cbor_event::LenSz::Len(n, _) => { + self.read += count as u64; + if self.read > n { + Err(DeserializeFailure::DefiniteLenMismatch(n, None)) + } else { + Ok(()) + } + } + cbor_event::LenSz::Indefinite => Ok(()), + } + } + + pub fn finish(&self) -> Result<(), DeserializeFailure> { + match self.deser_len { + cbor_event::LenSz::Len(n, _) => { + if self.read == n { + Ok(()) + } else { + Err(DeserializeFailure::DefiniteLenMismatch(n, Some(self.read))) + } + } + cbor_event::LenSz::Indefinite => Ok(()), + } + } +} + +pub trait DeserializeEmbeddedGroup { + fn deserialize_as_embedded_group( + raw: &mut Deserializer, + read_len: &mut CBORReadLen, + len: cbor_event::LenSz, + ) -> Result + where + Self: Sized; +} + +#[inline] +pub(crate) fn sz_max(sz: cbor_event::Sz) -> u64 { + match sz { + cbor_event::Sz::Inline => 23u64, + cbor_event::Sz::One => u8::MAX as u64, + cbor_event::Sz::Two => u16::MAX as u64, + cbor_event::Sz::Four => u32::MAX as u64, + cbor_event::Sz::Eight => u64::MAX, + } +} + +#[derive(Debug, PartialEq, Eq, Copy, Clone)] +pub enum LenEncoding { + Canonical, + Definite(cbor_event::Sz), + Indefinite, +} + +impl Default for LenEncoding { + fn default() -> Self { + Self::Canonical + } +} + +impl From for LenEncoding { + fn from(len_sz: cbor_event::LenSz) -> Self { + match len_sz { + cbor_event::LenSz::Len(len, sz) => { + if cbor_event::Sz::canonical(len) == sz { + Self::Canonical + } else { + Self::Definite(sz) + } + } + cbor_event::LenSz::Indefinite => Self::Indefinite, + } + } +} + +#[derive(Debug, PartialEq, Eq, Clone)] +pub enum StringEncoding { + Canonical, + Indefinite(Vec<(u64, cbor_event::Sz)>), + Definite(cbor_event::Sz), +} + +impl Default for StringEncoding { + fn default() -> Self { + Self::Canonical + } +} + +impl From for StringEncoding { + fn from(len_sz: cbor_event::StringLenSz) -> Self { + match len_sz { + cbor_event::StringLenSz::Len(sz) => Self::Definite(sz), + cbor_event::StringLenSz::Indefinite(lens) => Self::Indefinite(lens), + } + } +} +#[inline] +pub fn fit_sz(len: u64, sz: Option) -> cbor_event::Sz { + match sz { + Some(sz) => { + if len <= sz_max(sz) { + sz + } else { + cbor_event::Sz::canonical(len) + } + } + None => cbor_event::Sz::canonical(len), + } +} + +impl LenEncoding { + pub fn to_len_sz(&self, len: u64) -> cbor_event::LenSz { + match self { + Self::Canonical => cbor_event::LenSz::Len(len, cbor_event::Sz::canonical(len)), + Self::Definite(sz) => { + if sz_max(*sz) >= len { + cbor_event::LenSz::Len(len, *sz) + } else { + cbor_event::LenSz::Len(len, cbor_event::Sz::canonical(len)) + } + } + Self::Indefinite => cbor_event::LenSz::Indefinite, + } + } + + pub fn end<'a, W: Write + Sized>( + &self, + serializer: &'a mut Serializer, + ) -> cbor_event::Result<&'a mut Serializer> { + if *self == Self::Indefinite { + serializer.write_special(cbor_event::Special::Break)?; + } + Ok(serializer) + } +} + +impl StringEncoding { + pub fn to_str_len_sz(&self, len: u64) -> cbor_event::StringLenSz { + match self { + Self::Canonical => cbor_event::StringLenSz::Len(cbor_event::Sz::canonical(len)), + Self::Definite(sz) => { + if sz_max(*sz) >= len { + cbor_event::StringLenSz::Len(*sz) + } else { + cbor_event::StringLenSz::Len(cbor_event::Sz::canonical(len)) + } + } + Self::Indefinite(lens) => cbor_event::StringLenSz::Indefinite(lens.clone()), + } + } +} +pub trait SerializeEmbeddedGroup { + fn serialize_as_embedded_group<'a, W: Write + Sized>( + &self, + serializer: &'a mut Serializer, + ) -> cbor_event::Result<&'a mut Serializer>; +} + +pub trait ToCBORBytes { + fn to_cbor_bytes(&self) -> Vec; +} + +impl ToCBORBytes for T { + fn to_cbor_bytes(&self) -> Vec { + let mut buf = Serializer::new_vec(); + self.serialize(&mut buf).unwrap(); + buf.finalize() + } +} + +// This file was code-generated using an experimental CDDL to rust tool: +// https://github.com/dcSpark/cddl-codegen + +use super::cbor_encodings::*; +use super::*; +use crate::error::*; +use cbor_event::de::Deserializer; +use cbor_event::se::{Serialize, Serializer}; +use std::io::{BufRead, Seek, SeekFrom, Write}; + +impl cbor_event::se::Serialize for ExternCrateFoo { + fn serialize<'se, W: Write>( + &self, + serializer: &'se mut Serializer, + ) -> cbor_event::Result<&'se mut Serializer> { + serializer.write_tag_sz( + 11u64, + fit_sz( + 11u64, + self.encodings + .as_ref() + .map(|encs| encs.tag_encoding) + .unwrap_or_default(), + ), + )?; + serializer.write_array_sz( + self.encodings + .as_ref() + .map(|encs| encs.len_encoding) + .unwrap_or_default() + .to_len_sz(3), + )?; + serializer.write_unsigned_integer_sz( + self.index_0, + fit_sz( + self.index_0, + self.encodings + .as_ref() + .map(|encs| encs.index_0_encoding) + .unwrap_or_default(), + ), + )?; + serializer.write_text_sz( + &self.index_1, + self.encodings + .as_ref() + .map(|encs| encs.index_1_encoding.clone()) + .unwrap_or_default() + .to_str_len_sz(self.index_1.len() as u64), + )?; + serializer.write_bytes_sz( + &self.index_2, + self.encodings + .as_ref() + .map(|encs| encs.index_2_encoding.clone()) + .unwrap_or_default() + .to_str_len_sz(self.index_2.len() as u64), + )?; + self.encodings + .as_ref() + .map(|encs| encs.len_encoding) + .unwrap_or_default() + .end(serializer) + } +} + +impl Deserialize for ExternCrateFoo { + fn deserialize(raw: &mut Deserializer) -> Result { + let (tag, tag_encoding) = raw.tag_sz()?; + if tag != 11 { + return Err(DeserializeError::new( + "ExternCrateFoo", + DeserializeFailure::TagMismatch { + found: tag, + expected: 11, + }, + )); + } + let len = raw.array_sz()?; + let len_encoding: LenEncoding = len.into(); + let mut read_len = CBORReadLen::new(len); + read_len.read_elems(3)?; + read_len.finish()?; + (|| -> Result<_, DeserializeError> { + let (index_0, index_0_encoding) = raw + .unsigned_integer_sz() + .map_err(Into::::into) + .map(|(x, enc)| (x, Some(enc))) + .map_err(|e: DeserializeError| e.annotate("index_0"))?; + let (index_1, index_1_encoding) = raw + .text_sz() + .map_err(Into::::into) + .map(|(s, enc)| (s, StringEncoding::from(enc))) + .map_err(|e: DeserializeError| e.annotate("index_1"))?; + let (index_2, index_2_encoding) = raw + .bytes_sz() + .map_err(Into::::into) + .map(|(bytes, enc)| (bytes, StringEncoding::from(enc))) + .map_err(|e: DeserializeError| e.annotate("index_2"))?; + match len { + cbor_event::LenSz::Len(_, _) => (), + cbor_event::LenSz::Indefinite => match raw.special()? { + cbor_event::Special::Break => (), + _ => return Err(DeserializeFailure::EndingBreakMissing.into()), + }, + } + Ok(ExternCrateFoo { + index_0, + index_1, + index_2, + encodings: Some(ExternCrateFooEncoding { + len_encoding, + tag_encoding: Some(tag_encoding), + index_0_encoding, + index_1_encoding, + index_2_encoding, + }), + }) + })() + .map_err(|e| e.annotate("ExternCrateFoo")) + } +} diff --git a/tests/extern-dep-crate/src/sub/mod.rs b/tests/extern-dep-crate/src/sub/mod.rs new file mode 100644 index 0000000..a94a210 --- /dev/null +++ b/tests/extern-dep-crate/src/sub/mod.rs @@ -0,0 +1 @@ +pub mod module; \ No newline at end of file diff --git a/tests/extern-dep-crate/src/sub/module.rs b/tests/extern-dep-crate/src/sub/module.rs new file mode 100644 index 0000000..ec0a9b6 --- /dev/null +++ b/tests/extern-dep-crate/src/sub/module.rs @@ -0,0 +1 @@ +pub type UintTypedef = u64; \ No newline at end of file diff --git a/tests/extern-deps/inputs/_CDDL_CODEGEN_EXTERN_DEPS_DIR_/extern_dep_crate/mod.cddl b/tests/extern-deps/inputs/_CDDL_CODEGEN_EXTERN_DEPS_DIR_/extern_dep_crate/mod.cddl new file mode 100644 index 0000000..546e089 --- /dev/null +++ b/tests/extern-deps/inputs/_CDDL_CODEGEN_EXTERN_DEPS_DIR_/extern_dep_crate/mod.cddl @@ -0,0 +1 @@ +extern_crate_foo = _CDDL_CODEGEN_EXTERN_TYPE_ \ No newline at end of file diff --git a/tests/extern-deps/inputs/_CDDL_CODEGEN_EXTERN_DEPS_DIR_/extern_dep_crate/sub/module.cddl b/tests/extern-deps/inputs/_CDDL_CODEGEN_EXTERN_DEPS_DIR_/extern_dep_crate/sub/module.cddl new file mode 100644 index 0000000..9b43ff1 --- /dev/null +++ b/tests/extern-deps/inputs/_CDDL_CODEGEN_EXTERN_DEPS_DIR_/extern_dep_crate/sub/module.cddl @@ -0,0 +1 @@ +uint_typedef = uint \ No newline at end of file diff --git a/tests/extern-deps/inputs/a/c/foo.cddl b/tests/extern-deps/inputs/a/c/foo.cddl new file mode 100644 index 0000000..e425d7c --- /dev/null +++ b/tests/extern-deps/inputs/a/c/foo.cddl @@ -0,0 +1 @@ +foo = [uint_typedef, text, bytes] diff --git a/tests/extern-deps/inputs/a/mod.cddl b/tests/extern-deps/inputs/a/mod.cddl new file mode 100644 index 0000000..ea3fcb8 --- /dev/null +++ b/tests/extern-deps/inputs/a/mod.cddl @@ -0,0 +1 @@ +baz = [0, uint] \ No newline at end of file diff --git a/tests/extern-deps/inputs/b/bar.cddl b/tests/extern-deps/inputs/b/bar.cddl new file mode 100644 index 0000000..db288ab --- /dev/null +++ b/tests/extern-deps/inputs/b/bar.cddl @@ -0,0 +1,12 @@ +bar = { + foo: #6.1337([* foo]), + ? derp: uint, + 1 : uint / null, + ? 5: text, + five: 5, + foo_map: { * foo => foo }, + ? baz: baz, +} + +; test refs too +bar_typedef = bar \ No newline at end of file diff --git a/tests/extern-deps/inputs/lib.cddl b/tests/extern-deps/inputs/lib.cddl new file mode 100644 index 0000000..d6683b4 --- /dev/null +++ b/tests/extern-deps/inputs/lib.cddl @@ -0,0 +1,13 @@ +everything = [ + ; from a single-level nested mod + foo, + extern_crate_foo, + ; test using in arrays too + bars: [* bar], + ; and maps + table: { * uint => bar_typedef } + ; and from a multi-level nested mod + baz: baz, + ; and root dir mod + qux: qux, +] \ No newline at end of file diff --git a/tests/extern-deps/inputs/qux.cddl b/tests/extern-deps/inputs/qux.cddl new file mode 100644 index 0000000..18f5bd5 --- /dev/null +++ b/tests/extern-deps/inputs/qux.cddl @@ -0,0 +1 @@ +qux = [2, text] \ No newline at end of file diff --git a/tests/extern-deps/tests.rs b/tests/extern-deps/tests.rs new file mode 100644 index 0000000..e92fcc4 --- /dev/null +++ b/tests/extern-deps/tests.rs @@ -0,0 +1 @@ +// the test really only tests compilation so there are no unit tests here \ No newline at end of file