I'm trying to follow this guide to be able to have source code coverage for a project in Rust.
I did the following:
Installed grcov
cargo install grcov
Added llvm-tools-preview
rustup component add llvm-tools-preview
Set my RUSTFLAGS variable to "-Zinstrument-coverage"
set RUSTFLAGS="-Zinstrument-coverage"
I build my project
cargo build
Set my LLVM_PROFILE_FILE variable to: "test-%p-%m.profraw"
set LLVM_PROFILE_FILE="test-%p-%m.profraw"
Run my tests with
cargo test
But no .profraw files appears, I only have the following:
Am I missing some extra configuration?
Here is my environment information:
cargo 1.57.0 (b2e52d7ca 2021-10-21)
release: 1.57.0
host: x86_64-pc-windows-msvc
os: Windows 10.0.18363 (Windows 10 Enterprise) [64-bit]
Thank you in advance for your help.
I was seeing similar behavior with rust 1.61 nightly on windows. I noticed warning messages stating ""test-%p-%m.profraw"" could not be written. In my case, the fix was to change how I set the LLVM_PROFILE_FILE environment variable. If I set it like:
set LLVM_PROFILE_FILE=test-%p-%m.profraw without the wrapping quotation marks and re-run my tests, the .profraw files are generated.
Your mileage may vary. I had the same issue with the RUSTFLAGS environment variable where I had to remove the quotes for it to even compile.
Another noteworthy thing I encountered with 1.61 is a warning that -Zinstrument-coverage is deprecated in favor of -Cinstrument-coverage.
Related
I know that there are a lot of similar questions regarding rust-analyzer and I've checked them out but couldn't find the solution to my problem so I decided to ask a question myself. I've decided to start learning Rust and I'm having issues with rust-analyzer.
Here is my workspace structure:
I created a project using cargo and hoped that rust-analyzer will automatically register it but for some reason it fails.
I get this error message
> rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /home/remax/Storage/Projects/rust/rusttest/hello_cargo/Cargo.toml, cargo 1.61.0 (a028ae4 2022-04-29): Failed to run `"/home/remax/.cargo/bin/cargo" "metadata" "--format-version" "1" "--manifest-path" "/home/remax/Storage/Projects/rust/rusttest/hello_cargo/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"`: `cargo metadata` exited with an error: error: could not execute process `rustc -vV` (never executed)
Caused by:
No such file or directory (os error 2)
I honestly have no idea what to do.
My cargo version is 1.61.0
UPDATE: issue persists even with only rust project in workspace
You missed the rustup step. It is stated in the rust-analyzer extension that you need to install rustup first.
Quick start
install rustup
install the rust-analyzer extension.
rustup must be installed in the same system as Vscode. If you are using WLS Subsystem (like me), try installing rustup on Windows with the rustup-init.exe.
Run/Debug won't work (probably - I don't know why, but there's always cargo run) but you'll still get all the other features.
My Rust project no longer builds after some conflicts between my RLS plugin and terminal build. I searched around the web and found suggestion of removing my ~/.cargo/registry/index/*, but after that I can't even build any project.
Now the build always stops at
Updating crates.io index
Passing in the --verbose option doesn't help so I don't even know whether it's dying. What should I do next? How to debug this issue?
Delete the ~/.cargo/.package-cache file.
Change cargo source in ~/.cargo/config. This works for me.
For example:
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
I don't have root on my server, so I built a gcc in my working directory with the libs also installed somewhere there. It all went well when building node (7.9.4) with this gcc, until the make install finished. I tried to run node -v and there is an error produce:
/standard/location/of/dynamic/libs/for/the/servers/gcc/libstdc++.so.6: versionGLIBCXX_3.4.18' not found (required by ./node).`
So it seems like the node, although compiled and built with my own gcc, still resolves to the /usr/bin/gcc 's libraries when resolving.
Have I missed a flag while configuring? I only used --prefix and --without-snapshot, (not that I think the latter flag matters). Or are there environment variables like NODE_PATH that could do the trick?
You may need to set your LD_LIBRARY_PATH environment variable to point to the place where you have the libraries that you used to build your Node.
For more info see this:
http://www.tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
I am adding a dependency Package, and I am getting this error at build time:
error: NoSources("[...]/Tests/TestResources")
Please tell me how to get past this error. Is there a way to instruct SPM not to go into the Tests for a specific dependency? A package-specific exclude: [] statement or something.
$ swift --version
Swift version 3.0-dev (LLVM b361b0fc05, Clang 11493b0f62, Swift 24a0c3de75)
Target: x86_64-unknown-linux-gnu
Thank you!
You have exclude directive in Package.swift - https://github.com/apple/swift-package-manager/blob/master/Documentation/Package.swift.md
It seems you are using the snapshot of swift of March 1st, there is a defect in this version regarding excluding files in Tests https://bugs.swift.org/browse/SR-864. It is solved in the later versions, so you can switch to a newer version, the last one is of 24-th of March.
As a temporarily workaround, if you still want to use your current version of swift, you can just move TestResources out of Test directory.
I'm building a Rust game with Piston and I'm trying to use the SublimeLinter Rust package. When I open my .rs game files, I get this linter error:
extern crate piston; // linter error: "can't find crate for 'piston'"
If I check the Sublime console, I can see that the linter is finding rustc:
SublimeLinter: rust activated: /usr/local/bin/rustc
I don't see any obvious error messages in the console. I have piston listed as a dependency in my Cargo.toml and I'm able to cargo run successfully.
I'm a complete Rust & SublimeLinter newbie.
I get a similar error for whichever import I put first; for example if I move extern crate graphics; to be the first line in the file I get the error "can't find crate for 'graphics'".
EDIT: turns out enabling the "use-cargo" setting fixed the issue. I added a ".sublimelinterrc" file to my project root with these contents:
{
"linters": {
"rust": {
"use-crate-root": true,
"use-cargo": true
}
}
}
I have not been able to reproduce your error. However, I'll list what I did that seemed to work. Perhaps you will see a step where we diverged, and that will give you a hint of where to look.
I installed Sublime Text 3. I chose the stable channel, build 3083. I installed Package Control, and then three packages:
SublimeLinter (3.5.1)
SublimeLinter-contrib-rustc (1.3.5)
Rust (2015.05.28.16.43.21)
I restarted Sublime Text and opened a project of mine that uses Cargo and depends on other packages. I opened the console (ctrl-`) and enabled debug mode, which takes effect at the next Sublime restart.
Because I have non-standard install of Rust, I saw that Sublime was unable to run rustc due to missing dynamic libraries. I then closed Sublime, and opened it from my terminal: open /Applications/Sublime\ Text.app/Contents/MacOS/Sublime\ Text. This uses my environment variables set by my shell.
I saw that the linter was complaining that my library had no main method, so I enabled the use-cargo option.
SublimeLinter: rust output:
error: main function not found
error: aborting due to previous error
After changing the use-cargo setting, I caused a deliberate syntax error in my code and saw that it was highlighted. I then misnamed the crate in the extern crate line, and saw it was highlighted.
At no point did there seem to be a problem with finding crates. I could tell that cargo was being used via the console:
SublimeLinter: rust output:
Updating registry `https://github.com/rust-lang/crates.io-index`
Downloading rand v0.3.9
...