Skip to content

Commit 6303075

Browse files
committed
Allow elasticsearch to work with rust stable (#89)
This commit allows elasticsearch to work with rust stable. The only feature requiring rust nightly is external_doc feature to able to to test the README.md docs. This is now conditionally compiled when building with rust nightly, using rustc_version in a build.rs build script to set a cfg flag for the channel used. api_generator requires rust nightly still. The default toolchain to use for each package is in a rust-toolchain file in the root of each package directory. Closes #87 (cherry picked from commit a03fafb)
1 parent 0f3efdf commit 6303075

File tree

8 files changed

+72
-42
lines changed

8 files changed

+72
-42
lines changed

.ci/run-elasticsearch.ps1

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -202,41 +202,41 @@ if ($LASTEXITCODE -ne 0) {
202202
}
203203

204204
$environment = @(
205-
"--env", "node.name=`"$NODE_NAME`"",
206-
"--env", "cluster.name=`"$CLUSTER_NAME`"",
207-
"--env", "cluster.initial_master_nodes=`"$MASTER_NODE_NAME`"",
208-
"--env", "discovery.seed_hosts=`"$MASTER_NODE_NAME`"",
209-
"--env", "cluster.routing.allocation.disk.threshold_enabled=false",
210-
"--env", "bootstrap.memory_lock=true",
211-
"--env", "node.attr.testattr=test",
212-
"--env", "path.repo=/tmp",
213-
"--env", "repositories.url.allowed_urls=http://snapshot.test*"
205+
"--env", "node.name=`"$NODE_NAME`"",
206+
"--env", "cluster.name=`"$CLUSTER_NAME`"",
207+
"--env", "cluster.initial_master_nodes=`"$MASTER_NODE_NAME`"",
208+
"--env", "discovery.seed_hosts=`"$MASTER_NODE_NAME`"",
209+
"--env", "cluster.routing.allocation.disk.threshold_enabled=false",
210+
"--env", "bootstrap.memory_lock=true",
211+
"--env", "node.attr.testattr=test",
212+
"--env", "path.repo=/tmp",
213+
"--env", "repositories.url.allowed_urls=http://snapshot.test*"
214214
)
215215

216216
$volumes = @(
217-
"--volume", "${volume_name}:/usr/share/elasticsearch/data"
217+
"--volume", "${volume_name}:/usr/share/elasticsearch/data"
218218
)
219219

220220
if (-not ($version -contains "oss")) {
221221
$environment += @(
222-
"--env", "ELASTIC_PASSWORD=`"$ELASTIC_PASSWORD`"",
223-
"--env", "xpack.license.self_generated.type=trial",
224-
"--env", "xpack.security.enabled=true",
225-
"--env", "xpack.security.http.ssl.enabled=true",
226-
"--env", "xpack.security.http.ssl.verification_mode=certificate",
227-
"--env", "xpack.security.http.ssl.key=certs/testnode.key",
228-
"--env", "xpack.security.http.ssl.certificate=certs/testnode.crt",
229-
"--env", "xpack.security.http.ssl.certificate_authorities=certs/ca.crt",
230-
"--env", "xpack.security.transport.ssl.enabled=true",
231-
"--env", "xpack.security.transport.ssl.key=certs/testnode.key",
232-
"--env", "xpack.security.transport.ssl.certificate=certs/testnode.crt",
233-
"--env", "xpack.security.transport.ssl.certificate_authorities=certs/ca.crt"
222+
"--env", "ELASTIC_PASSWORD=`"$ELASTIC_PASSWORD`"",
223+
"--env", "xpack.license.self_generated.type=trial",
224+
"--env", "xpack.security.enabled=true",
225+
"--env", "xpack.security.http.ssl.enabled=true",
226+
"--env", "xpack.security.http.ssl.verification_mode=certificate",
227+
"--env", "xpack.security.http.ssl.key=certs/testnode.key",
228+
"--env", "xpack.security.http.ssl.certificate=certs/testnode.crt",
229+
"--env", "xpack.security.http.ssl.certificate_authorities=certs/ca.crt",
230+
"--env", "xpack.security.transport.ssl.enabled=true",
231+
"--env", "xpack.security.transport.ssl.key=certs/testnode.key",
232+
"--env", "xpack.security.transport.ssl.certificate=certs/testnode.crt",
233+
"--env", "xpack.security.transport.ssl.certificate_authorities=certs/ca.crt"
234234
)
235235

236236
$volumes += @(
237-
"--volume", "`"${SSL_CERT}:/usr/share/elasticsearch/config/certs/testnode.crt`"",
238-
"--volume", "`"${SSL_KEY}:/usr/share/elasticsearch/config/certs/testnode.key`"",
239-
"--volume", "`"${SSL_CA}:/usr/share/elasticsearch/config/certs/ca.crt`""
237+
"--volume", "`"${SSL_CERT}:/usr/share/elasticsearch/config/certs/testnode.crt`"",
238+
"--volume", "`"${SSL_KEY}:/usr/share/elasticsearch/config/certs/testnode.key`"",
239+
"--volume", "`"${SSL_CA}:/usr/share/elasticsearch/config/certs/ca.crt`""
240240
)
241241
}
242242

@@ -315,4 +315,4 @@ if ($DETACH) {
315315
$env:ES_TEST_SERVER = $localUri.ToString();
316316
exit 0
317317
}
318-
}
318+
}

