Is it possible to have multiple coexisting Rust installations? - settings

Would it be possible to have a nightly build Rust compiler for convenience (faster build cycle, auto-update) and a dev version of Rust cloned from GitHub for experimentation purposes?
The idea is I have a binary version of Rust for my various project and a version of Rust I can hack on, without them causing havoc between each other.
If it matters, assume my OS is Ubuntu 64-bit.

The current solution is to use rustup. Once installed, you can install multiple toolchains:
rustup install nightly
rustup install stable
rustup install 1.7
If you have a local build of Rust, you can link it as a toolchain
rustup toolchain link my-development /path/to/rust/code
You can pick a default toolchain
rustup default stable
Or add an override toolchain for a specific directory on your machine only via rustup
cd /my/cool/project
rustup override set nightly
Or add an override toolchain that lives with a specific directory, like a repository, via a rust-toolchain file
cd /my/cool/project
echo "nightly" > rust-toolchain
If you want to just use a different toolchain temporarily, you can use the "plus syntax":
rustc +1.7 --help
cargo +nightly build
In other cases you can use rustup run to run any arbitrary command in a specific toolchain:
rustup run nightly any command you want here
See also:
How to execute cargo test using the nightly channel?

Sure. In the development version, use the --prefix option to ./configure, e.g. --prefix=~/opt/rust-dev, and then its installed files will be contained entirely inside that directory.

Try to configure your IDE. Though I am working on Windows computer, I think the idea is similar to Ubuntu.
First, I've installed 3 versions of Rust into:
C:\Rust\64 beta MSVC 1.9
C:\Rust\64 nightly MSVC 1.10
C:\Rust\64 stable MSVC 1.8
Then I configured my IDE (in this case, IntelliJ IDEA 2016 + Rust Plug-In) to use different versions of Rust depending on build selector.
After this I can compile my code with different Rust versions just by selecting build-config from toolbar.

You also don't need to install your development version. You could just make symlink from somewhere in your $PATH to the rustc binary that lives somewhere inside the source tree/build directory, the compiler will find its dynamically linked dependencies and it will emit binaries that know about that path too (if even dynamically linked).

Try envirius.
It allows you to create any number of environments with any version of the rust.
For the first time it will download the source code of the rust and will compile it.
And it will take some time. But second and subsequent attempts will takes under 10 seconds as it just will copy the binaries into the target environment.
For example:
➥ nv mk --rust=0.9
Creating environment: rust-0.9 ...
* installing rust==0.9 ...
* done (in 5 secs.)
➥ nv ls
Available environment(s):
rust-0.9
➥ nv on rust-0.9
Environment rust-0.9 activated.
(rust-0.9) ➥ rustc -v
rustc 0.9

Usually when dealing with rustup, you're dealing with toolchains–a single installation of the Rust compiler. There are 3 major release channels:
stable
beta
nightly
The channel can be appended with optional date and host names: channel[-date][-host].
You can install multiple toolchains using rustup:
rustup toolchain install nightly
rustup toolchain install stable-x86_64-pc-windows-msvc
Be careful when nightly is installed as any updates using rustup update will also update stable.
You can have different level of overrides:
# command level
rustc +beta <command>
cargo +beta <command>
# environment level
export RUSTUP_TOOLCHAIN=nightly-2019-05-22
# directory level
rustup override set stable
The toolchain configuration can also be version controlled using a rust-toolchain file, which contains just the toolchain name.
$ cat rust-toolchain
nightly-2019-05-22
No host name can be configured in the rust-toolchain file.
The override precedence is:
An explicit toolchain, e.g. cargo +beta
The RUSTUP_TOOLCHAIN environment variable
A directory override, ala rustup override set beta
The rust-toolchain file
The default toolchain
Reference: https://github.com/rust-lang/rustup.rs#toolchain-specification

Related

How to get rid of rust target [Windows]

