From 06339a2699f8d231fd86aaf86222403d1540044c Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sun, 22 Jan 2023 21:14:13 -0500 Subject: [PATCH] Migrate away from tokio & reqwest, use smol & ureq --- Cargo.lock | 811 +++++++++++++------------------------ Cargo.toml | 12 +- src/cli/cli.rs | 2 +- src/cli/main.rs | 11 +- src/cli/utils/github.rs | 63 +-- src/lib/globals/fs.rs | 4 +- src/lib/globals/net.rs | 99 ++--- src/lib/globals/process.rs | 7 +- src/lib/globals/task.rs | 6 +- src/lib/lib.rs | 96 ++--- 10 files changed, 394 insertions(+), 717 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fcde72d..c1ec8c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,18 +15,114 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" [[package]] -name = "async-compression" -version = "0.3.15" +name = "async-channel" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942c7cd7ae39e91bde4820d74132e9862e62c2f386c3aa90ccf55949f5bad63a" +checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833" dependencies = [ - "flate2", + "concurrent-queue", + "event-listener", "futures-core", - "memchr", - "pin-project-lite", - "tokio", ] +[[package]] +name = "async-executor" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17adb73da160dfb475c183343c8cccd80721ea5a605d3eb57125f0a7b7a92d0b" +dependencies = [ + "async-lock", + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "slab", +] + +[[package]] +name = "async-fs" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "279cf904654eeebfa37ac9bb1598880884924aab82e290aa65c9e77a0e142e06" +dependencies = [ + "async-lock", + "autocfg", + "blocking", + "futures-lite", +] + +[[package]] +name = "async-io" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c374dda1ed3e7d8f0d9ba58715f924862c63eae6849c92d3a18e7fbde9e2794" +dependencies = [ + "async-lock", + "autocfg", + "concurrent-queue", + "futures-lite", + "libc", + "log", + "parking", + "polling", + "slab", + "socket2", + "waker-fn", + "windows-sys", +] + +[[package]] +name = "async-lock" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8101efe8695a6c17e02911402145357e718ac92d3ff88ae8419e84b1707b685" +dependencies = [ + "event-listener", + "futures-lite", +] + +[[package]] +name = "async-net" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4051e67316bc7eff608fe723df5d32ed639946adcd69e07df41fd42a7b411f1f" +dependencies = [ + "async-io", + "autocfg", + "blocking", + "futures-lite", +] + +[[package]] +name = "async-process" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6381ead98388605d0d9ff86371043b5aa922a3905824244de40dc263a14fcba4" +dependencies = [ + "async-io", + "async-lock", + "autocfg", + "blocking", + "cfg-if", + "event-listener", + "futures-lite", + "libc", + "signal-hook", + "windows-sys", +] + +[[package]] +name = "async-task" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" + +[[package]] +name = "atomic-waker" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "debc29dde2e69f9e47506b525f639ed42300fc014a3e007832592448fa8e4599" + [[package]] name = "autocfg" version = "1.1.0" @@ -45,6 +141,20 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "blocking" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c67b173a56acffd6d2326fb7ab938ba0b00a71480e14902b2591c87bc5741e8" +dependencies = [ + "async-channel", + "async-lock", + "async-task", + "atomic-waker", + "fastrand", + "futures-lite", +] + [[package]] name = "bstr" version = "0.2.17" @@ -60,12 +170,6 @@ version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" -[[package]] -name = "bytes" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" - [[package]] name = "cc" version = "1.0.78" @@ -116,21 +220,14 @@ dependencies = [ ] [[package]] -name = "core-foundation" -version = "0.9.3" +name = "concurrent-queue" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +checksum = "c278839b831783b70278b14df4d45e1beb1aad306c07bb796637de9a0e323e8e" dependencies = [ - "core-foundation-sys", - "libc", + "crossbeam-utils", ] -[[package]] -name = "core-foundation-sys" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" - [[package]] name = "crc32fast" version = "1.3.2" @@ -141,10 +238,10 @@ dependencies = [ ] [[package]] -name = "encoding_rs" -version = "0.8.31" +name = "crossbeam-utils" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" dependencies = [ "cfg-if", ] @@ -179,6 +276,12 @@ dependencies = [ "libc", ] +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + [[package]] name = "fastrand" version = "1.8.0" @@ -198,27 +301,6 @@ dependencies = [ "miniz_oxide", ] -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.1.0" @@ -228,21 +310,33 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "futures-channel" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" -dependencies = [ - "futures-core", -] - [[package]] name = "futures-core" version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" +[[package]] +name = "futures-io" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" + +[[package]] +name = "futures-lite" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + [[package]] name = "futures-macro" version = "0.3.25" @@ -254,12 +348,6 @@ dependencies = [ "syn", ] -[[package]] -name = "futures-sink" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" - [[package]] name = "futures-task" version = "0.3.25" @@ -280,31 +368,6 @@ dependencies = [ "slab", ] -[[package]] -name = "h2" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "heck" version = "0.4.0" @@ -320,77 +383,6 @@ dependencies = [ "libc", ] -[[package]] -name = "http" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" -dependencies = [ - "bytes", - "http", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" - -[[package]] -name = "httpdate" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" - -[[package]] -name = "hyper" -version = "0.14.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes", - "hyper", - "native-tls", - "tokio", - "tokio-native-tls", -] - [[package]] name = "idna" version = "0.3.0" @@ -401,16 +393,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "1.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" -dependencies = [ - "autocfg", - "hashbrown", -] - [[package]] name = "instant" version = "0.1.12" @@ -430,12 +412,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "ipnet" -version = "2.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" - [[package]] name = "is-terminal" version = "0.4.2" @@ -463,12 +439,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.139" @@ -481,16 +451,6 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" -[[package]] -name = "lock_api" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.17" @@ -518,10 +478,10 @@ dependencies = [ "mlua", "once_cell", "os_str_bytes", - "reqwest", "serde", "serde_json", - "tokio", + "smol", + "ureq", ] [[package]] @@ -530,12 +490,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" -[[package]] -name = "mime" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" - [[package]] name = "miniz_oxide" version = "0.6.2" @@ -545,18 +499,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" -dependencies = [ - "libc", - "log", - "wasi", - "windows-sys", -] - [[package]] name = "mlua" version = "0.8.7" @@ -577,24 +519,6 @@ dependencies = [ "serde", ] -[[package]] -name = "native-tls" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "num-traits" version = "0.2.15" @@ -604,67 +528,12 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "once_cell" version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" -[[package]] -name = "openssl" -version = "0.10.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7" -dependencies = [ - "autocfg", - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "os_str_bytes" version = "6.4.1" @@ -675,27 +544,10 @@ dependencies = [ ] [[package]] -name = "parking_lot" -version = "0.12.1" +name = "parking" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba1ef8814b5c993410bb3adfad7a5ed269563e4a2f90c41f5d85be7fb47133bf" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-sys", -] +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" [[package]] name = "percent-encoding" @@ -721,6 +573,20 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" +[[package]] +name = "polling" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22122d5ec4f9fe1b3916419b76be1e80bcb93f618d071d2edf841b137b2a2bd6" +dependencies = [ + "autocfg", + "cfg-if", + "libc", + "log", + "wepoll-ffi", + "windows-sys", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -764,60 +630,18 @@ dependencies = [ ] [[package]] -name = "redox_syscall" -version = "0.2.16" +name = "ring" +version = "0.16.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" dependencies = [ - "bitflags", -] - -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi", -] - -[[package]] -name = "reqwest" -version = "0.11.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c" -dependencies = [ - "async-compression", - "base64", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-tls", - "ipnet", - "js-sys", - "log", - "mime", - "native-tls", + "cc", + "libc", "once_cell", - "percent-encoding", - "pin-project-lite", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-native-tls", - "tokio-util", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", + "spin", + "untrusted", "web-sys", - "winreg", + "winapi", ] [[package]] @@ -840,6 +664,18 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "rustls" +version = "0.20.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +dependencies = [ + "log", + "ring", + "sct", + "webpki", +] + [[package]] name = "ryu" version = "1.0.12" @@ -847,41 +683,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" [[package]] -name = "schannel" -version = "0.1.21" +name = "sct" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" dependencies = [ - "windows-sys", -] - -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "security-framework" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645926f31b250a2dca3c232496c2d898d91036e45ca0e97e0e2390c54e11be36" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" -dependencies = [ - "core-foundation-sys", - "libc", + "ring", + "untrusted", ] [[package]] @@ -916,15 +724,13 @@ dependencies = [ ] [[package]] -name = "serde_urlencoded" -version = "0.7.1" +name = "signal-hook" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +checksum = "a253b5e89e2698464fc26b545c9edceb338e18a89effeeecfea192c3025be29d" dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", + "libc", + "signal-hook-registry", ] [[package]] @@ -946,10 +752,21 @@ dependencies = [ ] [[package]] -name = "smallvec" -version = "1.10.0" +name = "smol" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "13f2b548cd8447f8de0fdf1c592929f70f4fc7039a05e47404b0d096ec6987a1" +dependencies = [ + "async-channel", + "async-executor", + "async-fs", + "async-io", + "async-lock", + "async-net", + "async-process", + "blocking", + "futures-lite", +] [[package]] name = "socket2" @@ -961,6 +778,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "strsim" version = "0.10.0" @@ -978,20 +801,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tempfile" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" -dependencies = [ - "cfg-if", - "fastrand", - "libc", - "redox_syscall", - "remove_dir_all", - "winapi", -] - [[package]] name = "termcolor" version = "1.2.0" @@ -1016,93 +825,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -[[package]] -name = "tokio" -version = "1.24.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a12a59981d9e3c38d216785b0c37399f6e415e8d0712047620f189371b0bb" -dependencies = [ - "autocfg", - "bytes", - "libc", - "memchr", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys", -] - -[[package]] -name = "tokio-macros" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" -dependencies = [ - "native-tls", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", - "tracing", -] - -[[package]] -name = "tower-service" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" - -[[package]] -name = "tracing" -version = "0.1.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" -dependencies = [ - "cfg-if", - "pin-project-lite", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" -dependencies = [ - "once_cell", -] - -[[package]] -name = "try-lock" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" - [[package]] name = "unicode-bidi" version = "0.3.9" @@ -1124,6 +846,28 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "ureq" +version = "2.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "338b31dd1314f68f3aabf3ed57ab922df95ffcd902476ca7ba3c4ce7b908c46d" +dependencies = [ + "base64", + "flate2", + "log", + "once_cell", + "rustls", + "url", + "webpki", + "webpki-roots", +] + [[package]] name = "url" version = "2.3.1" @@ -1135,12 +879,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.4" @@ -1148,20 +886,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] -name = "want" -version = "0.3.0" +name = "waker-fn" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ - "log", - "try-lock", -] - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" [[package]] name = "wasm-bindgen" @@ -1188,18 +916,6 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "wasm-bindgen-macro" version = "0.2.83" @@ -1239,6 +955,34 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.22.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +dependencies = [ + "webpki", +] + +[[package]] +name = "wepoll-ffi" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" +dependencies = [ + "cc", +] + [[package]] name = "winapi" version = "0.3.9" @@ -1326,12 +1070,3 @@ name = "windows_x86_64_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" - -[[package]] -name = "winreg" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" -dependencies = [ - "winapi", -] diff --git a/Cargo.toml b/Cargo.toml index 110b314..d62ec39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,12 +23,12 @@ lto = true # Enable link-time optimization panic = "abort" # Remove extra panic info [dependencies] -anyhow = { version = "1.0.68" } +anyhow = "1.0.68" clap = { version = "4.1.1", features = ["derive"] } mlua = { version = "0.8.7", features = ["luau", "async", "serialize"] } -once_cell = { version = "1.17.0" } -os_str_bytes = { version = "6.4.1" } -reqwest = { version = "0.11.13", features = ["gzip", "deflate"] } +once_cell = "1.17.0" +os_str_bytes = "6.4.1" serde = { version = "1.0.152", features = ["derive"] } -serde_json = { version = "1.0.91" } -tokio = { version = "1.24.2", features = ["full"] } +serde_json = "1.0.91" +smol = "1.3.0" +ureq = "2.6.2" diff --git a/src/cli/cli.rs b/src/cli/cli.rs index d9bc98b..957e218 100644 --- a/src/cli/cli.rs +++ b/src/cli/cli.rs @@ -57,7 +57,7 @@ impl Cli { // Download definition files, if wanted let download_types_requested = self.download_selene_types || self.download_luau_types; if download_types_requested { - let client = GithubClient::new().map_err(mlua::Error::external)?; + let client = GithubClient::new(); let release = client .fetch_release_for_this_version() .await diff --git a/src/cli/main.rs b/src/cli/main.rs index 7eb5c43..78e2d45 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -10,9 +10,10 @@ mod utils; use cli::Cli; -#[tokio::main] -async fn main() -> Result<()> { - let cli = Cli::parse(); - cli.run().await?; - Ok(()) +fn main() -> Result<()> { + smol::block_on(async { + let cli = Cli::parse(); + cli.run().await?; + Ok(()) + }) } diff --git a/src/cli/utils/github.rs b/src/cli/utils/github.rs index f073865..8e63672 100644 --- a/src/cli/utils/github.rs +++ b/src/cli/utils/github.rs @@ -1,10 +1,10 @@ use std::env::current_dir; use anyhow::{bail, Context, Result}; -use reqwest::header::{HeaderMap, HeaderValue}; use serde::{Deserialize, Serialize}; use lune::utils::net::{get_github_owner_and_repo, get_request_user_agent_header}; +use smol::unblock; #[derive(Clone, Deserialize, Serialize)] pub struct ReleaseAsset { @@ -29,35 +29,28 @@ pub struct Release { } pub struct Client { - client: reqwest::Client, github_owner: String, github_repo: String, } impl Client { - pub fn new() -> Result { + pub fn new() -> Self { let (github_owner, github_repo) = get_github_owner_and_repo(); - let mut headers = HeaderMap::new(); - headers.insert( - "User-Agent", - HeaderValue::from_str(&get_request_user_agent_header())?, - ); - headers.insert( - "Accept", - HeaderValue::from_static("application/vnd.github+json"), - ); - headers.insert( - "X-GitHub-Api-Version", - HeaderValue::from_static("2022-11-28"), - ); - let client = reqwest::Client::builder() - .default_headers(headers) - .build()?; - Ok(Self { - client, + Self { github_owner, github_repo, - }) + } + } + + async fn get(&self, url: &str, headers: &[(&str, &str)]) -> Result { + let mut request = ureq::get(url) + .set("User-Agent", &get_request_user_agent_header()) + .set("Accept", "application/vnd.github+json") + .set("X-GitHub-Api-Version", "2022-11-28"); + for (header, value) in headers { + request = request.set(header, value); + } + unblock(|| Ok(request.send_string("")?.into_string()?)).await } pub async fn fetch_releases(&self) -> Result> { @@ -65,17 +58,8 @@ impl Client { "https://api.github.com/repos/{}/{}/releases", &self.github_owner, &self.github_repo ); - let response_bytes = self - .client - .get(release_api_url) - .send() - .await - .context("Failed to send releases request")? - .bytes() - .await - .context("Failed to get releases response bytes")?; - let response_body: Vec = serde_json::from_slice(&response_bytes)?; - Ok(response_body) + let response_string = self.get(&release_api_url, &[]).await?; + Ok(serde_json::from_str(&response_string)?) } pub async fn fetch_release_for_this_version(&self) -> Result { @@ -95,17 +79,8 @@ impl Client { .find(|asset| matches!(&asset.name, Some(name) if name == asset_name)) { let file_path = current_dir()?.join(asset_name); - let file_bytes = self - .client - .get(&asset.url) - .header("Accept", "application/octet-stream") - .send() - .await - .context("Failed to send asset download request")? - .bytes() - .await - .context("Failed to get asset download response bytes")?; - tokio::fs::write(&file_path, &file_bytes) + let file_string = self.get(&asset.url, &[]).await?; + smol::fs::write(&file_path, &file_string) .await .with_context(|| { format!("Failed to write file at path '{}'", &file_path.display()) diff --git a/src/lib/globals/fs.rs b/src/lib/globals/fs.rs index 00bc8bc..0ba70bb 100644 --- a/src/lib/globals/fs.rs +++ b/src/lib/globals/fs.rs @@ -1,7 +1,7 @@ use std::path::{PathBuf, MAIN_SEPARATOR}; use mlua::{Lua, Result}; -use tokio::fs; +use smol::{fs, prelude::*}; use crate::utils::table_builder::TableBuilder; @@ -30,7 +30,7 @@ async fn fs_read_file(_: &Lua, path: String) -> Result { async fn fs_read_dir(_: &Lua, path: String) -> Result> { let mut dir_strings = Vec::new(); let mut dir = fs::read_dir(&path).await.map_err(mlua::Error::external)?; - while let Some(dir_entry) = dir.next_entry().await.map_err(mlua::Error::external)? { + while let Some(dir_entry) = dir.try_next().await.map_err(mlua::Error::external)? { if let Some(dir_path_str) = dir_entry.path().to_str() { dir_strings.push(dir_path_str.to_owned()); } else { diff --git a/src/lib/globals/net.rs b/src/lib/globals/net.rs index d1cb278..238b435 100644 --- a/src/lib/globals/net.rs +++ b/src/lib/globals/net.rs @@ -1,10 +1,6 @@ -use std::{collections::HashMap, str::FromStr}; +use std::collections::HashMap; use mlua::{Error, Lua, LuaSerdeExt, Result, Table, Value}; -use reqwest::{ - header::{HeaderMap, HeaderName, HeaderValue}, - Method, -}; use crate::utils::{net::get_request_user_agent_header, table_builder::TableBuilder}; @@ -38,7 +34,7 @@ async fn net_request<'lua>(lua: &'lua Lua, config: Value<'lua>) -> Result { let url = s.to_string_lossy().to_string(); let method = "GET".to_string(); - (url, method, None, None) + (url, method, HashMap::new(), None) } Value::Table(tab) => { // Extract url @@ -58,17 +54,14 @@ async fn net_request<'lua>(lua: &'lua Lua, config: Value<'lua>) -> Result("headers") { Ok(config_headers) => { - let mut lua_headers = HeaderMap::new(); + let mut lua_headers = HashMap::new(); for pair in config_headers.pairs::() { - let (key, value) = pair?; - lua_headers.insert( - HeaderName::from_str(key.to_str()?).map_err(Error::external)?, - HeaderValue::from_str(value.to_str()?).map_err(Error::external)?, - ); + let (key, value) = pair?.to_owned(); + lua_headers.insert(key, value); } - Some(lua_headers) + lua_headers } - Err(_) => None, + Err(_) => HashMap::new(), }; // Extract body let body = match tab.raw_get::<&str, mlua::String>("body") { @@ -85,58 +78,46 @@ async fn net_request<'lua>(lua: &'lua Lua, config: Value<'lua>) -> Result meth, - Err(_) => { + let method = method.trim().to_ascii_uppercase(); + let method = match method.as_ref() { + "GET" | "POST" | "PUT" | "DELETE" | "HEAD" | "OPTIONS" | "PATCH" => &method, + _ => { return Err(Error::RuntimeError(format!( "Invalid request config method '{}'", &method ))) } }; - // Extract headers from config, force user agent - let mut header_map = if let Some(headers) = headers { - headers - } else { - HeaderMap::new() - }; - header_map.insert( - "User-Agent", - HeaderValue::from_str(&get_request_user_agent_header()).map_err(Error::external)?, - ); - // Create a client to send a request with - // FUTURE: Try to reuse this client - let client = reqwest::Client::builder() - .build() - .map_err(Error::external)?; // Create and send the request - let mut request = client.request(method, url).headers(header_map); - if let Some(body) = body { - request = request.body(body); + let mut request = ureq::request(method, &url); + for (header, value) in headers { + request = request.set(header.to_str()?, value.to_str()?); } - let response = request.send().await.map_err(Error::external)?; - // Extract status, headers, body - let res_status = response.status(); - let res_headers = response.headers().clone(); - let res_bytes = response.bytes().await.map_err(Error::external)?; - // Construct and return a readonly lua table with results - TableBuilder::new(lua)? - .with_value("ok", res_status.is_success())? - .with_value("statusCode", res_status.as_u16())? - .with_value( - "statusMessage", - res_status.canonical_reason().unwrap_or("?"), - )? - .with_value( - "headers", - res_headers + let response = request + .set("User-Agent", &get_request_user_agent_header()) // Always force user agent + .send_bytes(&body.unwrap_or_default()); + match response { + Ok(res) | Err(ureq::Error::Status(_, res)) => { + // Extract status, headers + let res_status = res.status(); + let res_status_text = res.status_text().to_owned(); + let res_header_names = &res.headers_names(); + let res_headers = res_header_names .iter() - .filter_map(|(key, value)| match value.to_str() { - Ok(value) => Some((key.as_str(), value)), - Err(_) => None, - }) - .collect::>(), - )? - .with_value("body", lua.create_string(&res_bytes)?)? - .build_readonly() + .map(|name| (name.to_owned(), res.header(name).unwrap().to_owned())) + .collect::>(); + // Read response bytes + let mut res_bytes = Vec::new(); + res.into_reader().read_to_end(&mut res_bytes)?; + // Construct and return a readonly lua table with results + TableBuilder::new(lua)? + .with_value("ok", (200..300).contains(&res_status))? + .with_value("statusCode", res_status)? + .with_value("statusMessage", res_status_text)? + .with_value("headers", res_headers)? + .with_value("body", lua.create_string(&res_bytes)?)? + .build_readonly() + } + Err(e) => Err(Error::external(e)), + } } diff --git a/src/lib/globals/process.rs b/src/lib/globals/process.rs index 0ce23d9..d691ed6 100644 --- a/src/lib/globals/process.rs +++ b/src/lib/globals/process.rs @@ -5,7 +5,7 @@ use std::{ use mlua::{Error, Function, Lua, MetaMethod, Result, Table, Value}; use os_str_bytes::RawOsString; -use tokio::process::Command; +use smol::process::Command; use crate::utils::table_builder::TableBuilder; @@ -113,10 +113,7 @@ async fn process_spawn(lua: &Lua, (program, args): (String, Option>) .stderr(Stdio::piped()) .spawn() .map_err(mlua::Error::external)?; - let output = child - .wait_with_output() - .await - .map_err(mlua::Error::external)?; + let output = child.output().await.map_err(mlua::Error::external)?; // NOTE: If an exit code was not given by the child process, // we default to 1 if it yielded any error output, otherwise 0 let code = output diff --git a/src/lib/globals/task.rs b/src/lib/globals/task.rs index 680e056..2bc51b1 100644 --- a/src/lib/globals/task.rs +++ b/src/lib/globals/task.rs @@ -1,7 +1,7 @@ -use std::time::Duration; +use std::time::{Duration, Instant}; use mlua::{Error, Function, Lua, Result, Table, Thread, Value, Variadic}; -use tokio::time::{self, Instant}; +use smol::Timer; use crate::utils::table_builder::TableBuilder; @@ -78,7 +78,7 @@ async fn task_spawn<'a>(lua: &'a Lua, (tof, args): (Value<'a>, Vararg<'a>)) -> R // the async wait function inside of a coroutine async fn task_wait(_: &Lua, duration: Option) -> Result { let start = Instant::now(); - time::sleep( + Timer::after( duration .map(Duration::from_secs_f32) .unwrap_or(Duration::ZERO), diff --git a/src/lib/lib.rs b/src/lib/lib.rs index c84ed37..8331c0f 100644 --- a/src/lib/lib.rs +++ b/src/lib/lib.rs @@ -1,8 +1,7 @@ use std::collections::HashSet; use anyhow::{bail, Result}; -use mlua::Lua; -use tokio::task; +use mlua::prelude::*; pub mod globals; pub mod utils; @@ -62,46 +61,33 @@ impl Lune { } pub async fn run(&self, name: &str, chunk: &str) -> Result<()> { - let run_name = name.to_owned(); - let run_chunk = chunk.to_owned(); - let run_globals = self.globals.to_owned(); - let run_args = self.args.to_owned(); - // Spawn a thread-local task so that we can then spawn - // more tasks in our globals without the Send requirement - let local = task::LocalSet::new(); - local - .run_until(async move { - task::spawn_local(async move { - let lua = Lua::new(); - for global in &run_globals { - match &global { - LuneGlobal::Console => create_console(&lua).await?, - LuneGlobal::Fs => create_fs(&lua).await?, - LuneGlobal::Net => create_net(&lua).await?, - LuneGlobal::Process => create_process(&lua, run_args.clone()).await?, - LuneGlobal::Task => create_task(&lua).await?, - } + smol::block_on(async { + let lua = Lua::new(); + for global in &self.globals { + match &global { + LuneGlobal::Console => create_console(&lua).await?, + LuneGlobal::Fs => create_fs(&lua).await?, + LuneGlobal::Net => create_net(&lua).await?, + LuneGlobal::Process => create_process(&lua, self.args.clone()).await?, + LuneGlobal::Task => create_task(&lua).await?, + } + } + let result = lua.load(chunk).set_name(name)?.exec_async().await; + match result { + Ok(_) => Ok(()), + Err(e) => { + if cfg!(test) { + bail!(pretty_format_luau_error(&e)) + } else { + bail!( + "\n{}\n{}", + format_label("ERROR"), + pretty_format_luau_error(&e) + ) } - let result = lua.load(&run_chunk).set_name(&run_name)?.exec_async().await; - match result { - Ok(_) => Ok(()), - Err(e) => { - if cfg!(test) { - bail!(pretty_format_luau_error(&e)) - } else { - bail!( - "\n{}\n{}", - format_label("ERROR"), - pretty_format_luau_error(&e) - ) - } - } - } - }) - .await - .unwrap() - }) - .await + } + } + }) } } @@ -109,26 +95,28 @@ impl Lune { mod tests { use crate::Lune; use anyhow::Result; + use smol::fs::read_to_string; use std::env::current_dir; - use tokio::fs::read_to_string; const ARGS: &[&str] = &["Foo", "Bar"]; macro_rules! run_tests { ($($name:ident: $value:expr,)*) => { $( - #[tokio::test] - async fn $name() -> Result<()> { - let path = current_dir() - .unwrap() - .join(format!("src/tests/{}.luau", $value)); - let script = read_to_string(&path) - .await - .unwrap(); - let lune = Lune::new() - .with_args(ARGS.clone().iter().map(ToString::to_string).collect()) - .with_all_globals(); - lune.run($value, &script).await + #[test] + fn $name() -> Result<()> { + smol::block_on(async { + let path = current_dir() + .unwrap() + .join(format!("src/tests/{}.luau", $value)); + let script = read_to_string(&path) + .await + .unwrap(); + let lune = Lune::new() + .with_args(ARGS.clone().iter().map(ToString::to_string).collect()) + .with_all_globals(); + lune.run($value, &script).await + }) } )* }