From c1cc49d9661f60ff7272f902ac0cf8bf50ad553f Mon Sep 17 00:00:00 2001 From: Brian Pursley Date: Thu, 31 Oct 2024 10:57:28 -0400 Subject: [PATCH] Support Postgres 17 - Update Rust toolchain to 1.82.0 - Upgrade pgrx to 0.12.7 - Upgrade lettre to 0.11.10 - Add CI testing for multiple Postgres versions - Add CI status badge --- .github/workflows/ci.yml | 38 +++- CONTRIBUTING.md | 5 + Cargo.lock | 403 ++++++++++++++++++--------------------- Cargo.toml | 26 ++- Makefile | 14 +- README.md | 2 + src/bin/pgrx_embed.rs | 1 + src/lib.rs | 90 +++++---- 8 files changed, 305 insertions(+), 274 deletions(-) create mode 100644 src/bin/pgrx_embed.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd18a86..6336549 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,13 +18,37 @@ on: jobs: test: name: Test - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest + strategy: + matrix: + PG_VERSION: [pg14, pg15, pg16, pg17] + env: + PG_VERSION: ${{ matrix.PG_VERSION }} steps: - - uses: actions/checkout@v4 - - uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Rust Toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.77.2 + toolchain: 1.82.0 components: clippy, rustfmt - - run: make init - - run: make lint - - run: make test + + - name: Cache Rust + uses: Swatinem/rust-cache@v2 + + - name: Cache pgrx + uses: actions/cache@v4 + with: + path: | + ~/.pgrx/ + key: ${{ runner.os }}-${{ matrix.PG_VERSION }}-pgrx + + - name: Init + run: make init + + - name: Lint + run: make lint + + - name: Test + run: make test diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 03546d8..325d0bf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,10 @@ # pg_smtp_client +## Install dependencies (needed for testing postgres 17) +```shell +sudo apt-get install bison flex +``` + ## Setup ```shell diff --git a/Cargo.lock b/Cargo.lock index 49f44bb..5243f30 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -44,6 +44,16 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "annotate-snippets" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccaf7e9dfbb6ab22c82e473cd1a8a7bd313c19a5b7e40970f3d89ef5a5c9e81e" +dependencies = [ + "unicode-width", + "yansi-term", +] + [[package]] name = "anstyle" version = "1.0.7" @@ -64,16 +74,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", -] - -[[package]] -name = "atomic-polyfill" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" -dependencies = [ - "critical-section", + "syn", ] [[package]] @@ -83,18 +84,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b29ec3788e96fb4fdb275ccb9d62811f2fa903d76c5eb4dd6fe7d09a7ed5871f" dependencies = [ "cfg-if", - "rustc_version 0.3.3", -] - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", + "rustc_version", ] [[package]] @@ -132,22 +122,21 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bindgen" -version = "0.69.4" +version = "0.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" +checksum = "f49d8fed880d473ea71efb9bf597651e77201bdd4893efe54c9e5d65ae04ce6f" dependencies = [ + "annotate-snippets", "bitflags 2.5.0", "cexpr", "clang-sys", "itertools", - "lazy_static", - "lazycell", "proc-macro2", "quote", "regex", "rustc-hash", "shlex", - "syn 2.0.66", + "syn", ] [[package]] @@ -216,11 +205,43 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +[[package]] +name = "camino" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24b1f0365a6c6bb4020cd05806fd0d33c44d38046b8bd7f0e40814b9763cabfc" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037" +dependencies = [ + "camino", + "cargo-platform", + "semver 1.0.23", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "cargo_toml" -version = "0.16.3" +version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3f9629bc6c4388ea699781dc988c2b99766d7679b151c81990b4fa1208fafd3" +checksum = "a98356df42a2eb1bd8f1793ae4ee4de48e384dd974ce5eac8eee802edb7492be" dependencies = [ "serde", "toml", @@ -232,6 +253,16 @@ version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" +[[package]] +name = "cee-scape" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d67dfb052149f779f77e9ce089cea126e00657e8f0d11dafc7901fde4291101" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "cexpr" version = "0.6.0" @@ -280,12 +311,13 @@ dependencies = [ [[package]] name = "clap-cargo" -version = "0.11.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25122ca6ebad5f53578c26638afd9f0160426969970dc37ec6c363ff6b082ebd" +checksum = "23b2ea69cefa96b848b73ad516ad1d59a195cdf9263087d977f648a818c8b43e" dependencies = [ + "anstyle", + "cargo_metadata", "clap", - "doc-comment", ] [[package]] @@ -307,7 +339,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] [[package]] @@ -350,12 +382,6 @@ dependencies = [ "libc", ] -[[package]] -name = "critical-section" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" - [[package]] name = "crossbeam-deque" version = "0.8.5" @@ -402,27 +428,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "dirs" -version = "5.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" -dependencies = [ - "dirs-sys", -] - -[[package]] -name = "dirs-sys" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" -dependencies = [ - "libc", - "option-ext", - "redox_users", - "windows-sys 0.48.0", -] - [[package]] name = "displaydoc" version = "0.2.4" @@ -431,15 +436,9 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] -[[package]] -name = "doc-comment" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" - [[package]] name = "either" version = "1.12.0" @@ -479,7 +478,7 @@ checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] [[package]] @@ -592,7 +591,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] [[package]] @@ -665,9 +664,9 @@ checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403" [[package]] name = "hash32" -version = "0.2.1" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" dependencies = [ "byteorder", ] @@ -684,14 +683,11 @@ dependencies = [ [[package]] name = "heapless" -version = "0.7.17" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" dependencies = [ - "atomic-polyfill", "hash32", - "rustc_version 0.4.0", - "spin", "stable_deref_trait", ] @@ -703,12 +699,9 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" [[package]] name = "hmac" @@ -719,6 +712,15 @@ dependencies = [ "digest", ] +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "hostname" version = "0.4.0" @@ -851,17 +853,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", -] - -[[package]] -name = "idna" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", + "syn", ] [[package]] @@ -892,6 +884,17 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "is-terminal" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "is_ci" version = "1.2.0" @@ -928,17 +931,11 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "lettre" -version = "0.11.7" +version = "0.11.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a62049a808f1c4e2356a2a380bd5f2aca3b011b0b482cf3b914ba1731426969" +checksum = "0161e452348e399deb685ba05e55ee116cae9410f4f51fe42d597361444521d9" dependencies = [ "base64 0.22.1", "chumsky", @@ -948,7 +945,7 @@ dependencies = [ "futures-util", "hostname", "httpdate", - "idna 0.5.0", + "idna", "mime", "native-tls", "nom", @@ -981,16 +978,6 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" -[[package]] -name = "libredox" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" -dependencies = [ - "bitflags 2.5.0", - "libc", -] - [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -1035,15 +1022,6 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "memoffset" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" -dependencies = [ - "autocfg", -] - [[package]] name = "mime" version = "0.3.17" @@ -1160,7 +1138,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] [[package]] @@ -1181,19 +1159,14 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "option-ext" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" - [[package]] name = "owo-colors" -version = "3.5.0" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" +checksum = "fb37767f6569cd834a413442455e0f066d0d522de8630436e2a1761d9726ba56" dependencies = [ - "supports-color", + "supports-color 2.1.0", + "supports-color 3.0.1", ] [[package]] @@ -1219,6 +1192,12 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "pathsearch" version = "0.2.0" @@ -1258,7 +1237,7 @@ dependencies = [ [[package]] name = "pg_smtp_client" -version = "0.1.1" +version = "0.2.0" dependencies = [ "lettre", "pgrx", @@ -1267,9 +1246,9 @@ dependencies = [ [[package]] name = "pgrx" -version = "0.11.4" +version = "0.12.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d4af45e16c27d0c7c12665f0cc5a714258c581a39901ee1488edd79a3c4c5a5" +checksum = "eb67c795a2718ecd599be132582fbc6b714ed9e15a23291bf08b565bab2be28e" dependencies = [ "atomic-traits", "bitflags 2.5.0", @@ -1282,7 +1261,6 @@ dependencies = [ "pgrx-pg-sys", "pgrx-sql-entity-graph", "seahash", - "seq-macro", "serde", "serde_cbor", "serde_json", @@ -1290,86 +1268,96 @@ dependencies = [ "uuid", ] +[[package]] +name = "pgrx-bindgen" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "433d56944dc948c6033cb38198895ff4a36432e2343c3b9891a0ec94d2913ef1" +dependencies = [ + "bindgen", + "cc", + "clang-sys", + "eyre", + "pgrx-pg-config", + "proc-macro2", + "quote", + "shlex", + "syn", + "walkdir", +] + [[package]] name = "pgrx-macros" -version = "0.11.4" +version = "0.12.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a8e65ea4e93a273f42bc2ca024d2c65379541f223157f136db4b7d436088027" +checksum = "9160f3affc241fa473a5f9e3bceca7cc8923132cbf81629f9851a01b81c674bf" dependencies = [ "pgrx-sql-entity-graph", "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] name = "pgrx-pg-config" -version = "0.11.4" +version = "0.12.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93074d31fc2f47c74ab46920fffa9ed9fb704fc8ffc07f8331c1e3b38e7ef88b" +checksum = "5a0703033b0d1269ca9facdb436b439e3a92e303a6ea5c13107dd8b228c4c294" dependencies = [ "cargo_toml", - "dirs", "eyre", + "home", "owo-colors", "pathsearch", "serde", - "serde_derive", "serde_json", + "thiserror", "toml", "url", ] [[package]] name = "pgrx-pg-sys" -version = "0.11.4" +version = "0.12.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3f58b876cd9745609217c891978dd19023c9ccbfaa011c1a5af7f720e1c3fb" +checksum = "b65132c32c8f90f4f6fa66d6b085cbd1657c95ea70e927104737f578ea9b7190" dependencies = [ - "bindgen", - "clang-sys", - "eyre", + "cee-scape", "libc", - "memoffset", - "once_cell", + "pgrx-bindgen", "pgrx-macros", - "pgrx-pg-config", "pgrx-sql-entity-graph", - "proc-macro2", - "quote", "serde", - "shlex", "sptr", - "syn 1.0.109", - "walkdir", ] [[package]] name = "pgrx-sql-entity-graph" -version = "0.11.4" +version = "0.12.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3db12a1066a0ebecb8bae7aacf5b41f8e1c27c18ed914ee2a35fc2a974cd08e3" +checksum = "0d1e11e53d544d2e84860493d0f983c9c58b927d1f24ddcd907602f89e3cb887" dependencies = [ "convert_case", "eyre", "petgraph", "proc-macro2", "quote", - "syn 1.0.109", + "syn", + "thiserror", "unescape", ] [[package]] name = "pgrx-tests" -version = "0.11.4" +version = "0.12.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e28115c05db260b63e3cde7e02de861b954dae19124261650f9c60b4667e8d4" +checksum = "f9f9b6c225f94c621f252e62fe0ac141ba452d177b79f32bab401aaf4f1db0b3" dependencies = [ "clap-cargo", "eyre", "libc", - "once_cell", "owo-colors", + "paste", "pgrx", "pgrx-macros", "pgrx-pg-config", @@ -1610,17 +1598,6 @@ dependencies = [ "bitflags 2.5.0", ] -[[package]] -name = "redox_users" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" -dependencies = [ - "getrandom", - "libredox", - "thiserror", -] - [[package]] name = "regex" version = "1.10.5" @@ -1671,15 +1648,6 @@ dependencies = [ "semver 0.11.0", ] -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver 1.0.23", -] - [[package]] name = "rustix" version = "0.38.34" @@ -1778,6 +1746,9 @@ name = "semver" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +dependencies = [ + "serde", +] [[package]] name = "semver-parser" @@ -1788,12 +1759,6 @@ dependencies = [ "pest", ] -[[package]] -name = "seq-macro" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4" - [[package]] name = "serde" version = "1.0.203" @@ -1821,7 +1786,7 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] [[package]] @@ -1892,15 +1857,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - [[package]] name = "sptr" version = "0.3.2" @@ -1945,23 +1901,21 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "supports-color" -version = "1.3.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ba6faf2ca7ee42fdd458f4347ae0a9bd6bcc445ad7cb57ad82b383f18870d6f" +checksum = "d6398cde53adc3c4557306a96ce67b302968513830a77a95b2b17305d9719a89" dependencies = [ - "atty", + "is-terminal", "is_ci", ] [[package]] -name = "syn" -version = "1.0.109" +name = "supports-color" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "8775305acf21c96926c900ad056abeef436701108518cf890020387236ac5a77" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "is_ci", ] [[package]] @@ -1983,14 +1937,14 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] [[package]] name = "sysinfo" -version = "0.29.11" +version = "0.30.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd727fc423c2060f6c92d9534cef765c65a6ed3f428a03d7def74a8c4348e666" +checksum = "0a5b4ddaee55fb2bea2bf0e5000747e5f5c0de765e5a5ff87f4cd106439f4bb3" dependencies = [ "cfg-if", "core-foundation-sys", @@ -1998,7 +1952,7 @@ dependencies = [ "ntapi", "once_cell", "rayon", - "winapi", + "windows", ] [[package]] @@ -2036,7 +1990,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] [[package]] @@ -2209,6 +2163,12 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + [[package]] name = "url" version = "2.5.1" @@ -2216,7 +2176,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7c25da092f0a868cdf09e8674cd3b7ef3a7d92a24253e663a2fb85e2496de56" dependencies = [ "form_urlencoded", - "idna 1.0.0", + "idna", "percent-encoding", ] @@ -2305,7 +2265,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.66", + "syn", "wasm-bindgen-shared", ] @@ -2327,7 +2287,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2578,6 +2538,15 @@ dependencies = [ "tap", ] +[[package]] +name = "yansi-term" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe5c30ade05e61656247b2e334a031dfd0cc466fadef865bdcdea8d537951bf1" +dependencies = [ + "winapi", +] + [[package]] name = "yoke" version = "0.7.4" @@ -2598,7 +2567,7 @@ checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", "synstructure", ] @@ -2619,7 +2588,7 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] [[package]] @@ -2639,7 +2608,7 @@ checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", "synstructure", ] @@ -2662,5 +2631,5 @@ checksum = "97cf56601ee5052b4417d90c8755c6683473c926039908196cf35d99f893ebe7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] diff --git a/Cargo.toml b/Cargo.toml index bde9b78..d4bf2be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,22 +1,36 @@ [package] name = "pg_smtp_client" -version = "0.1.1" +version = "0.2.0" edition = "2021" publish = false [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] + +[[bin]] +name = "pgrx_embed_pg_smtp_client" +path = "./src/bin/pgrx_embed.rs" [features] -default = ["pg16"] +default = ["pg17"] pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ] pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ] pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ] +pg17 = ["pgrx/pg17", "pgrx-tests/pg17" ] pg_test = [] [dependencies] -pgrx = "=0.11.4" -lettre = "=0.11.7" +pgrx = "0.12.7" +lettre = "=0.11.10" [dev-dependencies] -pgrx-tests = "=0.11.4" +pgrx-tests = "0.12.7" + +[profile.dev] +panic = "unwind" + +[profile.release] +panic = "unwind" +opt-level = 3 +lto = "fat" +codegen-units = 1 diff --git a/Makefile b/Makefile index 8d85d04..b561fa0 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ PYTHON ?= $(shell which python3 || which python) PIP ?= $(shell which pip3 || which pip) -PG_VERSION ?= 16 +PG_VERSION ?= pg17 + +.PHONY: build +build: + @cargo build .PHONY: run run: @@ -12,13 +16,13 @@ clean: .PHONY: init init: - @cargo install --locked cargo-pgrx@0.11.4 - @if ! cargo pgrx info version pg$(PG_VERSION) >/dev/null 2>&1; then cargo pgrx init --pg$(PG_VERSION) download; else echo "pg$(PG_VERSION) already installed"; fi + @cargo install --locked cargo-pgrx@0.12.7 + @if ! cargo pgrx info version $(PG_VERSION) >/dev/null 2>&1; then cargo pgrx init --$(PG_VERSION) download; else echo "$(PG_VERSION) already installed"; fi .PHONY: lint lint: @cargo fmt --check - @cargo clippy + @cargo clippy --no-default-features --features $(PG_VERSION) .PHONY: test test: @@ -27,4 +31,4 @@ test: @$(PIP) install aiosmtpd @trap 'kill `cat /tmp/smtpd.pid`' EXIT; \ $(PYTHON) -m aiosmtpd -n & echo $$! > /tmp/smtpd.pid; \ - cargo pgrx test pg$(PG_VERSION) + cargo pgrx test diff --git a/README.md b/README.md index 5b9e04d..ccb0107 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # pg_smtp_client +[![CI](https://github.com/brianpursley/pg_smtp_client/actions/workflows/ci.yml/badge.svg)](https://github.com/brianpursley/pg_smtp_client/actions/workflows/ci.yml) + A Postgres extension to send emails using SMTP. ## Installation diff --git a/src/bin/pgrx_embed.rs b/src/bin/pgrx_embed.rs new file mode 100644 index 0000000..5f5c4d8 --- /dev/null +++ b/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +::pgrx::pgrx_embed!(); diff --git a/src/lib.rs b/src/lib.rs index 74ea978..7da3122 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,12 +15,12 @@ mod smtp_client { use lettre::transport::smtp::client::{Tls, TlsParameters}; use lettre::{Message, SmtpTransport, Transport}; - fn create_mailer( - smtp_server: Option<&str>, + fn create_mailer<'a>( + smtp_server: Option<&'a str>, smtp_port: Option, smtp_tls: Option, - smtp_username: Option<&str>, - smtp_password: Option<&str>, + smtp_username: Option<&'a str>, + smtp_password: Option<&'a str>, ) -> Result { let server = smtp_server .map_or_else(guc::get_smtp_server, |x| Some(x.to_string())) @@ -57,14 +57,14 @@ mod smtp_client { } #[allow(clippy::too_many_arguments)] - fn create_message( - subject: &str, - body: &str, + fn create_message<'a>( + subject: &'a str, + body: &'a str, html: bool, - from_address: Option<&str>, - recipients: Option>>, - ccs: Option>>, - bccs: Option>>, + from_address: Option<&'a str>, + recipients: Option>>, + ccs: Option>>, + bccs: Option>>, keep_bcc_header: bool, ) -> Result { let mut email = Message::builder().subject(subject); @@ -83,7 +83,7 @@ mod smtp_client { } if let Some(items) = recipients { - for addr in items.into_iter().flatten() { + for addr in items.iter().flatten() { if let Ok(parsed_addr) = addr.parse() { email = email.to(parsed_addr); } else { @@ -93,7 +93,7 @@ mod smtp_client { } if let Some(items) = ccs { - for addr in items.into_iter().flatten() { + for addr in items.iter().flatten() { if let Ok(parsed_addr) = addr.parse() { email = email.cc(parsed_addr); } else { @@ -106,7 +106,7 @@ mod smtp_client { if keep_bcc_header { email = email.keep_bcc(); } - for addr in items.into_iter().flatten() { + for addr in items.iter().flatten() { if let Ok(parsed_addr) = addr.parse() { email = email.bcc(parsed_addr); } else { @@ -124,19 +124,19 @@ mod smtp_client { #[pg_extern] #[allow(clippy::too_many_arguments)] - fn send_email( - subject: &str, - body: &str, + fn send_email<'a>( + subject: &'a str, + body: &'a str, html: default!(bool, "false"), - from_address: default!(Option<&str>, "NULL"), - recipients: default!(Option>>, "NULL"), - ccs: default!(Option>>, "NULL"), - bccs: default!(Option>>, "NULL"), - smtp_server: default!(Option<&str>, "NULL"), + from_address: default!(Option<&'a str>, "NULL"), + recipients: default!(Option>>, "NULL"), + ccs: default!(Option>>, "NULL"), + bccs: default!(Option>>, "NULL"), + smtp_server: default!(Option<&'a str>, "NULL"), smtp_port: default!(Option, "NULL"), smtp_tls: default!(Option, "NULL"), - smtp_username: default!(Option<&str>, "NULL"), - smtp_password: default!(Option<&str>, "NULL"), + smtp_username: default!(Option<&'a str>, "NULL"), + smtp_password: default!(Option<&'a str>, "NULL"), ) -> String { let mailer = create_mailer( smtp_server, @@ -224,7 +224,7 @@ mod smtp_client { "test body", false, Some("from@example.com"), - Some(vec![Some("to@example.com")]), + Some(vec![Some("to@example.com".to_string())]), None, None, Some("127.0.0.1"), @@ -251,7 +251,7 @@ mod smtp_client { "test body", false, None, - Some(vec![Some("to@example.com")]), + Some(vec![Some("to@example.com".to_string())]), None, None, None, @@ -271,7 +271,7 @@ mod smtp_client { "test body", false, None, - Some(vec![Some("to@example.com")]), + Some(vec![Some("to@example.com".to_string())]), None, None, None, @@ -289,7 +289,7 @@ mod smtp_client { "Test Body", false, Some("from@example.com"), - Some(vec![Some("to@example.com")]), + Some(vec![Some("to@example.com".to_string())]), None, None, false, @@ -310,7 +310,10 @@ mod smtp_client { "Test Body", false, Some("from@example.com"), - Some(vec![Some("to1@example.com"), Some("to2@example.com")]), + Some(vec![ + Some("to1@example.com".to_string()), + Some("to2@example.com".to_string()), + ]), None, None, false, @@ -331,9 +334,9 @@ mod smtp_client { "Test Body", false, Some("from@example.com"), - Some(vec![Some("to@example.com")]), - Some(vec![Some("cc@example.com")]), - Some(vec![Some("bcc@example.com")]), + Some(vec![Some("to@example.com".to_string())]), + Some(vec![Some("cc@example.com".to_string())]), + Some(vec![Some("bcc@example.com".to_string())]), true, ) .unwrap(); @@ -352,9 +355,18 @@ mod smtp_client { "Test Body", false, Some("from@example.com"), - Some(vec![Some("to1@example.com"), Some("to2@example.com")]), - Some(vec![Some("cc1@example.com"), Some("cc2@example.com")]), - Some(vec![Some("bcc1@example.com"), Some("bcc2@example.com")]), + Some(vec![ + Some("to1@example.com".to_string()), + Some("to2@example.com".to_string()), + ]), + Some(vec![ + Some("cc1@example.com".to_string()), + Some("cc2@example.com".to_string()), + ]), + Some(vec![ + Some("bcc1@example.com".to_string()), + Some("bcc2@example.com".to_string()), + ]), true, ) .unwrap(); @@ -376,7 +388,7 @@ mod smtp_client { "Test Body", false, None, - Some(vec![Some("to@example.com")]), + Some(vec![Some("to@example.com".to_string())]), None, None, false, @@ -400,7 +412,7 @@ mod smtp_client { "Test Body", false, Some("override@example.com"), - Some(vec![Some("to@example.com")]), + Some(vec![Some("to@example.com".to_string())]), None, None, false, @@ -421,7 +433,7 @@ mod smtp_client { "Test Body", false, None, - Some(vec![Some("to@example.com")]), + Some(vec![Some("to@example.com".to_string())]), None, None, false, @@ -430,7 +442,7 @@ mod smtp_client { assert!(result.is_err()); assert_eq!( result.unwrap_err(), - format!("From address not provided and no default configured") + "From address not provided and no default configured" ); } }