From 57ec82950c2dfde07f2474063d69f85c74edec42 Mon Sep 17 00:00:00 2001 From: Maxim <59533214+biryukovmaxim@users.noreply.github.com> Date: Wed, 30 Nov 2022 15:16:23 +0400 Subject: [PATCH] Feature/support actix web (#491) * Support actix-web: impl Service * Support actix-web: cli + boilerplate code * Support actix-web: add framework to doc comment * Support actix-web: add e2e test * Support actix-web: fmt * Support actix-web: sorting toml deps * Support actix-web: add actix-web to ci * Support actix-web: formatted boilerplate code for actix-web hello world example * Support actix-web: formatted boilerplate code for actix-web hello world example Support actix-web: update cargo lock zstd dep * Support actix-web: simplify example * Support actix-web: add test, change example dependency * fix: e2e test assert, reset example module Co-authored-by: maksim Co-authored-by: oddgrd <29732646+oddgrd@users.noreply.github.com> --- .circleci/config.yml | 2 +- Cargo.lock | 353 +++++++++++++++++++++--- cargo-shuttle/src/args.rs | 21 +- cargo-shuttle/src/init.rs | 93 ++++++- cargo-shuttle/tests/integration/init.rs | 2 + cargo-shuttle/tests/integration/run.rs | 16 ++ e2e/tests/integration/actix_web.rs | 23 ++ e2e/tests/integration/main.rs | 1 + service/Cargo.toml | 2 + service/src/lib.rs | 20 ++ 10 files changed, 476 insertions(+), 57 deletions(-) create mode 100644 e2e/tests/integration/actix_web.rs diff --git a/.circleci/config.yml b/.circleci/config.yml index d0006a617..95dceb694 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -251,7 +251,7 @@ workflows: - workspace-fmt matrix: parameters: - framework: ["web-axum", "web-rocket", "web-poem", "web-thruster", "web-tide", "web-tower","web-warp", "web-salvo", "bot-serenity"] + framework: ["web-actix-web", "web-axum", "web-rocket", "web-poem", "web-thruster", "web-tide", "web-tower","web-warp", "web-salvo", "bot-serenity"] - check-standalone: matrix: parameters: diff --git a/Cargo.lock b/Cargo.lock index fb00254c2..bdc080d3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,6 +30,185 @@ dependencies = [ "tracing-futures", ] +[[package]] +name = "actix-codec" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57a7559404a7f3573127aab53c08ce37a6c6a315c374a31070f3c91cd1b4a7fe" +dependencies = [ + "bitflags", + "bytes 1.3.0", + "futures-core", + "futures-sink", + "log", + "memchr", + "pin-project-lite 0.2.9", + "tokio", + "tokio-util 0.7.3", +] + +[[package]] +name = "actix-http" +version = "3.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c83abf9903e1f0ad9973cc4f7b9767fd5a03a583f51a5b7a339e07987cd2724" +dependencies = [ + "actix-codec", + "actix-rt", + "actix-service", + "actix-utils", + "ahash", + "base64 0.13.0", + "bitflags", + "brotli", + "bytes 1.3.0", + "bytestring", + "derive_more", + "encoding_rs", + "flate2", + "futures-core", + "h2", + "http 0.2.8", + "httparse", + "httpdate", + "itoa 1.0.2", + "language-tags", + "local-channel", + "mime", + "percent-encoding", + "pin-project-lite 0.2.9", + "rand 0.8.5", + "sha1 0.10.4", + "smallvec", + "tracing", + "zstd", +] + +[[package]] +name = "actix-macros" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "465a6172cf69b960917811022d8f29bc0b7fa1398bc4f78b3c466673db1213b6" +dependencies = [ + "quote 1.0.21", + "syn 1.0.99", +] + +[[package]] +name = "actix-router" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d66ff4d247d2b160861fa2866457e85706833527840e4133f8f49aa423a38799" +dependencies = [ + "bytestring", + "http 0.2.8", + "regex", + "serde", + "tracing", +] + +[[package]] +name = "actix-rt" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ea16c295198e958ef31930a6ef37d0fb64e9ca3b6116e6b93a8bdae96ee1000" +dependencies = [ + "futures-core", + "tokio", +] + +[[package]] +name = "actix-server" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0da34f8e659ea1b077bb4637948b815cd3768ad5a188fdcd74ff4d84240cd824" +dependencies = [ + "actix-rt", + "actix-service", + "actix-utils", + "futures-core", + "futures-util", + "mio", + "num_cpus", + "socket2", + "tokio", + "tracing", +] + +[[package]] +name = "actix-service" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b894941f818cfdc7ccc4b9e60fa7e53b5042a2e8567270f9147d5591893373a" +dependencies = [ + "futures-core", + "paste", + "pin-project-lite 0.2.9", +] + +[[package]] +name = "actix-utils" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88a1dcdff1466e3c2488e1cb5c36a71822750ad43839937f85d2f4d9f8b705d8" +dependencies = [ + "local-waker", + "pin-project-lite 0.2.9", +] + +[[package]] +name = "actix-web" +version = "4.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d48f7b6534e06c7bfc72ee91db7917d4af6afe23e7d223b51e68fffbb21e96b9" +dependencies = [ + "actix-codec", + "actix-http", + "actix-macros", + "actix-router", + "actix-rt", + "actix-server", + "actix-service", + "actix-utils", + "actix-web-codegen", + "ahash", + "bytes 1.3.0", + "bytestring", + "cfg-if 1.0.0", + "cookie 0.16.0", + "derive_more", + "encoding_rs", + "futures-core", + "futures-util", + "http 0.2.8", + "itoa 1.0.2", + "language-tags", + "log", + "mime", + "once_cell", + "pin-project-lite 0.2.9", + "regex", + "serde", + "serde_json", + "serde_urlencoded", + "smallvec", + "socket2", + "time 0.3.11", + "url", +] + +[[package]] +name = "actix-web-codegen" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa9362663c8643d67b2d5eafba49e4cb2c8a053a29ed00a0bea121f17c76b13" +dependencies = [ + "actix-router", + "proc-macro2 1.0.43", + "quote 1.0.21", + "syn 1.0.99", +] + [[package]] name = "adler" version = "1.0.2" @@ -520,7 +699,7 @@ dependencies = [ "aws-smithy-json", "aws-smithy-types", "aws-types", - "bytes 1.1.0", + "bytes 1.3.0", "hex 0.4.3", "http 0.2.8", "hyper", @@ -554,7 +733,7 @@ dependencies = [ "aws-smithy-http", "aws-smithy-types", "aws-types", - "bytes 1.1.0", + "bytes 1.3.0", "http 0.2.8", "http-body", "lazy_static", @@ -580,7 +759,7 @@ dependencies = [ "aws-smithy-types", "aws-smithy-xml", "aws-types", - "bytes 1.1.0", + "bytes 1.3.0", "http 0.2.8", "tokio-stream", "tower", @@ -602,7 +781,7 @@ dependencies = [ "aws-smithy-json", "aws-smithy-types", "aws-types", - "bytes 1.1.0", + "bytes 1.3.0", "http 0.2.8", "tokio-stream", "tower", @@ -625,7 +804,7 @@ dependencies = [ "aws-smithy-types", "aws-smithy-xml", "aws-types", - "bytes 1.1.0", + "bytes 1.3.0", "http 0.2.8", "tower", ] @@ -683,7 +862,7 @@ dependencies = [ "aws-smithy-http", "aws-smithy-http-tower", "aws-smithy-types", - "bytes 1.1.0", + "bytes 1.3.0", "fastrand", "http 0.2.8", "http-body", @@ -703,7 +882,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cc1af50eac644ab6f58e5bae29328ba3092851fc2ce648ad139134699b2b66f" dependencies = [ "aws-smithy-types", - "bytes 1.1.0", + "bytes 1.3.0", "bytes-utils", "futures-core", "http 0.2.8", @@ -724,7 +903,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1bf4c4664dff2febf91f8796505c5bc8f38a0bff0d1397d1d3fdda17bd5c5d1" dependencies = [ "aws-smithy-http", - "bytes 1.1.0", + "bytes 1.3.0", "http 0.2.8", "http-body", "pin-project-lite 0.2.9", @@ -798,7 +977,7 @@ dependencies = [ "axum-core", "base64 0.13.0", "bitflags", - "bytes 1.1.0", + "bytes 1.3.0", "futures-util", "headers", "http 0.2.8", @@ -830,7 +1009,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4f44a0e6200e9d11a1cdc989e4b358f6e3d354fbf48478f345a17f4e43f8635" dependencies = [ "async-trait", - "bytes 1.1.0", + "bytes 1.3.0", "futures-util", "http 0.2.8", "http-body", @@ -844,7 +1023,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8456dab8f11484979a86651da8e619b355ede5d61a160755155f6c344bd18c47" dependencies = [ "arc-swap", - "bytes 1.1.0", + "bytes 1.3.0", "futures-util", "http 0.2.8", "http-body", @@ -966,7 +1145,7 @@ checksum = "d82e7850583ead5f8bbef247e2a3c37a19bd576e8420cd262a6711921827e1e5" dependencies = [ "base64 0.13.0", "bollard-stubs", - "bytes 1.1.0", + "bytes 1.3.0", "futures-core", "futures-util", "hex 0.4.3", @@ -1087,9 +1266,9 @@ checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" [[package]] name = "bytes" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" +checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" [[package]] name = "bytes-utils" @@ -1097,7 +1276,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1934a3ef9cac8efde4966a92781e77713e1ba329f1d42e446c7d7eba340d8ef1" dependencies = [ - "bytes 1.1.0", + "bytes 1.3.0", "either", ] @@ -1107,6 +1286,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c58ec36aac5066d5ca17df51b3e70279f5670a72102f5752cb7e7c856adfc70" +[[package]] +name = "bytestring" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7f83e57d9154148e355404702e2694463241880b939570d7c97c014da7a69a1" +dependencies = [ + "bytes 1.3.0", +] + [[package]] name = "cache-padded" version = "1.2.0" @@ -1483,7 +1671,7 @@ version = "4.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a604e93b79d1808327a6fca85a6f2d69de66461e7620f5a4cbf5fb4d1d7c948" dependencies = [ - "bytes 1.1.0", + "bytes 1.3.0", "memchr", ] @@ -1555,6 +1743,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + [[package]] name = "cookie" version = "0.14.4" @@ -1983,6 +2177,19 @@ dependencies = [ "syn 1.0.99", ] +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case", + "proc-macro2 1.0.43", + "quote 1.0.21", + "rustc_version 0.4.0", + "syn 1.0.99", +] + [[package]] name = "devise" version = "0.3.1" @@ -2578,7 +2785,7 @@ version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" dependencies = [ - "bytes 1.1.0", + "bytes 1.3.0", "fnv", "futures-core", "futures-sink", @@ -2635,7 +2842,7 @@ checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584" dependencies = [ "base64 0.13.0", "bitflags", - "bytes 1.1.0", + "bytes 1.3.0", "headers-core", "http 0.2.8", "httpdate", @@ -2770,7 +2977,7 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" dependencies = [ - "bytes 1.1.0", + "bytes 1.3.0", "fnv", "itoa 1.0.2", ] @@ -2781,7 +2988,7 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ - "bytes 1.1.0", + "bytes 1.3.0", "http 0.2.8", "pin-project-lite 0.2.9", ] @@ -2850,7 +3057,7 @@ version = "0.14.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" dependencies = [ - "bytes 1.1.0", + "bytes 1.3.0", "futures-channel", "futures-core", "futures-util", @@ -2939,7 +3146,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ - "bytes 1.1.0", + "bytes 1.3.0", "hyper", "native-tls", "tokio", @@ -3178,6 +3385,12 @@ dependencies = [ "log", ] +[[package]] +name = "language-tags" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388" + [[package]] name = "lazy_static" version = "1.4.0" @@ -3273,6 +3486,24 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +[[package]] +name = "local-channel" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f303ec0e94c6c54447f84f3b0ef7af769858a9c4ef56ef2a986d3dcd4c3fc9c" +dependencies = [ + "futures-core", + "futures-sink", + "futures-util", + "local-waker", +] + +[[package]] +name = "local-waker" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e34f76eb3611940e0e7d53a9aaa4e6a3151f69541a282fd0dad5571420c53ff1" + [[package]] name = "lock_api" version = "0.4.7" @@ -3473,7 +3704,7 @@ version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f8f35e687561d5c1667590911e6698a8cb714a134a7505718a182e7bc9d3836" dependencies = [ - "bytes 1.1.0", + "bytes 1.3.0", "encoding_rs", "futures-util", "http 0.2.8", @@ -3773,7 +4004,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1edc79add46364183ece1a4542592ca593e6421c60807232f5b8f7a31703825d" dependencies = [ "async-trait", - "bytes 1.1.0", + "bytes 1.3.0", "http 0.2.8", "opentelemetry_api", "reqwest", @@ -4044,7 +4275,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16d0fec4acc8779b696e3ff25527884fb17cda6cf59a249c57aa1af1e2f65b36" dependencies = [ "async-trait", - "bytes 1.1.0", + "bytes 1.3.0", "futures-util", "headers", "http 0.2.8", @@ -4230,7 +4461,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "399c3c31cdec40583bb68f0b18403400d01ec4289c383aa047560439952c4dd7" dependencies = [ - "bytes 1.1.0", + "bytes 1.3.0", "prost-derive", ] @@ -4240,7 +4471,7 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f835c582e6bd972ba8347313300219fed5bfa52caf175298d860b61ff6069bb" dependencies = [ - "bytes 1.1.0", + "bytes 1.3.0", "heck", "itertools", "lazy_static", @@ -4273,7 +4504,7 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dfaa718ad76a44b3415e6c4d53b17c8f99160dcb3a99b10470fce8ad43f6e3e" dependencies = [ - "bytes 1.1.0", + "bytes 1.3.0", "prost", ] @@ -4633,7 +4864,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" dependencies = [ "base64 0.13.0", - "bytes 1.1.0", + "bytes 1.3.0", "encoding_rs", "futures-core", "futures-util", @@ -4773,7 +5004,7 @@ dependencies = [ "atomic", "atty", "binascii", - "bytes 1.1.0", + "bytes 1.3.0", "either", "figment", "futures", @@ -5021,7 +5252,7 @@ dependencies = [ "async-compression", "async-trait", "base64 0.13.0", - "bytes 1.1.0", + "bytes 1.3.0", "cookie 0.16.0", "encoding_rs", "enumflags2", @@ -5289,7 +5520,7 @@ dependencies = [ "async-tungstenite", "base64 0.13.0", "bitflags", - "bytes 1.1.0", + "bytes 1.3.0", "cfg-if 1.0.0", "flate2", "futures", @@ -5453,7 +5684,7 @@ dependencies = [ "anyhow", "async-trait", "axum", - "bytes 1.1.0", + "bytes 1.3.0", "cargo", "cargo_metadata", "chrono", @@ -5590,6 +5821,7 @@ dependencies = [ name = "shuttle-service" version = "0.7.2" dependencies = [ + "actix-web", "anyhow", "async-std", "async-trait", @@ -5784,7 +6016,7 @@ dependencies = [ "atoi 0.4.0", "bitflags", "byteorder", - "bytes 1.1.0", + "bytes 1.3.0", "crc 2.1.0", "crossbeam-queue", "either", @@ -5832,7 +6064,7 @@ dependencies = [ "base64 0.13.0", "bitflags", "byteorder", - "bytes 1.1.0", + "bytes 1.3.0", "chrono", "crc 3.0.0", "crossbeam-queue", @@ -6276,7 +6508,7 @@ checksum = "4bc22b1c2267be6d1769c6d787936201341f03c915456ed8a8db8d40d665215f" dependencies = [ "async-trait", "bytes 0.5.6", - "bytes 1.1.0", + "bytes 1.3.0", "fnv", "futures", "http 0.1.21", @@ -6426,7 +6658,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" dependencies = [ "autocfg 1.1.0", - "bytes 1.1.0", + "bytes 1.3.0", "libc", "memchr", "mio", @@ -6511,7 +6743,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53474327ae5e166530d17f2d956afcb4f8a004de581b3cae10f12006bc8163e3" dependencies = [ "async-stream", - "bytes 1.1.0", + "bytes 1.3.0", "futures-core", "tokio", "tokio-stream", @@ -6550,7 +6782,7 @@ version = "0.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "36943ee01a6d67977dd3f84a5a1d2efeb4ada3a1ae771cadfaa535d9d9fc6507" dependencies = [ - "bytes 1.1.0", + "bytes 1.3.0", "futures-core", "futures-io", "futures-sink", @@ -6566,7 +6798,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45" dependencies = [ - "bytes 1.1.0", + "bytes 1.3.0", "futures-core", "futures-sink", "pin-project-lite 0.2.9", @@ -6623,7 +6855,7 @@ dependencies = [ "async-trait", "axum", "base64 0.13.0", - "bytes 1.1.0", + "bytes 1.3.0", "futures-core", "futures-util", "h2", @@ -6685,7 +6917,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aba3f3efabf7fb41fae8534fc20a817013dd1c12cb45441efb6c82e6556b4cd8" dependencies = [ "bitflags", - "bytes 1.1.0", + "bytes 1.3.0", "futures-core", "futures-util", "http 0.2.8", @@ -6704,7 +6936,7 @@ checksum = "3c530c8675c1dbf98facee631536fa116b5fb6382d7dd6dc1b118d970eafe3ba" dependencies = [ "base64 0.13.0", "bitflags", - "bytes 1.1.0", + "bytes 1.3.0", "futures-core", "futures-util", "http 0.2.8", @@ -6890,7 +7122,7 @@ checksum = "a0b2d8558abd2e276b0a8df5c05a2ec762609344191e5fd23e292c910e9165b5" dependencies = [ "base64 0.13.0", "byteorder", - "bytes 1.1.0", + "bytes 1.3.0", "http 0.2.8", "httparse", "log", @@ -6909,7 +7141,7 @@ checksum = "e27992fd6a8c29ee7eef28fc78349aa244134e10ad447ce3b9f0ac0ed0fa4ce0" dependencies = [ "base64 0.13.0", "byteorder", - "bytes 1.1.0", + "bytes 1.3.0", "http 0.2.8", "httparse", "log", @@ -7228,7 +7460,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cef4e1e9114a4b7f1ac799f16ce71c14de5778500c5450ec6b7b920c55b587e" dependencies = [ - "bytes 1.1.0", + "bytes 1.3.0", "futures-channel", "futures-util", "headers", @@ -7563,3 +7795,32 @@ name = "zeroize" version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94693807d016b2f2d2e14420eb3bfcca689311ff775dcf113d74ea624b7cdf07" + +[[package]] +name = "zstd" +version = "0.11.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "5.0.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.4+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fa202f2ef00074143e219d15b62ffc317d17cc33909feac471c044087cad7b0" +dependencies = [ + "cc", + "libc", +] diff --git a/cargo-shuttle/src/args.rs b/cargo-shuttle/src/args.rs index de3f12a63..c3f4ce2e1 100644 --- a/cargo-shuttle/src/args.rs +++ b/cargo-shuttle/src/args.rs @@ -146,32 +146,35 @@ pub struct RunArgs { #[derive(Parser, Debug)] pub struct InitArgs { + /// Initialize with actix-web framework + #[clap(long="actix-web", conflicts_with_all = &["axum", "rocket", "tide", "tower", "poem", "serenity", "warp", "salvo", "thruster"])] + pub actix_web: bool, /// Initialize with axum framework - #[clap(long, conflicts_with_all = &["rocket", "tide", "tower", "poem", "serenity", "warp", "salvo", "thruster"])] + #[clap(long, conflicts_with_all = &["actix-web","rocket", "tide", "tower", "poem", "serenity", "warp", "salvo", "thruster"])] pub axum: bool, /// Initialize with rocket framework - #[clap(long, conflicts_with_all = &["axum", "tide", "tower", "poem", "serenity", "warp", "salvo", "thruster"])] + #[clap(long, conflicts_with_all = &["actix-web","axum", "tide", "tower", "poem", "serenity", "warp", "salvo", "thruster"])] pub rocket: bool, /// Initialize with tide framework - #[clap(long, conflicts_with_all = &["axum", "rocket", "tower", "poem", "serenity", "warp", "salvo", "thruster"])] + #[clap(long, conflicts_with_all = &["actix-web","axum", "rocket", "tower", "poem", "serenity", "warp", "salvo", "thruster"])] pub tide: bool, /// Initialize with tower framework - #[clap(long, conflicts_with_all = &["axum", "rocket", "tide", "poem", "serenity", "warp", "salvo", "thruster"])] + #[clap(long, conflicts_with_all = &["actix-web","axum", "rocket", "tide", "poem", "serenity", "warp", "salvo", "thruster"])] pub tower: bool, /// Initialize with poem framework - #[clap(long, conflicts_with_all = &["axum", "rocket", "tide", "tower", "serenity", "warp", "salvo", "thruster"])] + #[clap(long, conflicts_with_all = &["actix-web","axum", "rocket", "tide", "tower", "serenity", "warp", "salvo", "thruster"])] pub poem: bool, /// Initialize with salvo framework - #[clap(long, conflicts_with_all = &["axum", "rocket", "tide", "tower", "poem", "warp", "serenity", "thruster"])] + #[clap(long, conflicts_with_all = &["actix-web","axum", "rocket", "tide", "tower", "poem", "warp", "serenity", "thruster"])] pub salvo: bool, /// Initialize with serenity framework - #[clap(long, conflicts_with_all = &["axum", "rocket", "tide", "tower", "poem", "warp", "salvo", "thruster"])] + #[clap(long, conflicts_with_all = &["actix-web","axum", "rocket", "tide", "tower", "poem", "warp", "salvo", "thruster"])] pub serenity: bool, /// Initialize with warp framework - #[clap(long, conflicts_with_all = &["axum", "rocket", "tide", "tower", "poem", "serenity", "salvo", "thruster"])] + #[clap(long, conflicts_with_all = &["actix-web","axum", "rocket", "tide", "tower", "poem", "serenity", "salvo", "thruster"])] pub warp: bool, /// Initialize with thruster framework - #[clap(long, conflicts_with_all = &["axum", "rocket", "tide", "tower", "poem", "warp", "salvo", "serenity"])] + #[clap(long, conflicts_with_all = &["actix-web","axum", "rocket", "tide", "tower", "poem", "warp", "salvo", "serenity"])] pub thruster: bool, /// Path to initialize a new shuttle project #[clap( diff --git a/cargo-shuttle/src/init.rs b/cargo-shuttle/src/init.rs index d4309aa7e..0a27c21e8 100644 --- a/cargo-shuttle/src/init.rs +++ b/cargo-shuttle/src/init.rs @@ -21,6 +21,51 @@ pub trait ShuttleInit { fn get_boilerplate_code_for_framework(&self) -> &'static str; } +pub struct ShuttleInitActixWeb; + +impl ShuttleInit for ShuttleInitActixWeb { + fn set_cargo_dependencies( + &self, + dependencies: &mut Table, + manifest_path: &Path, + url: &Url, + get_dependency_version_fn: GetDependencyVersionFn, + ) { + set_key_value_dependency_version( + "actix-web", + dependencies, + manifest_path, + url, + true, + get_dependency_version_fn, + ); + + set_inline_table_dependency_features( + "shuttle-service", + dependencies, + vec!["web-actix-web".to_string()], + ); + } + + fn get_boilerplate_code_for_framework(&self) -> &'static str { + indoc! {r#" + use actix_web::web::{resource, ServiceConfig}; + use shuttle_service::ShuttleActixWeb; + + async fn hello_world() -> &'static str { + "Hello World!" + } + + #[shuttle_service::main] + async fn actix_web( + ) -> ShuttleActixWeb { + Ok(move |cfg: &mut ServiceConfig| { + cfg.service(resource("/hello").to(hello_world)); + }) + }"#} + } +} + pub struct ShuttleInitAxum; impl ShuttleInit for ShuttleInitAxum { @@ -556,6 +601,9 @@ impl ShuttleInit for ShuttleInitNoOp { /// for writing framework-specific dependencies to `Cargo.toml` and generating /// boilerplate code in `src/lib.rs`. pub fn get_framework(init_args: &InitArgs) -> Box { + if init_args.actix_web { + return Box::new(ShuttleInitActixWeb); + } if init_args.axum { return Box::new(ShuttleInitAxum); } @@ -742,6 +790,7 @@ mod shuttle_init_tests { fn init_args_factory(framework: &str) -> InitArgs { let mut init_args = InitArgs { + actix_web: false, axum: false, rocket: false, tide: false, @@ -755,6 +804,7 @@ mod shuttle_init_tests { }; match framework { + "actix-web" => init_args.actix_web = true, "axum" => init_args.axum = true, "rocket" => init_args.rocket = true, "tide" => init_args.tide = true, @@ -790,9 +840,19 @@ mod shuttle_init_tests { #[test] fn test_get_framework_via_get_boilerplate_code() { let frameworks = vec![ - "axum", "rocket", "tide", "tower", "poem", "salvo", "serenity", "warp", "thruster", + "actix-web", + "axum", + "rocket", + "tide", + "tower", + "poem", + "salvo", + "serenity", + "warp", + "thruster", ]; let framework_inits: Vec> = vec![ + Box::new(ShuttleInitActixWeb), Box::new(ShuttleInitAxum), Box::new(ShuttleInitRocket), Box::new(ShuttleInitTide), @@ -879,6 +939,37 @@ mod shuttle_init_tests { assert_eq!(cargo_toml.to_string(), expected); } + #[test] + fn test_set_cargo_dependencies_actix_web() { + let mut cargo_toml = cargo_toml_factory(); + let dependencies = cargo_toml["dependencies"].as_table_mut().unwrap(); + let manifest_path = PathBuf::new(); + let url = Url::parse("https://shuttle.rs").unwrap(); + + set_inline_table_dependency_version( + "shuttle-service", + dependencies, + &manifest_path, + &url, + false, + mock_get_latest_dependency_version, + ); + + ShuttleInitActixWeb.set_cargo_dependencies( + dependencies, + &manifest_path, + &url, + mock_get_latest_dependency_version, + ); + + let expected = indoc! {r#" + [dependencies] + shuttle-service = { version = "1.0", features = ["web-actix-web"] } + actix-web = "1.0" + "#}; + + assert_eq!(cargo_toml.to_string(), expected); + } #[test] fn test_set_cargo_dependencies_axum() { diff --git a/cargo-shuttle/tests/integration/init.rs b/cargo-shuttle/tests/integration/init.rs index 25de27008..f52dd35c1 100644 --- a/cargo-shuttle/tests/integration/init.rs +++ b/cargo-shuttle/tests/integration/init.rs @@ -20,6 +20,7 @@ async fn cargo_shuttle_init(path: PathBuf) -> anyhow::Result { name: None, }, cmd: Command::Init(InitArgs { + actix_web: false, axum: false, rocket: false, tide: false, @@ -48,6 +49,7 @@ async fn cargo_shuttle_init_framework(path: PathBuf) -> anyhow::Result` | web-tower | [tower](https://docs.rs/tower/0.4.12) | 0.14.12 | [GitHub](https://github.com/shuttle-hq/examples/tree/main/tower/hello-world) | /// | `ShuttleSerenity` | bot-serenity | [serenity](https://docs.rs/serenity/0.11.5) | 0.11.5 | [GitHub](https://github.com/shuttle-hq/examples/tree/main/serenity/hello-world) | +/// | `ShuttleActixWeb` | web-actix-web| [actix-web](https://docs.rs/actix-web/4.2.1)| 4.2.1 | [GitHub](https://github.com/shuttle-hq/examples/tree/main/actix-web/hello-world) | + /// /// # Getting shuttle managed resources /// Shuttle is able to manage resource dependencies for you. These resources are passed in as inputs to your `#[shuttle_service::main]` function and are configured using attributes: @@ -544,6 +546,24 @@ impl Service for sync_wrapper::SyncWrapper { } } +#[cfg(feature = "web-actix-web")] +#[async_trait] +impl Service for F +where + F: FnOnce(&mut actix_web::web::ServiceConfig) + Sync + Send + Copy + Clone + 'static, +{ + async fn bind(self: Box, addr: SocketAddr) -> Result<(), Error> { + let srv = actix_web::HttpServer::new(move || actix_web::App::new().configure(*self)) + .bind(addr)? + .run(); + srv.await.map_err(error::CustomError::new)?; + + Ok(()) + } +} +#[cfg(feature = "web-actix-web")] +pub type ShuttleActixWeb = Result; + #[cfg(feature = "web-axum")] pub type ShuttleAxum = Result, Error>;