[Solved] Rustup.rs: Upgrade to rust nightly


#1

Hi,
in order to perform benchmarks, I want to upgrade to rust nightly.
I tried this with rustup:

I'm going to ask you the value of each these installation options.
You may simply press the Enter key to leave unchanged.

Default host triple?


Default toolchain? (stable/beta/nightly)
nightly

Modify PATH variable? (y/n)
y


Current installation options:

   default host triple: x86_64-unknown-linux-gnu
     default toolchain: nightly
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
1

info: updating existing rustup installation


Rust is installed now. Great!

To get started you need Cargo's bin directory in your PATH environment 
variable. Next time you log in this will be done automatically.

To configure your current shell run source $HOME/.cargo/env.

I ran the source command in my shell session, but cargo still complains:

error: use of unstable library feature 'test' (see issue #27812)

Any ideas?


#2

Your transcript doesn’t include rustup actually downloading anything or you making sure PATH is set properly. It seems possible that you already had Rust installed via some other method. What do these commands show?

which cargo
which rustc
rustc -V
cargo -V

#3

Seems, that cargo is linked correctly and rustc not:

bash-4.3$ which cargo
/home/stefano/.cargo/bin/cargo
bash-4.3$ which rustc
/home/stefano/.cargo/bin/rustc
bash-4.3$ rustc -V
rustc 1.10.0 (cfcb716cf 2016-07-03)
bash-4.3$ cargo -V
cargo 0.11.0-nightly (259324c 2016-05-20)

#4

Eh, it seems cargo always has ‘nightly’ in its version so that doesn’t indicate much, but cargo 0.11 matches rustc 1.10. If the paths are all right the next useful command would be rustup show.


#5

Ok, this installed and set at least the nightly build
rustup default nightly

bash-4.3$ rustc -V
rustc 1.12.0-nightly (27e766d7b 2016-07-19)
bash-4.3$ cargo -V
cargo 0.13.0-nightly (664125b 2016-07-19)

But I still get an error:

Compiling random_choice v0.1.0 (file:///home/stefano/Dokumente/Programming/rust/Rust_Random_Choice)
src/lib.rs:140:5: 140:23 error: use of unstable library feature 'test' (see issue #27812) 
src/lib.rs:140     extern crate test;

Do I have to configure sth. in my source code?

This is my code:

#[cfg(test)]
mod benches {
    #![feature(test)]

    extern crate test;
    use self::test::Bencher;

    #[bench]
    fn bench_random_choice_64(b: &mut Bencher) {
        let capacity: usize = 1000;
        let mut samples: Vec<f64> = Vec::with_capacity(capacity);
        let mut weights: Vec<f64> = Vec::with_capacity(capacity);

        for i in 0..capacity {
            samples.push((i + 1usize) as f64);
            weights.push((i + 1usize) as f64);
        }
        b.iter(|| {
            super::RandomChoice::random_choice_f64(&samples, &weights, 1200 as usize);
        });
    }
}

#6

I don’t think the #![feature(...)] attribute works in submodules. It needs to be set at the top of the crate.


#7

You are, right. Thanks! :slight_smile:


#8

Another question: What, if somebody just wants to use my library? I don’t want to force him to nightly rust.


#9

You can gate this on a crate feature or perhaps on cfg(test). https://chrismorgan.info/blog/rust-cfg_attr.html


#10

You can conditionally use that feature when compiling in test mode with cfg_attr:

#![cfg_attr(test, feature(test))]

#11

Thx! :slight_smile:


#12

Put benchmarks in a directory called benches.
cargo bench will pick them up (of course this will only work with a nightly compiler).
Everything will else will work just fine without nightly.