How can I clean cargo stuff? - rust

I tried to install Parity (an Ethereum client) on my CHIP computer (similar to a Raspberry Pi with 4GB memory). I cloned the repository and ran
cargo build --release
After a while I noticed that about 40% of the memory was used and I stopped the installation process. There was only 20% used before, so now I want to clean all of this Rust stuff. How can I do that?

Cargo places all temporary build files into the target/ directory. Sometimes, if not already present, Cargo also creates a Cargo.lock file. The directory can be removed by executing:
cargo clean
Cargo also saves the package index and the source code of dependencies globally in ~/.cargo/registry/.

Related

How to install a Rust dependency in an environment with no internet?

I would like to use the tango client crate for a Rust project at work, however the environment that I will be developing this in does not have direct access to the internet. This means that the standard method of adding the dependency to Cargo.toml and running cargo build fails due to a network error.
The environment doesn't prevent me from copying data downloaded to an internet-connected computer, and so I was hoping that there would be a way for me to package the necessary files locally, and then point Cargo.toml to that location.
Is this possible? If so, how?
Answering my own question, thanks to a tip in a comment from #Dogbert.
The trick was to use cargo vendor on the machine that has an internet connection. This will produce a directory called vendor that can be transferred to the other environment. On that environment, and within the directory from which you will run cargo build, create a new file in .cargo/config.
[source]
[source.local_vendor]
directory = "vendor"
[source.crates-io]
replace-with = "local_vendor"
Once you've done this, then cargo build should work.

How to cargo build only target but not dependencies

I work on a Rust project that has a lot of packages as explicit or implicit dependencies (~420). When I want to rebuild the target after changing the .env file (that configures things like IP to download files from), I would like to rebuild only the packages that I authored, not all the dependencies.
How can I tell cargo build to use the previously compiled dependencies, but not use the previously compiled package that uses the .env file as input?
Ideally, cargo build would realize that the .env file has changed and automatically decide to rebuild only the parts that use the .env file, but unfortunately this doesn't seem to be the case.
So the second best solution is to manually tell cargo build at which point in the build graph to start off again.
We're using the dotenv crate https://crates.io/crates/dotenv crate to read the .env file.
I tried cargo clean -p nextclade to tell it to clean only the package in question that I'm working on - but that still cleans up all the dependencies which cause my build to take 5 minutes rather than 2 minutes (if using compiled dependencies).
There's a question that seems to ask a similar question, but that question is actually a different use case/set up, so it's not a duplicate: How does cargo decide whether to rebuild the deps or not?

Stuck in compilation (substrate-node-template:make build )

I followed the tutorialenter link description here to this step,
make build
WASM_BUILD_TOOLCHAIN=nightly-2020-10-05 cargo build --release
Compiling node-template-runtime v2.0.0 (/home/wangliqiu2021/CLionProjects/substrate-node-template/runtime)
Building [=====================================================> ] 857/861: node-template-runtime(build)
Cargo has been executed for a long time(almost one+ hour) without ending,It seems to be stuck, does anyone know the reason?help me
OS:Ubuntu 20.04
CPU: AMD Ryzen 7 1700 Eight-Core Processor
The compile is not stuck in compilation, it is just taking a while due to the 800+ dependencies. From #gnunicorn on this github issue:
Rust isn't particular quick with the compiling at the moment and opaque to the person in front, at this step (when compiling node-template-runtime) we are actually building the project twice: once natively and once in wasm. So at some step in between it appears as if nothing happens and that can take up to half the total build time – if the other part took e.g. 10minutes then this process might take another 10min without any indicator of process (other than the CPU pumping hard).
You are doing a release build (cargo build --release) which enables optimizations. For development purposes, a regular build or just a cargo check will be substantially faster.
Some comments in the linked GitHub issue mentioned that running a cargo clean and rebuilding helped speed up compile times, so you can try that as well.
From your username. I think you are in China, same as me.
node-template-runtime(build) means you're compiling the runtime into a wasm file. During this, it might need a download (so try to use a VPN).
The download only happened in 1.0.0 https://docs.rs/substrate-wasm-builder/1.0.0/substrate_wasm_builder/?search=
Also, the wasm compiling will take a long time too (depend on your hardware).
In the 2016 MacBookPro, the whole compiling takes 30mins.
Moreover, there might be a bug in that build.rs. Sometimes I've to run cargo clean. If I interrupt the compiling while node-template-runtime(build).
I found the reason.
$CARGO_HOME/config.toml:
[build]
target-dir = "target"
remove it.
In my case the issue was, that the WASM runtime build expects to find the WASM files inside the local target directory.
If the build can't find the local WASM files in the target directory - it just hangs or deadlocks (e.g. GitHub issue).
I had to change the target-dir setting in ~/.cargo/config.toml.
You can also override the global setting with a local env var:
CARGO_TARGET_DIR=target cargo build
Or you can use the cargo CLI flags:
cargo build --target-dir=target
Note that some of the wasm-builder based build scripts ignore the CARGO_TARGET_DIR env variable (e.g. wasm_project.rs).