.ci/run-tests.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ param (
88
[ValidateSet("oss", "xpack")]
99
$TEST_SUITE = "xpack",
1010

11-
# TODO: move to stable once elasticsearch-rs compiles on stable
1211
[string]
1312
[Parameter(Mandatory = $false)]
13+
[ValidateSet("nightly", "stable")]
1414
$RUST_VERSION = "nightly",
1515

1616
[string]
@@ -27,6 +27,11 @@ trap {
2727
cleanup
2828
}
2929

30+
$toolchain = ""
31+
if ($RUST_VERSION -eq "nightly") {
32+
$toolchain = "+nightly"
33+
}
34+
3035
$NODE_NAME = "es1"
3136
$elasticsearch_image= "elasticsearch"
3237
$elasticsearch_url = "https://elastic:changeme@${NODE_NAME}:9200"
@@ -126,7 +131,7 @@ docker run `
126131
--name elasticsearch-rs `
127132
--rm `
128133
elastic/elasticsearch-rs `
129-
cargo test $CARGO_TEST_FLAGS
134+
cargo $toolchain test $CARGO_TEST_FLAGS
130135

131136
$runExitCode = $LASTEXITCODE
132137

CONTRIBUTING.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,22 @@ The `quote` and `syn` crates help
7171
7272
### Current development setup
7373
74-
Use Rust nightly for development for now:
74+
The required toolchain for packages in the workspace are controlled
75+
by a `rust-toolchain` file in the root of each package.
7576
76-
```sh
77-
> rustup show
78-
...
77+
`elasticsearch` package compiles and runs with rust stable.
7978
80-
active toolchain
81-
----------------
79+
`elasticsearch` tests incorporate testing the examples
80+
given in the README.md file, using the
81+
[`external_doc`](https://doc.rust-lang.org/unstable-book/language-features/external-doc.html)
82+
experimental feature. To run these tests too, run with cargo nightly,
83+
using the `+<toolchain>` command line override
8284
83-
nightly-x86_64-pc-windows-msvc (default)
84-
rustc 1.41.0-nightly (a44774c3a 2019-11-25)
85+
```sh
86+
cargo +nightly test -p elasticsearch --doc
8587
```
8688

87-
It is expected to move to rust stable once dependencies compile on stable.
89+
`api_generator` package requires rust nightly.
8890

8991
### Coding style guide
9092

File renamed without changes.

elasticsearch/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ futures = "0.3.1"
3737
http = "0.2"
3838
hyper = { version = "0.13", default-features = false, features = ["tcp", "stream"] }
3939
sysinfo = "0.12.0"
40-
tokio = { version = "0.2.0", default-features = false, features = ["macros", "tcp", "time"] }
40+
tokio = { version = "0.2.0", default-features = false, features = ["macros", "tcp", "time"] }
41+
42+
[build-dependencies]
43+
rustc_version = "0.2"

elasticsearch/build.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
extern crate rustc_version;
2+
use rustc_version::{version_meta, Channel};
3+
4+
fn main() {
5+
match version_meta().unwrap().channel {
6+
Channel::Stable => {
7+
println!("cargo:rustc-cfg=RUSTC_IS_STABLE");
8+
}
9+
Channel::Beta => {
10+
println!("cargo:rustc-cfg=RUSTC_IS_BETA");
11+
}
12+
Channel::Nightly => {
13+
println!("cargo:rustc-cfg=RUSTC_IS_NIGHTLY");
14+
}
15+
Channel::Dev => {
16+
println!("cargo:rustc-cfg=RUSTC_IS_DEV");
17+
}
18+
}
19+
}

elasticsearch/rust-toolchain

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
stable

elasticsearch/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,10 @@
301301
// TODO: turn on before releasing :) Will require adding documentation within all REST API specs
302302
// #![deny(missing_docs)]
303303

304-
// also test examples in README
305-
#![feature(external_doc)]
306-
#[doc(include = "../../README.md")]
307-
#[cfg(doctest)]
304+
// also test examples in README when using rust nightly.
305+
// required as external_doc feature requires nightly
306+
#![cfg_attr(RUSTC_IS_NIGHTLY, feature(external_doc))]
307+
#[cfg_attr(RUSTC_IS_NIGHTLY, doc(include = "../../README.md"), cfg(doctest))]
308308
type _DoctestReadme = ();
309309

310310
#[macro_use]

0 commit comments

Comments
 (0)