From c658d171f80bc85ce2569e490cb9a43da9f60174 Mon Sep 17 00:00:00 2001 From: liushuyu Date: Wed, 18 Aug 2021 07:32:34 -0600 Subject: [PATCH] cargo/manifests: allow user to use native-tls if `ring` is unsupported (#1587) * cargo/manifests: allow user to use native-tls ... ... if `ring` can't be used on the user's platform (e.g. mips/ppc/riscv) * CI: test for native tls build --- Cargo.lock | 147 ++++++++++++++++++ Cargo.toml | 5 + azure-pipelines.yml | 4 +- components/link_checker/Cargo.toml | 6 +- components/site/Cargo.toml | 5 + components/templates/Cargo.toml | 6 +- .../getting-started/installation.md | 6 + 7 files changed, 176 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 219f3087..94b92552 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -318,6 +318,22 @@ dependencies = [ "utils", ] +[[package]] +name = "core-foundation" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" + [[package]] name = "cpufeatures" version = "0.1.5" @@ -607,6 +623,21 @@ 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.0.1" @@ -981,6 +1012,19 @@ dependencies = [ "webpki", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes 1.0.1", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "idna" version = "0.2.3" @@ -1515,6 +1559,24 @@ dependencies = [ "serde_urlencoded", ] +[[package]] +name = "native-tls" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "net2" version = "0.2.37" @@ -1756,6 +1818,39 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "openssl" +version = "0.10.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "549430950c79ae24e6d02e0b7404534ecf311d94cc9f861e9e4020187d13d885" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "foreign-types", + "libc", + "once_cell", + "openssl-sys", +] + +[[package]] +name = "openssl-probe" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" + +[[package]] +name = "openssl-sys" +version = "0.9.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a7907e3bfa08bb85105209cdfcb6c63d109f8f6c1ed6ca318fff5c1853fbc1d" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "parse-zoneinfo" version = "0.3.0" @@ -2173,17 +2268,20 @@ dependencies = [ "http-body", "hyper", "hyper-rustls", + "hyper-tls", "ipnet", "js-sys", "lazy_static", "log", "mime", + "native-tls", "percent-encoding", "pin-project-lite", "rustls", "serde", "serde_urlencoded", "tokio", + "tokio-native-tls", "tokio-rustls", "url", "wasm-bindgen", @@ -2283,6 +2381,16 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi 0.3.9", +] + [[package]] name = "scoped_threadpool" version = "0.1.9" @@ -2317,6 +2425,29 @@ dependencies = [ "library", ] +[[package]] +name = "security-framework" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23a2ac85147a3a11d77ecf1bc7166ec0b92febfa4461c37944e180f319ece467" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4effb91b4b8b6fb7732e670b6cee160278ff8e6bf485c7805d9e319d76e284" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" version = "1.0.127" @@ -2750,6 +2881,16 @@ dependencies = [ "winapi 0.3.9", ] +[[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-rustls" version = "0.22.0" @@ -2988,6 +3129,12 @@ dependencies = [ "walkdir", ] +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "vec_map" version = "0.8.2" diff --git a/Cargo.toml b/Cargo.toml index b1471b58..33837707 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,6 +49,11 @@ search = { path = "components/search" } [dev-dependencies] same-file = "1" +[features] +default = ["rust-tls"] +rust-tls = ["site/rust-tls"] +native-tls = ["site/native-tls"] + [workspace] members = [ "components/config", diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 9c61e0d1..87e7dec3 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -36,8 +36,10 @@ stages: echo "##vso[task.setvariable variable=PATH;]%PATH%;%USERPROFILE%\.cargo\bin" displayName: Windows install rust condition: eq( variables['Agent.OS'], 'Windows_NT' ) + - script: cargo build --all --no-default-features --features=native-tls && cargo clean + displayName: Cargo build (Native TLS) - script: cargo build --all - displayName: Cargo build + displayName: Cargo build (Rust TLS) - script: cargo test --all displayName: Cargo test diff --git a/components/link_checker/Cargo.toml b/components/link_checker/Cargo.toml index be10bd50..15de74d7 100644 --- a/components/link_checker/Cargo.toml +++ b/components/link_checker/Cargo.toml @@ -13,7 +13,11 @@ errors = { path = "../errors" } [dependencies.reqwest] version = "0.11" default-features = false -features = ["blocking", "rustls-tls"] +features = ["blocking"] [dev-dependencies] mockito = "0.30" + +[features] +rust-tls = ["reqwest/rustls-tls"] +native-tls = ["reqwest/default-tls"] diff --git a/components/site/Cargo.toml b/components/site/Cargo.toml index 7ab0bb42..d8589dac 100644 --- a/components/site/Cargo.toml +++ b/components/site/Cargo.toml @@ -31,3 +31,8 @@ link_checker = { path = "../link_checker" } [dev-dependencies] tempfile = "3" path-slash = "0.1.4" + +[features] +default = [] +rust-tls = ["templates/rust-tls", "link_checker/rust-tls"] +native-tls = ["templates/native-tls", "link_checker/native-tls"] diff --git a/components/templates/Cargo.toml b/components/templates/Cargo.toml index 66260818..6ee0cca8 100644 --- a/components/templates/Cargo.toml +++ b/components/templates/Cargo.toml @@ -28,8 +28,12 @@ rendering = { path = "../rendering" } [dependencies.reqwest] version = "0.11" default-features = false -features = ["blocking", "rustls-tls"] +features = ["blocking"] [dev-dependencies] mockito = "0.30" tempfile = "3" + +[features] +rust-tls = ["reqwest/rustls-tls"] +native-tls = ["reqwest/default-tls"] diff --git a/docs/content/documentation/getting-started/installation.md b/docs/content/documentation/getting-started/installation.md index 09d94a33..5e320905 100644 --- a/docs/content/documentation/getting-started/installation.md +++ b/docs/content/documentation/getting-started/installation.md @@ -155,6 +155,12 @@ From a terminal, you can now run the following command: $ cargo build --release ``` +If you encountered compilation errors like `error: failed to run custom build command for 'ring v0.16.20'`, you can try the command below instead: + +```sh +$ cargo build --release --no-default-features --features=native-tls +``` + The binary will be available in the `target/release` directory. You can move it in your `$PATH` to have the `zola` command available globally or in a directory if you want for example to have the binary in the same repository as the site.