haskell `stack` commands for uninstall/clean up?

stack setup download and installs GHC for project,
~/.stack/programs,
~/.stack/snapshots
and somewhere else which I don't know yet)
stack build downloads dependencies and build them.
~/.stack/setup-exe-cache and somewhere else.
I want to clean up project-wide ghc and downloaded dependencies/build output from them, plus all the other project related things on my disk.
There's no way to do this other than just manually delete them?
stack clean command clears local cache in .stack-work.
The feature for cleaning .stack cache is not implemented yet. See this GitHub issue:
https://github.com/commercialhaskell/stack/issues/133
stack setup installs GHC for project but it stores GHC globally (so you don't need to install GHC again for another project if this project uses same version of GHC).
You can just do rm -rf .stack-work to clean project local build cache (built modules, github dependencies for project, etc.). Though, rm -rf .stack-work won't work for multipackage project. Just do stack clean --full to clear local cache completely for project.
To clean global cache, you can just do rm -rf ~/.stack.
Thus, again, citing latest comment from issue discussion:
The garbage collection question definitely needs to be answered in some form or another. If possible, I think I might find a documentation solution preferable to a new command. It would be great if the manual discussed the directory structure of ~/.stack and explained what directories were safe to delete.

How set up rapidjson without git

I need to use rapidjson as a third party library to replace libjson. I'm trying to figure out how to build it so I can use it's build files in my project (dependency list).
I downloaded rapidjson from github, and I'm trying to get a buildable project. I'm looking at the instructions at rapidjson website, and it's showing that I need to do the following, below (Installation).
We don't use git, so what would I need to do instead of the git submodule update --init step?
Why would I need a build dir in the include/rapidjson directory with nothing in it?
When I cd to build and type cmake, it seems to be missing parameters. What is the full cmake command? Thanks!
Installation
RapidJSON is a header-only C++ library. Just copy the include/rapidjson folder to system or project's include path.
RapidJSON uses following software as its dependencies:
•CMake as a general build tool
•(optional)Doxygen to build documentation
•(optional)googletest for unit and performance testing
To generate user documentation and run tests please proceed with the steps below:
1.Execute git submodule update --init to get the files of thirdparty submodules (google test).
2.Create directory called build in rapidjson source directory.
3.Change to build directory and run cmake .. command to configure your build. Windows users can do the same with cmake-gui application.
4.On Windows, build the solution found in the build directory. On Linux, run make from the build directory.
On successfull build you will find compiled test and example binaries in bin directory. The generated documentation will be available in doc/html directory of the build tree. To run tests after finished build please run make test or ctest from your build tree. You can get detailed output using ctest -V command.
It is possible to install library system-wide by running make install command from the build tree with administrative privileges. This will install all files according to system preferences. Once RapidJSON is installed, it is possible to use it from other CMake projects by adding find_package(RapidJSON) line to your CMakeLists.txt.
It is header-only library. So if you just want to integrate it into your project, just copy the /include folder to your project, and it should works.
All other instructions are for building unit tests, performance tests and documentation.

Resources