How to make Travis CI work with Rust 0.12.0 and Cargo? - rust

I am trying to make Travis CI build and test the contents of my GitHub repository, which is compatible with Rust 0.12.0 and an older Cargo:
rustc 0.12.0 (ba4081a5a 2014-10-07 13:44:41 -0700)
cargo 0.0.1-pre-nightly (861c07f 2014-10-07 23:29:57 +0000)
I have specified Rust 0.12.0 in the .travis.yml:
language: rust
rust: 0.12.0
script:
- cargo build --verbose
- cargo test --verbose
- rustdoc --test README.md -L target
- cargo doc
The issue I seem to be hitting is that Travis will pick the latest Cargo nightly:
cargo 0.0.1-pre-nightly (fd5d7a9 2014-12-25 04:28:40 +0000)
But this newer version is incompatible with Rust 0.12.0, as it is now using --emit=dep-info where it used to use --dep-info:
--dep-info [FILENAME]
Output dependency info to <filename> after compiling,
in a format suitable for use by Makefiles
This gives rustc invocation errors, as the value for is --emit is invalid:
Running `rustc src/sqlite3.rs --crate-name sqlite3 --crate-type lib -g -C metadata=1c7080eec8c6f90d -C extra-filename=-1c7080eec8c6f90d --out-dir target/deps --emit=dep-info,link -L target/deps -L target/deps -Awarnings`
...
error: unknown emission type: `dep-info`
...
Could not compile `sqlite3`.
I have been looking at other repositories for how to get around this, but it seems they either do not use Cargo with 0.12.0 (which works with Travis) or hit the same issue, like here: https://travis-ci.org/eliovir/rust-ini
I have failed to find any repository that works with Travis, rust 0.12.0 and Cargo. If I can specify the version of Cargo somewhere, I would be able to get around this, but I have failed to find a way to do so in the .travis.yml file.
Of course, with Rust 1.0 coming up, I will just wait for it, if there is no obvious solution that I have overlooked :-)

