diff --git a/.gitignore b/.gitignore index 22ed0324..00faa555 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .vscode .idea target -/test /benchmark/output diff --git a/Cargo.lock b/Cargo.lock index dc57c3bd..9a14f812 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -130,7 +130,7 @@ checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -152,7 +152,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -163,7 +163,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -180,9 +180,9 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "axum" -version = "0.7.7" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "504e3947307ac8326a5437504c517c4b56716c9d98fac0028c2acc7ca47d70ae" +checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" dependencies = [ "async-trait", "axum-core", @@ -199,7 +199,7 @@ dependencies = [ "pin-project-lite", "rustversion", "serde", - "sync_wrapper 1.0.1", + "sync_wrapper 1.0.2", "tower 0.5.1", "tower-layer", "tower-service", @@ -220,7 +220,7 @@ dependencies = [ "mime", "pin-project-lite", "rustversion", - "sync_wrapper 1.0.1", + "sync_wrapper 1.0.2", "tower-layer", "tower-service", ] @@ -320,9 +320,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.37" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40545c26d092346d8a8dab71ee48e7685a7a9cba76e634790c215b41a4a7b4cf" +checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" dependencies = [ "jobserver", "libc", @@ -355,9 +355,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.20" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" +checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" dependencies = [ "clap_builder", "clap_derive", @@ -365,9 +365,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.20" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" +checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" dependencies = [ "anstream", "anstyle", @@ -385,14 +385,14 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] name = "clap_lex" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" [[package]] name = "code-generation" @@ -477,9 +477,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.14" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3" dependencies = [ "libc", ] @@ -616,7 +616,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -664,7 +664,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -729,7 +729,7 @@ dependencies = [ "http 1.1.0", "http-body 1.0.1", "http-body-util", - "hyper 1.5.0", + "hyper 1.5.1", "hyper-util", "metainfo", "motore", @@ -771,9 +771,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.34" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0" +checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" dependencies = [ "crc32fast", "miniz_oxide", @@ -881,7 +881,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -1002,9 +1002,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +checksum = "ccae279728d634d083c00f6099cb58f01cc99c145b84b8be2f6c74618d79922e" dependencies = [ "atomic-waker", "bytes", @@ -1033,9 +1033,9 @@ checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "hashbrown" -version = "0.15.1" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" [[package]] name = "heck" @@ -1235,14 +1235,14 @@ dependencies = [ [[package]] name = "hyper" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbbff0a806a4728c99295b254c8838933b5b082d75e3cb70c8dab21fdfbcfa9a" +checksum = "97818827ef4f364230e16705d4706e2897df2bb60617d6ca15d598025a3c481f" dependencies = [ "bytes", "futures-channel", "futures-util", - "h2 0.4.6", + "h2 0.4.7", "http 1.1.0", "http-body 1.0.1", "httparse", @@ -1276,9 +1276,9 @@ checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ "futures-util", "http 1.1.0", - "hyper 1.5.0", + "hyper 1.5.1", "hyper-util", - "rustls 0.23.16", + "rustls 0.23.18", "rustls-pki-types", "tokio", "tokio-rustls 0.26.0", @@ -1291,7 +1291,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0" dependencies = [ - "hyper 1.5.0", + "hyper 1.5.1", "hyper-util", "pin-project-lite", "tokio", @@ -1306,7 +1306,7 @@ checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", "http-body-util", - "hyper 1.5.0", + "hyper 1.5.1", "hyper-util", "native-tls", "tokio", @@ -1325,7 +1325,7 @@ dependencies = [ "futures-util", "http 1.1.0", "http-body 1.0.1", - "hyper 1.5.0", + "hyper 1.5.1", "pin-project-lite", "socket2", "tokio", @@ -1471,17 +1471,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", -] - -[[package]] -name = "idna" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", + "syn 2.0.89", ] [[package]] @@ -1532,7 +1522,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.15.1", + "hashbrown 0.15.2", ] [[package]] @@ -1600,9 +1590,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "jobserver" @@ -1630,9 +1620,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.162" +version = "0.2.165" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" +checksum = "fcb4d3d38eab6c5239a362fa8bae48c03baf980a6e7079f063942d563ef3533e" [[package]] name = "libgit2-sys" @@ -1693,9 +1683,9 @@ checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "litemap" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" [[package]] name = "litrs" @@ -1828,9 +1818,9 @@ dependencies = [ [[package]] name = "mockall" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c28b3fb6d753d28c20e826cd46ee611fda1cf3cde03a443a974043247c065a" +checksum = "39a6bfcc6c8c7eed5ee98b9c3e33adc726054389233e201c95dab2d41a3839d2" dependencies = [ "cfg-if", "downcast", @@ -1842,14 +1832,14 @@ dependencies = [ [[package]] name = "mockall_derive" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "341014e7f530314e9a1fdbc7400b244efea7122662c96bfa248c31da5bfb2020" +checksum = "25ca3004c2efe9011bd4e461bd8256445052b9615405b4f7ea43fc8ca5c20898" dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -1861,7 +1851,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -2024,7 +2014,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -2071,7 +2061,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -2082,9 +2072,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "300.4.0+3.4.0" +version = "300.4.1+3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a709e02f2b4aca747929cca5ed248880847c650233cf8b8cdc48f40aaf4898a6" +checksum = "faa4eac4138c62414b5622d1b31c5c304f34b406b013c079c2bbc652fdd6678c" dependencies = [ "cc", ] @@ -2187,9 +2177,9 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "pathdiff" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c5ce1153ab5b689d0c074c4e7fc613e942dfb7dd9eea5ab202d2ad91fe361" +checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" [[package]] name = "percent-encoding" @@ -2237,7 +2227,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -2251,9 +2241,8 @@ dependencies = [ [[package]] name = "pilota" -version = "0.11.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6eb56fd2aeff9784e6c4a0f6eca4f527bacba60716c198a47057b980775ccf3b" +version = "0.11.8" +source = "git+https://github.com/cloudwego/pilota.git?branch=main#064047795bd4615fc5fed393cdcfa14bd2f3206d" dependencies = [ "ahash", "anyhow", @@ -2274,9 +2263,8 @@ dependencies = [ [[package]] name = "pilota-build" -version = "0.11.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "996a8c160a151f95b19e96b38728e7981ac198dcb2e46f1196378745b2c00362" +version = "0.11.26" +source = "git+https://github.com/cloudwego/pilota.git?branch=main#064047795bd4615fc5fed393cdcfa14bd2f3206d" dependencies = [ "ahash", "anyhow", @@ -2299,7 +2287,7 @@ dependencies = [ "scoped-tls", "serde", "serde_yaml", - "syn 2.0.87", + "syn 2.0.89", "toml", "tracing", "tracing-subscriber", @@ -2308,8 +2296,7 @@ dependencies = [ [[package]] name = "pilota-thrift-parser" version = "0.11.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f96e098d21a8d4f88242e9523140036a0e31bde96edc915c7b5ed24e32980c8" +source = "git+https://github.com/cloudwego/pilota.git?branch=main#064047795bd4615fc5fed393cdcfa14bd2f3206d" dependencies = [ "nom", ] @@ -2331,7 +2318,7 @@ checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -2354,9 +2341,9 @@ checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "portable-atomic" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" +checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6" [[package]] name = "powerfmt" @@ -2420,9 +2407,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.89" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -2480,11 +2467,11 @@ checksum = "33cb294fe86a74cbcf50d4445b37da762029549ebeea341421c7c70370f86cac" [[package]] name = "publicsuffix" -version = "2.2.3" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96a8c1bda5ae1af7f99a2962e49df150414a43d62404644d98dd5c3a93d07457" +checksum = "6f42ea446cab60335f76979ec15e12619a2165b5ae2c12166bef27d283a9fadf" dependencies = [ - "idna 0.3.0", + "idna 1.0.3", "psl-types", ] @@ -2616,7 +2603,7 @@ checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.8", + "regex-automata 0.4.9", "regex-syntax 0.8.5", ] @@ -2631,9 +2618,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -2704,11 +2691,11 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2 0.4.6", + "h2 0.4.7", "http 1.1.0", "http-body 1.0.1", "http-body-util", - "hyper 1.5.0", + "hyper 1.5.1", "hyper-rustls 0.27.3", "hyper-tls", "hyper-util", @@ -2725,7 +2712,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", - "sync_wrapper 1.0.1", + "sync_wrapper 1.0.2", "system-configuration 0.6.1", "tokio", "tokio-native-tls", @@ -2794,9 +2781,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.40" +version = "0.38.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0" +checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" dependencies = [ "bitflags 2.6.0", "errno", @@ -2833,9 +2820,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.16" +version = "0.23.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e" +checksum = "9c9cc1d47e243d655ace55ed38201c19ae02c148ae56412ab8750e8f0166ab7f" dependencies = [ "log", "once_cell", @@ -2943,9 +2930,9 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" dependencies = [ "windows-sys 0.59.0", ] @@ -3003,29 +2990,29 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] name = "serde_json" -version = "1.0.132" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "itoa", "memchr", @@ -3139,11 +3126,20 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sonic-number" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8a74044c092f4f43ca7a6cfd62854cf9fb5ac8502b131347c990bf22bef1dfe" +dependencies = [ + "cfg-if", +] + [[package]] name = "sonic-rs" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "531b13eca9f20046cbaddc82e60399ed4337f34da923aba1437467a3da3eebac" +checksum = "af7c58fc3de31b4d0e6b3043d7ff346163cf65fd3a70660b92bb9828626eeaca" dependencies = [ "bumpalo", "bytes", @@ -3153,9 +3149,20 @@ dependencies = [ "ryu", "serde", "simdutf8", + "sonic-number", + "sonic-simd", "thiserror 2.0.3", ] +[[package]] +name = "sonic-simd" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940a24e82c9a97483ef66cef06b92160a8fa5cd74042c57c10b24d99d169d2fc" +dependencies = [ + "cfg-if", +] + [[package]] name = "spin" version = "0.9.8" @@ -3202,9 +3209,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.87" +version = "2.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" dependencies = [ "proc-macro2", "quote", @@ -3219,9 +3226,9 @@ checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" [[package]] name = "sync_wrapper" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" dependencies = [ "futures-core", ] @@ -3234,7 +3241,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -3357,7 +3364,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -3368,7 +3375,7 @@ checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -3463,7 +3470,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -3503,7 +3510,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "rustls 0.23.16", + "rustls 0.23.18", "rustls-pki-types", "tokio", ] @@ -3603,11 +3610,11 @@ dependencies = [ "axum", "base64 0.22.1", "bytes", - "h2 0.4.6", + "h2 0.4.7", "http 1.1.0", "http-body 1.0.1", "http-body-util", - "hyper 1.5.0", + "hyper 1.5.1", "hyper-timeout", "hyper-util", "percent-encoding", @@ -3729,14 +3736,14 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] name = "tracing-core" -version = "0.1.32" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" dependencies = [ "once_cell", "valuable", @@ -3815,9 +3822,9 @@ checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" [[package]] name = "unicode-ident" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "unicode-normalization" @@ -3870,19 +3877,19 @@ dependencies = [ "flate2", "log", "once_cell", - "rustls 0.23.16", + "rustls 0.23.18", "rustls-pki-types", "serde", "serde_json", "url", - "webpki-roots 0.26.6", + "webpki-roots 0.26.7", ] [[package]] name = "url" -version = "2.5.3" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" dependencies = [ "form_urlencoded", "idna 1.0.3", @@ -3965,7 +3972,7 @@ dependencies = [ "tokio-stream", "tower 0.5.1", "tracing", - "webpki-roots 0.26.6", + "webpki-roots 0.26.7", ] [[package]] @@ -3991,7 +3998,7 @@ dependencies = [ "quote", "serde", "serde_yaml", - "syn 2.0.87", + "syn 2.0.89", "tempfile", "url_path", "volo", @@ -4045,12 +4052,12 @@ dependencies = [ "flate2", "futures", "futures-util", - "h2 0.4.6", + "h2 0.4.7", "hex", "http 1.1.0", "http-body 1.0.1", "http-body-util", - "hyper 1.5.0", + "hyper 1.5.1", "hyper-timeout", "hyper-util", "matchit 0.8.5", @@ -4091,7 +4098,7 @@ dependencies = [ "http 1.1.0", "http-body 1.0.1", "http-body-util", - "hyper 1.5.0", + "hyper 1.5.1", "hyper-util", "ipnet", "itoa", @@ -4204,7 +4211,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", "wasm-bindgen-shared", ] @@ -4238,7 +4245,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4267,9 +4274,9 @@ checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" [[package]] name = "webpki-roots" -version = "0.26.6" +version = "0.26.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +checksum = "5d642ff16b7e79272ae451b7322067cdc17cadf68c23264be9d94a32319efe7e" dependencies = [ "rustls-pki-types", ] @@ -4362,7 +4369,7 @@ checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -4373,7 +4380,7 @@ checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -4596,9 +4603,9 @@ checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" [[package]] name = "yoke" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" dependencies = [ "serde", "stable_deref_trait", @@ -4608,13 +4615,13 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", "synstructure", ] @@ -4636,27 +4643,27 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] name = "zerofrom" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" dependencies = [ "zerofrom-derive", ] [[package]] name = "zerofrom-derive" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", "synstructure", ] @@ -4685,5 +4692,5 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] diff --git a/Cargo.toml b/Cargo.toml index 33a8ea36..ea4715fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,15 +24,15 @@ license = "MIT OR Apache-2.0" rust-version = "1.80.0" [workspace.dependencies] -pilota = "0.11" -pilota-build = "0.11" -pilota-thrift-parser = "0.11" -# pilota = { git = "https://github.com/cloudwego/pilota", branch = "main" } -# pilota-build = { git = "https://github.com/cloudwego/pilota", branch = "main" } -# pilota-thrift-parser = { git = "https://github.com/cloudwego/pilota", branch = "main" } +#pilota = "0.11" +#pilota-build = "0.11" +#pilota-thrift-parser = "0.11" +pilota = { git = "https://github.com/cloudwego/pilota.git", branch = "main" } +pilota-build = { git = "https://github.com/cloudwego/pilota.git", branch = "main" } +pilota-thrift-parser = { git = "https://github.com/cloudwego/pilota.git", branch = "main" } motore = "0.4" -# motore = { git = "https://github.com/cloudwego/motore", branch = "main" } +# motore = { git = "https://github.com/cloudwego/motore.git", branch = "main" } metainfo = "0.7" diff --git a/examples/volo-gen/volo.yml b/examples/volo-gen/volo.yml index ce0210e4..58fe48e3 100644 --- a/examples/volo-gen/volo.yml +++ b/examples/volo-gen/volo.yml @@ -22,6 +22,7 @@ entries: thrift: filename: thrift_gen.rs protocol: thrift + split_generated_files: true services: - idl: source: local diff --git a/scripts/volo-cli-test.sh b/scripts/volo-cli-test.sh index e3236c77..1ebbcf7e 100644 --- a/scripts/volo-cli-test.sh +++ b/scripts/volo-cli-test.sh @@ -43,13 +43,22 @@ append_volo_dep_item() { echo "$1 = { path = \"$VOLO_DIR/$1\" }" >> Cargo.toml } +append_pilota_dep_item() { + echo "$1 = { git = \"https://github.com/cloudwego/pilota.git\", branch = \"main\" }" >> Cargo.toml +} + patch_cargo_toml() { echo "[patch.crates-io]" >> Cargo.toml + append_volo_dep_item volo append_volo_dep_item volo-build append_volo_dep_item volo-thrift append_volo_dep_item volo-grpc append_volo_dep_item volo-http + + append_pilota_dep_item pilota + append_pilota_dep_item pilota-build + append_pilota_dep_item pilota-thrift-parser } thrift_test() { diff --git a/tests/code-generation-workspace-split/.gitignore b/tests/code-generation-workspace-split/.gitignore new file mode 100644 index 00000000..ebffaa3e --- /dev/null +++ b/tests/code-generation-workspace-split/.gitignore @@ -0,0 +1,5 @@ +common +rpc_article +rpc_author +rpc_image +Cargo.lock diff --git a/tests/code-generation-workspace-split/Cargo.toml b/tests/code-generation-workspace-split/Cargo.toml new file mode 100644 index 00000000..f3f7e467 --- /dev/null +++ b/tests/code-generation-workspace-split/Cargo.toml @@ -0,0 +1,40 @@ +[[bin]] +bench = false +name = "gen" +test = false + +[dependencies.pilota-build] +branch = "main" +git = "https://github.com/cloudwego/pilota" + +[dependencies.volo-build] +workspace = true + +[package] +edition = "2021" +name = "code-generation-workspace-split" +publish = false +version = "0.0.0" + +[workspace] +members = [ +] + +[workspace.dependencies] +anyhow = "1" +async-trait = "0.1" +lazy_static = "1" +serde = "1" + +[workspace.dependencies.pilota] +branch = "main" +git = "https://github.com/cloudwego/pilota" + +[workspace.dependencies.volo] +path = "../../volo" + +[workspace.dependencies.volo-build] +path = "../../volo-build" + +[workspace.dependencies.volo-thrift] +path = "../../volo-thrift" diff --git a/tests/code-generation-workspace-split/src/bin/gen.rs b/tests/code-generation-workspace-split/src/bin/gen.rs new file mode 100644 index 00000000..b5dc6991 --- /dev/null +++ b/tests/code-generation-workspace-split/src/bin/gen.rs @@ -0,0 +1,7 @@ +use volo_build::plugin::SerdePlugin; + +fn main() { + volo_build::workspace::Builder::thrift() + .plugin(SerdePlugin) + .gen() +} diff --git a/tests/code-generation-workspace-split/thrift/article.thrift b/tests/code-generation-workspace-split/thrift/article.thrift new file mode 100644 index 00000000..164efc8e --- /dev/null +++ b/tests/code-generation-workspace-split/thrift/article.thrift @@ -0,0 +1,34 @@ +include "image.thrift" +include "author.thrift" +include "common.thrift" + +namespace rs article + +enum Status { + NORMAL = 0, + DELETED = 1, +} + +struct Article { + 1: required i64 id, + 2: required string title, + 3: required string content, + 4: required author.Author author, + 5: required Status status, + 6: required list images, + 7: required common.CommonData common_data, +} + +struct GetArticleRequest { + 1: required i64 id, +} + +struct GetArticleResponse { + 1: required Article article, +} + +service ArticleService { + GetArticleResponse GetArticle(1: GetArticleRequest req), +} + +service articleService {} \ No newline at end of file diff --git a/tests/code-generation-workspace-split/thrift/author.thrift b/tests/code-generation-workspace-split/thrift/author.thrift new file mode 100644 index 00000000..9af3823e --- /dev/null +++ b/tests/code-generation-workspace-split/thrift/author.thrift @@ -0,0 +1,24 @@ +include "image.thrift" +include "common.thrift" + +namespace rs author + +struct Author { + 1: required i64 id, + 2: required string username, + 3: required string email, + 4: required image.Image avatar, + 5: required common.CommonData common_data, +} + +struct GetAuthorRequest { + 1: required i64 id, +} + +struct GetAuthorResponse { + 1: required Author author, +} + +service AuthorService { + GetAuthorResponse GetAuthor(1: GetAuthorRequest req), +} \ No newline at end of file diff --git a/tests/code-generation-workspace-split/thrift/cdn.thrift b/tests/code-generation-workspace-split/thrift/cdn.thrift new file mode 100644 index 00000000..c6847a3c --- /dev/null +++ b/tests/code-generation-workspace-split/thrift/cdn.thrift @@ -0,0 +1,9 @@ +include "common.thrift" + +namespace rs article.image.cdn + +struct CDN { + 1: required i64 id, + 2: required string url, + 3: required common.CommonData common_data, +} \ No newline at end of file diff --git a/tests/code-generation-workspace-split/thrift/common.thrift b/tests/code-generation-workspace-split/thrift/common.thrift new file mode 100644 index 00000000..517116f1 --- /dev/null +++ b/tests/code-generation-workspace-split/thrift/common.thrift @@ -0,0 +1,7 @@ +namespace rs common + +struct CommonData { + 1: required i64 id, + 2: required string name, + 3: required string description, +} \ No newline at end of file diff --git a/tests/code-generation-workspace-split/thrift/image.thrift b/tests/code-generation-workspace-split/thrift/image.thrift new file mode 100644 index 00000000..b1d4ec86 --- /dev/null +++ b/tests/code-generation-workspace-split/thrift/image.thrift @@ -0,0 +1,23 @@ +include "common.thrift" +include "cdn.thrift" + +namespace rs article.image + +struct Image { + 1: required i64 id, + 2: required string url, + 3: required cdn.CDN cdn, + 4: required common.CommonData common_data, +} + +struct GetImageRequest { + 1: required i64 id, +} + +struct GetImageResponse { + 1: required Image image, +} + +service ImageService { + GetImageResponse GetImage(1: GetImageRequest req), +} \ No newline at end of file diff --git a/tests/code-generation-workspace-split/volo.workspace.yml b/tests/code-generation-workspace-split/volo.workspace.yml new file mode 100644 index 00000000..ee974a99 --- /dev/null +++ b/tests/code-generation-workspace-split/volo.workspace.yml @@ -0,0 +1,33 @@ +common_crate_name: "common" # common_crate_name = "common" by default +touch_all: true +dedups: [] # remove the repeated structure generation in one entry +special_namings: [] +split_generated_files: true +# repos: # exsit if non-local +# { repo }: # repo = extract the name from url by default +# url: { git } # url = repo git url +# ref: { ref } # ref = "HEAD" by default +# lock: { commit hash } # lock is the last commit hash +services: + - idl: + source: local + # repo: { repo } # required for git source + path: thrift/article.thrift # git path must be relative to the repo root dir + # includes: { includes list } # required for protobuf + codegen_option: + touch: [] + keep_unknown_fields: false # A->B->C, B could use this to transfer the unknown fields which is needed by A and C. + config: + crate_name: rpc_article + - idl: + source: local + path: thrift/author.thrift + codegen_option: + config: + crate_name: rpc_author + - idl: + source: local + path: thrift/image.thrift + codegen_option: + config: + crate_name: rpc_image diff --git a/tests/code-generation/volo.yml b/tests/code-generation/volo.yml index 77cf2c76..efeaa979 100644 --- a/tests/code-generation/volo.yml +++ b/tests/code-generation/volo.yml @@ -3,6 +3,7 @@ entries: proto: filename: proto_gen.rs protocol: protobuf + split_generated_files: true repos: protobuf: url: https://github.com/protocolbuffers/protobuf.git @@ -18,6 +19,7 @@ entries: thrift: filename: thrift_gen.rs protocol: thrift + split_generated_files: true repos: thrift: url: https://github.com/apache/thrift.git diff --git a/volo-build/src/config_builder.rs b/volo-build/src/config_builder.rs index 60bb0637..0ac4d72f 100644 --- a/volo-build/src/config_builder.rs +++ b/volo-build/src/config_builder.rs @@ -125,6 +125,17 @@ impl InnerBuilder { } } + pub fn split_generated_files(self, split_generated_files: bool) -> Self { + match self { + InnerBuilder::Protobuf(inner) => { + InnerBuilder::Protobuf(inner.split_generated_files(split_generated_files)) + } + InnerBuilder::Thrift(inner) => { + InnerBuilder::Thrift(inner.split_generated_files(split_generated_files)) + } + } + } + pub fn common_crate_name(self, name: FastStr) -> Self { match self { InnerBuilder::Protobuf(inner) => InnerBuilder::Protobuf(inner.common_crate_name(name)), @@ -192,6 +203,7 @@ impl ConfigBuilder { .add_services(service_builders) .ignore_unused(!entry.common_option.touch_all) .special_namings(entry.common_option.special_namings) + .split_generated_files(entry.common_option.split_generated_files) .dedup(entry.common_option.dedups) .write()?; diff --git a/volo-build/src/lib.rs b/volo-build/src/lib.rs index 322dddb8..4694fc8d 100644 --- a/volo-build/src/lib.rs +++ b/volo-build/src/lib.rs @@ -112,6 +112,13 @@ impl Builder { self } + pub fn split_generated_files(mut self, split_generated_files: bool) -> Self { + self.pilota_builder = self + .pilota_builder + .split_generated_files(split_generated_files); + self + } + pub fn special_namings(mut self, namings: impl IntoIterator) -> Self { self.pilota_builder = self.pilota_builder.special_namings(namings); self diff --git a/volo-build/src/model.rs b/volo-build/src/model.rs index e0566971..8c266bf0 100644 --- a/volo-build/src/model.rs +++ b/volo-build/src/model.rs @@ -22,6 +22,8 @@ pub struct CommonOption { pub dedups: Vec, #[serde(default, skip_serializing_if = "Vec::is_empty")] pub special_namings: Vec, + #[serde(default, skip_serializing_if = "is_false")] + pub split_generated_files: bool, } #[derive(Serialize, Deserialize, Debug, Clone)] diff --git a/volo-build/src/thrift_backend.rs b/volo-build/src/thrift_backend.rs index df411fde..100cf627 100644 --- a/volo-build/src/thrift_backend.rs +++ b/volo-build/src/thrift_backend.rs @@ -1,7 +1,10 @@ +use std::{io::Write, path::Path}; + use itertools::Itertools; use pilota_build::{ codegen::thrift::DecodeHelper, db::RirDatabase, + middle::context::Mode, rir::{self, Method}, tags::RustWrapperArc, CodegenBackend, Context, DefId, IdentName, Symbol, ThriftBackend, @@ -15,7 +18,7 @@ pub struct VoloThriftBackend { } impl VoloThriftBackend { - fn codegen_service_anonymous_type(&self, stream: &mut String, def_id: DefId) { + fn codegen_service_anonymous_type(&self, stream: &mut String, def_id: DefId, base_dir: &Path) { let service_name = self.cx().rust_name(def_id); let methods = self.cx().service_methods(def_id); let methods_names = methods.iter().map(|m| &**m.name).collect::>(); @@ -48,7 +51,7 @@ impl VoloThriftBackend { let res_recv_name = format!("{service_name}ResponseRecv"); let res_send_name = format!("{service_name}ResponseSend"); - let req_impl = { + let (req_recv_impl, req_send_impl) = { let mk_decode = |is_async: bool, is_send: bool| { let helper = DecodeHelper::new(is_async); let mut match_methods = String::new(); @@ -94,7 +97,7 @@ impl VoloThriftBackend { match_size = "_ => unreachable!(),".to_string(); } - format! { + let recv_impl = format! { r#"impl ::volo_thrift::EntryMessage for {req_recv_name} {{ fn encode(&self, __protocol: &mut T) -> ::core::result::Result<(), ::pilota::thrift::ThriftException> {{ match self {{ @@ -119,9 +122,11 @@ impl VoloThriftBackend { {match_size} }} }} - }} + }}"# + }; - impl ::volo_thrift::EntryMessage for {req_send_name} {{ + let send_impl = format! { + r#"impl ::volo_thrift::EntryMessage for {req_send_name} {{ fn encode(&self, __protocol: &mut T) -> ::core::result::Result<(), ::pilota::thrift::ThriftException> {{ match self {{ {match_encode} @@ -146,10 +151,12 @@ impl VoloThriftBackend { }} }} }}"# - } + }; + + (recv_impl, send_impl) }; - let res_impl = { + let (res_recv_impl, res_send_impl) = { let mk_decode = |is_async: bool, is_send: bool| { let helper = DecodeHelper::new(is_async); let mut match_methods = String::new(); @@ -195,7 +202,8 @@ impl VoloThriftBackend { let send_decode_async = mk_decode(true, true); let recv_decode = mk_decode(false, false); let recv_decode_async = mk_decode(true, false); - format! { + + let recv_impl = format! { r#"impl ::volo_thrift::EntryMessage for {res_recv_name} {{ fn encode(&self, __protocol: &mut T) -> ::core::result::Result<(), ::pilota::thrift::ThriftException> {{ match self {{ @@ -220,9 +228,11 @@ impl VoloThriftBackend { {match_size} }} }} - }} + }}"# + }; - impl ::volo_thrift::EntryMessage for {res_send_name} {{ + let send_impl = format! { + r#"impl ::volo_thrift::EntryMessage for {res_send_name} {{ fn encode(&self, __protocol: &mut T) -> ::core::result::Result<(), ::pilota::thrift::ThriftException> {{ match self {{ {match_encode} @@ -247,7 +257,9 @@ impl VoloThriftBackend { }} }} }}"# - } + }; + + (recv_impl, send_impl) }; let req_recv_variants = crate::join_multi_strs!( ",", @@ -267,8 +279,74 @@ impl VoloThriftBackend { ",", |variant_names, result_send_names| -> "{variant_names}({result_send_names})" ); - stream.push_str(&format! { - r#"#[derive(Debug, Clone)] + + if self.cx().split { + let req_recv_stream = format! { + r#"#[derive(Debug, Clone)] + pub enum {req_recv_name} {{ + {req_recv_variants} + }} + + {req_recv_impl} + "# + }; + + let req_send_stream = format! { + r#"#[derive(Debug, Clone)] + pub enum {req_send_name} {{ + {req_send_variants} + }} + + {req_send_impl} + "# + }; + + let res_recv_stream = format! { + r#"#[derive(Debug, Clone)] + pub enum {res_recv_name} {{ + {res_recv_variants} + }} + {res_recv_impl} + "# + }; + + let res_send_stream = format! { + r#"#[derive(Debug, Clone)] + pub enum {res_send_name} {{ + {res_send_variants} + }} + + {res_send_impl} + "# + }; + + Self::write_item( + stream, + base_dir, + format!("enum_{}.rs", &req_recv_name), + req_recv_stream, + ); + Self::write_item( + stream, + base_dir, + format!("enum_{}.rs", &res_recv_name), + res_recv_stream, + ); + Self::write_item( + stream, + base_dir, + format!("enum_{}.rs", &req_send_name), + req_send_stream, + ); + Self::write_item( + stream, + base_dir, + format!("enum_{}.rs", &res_send_name), + res_send_stream, + ); + } else { + stream.push_str(&format! { + r#"#[derive(Debug, Clone)] pub enum {req_recv_name} {{ {req_recv_variants} }} @@ -288,9 +366,27 @@ impl VoloThriftBackend { {res_send_variants} }} - {req_impl} - {res_impl}"# - }); + {req_recv_impl} + {req_send_impl} + {res_recv_impl} + {res_send_impl} + "# + }); + } + } + + fn write_item(stream: &mut String, base_dir: &Path, name: String, impl_str: String) { + let req_recv_buf = base_dir.join(&name); + let req_recv_file = req_recv_buf.as_path(); + Self::write_file(req_recv_file, impl_str); + stream.push_str(format!("include!(\"{}\");", &name).as_str()); + } + + fn write_file(path: &Path, stream: String) { + let mut req_file_writer = std::io::BufWriter::new(std::fs::File::create(path).unwrap()); + req_file_writer.write_all(stream.as_bytes()).unwrap(); + req_file_writer.flush().unwrap(); + pilota_build::fmt::fmt_file(path); } fn method_ty_path(&self, service_name: &Symbol, method: &Method, suffix: &str) -> FastStr { @@ -371,6 +467,50 @@ impl pilota_build::CodegenBackend for VoloThriftBackend { let mut client_methods = Vec::new(); let mut oneshot_client_methods = Vec::new(); + let path = self.cx().item_path(def_id); + let path = path.as_ref(); + + // Locate directory based on the full item path + let base_dir = match self.cx().mode.as_ref() { + // In a workspace mode, the base directory is next to the `.rs` file for the service + Mode::Workspace(info) => { + let mut dir = info.dir.clone(); + if path.is_empty() { + dir + } else { + dir.push(path[0].0.as_str()); + if path.len() > 1 { + dir.push("src"); + for segment in path.iter().skip(1) { + dir.push(Path::new(segment.0.as_str())); + } + } + dir + } + } + // In single file mode, the files directory is the root + // The base directory path is the root + the item path + Mode::SingleFile { file_path } => { + let mut dir = file_path.clone(); + dir.pop(); + for segment in path { + dir.push(Path::new(segment.0.as_str())); + } + dir + } + }; + + let base_dir = if let Some(suffix) = self.cx().names.get(&def_id) { + format!("{}_{suffix}", base_dir.display()) + } else { + base_dir.display().to_string() + }; + let base_dir = Path::new(&base_dir); + + if self.cx().split { + std::fs::create_dir_all(base_dir).expect("Failed to create base directory"); + } + all_methods.iter().for_each(|m| { let name = self.cx().rust_name(m.def_id); let resp_type = self.cx().codegen_item_ty(m.ret.kind.clone()); @@ -530,12 +670,35 @@ impl pilota_build::CodegenBackend for VoloThriftBackend { {user_handler} )),"#); - stream.push_str(&format! { + let mut mod_rs_stream = String::new(); + + let server_string = format! { r#"pub struct {server_name} {{ inner: S, // handler }} - pub struct {mk_client_name}; + impl {server_name} where S: {service_name} + ::core::marker::Send + ::core::marker::Sync + 'static {{ + pub fn new(inner: S) -> ::volo_thrift::server::Server>>, ::volo_thrift::tracing::DefaultProvider> {{ + ::volo_thrift::server::Server::new(Self {{ + inner, + }}) + }} + }} + + impl ::volo::service::Service<::volo_thrift::context::ServerContext, {req_recv_name}> for {server_name} where T: {service_name} + Send + Sync + 'static {{ + type Response = {res_send_name}; + type Error = ::volo_thrift::ServerError; + + async fn call<'s, 'cx>(&'s self, _cx: &'cx mut ::volo_thrift::context::ServerContext, req: {req_recv_name}) -> ::std::result::Result {{ + match req {{ + {handler} + }} + }} + }}"# + }; + + let client_string = format! { + r#" pub struct {mk_client_name}; pub type {client_name} = {generic_client_name}<::volo::service::BoxCloneService<::volo_thrift::context::ClientContext, {req_send_name}, ::std::option::Option<{res_recv_name}>, ::volo_thrift::ClientError>>; @@ -580,29 +743,44 @@ impl pilota_build::CodegenBackend for VoloThriftBackend { {{ ::volo_thrift::client::ClientBuilder::new(service_name, {mk_client_name}) }} - }} - + }}"# + }; - impl {server_name} where S: {service_name} + ::core::marker::Send + ::core::marker::Sync + 'static {{ - pub fn new(inner: S) -> ::volo_thrift::server::Server>>, ::volo_thrift::tracing::DefaultProvider> {{ - ::volo_thrift::server::Server::new(Self {{ - inner, - }}) - }} - }} + if self.cx().split { + Self::write_item( + &mut mod_rs_stream, + base_dir, + format!("service_{}Server.rs", service_name), + server_string, + ); + Self::write_item( + &mut mod_rs_stream, + base_dir, + format!("service_{}Client.rs", service_name), + client_string, + ); + } else { + stream.push_str(&server_string); + stream.push_str(&client_string); + } - impl ::volo::service::Service<::volo_thrift::context::ServerContext, {req_recv_name}> for {server_name} where T: {service_name} + Send + Sync + 'static {{ - type Response = {res_send_name}; - type Error = ::volo_thrift::ServerError; + if self.cx().split { + self.codegen_service_anonymous_type(&mut mod_rs_stream, def_id, base_dir); + } else { + self.codegen_service_anonymous_type(stream, def_id, base_dir); + } - async fn call<'s, 'cx>(&'s self, _cx: &'cx mut ::volo_thrift::context::ServerContext, req: {req_recv_name}) -> ::std::result::Result {{ - match req {{ - {handler} - }} - }} - }}"# - }); - self.codegen_service_anonymous_type(stream, def_id); + if self.cx().split { + let mod_rs_file_path = base_dir.join("mod.rs"); + Self::write_file(&mod_rs_file_path, mod_rs_stream); + stream.push_str( + format!( + "include!(\"{}/mod.rs\");", + base_dir.file_name().unwrap().to_str().unwrap() + ) + .as_str(), + ); + } } fn codegen_service_method(&self, _service_def_id: DefId, method: &Method) -> String { @@ -698,7 +876,7 @@ impl pilota_build::CodegenBackend for VoloThriftBackend { fn rust_name(cx: &Context, def_id: DefId) -> FastStr { let name = cx.rust_name(def_id); - if cx.names.contains(&def_id) { + if cx.names.contains_key(&def_id) { name.0 } else { name.0.upper_camel_ident() diff --git a/volo-build/src/workspace.rs b/volo-build/src/workspace.rs index 425b8cc4..9d17a294 100644 --- a/volo-build/src/workspace.rs +++ b/volo-build/src/workspace.rs @@ -106,6 +106,7 @@ where .dedup(config.common_option.dedups) .special_namings(config.common_option.special_namings) .common_crate_name(config.common_crate_name) + .split_generated_files(config.common_option.split_generated_files) .pilota_builder .compile_with_config(idl_services, pilota_build::Output::Workspace(work_dir)); } @@ -148,6 +149,13 @@ where self } + pub fn split_generated_files(mut self, split_generated_files: bool) -> Self { + self.pilota_builder = self + .pilota_builder + .split_generated_files(split_generated_files); + self + } + pub fn touch( mut self, items: impl IntoIterator>)>, diff --git a/volo-cli/src/migrate.rs b/volo-cli/src/migrate.rs index 49ea9dd4..69cf69e5 100644 --- a/volo-cli/src/migrate.rs +++ b/volo-cli/src/migrate.rs @@ -49,6 +49,7 @@ impl CliCommand for Migrate { touch_all: old_entry.touch_all, dedups: Vec::new(), special_namings: Vec::new(), + split_generated_files: false, }, }; diff --git a/volo-thrift/Cargo.toml b/volo-thrift/Cargo.toml index b0f63e1a..c25adfd2 100644 --- a/volo-thrift/Cargo.toml +++ b/volo-thrift/Cargo.toml @@ -56,3 +56,5 @@ multiplex = [] # unsafe-codec can achieve better performance for thrift binary protocol, but may cause undefined behavior # if the thrift message is malformed. unsafe-codec = [] +# This will use unwrap_unchecked instead of unwrap in some places. +unsafe_unchecked = []