For some reason the thumbv7m-none-eabi target is in every rust project i create
I have reinstalled rust completely (from the uninstaller and deleting .cargo and .rustup)
rustup show:
rustup home: C:\Users\USER\.rustup
stable-x86_64-pc-windows-msvc (default)
rustc 1.61.0 (fe5b13d68 2022-05-18)
rustup target list does not list thumbv7m-none-eabi as installed
rustup target remove does not work either.
This results in me not being able to use the std library in any project whatsoever.
SOLVED:
Vscode settings.json was set to add --target thumbv7m-none-eabi for some reason.
Thats why reinstalls fixed nothing and i was just going insane

When you build llvm from source, how do you install it to your system?

When reading through this:
https://www.llvm.org/docs/CMake.html
It tells you how to install to a target, but it doesn't tell you how to install to the system.
cmake --build . --target install
I am not sure what the target is in this case, nor how to properly configure it so it appears as a standard installation into my ubuntu system, insofar as it would be functionally the same as if I installed the development debian packages, and have it picked up by any other build looking to see if the libraries are installed.
Hence, how do I install all the projects under the llvm suite, from source, into Linux?
That command will install LLVM and all the configured projects (via LLVM_ENABLE_PROJECTS) to whatever location you specified in the first step with the CMAKE_INSTALL_PREFIX variable.
If you did not set it, it takes on a platform-dependent value, most likely /usr/local on Linux. This is an appropriate place to put it. I would discourage you from trespassing on the package manager's territory. Untold misery is likely to result.
A "target" in CMake (and many other build systems) is just "something that must be done". Usually it's "compile something to a file with a corresponding name", but it can also be "run an installation script". CMake creates an install target for that purpose in every project. It's also a popular convention in Make/autotools based build systems.

Differences between Apple LLVM and LLVM

I have Apple's command line tools version 9.1 installed and am working through an LLVM tutorial. I need to use some libraries like llvm/ADT and llvm/IR but get an error when I run the code.
main.cpp:1:10: fatal error: 'llvm/ADT/APFloat.h' file not found
#include "llvm/ADT/APFloat.h"
^~~~~~~~~~~~~~~~~~~~
1 error generated.
I also don't seem to have tools such as the assembler. Are these things not usable with Apple's version? And can I install LLVM without conflicting with Apple's version?
Apple's fork misses most of the library,headers and command-line tools in the llvm trunk.
I suggest you compile a new llvm copy from trunk.
Conflicting depends on how you configure everything. You can:
Install your new copy to global location, where your $PATH configuration is responsible for choosing which version to use.
Install as a separate Xcode Toolchain.
Here is a build script I've been using:
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DLLVM_APPEND_VC_REV=on -DLLVM_ENABLE_EH=on -DLLVM_ENABLE_RTTI=on -DLLVM_CREATE_XCODE_TOOLCHAIN=on -DCMAKE_INSTALL_PREFIX=~/Library/Developer/ ../LLVM
Running ninja install will install to global location, otherwise run ninja install-xcode-toolchain to install as a separate toolchain
In your case I suggest installing to global location to avoid the trouble of messing with CFLAGS/LDFLAGS/Header Search Path. Then remove the installation manually after you are done with the tutorial
EDIT: You might also want to check out the official build guide https://llvm.org/docs/CMake.html
For your use case, in-tree building is also a feasible option(Providing you are familiar with write cmake configs)
Actually, there is no need to build the LLVM yourself. You can get prebuilt version for your platform here: http://releases.llvm.org
In your case it would be something like this:
cd /opt
wget http://releases.llvm.org/5.0.0/clang+llvm-5.0.0-x86_64-apple-darwin.tar.xz
tar xvf clang+llvm-5.0.0-x86_64-apple-darwin.tar.xz
mv clang+llvm-5.0.0-x86_64-apple-darwin llvm-5.0.0
After that you will have everything under /opt/llvm-5.0.0, e.g.:
/opt/llvm-5.0.0/bin/clang
/opt/llvm-5.0.0/bin/llvm-config
/opt/llvm-5.0.0/lib/libc++.a
etc.
P.S. I use /opt just as an example, feel free to pick any other directory that fits you best.

Step by step instruction to install Rust and Cargo for mingw with Msys2?