I agree that tracking nightly is probably the best bet. If there are dependencies you rely on that aren't being updated, then maybe that's a sign that they wont be updated come 1.0 time, either!
All that being said, Travis does allow you to install things before your build. This is completely untested, but you might be able to do something like
before_script:
- wget https://static.rust-lang.org/dist/rust-0.12.0-x86_64-unknown-linux-gnu.tar.gz
- tar -xvf rust-0.12.0-x86_64-unknown-linux-gnu.tar.gz
- ./rust-0.12.0-x86_64-unknown-linux-gnu/install.sh --prefix /tmp/rust-0.12/
- export PATH=$PATH:$PWD/tmp/rust-0.12/bin
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/tmp/rust-0.12/lib
This would download Rust 0.12, unpack and install it somewhere writable (doesn't really matter where). Then you setup env vars to point out where Rust is. Do the same to download a compatible version of Cargo.
If Travis has a "bare" language pack, that would be the best. Otherwise you could try using the Rust buildpack, or maybe just anything else (to avoid dealing with multiple rustc versions).

Related

Rust & Amethyst - Error [E0433]: failed to resolve: could not find `__rt` in `quote`

I'm learning Rust from "Practical Rust Projects" by Shing Lyu. I'm now trying to build a game following the steps in Chapter 4. I'm working on Ubuntu 18.04 LTS.
After installing Rust and the Amethyst command line, I created a new project via amethyst new cat_volleyball. The next step is to run the engine using cargo run --features=vulkan
. When I do so, I get the error prompt below. Do you have suggestions on how to fix this?
error[E0433]: failed to resolve: could not find `__rt` in `quote`
--> /home/alberto/.cargo/registry/src/github.com-1ecc6299db9ec823/err-derive-0.1.6/src/lib.rs:145:63
|
145 | fn display_body(s: &synstructure::Structure) -> Option<quote::__rt::TokenStream> {
| ^^^^ could not find `__rt` in `quote`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0433`.
error: could not compile `err-derive`.
warning: build failed, waiting for other jobs to finish...
TL;DR Edit the Cargo.lock manually, please check the title below : How to force cargo to use yanked version of sub-dependency (for the proper steps)
Why this happens ?
This happened because in err-derive-0.1.6 is using quote-1.0.2 as dependency but in it's cargo.toml dependency declared like this:
[dependencies.quote]
version = "1.0.2"
This means cargo will use the latest minor update, so if quote-1.0.3 is out then cargo will use 1.0.3 instead 1.0.2. Please check caret-requirement. The problem in here is quote-1.0.3 breaks backward compatibility that comes from quote-1.0.2. In this case quote
How to force cargo to use specific version of sub-dependency
You can fix this issue by forcing the sub-dependency to use compatible version for your dependency.
This command will do it :
> cargo update -p quote --precise 1.0.2
How to force cargo to use yanked version of sub-dependency
Looks like quote-1.0.2 was yanked from crates.io, so command up above will not work because cargo will not be able to find the yanked version on crates.io . Since cargo update modifies the cargo.lock we can do it manually. To start clean :
Remove Cargo.lock
Run cargo update ( this will generate latest version Cargo.lock )
Edit Cargo.lock
Find the incompatible version of package in cargo.lock which is quote-1.0.3, It should look like this:
[[package]]
name = "quote"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
then simply change version to the compatible version in our case it is "1.0.2"
[[package]]
name = "quote"
version = "1.0.2"
After doing that do not run cargo update again, it will overwrite your changes and you'll not able to compile your project. Please remember this is a workaround for being able to continue the development, there is a reason to yank crates, do not use it in production it is best to wait dependent crates to update itself.
Note : In some cases you may get an error after editing cargo.lock:
error: Found argument 'Cargo.lock' which wasn't expected, or isn't valid in this context
#albus_c fixed this by doing :
A note for posterity: I fixed the issue removing rustc
(sudo apt remove rustc) and reinstalled as recommended on the Rust website,
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
After that everything worked fine.

How do I build for Mac Catalyst / x86_64-apple-ios-macabi?

The output of rustup target list --toolchain nightly does not contain x86_64-apple-ios-macabi, even though it is in src/librustc_target on the Rust master branch.
How do I build for Mac Catalyst / x86_64-apple-ios-macabi?
The x86_64-apple-ios-macabi target is available on the nightly (5c5b8afd8 2019-11-16) compiler. Just because a target is available does not mean that the standard library and friends are compiled or available to rustup:
% rustc +nightly --print target-list | grep macabi
x86_64-apple-ios-macabi
Rust has a tier system (which is the subject of a proposed RFC). This target is so new it's not even listed on the tier list, but it's undoubtedly going to be tier 3. Tier 2.5 says (emphasis mine):
Tier 2.5 platforms can be thought of as "guaranteed to build", but without builds available through rustup
In the meantime, you will need to build your own libcore / libstd from source. I don't have the time nor ability to actually test that the compilation works, but something like these choices are the general starting path:
build-std
The unstable -Z build-std flag can be used to build the standard library:
% cargo +nightly build -Z build-std --target x86_64-apple-ios-macabi
Xargo
Building the standard library can be done using the xargo tool.
% rustup override set nightly
info: using existing install for 'nightly-x86_64-apple-darwin'
info: override toolchain for '/private/tmp/example' set to 'nightly-x86_64-apple-darwin'
nightly-x86_64-apple-darwin unchanged - rustc 1.41.0-nightly (5c5b8afd8 2019-11-16)
% cat > Xargo.toml
[target.x86_64-apple-ios-macabi.dependencies.std]
# features = ["jemalloc"] # Whatever is appropriate
% xargo build --target x86_64-apple-ios-macabi
# Iterate until libcore and libstd compile and work for your platform
#shepmaster 's answer is correct. In detail, you have to:
Install Xargo:
cargo install xargo
cd in your project
use the nighly build:
rustup override set nightly
create the Xargo.toml file with content:
[target.x86_64-apple-ios-macabi.dependencies.std]
In your projects Cargo.toml, make sure the [profile.release] section contains panic = "abort". If it does not, add it.
When building the project, use xargoinstead of cargo.
Shepmaster's answer is a little outdated. Cargo now supports the -Zbuild-std command. Using it, you can target any of the targets that rustc itself supports even if they aren't listed on rustup +nightly target list. Simply:
rustc +nightly --print target-list
and
cargo +nightly build -Z build-std --target x86_64-apple-ios-macabi
should be enough now. You don't need xargo to build the standard lib anymore.
If you have an old installation of rust, you might need to remove old nightly (or at least for me it fails to update nightly):
rustup toolchain remove nightly
rustup update
rustup toolchain install nightly

Cannot use cargo uninstall to uninstall packages in ~/.cargo: package id specification matched no package

I'm having trouble uninstalling Cargo-installed packages from my system.
There are packages like rand-0.3.22 that are obviously installed under $HOME/.cargo
ls ~/.cargo/registry/src/github.com-1ecc6299db9ec823/ra
racer-2.0.14/ rand-0.3.22/ rand-0.4.2/
rand-0.4.3/ rand-0.5.5/ rand_core-0.2.1/
rawpointer-0.1.0/ rayon-1.0.2/ rayon-core-1.4.1/
This can also be verified by using cargo pkgid
cargo pkgid -p rand
error: There are multiple `rand` packages in your project, and the specification `rand` is ambiguous.
Please re-run this command with `-p <spec>` where `<spec>` is one of the following:
rand:0.5.5
rand:0.4.3
rand:0.3.22
However, I'm unable to remove that package with cargo uninstall. None of these seem to work:
cargo uninstall rand
cargo uninstall -- rand:0.4.3
cargo uninstall https://github.com/rust-lang/crates.io-index#rand:0.4.3
For any of the commands above I get:
error: invalid package id specification: <name-of-package-i-specified>
This seems like a rather basic operation so I suspect it's something fundamental to how cargo-uninstall is to be used.
Any pointers?
cargo uninstall undoes the effect of cargo install. You did not cargo install rand, because it is just a library, not an executable program. That means it was not installed.
The ~/.cargo/registry is just a cache of build dependencies. Feel free to wipe it anytime; cargo will re-download and re-build whatever it needs when it does.
Yes, it is wrong. Cargo should be using .local, .config and .cache as appropriate; then it would be obvious what you can just clean up. Using arbitrary dot-dirs is an insult at this day and age. It was reported, several times probably. Nobody got around to fixing it yet.

How to make `include!` work with macros defined in external crates?

When using serde in stable as recommended by the respective blog post, one will have to use the built-in include! macro to pull in a file generated by serde-codegen.
The file linked here shows this in a more complex example which can use rustc nightly as well as rustc stable.
However, as the docs of include! suggest, it does not behave hygienically.
What this means was unclear to me until I ran into the issue that macros defined in an external crate, yup-hyper-mock, were not defined at include-time. Some tests showed that even something like extern crate foo-bar-snoo-snoo; will not trigger an error at include-time, showing that it was not yet evaluated at all.
The problem arises from include! trying to expand macros, and failing if these are coming from external crates which haven't been evaluated yet.
An attempt of mine to define empty macros with the correct signature cause the include! macro to work, but the compile would fail later as include! would actually expand the macro right away, which was empty at the time of the include.
Is there a way to make include! work with macros defined in external crates? Alternatively, can you imagine a workaround to make my particular case work?
Personally I think include! should not expand macros at all, but leave that to the next compile step which should bring in external crates - maybe we are looking at a bug in rustc, but I am not sure about that.
How to reproduce
Please note that both stable and nightly compilers show the same issues.
git clone --branch syntex https://github.com/Byron/yup-oauth2
cd yup-oauth2
git reset --hard f59d97d
# build and test fail because 'include!' runs before crates are pulled
# in, but still expands macros
cargo build
cargo test
Meta
stable
➜ yup-oauth2 git:(syntex) rustc --version --verbose
rustc 1.0.0 (a59de37e9 2015-05-13) (built 2015-05-14)
binary: rustc
commit-hash: a59de37e99060162a2674e3ff45409ac73595c0e
commit-date: 2015-05-13
build-date: 2015-05-14
host: x86_64-apple-darwin
release: 1.0.0
nightly
➜ yup-oauth2 git:(syntex) rustc --version --verbose
rustc 1.2.0-nightly (2228ce10c 2015-06-09)
binary: rustc
commit-hash: 2228ce10c6d83c17b6346396aa7c7ef9082f1c04
commit-date: 2015-06-09
host: x86_64-apple-darwin
release: 1.2.0-nightly

Is it possible to download previous nightly builds?

I have downloaded the latest Rust nightly and added this dependency to Cargo.toml:
[dependencies.http]
git = "https://github.com/chris-morgan/rust-http.git"
I'm getting lots of errors for cargo build:
...
error: aborting due to 7 previous errors
...
error: aborting due to previous error
Could not compile `regex`.
I guess this is because some dependencies have not been updated to the latest rust version. Is it possible to download the nightly from yesterday or the day before?
Installed versions:
$ rustc --version
rustc 0.13.0-nightly (c89417130 2015-01-02 21:56:13 +0000)
$ cargo --version
cargo 0.0.1-pre-nightly (1a1868b 2014-12-31 21:39:41 +0000)
If you are using rustup (the currently preferred manner of installing Rust):
rustup install nightly-2016-06-03
If you want to use the standalone Rust installers, previous versions are kept. From this Reddit thread, which links to this Rust issue:
They are officially hosted.
wget https://static.rust-lang.org/dist/2014-12-08/rust-nightly-x86_64-apple-darwin.pkg
wget https://static.rust-lang.org/dist/2014-12-12/rust-nightly-x86_64-unknown-linux-gnu.tar.gz
If you are still using rustup.sh (not .rs), you should be able to use something like:
rustup.sh --channel=nightly --date=2016-06-03

Resources