I tried to install Rust on Cygwin but failed to be able link with mingw. Now I am trying to install it with Msys2. I already installed Msys2 and Mingw. I tried to follow this wiki page but I got lost at number 2:
Download and install Rust+Cargo using the installer but be sure to disable the Linker and platform libraries option.
Is it referring to the "rustup-init.exe" on the install page? Should I double click to run this file or run it from Msys2? I tried to run from Msys2 and got the options:
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
I don't know what to do next.
The Using Rust on Windows page you linked to dates from before rustup replaced the installer as the default option to install Rust. Installers are still available, but you should use rustup if possible, because it makes it easy to update and to use multiple toolchains at once (e.g. stable, beta and nightly). If you must use the installer, just select the x86_64-pc-windows-gnu installer and follow the step from the Using Rust on Windows page. If you're using rustup, read on.
By default, rustup on Windows installs the compiler and tools targeting the MSVC toolchain, rather than the GNU/MinGW-w64 toolchain. At the initial menu, select 2) Customize installation. When asked for a host triple, enter x86_64-pc-windows-gnu. Then make a choice for the other questions, then proceed with the installation.
Note: If rustup is already installed, then rerunning rustup-init won't actually install the requested toolchain. Instead, run rustup toolchain install stable-x86_64-pc-windows-gnu if you already have the MSVC-based toolchain. Then run rustup default stable-x86_64-pc-windows-gnu to set the GNU-based toolchain as the default.
Rustup will install the MinGW linker and platform libraries automatically (as part of the rust-mingw component) and refuses to let you remove them. If you prefer to use the MinGW linker and libraries you installed with MSYS2, you'll need to create a .cargo/config file (either in your profile directory, i.e. C:\Users\you\.cargo\config, or in your project's directory if this configuration is specific to a project). The contents of that file might look like this:
[target.x86_64-pc-windows-gnu]
linker = "C:\\msys2\\mingw64\\bin\\gcc.exe"
ar = "C:\\msys2\\mingw64\\bin\\ar.exe"
Rustup will modify the PATH environment variable unless you told it not to. However, MSYS2 resets PATH by default when you launch, so when you try to invoke cargo or rustc from your MSYS2 shell, it might not find it. You'll need to edit your .profile/.bash_profile script to set the PATH correctly (you need to prepend /c/Users/yourname/.cargo/bin: to PATH).
my problem resolved by following way
Run rustup toolchain install stable-x86_64-pc-windows-gnu
Second open .rustup folder
Open settings.toml file
Change first line with: default_toolchain = "stable-x86_64-pc-windows-gnu"
done!
I wrote a complete guide on how to
install Rust on windows with Visual Studio Code and MSYS2 MinGW
on the page found here:
https://stackoverflow.com/a/68835925/4230643

how to use cmake that installed in a non-standard path?

I am on Ubuntu 14.04.3 platform. While I was compiling a project it asked cmake version 3.2 which is not present in my system. I compiled the latest version of cmake from source code and installed it into /usr/local/bin directory. When I attempt to compile project again, its cmake detects the cmake in /usr/bin which is lower version. Then cmake ..
process aborts with lower version error. Is there any built-in cmake variable or environment variable for setting path of the cmake?
EDIT:
I just found a cmake variable CMAKE_COMMAND that supposedly does what I want.
But when I insert CMAKE_COMMAND = /usr/local/bin/cmake line into cmakelist.txt then I go to build directory and issue /usr/local/bin/cmake ..
I get :
Expected a command name, got unquoted argument with text
I searched for it on the net but didn't find a solution.
If you have different versions of a software or library installed you may use stow to install and switch between the two. Especially if you want to install a newer version of a software that is not available in one's Linux distribution. So in case the new version is not yet stable you can still switch to the previous one. For example while building cmake 3.2 you can specify the prefix as
./configure --prefix=/usr/local/stow/cmake-3.2/
and then
cd /usr/local/stow
sudo stow cmake-3.2
and if you want to remove the links you can use the following command
sudo stow --delete cmake-3.2
Please keep in mind stow does not delete files. It only makes and deletes links.

Resources