Criterion external bench folder not found - cargo bench is asking for bench.path

First of all: I'm really new to Rust, Therefore I ask for help for a fool.

My System: Win10 + current version of Rust and VSCode

I have created a workspace in Rust in which various crates are created under the "korpus" folder and everything works quite well.

Now I have created the bench-folder on a higher folder level under the folder coderevision and there again my file to run the benchmark.

I know that this configuration is unusual, but this is my choice.

Now when I run the command: cargo bench I am asked to do this: "Please specify bench.path if you want to use a non-default path."

I've tried a lot, but can't find a solution. I did a google search for the term but could not find it

What do I have to do specifically (please provide detailed instructions) so that cargo bench automatically knows where my bench folder is located?

I am very grateful for any help, as I am simply stuck here

You have bench directory, but Cargo wants benches.

Thanks for the little hint.
Nevertheless, this does not change the fundamental problem
I have corrected the name of the folder and logically I still get the same error message

If your configuration is unusual, you have to put in a little more effort to tell Cargo where to find your benchmarks, by explicitly defining them in your Cargo.toml. Please try and add this to the Cargo.toml file of your workspace and see if it solves your problem:

name = "neuronen_benchmark"
path = "coderevision/benches/"

As a side node, it would be better and more accessible to people that rely on screen readers if you could share your code not via screenshots, but copied and wrapped in a code block like this:

your code

You can share your directory structure by running tree . in your console with your workspace directory as the working directory (on Linux, but I think on Windows as well).

1 Like

First of all, thank you very much for your helpful tips. I still have a lot to learn.

Although your suggestion with:
path = "coderevision/benches/"

only produced a different error message:
error: couldn't read corpus\neurons\coderevision/benches/

this gave me the idea of using an absolute path and it worked immediately.
path = "/40-Rust/Projekte/inkubator/coderevision/benches/"

Maybe you just have to modify your suggested path to make it work?

I have already tried a few variants but unfortunately without success. Do you have any other ideas?

What I found striking about the error message is that there are backslashes at the beginning and slashes at the end, which I perceive as inconsistent

Here is an excerpt from the directory tree:

│ ├───benches
│ └───tests
│ └───src
│ ├───aufgaben
│ ├───krabbelkiste
│ ├───praxisdaten
│ └───wissensdaten
│ ├───datenaufbereitung
│ │ └───src
│ ├───gehirn
│ │ └───src
│ ├───kommunikation
│ │ └───src
│ ├───motorik
│ │ └───src
│ ├───neuronen
│ │ └───src
│ ├───richtschnur
│ │ └───src
│ └───sensoren
│ └───src
│ ├───gui
│ │ └───src
│ ├───leitstand
│ │ └───src
│ └───werkzeuge
│ └───src

Ah yes. I thought you were adding the path to the workspace's Cargo.toml, not the korpus/neuronen/Cargo.toml file. In that case your path must be ../../coderevision/benches/neuronen_benchmark_rs, as Cargo interprets relative paths as being relative to the package's root directory (korpus/neuronen in your case).

It's still not working: The ERROR:
error: couldn't read korpus\neuronen\../../coderevision/benches/neuronen_benchmark_rs:

Huh. Does it work with backslashes?

I tried that, but VSCode already gives me an error message invalid escape sequence.

and placing it completely in the workspace toml is also not possible because [[bench]] is not permitted in it

Yes, it makes sense that you can't define targets in a virtual workspace, my bad for suggesting it.

As to your problem with the path, I have no idea why it doesn't work with a relative path. I've recreated your project structure and added

name = "neuronen_benchmark"
path = "../../coderevision/benches/"

to my korpus/neuronen/Cargo.toml and it executes the benchmarks from that file. I'm running on Linux though, I don't know if there's something one has to do differently on Windows.

1 Like

I think you've hit the bull's eye. Probably a bug that is only noticeable under Windows

I hope that a developer reads this and reports or fixes the bug. Unfortunately I am too inexperienced to take care of it

Danke für die Zeit die du dir für mich genommen hast. N8

1 Like

cc @weihanglo (hope it is alright to tag you here. I thought it'd be easier than opening a new issue as I believe there must be some other explanation than a bug to why a relative path doesn't work but an absolute path does—it's probably just me missing something)

Hmm… I am not sure how it didn't work out. Almost all Windows APIs support forward and backward slashes. Unfortunately I have no spare Windows machine at hands :disappointed:.

I would suggest not using relative paths outside the package root directory. It might cause problems when sharing the package, and when running cargo package it would be an error if I remember correctly. I would recommend symlinks.

1 Like

Too bad, that's not quite what I had hoped for. Thanks for the effort, though. I'll keep looking for a solution

I found something here. I don't know exactly whether it's transferable for me yet, but I'll keep going on.

integration testing - Use rust cargo to run tests in workspace root - Stack Overflow

I have now found a suitable replacement solution for myself.

I have adopted the suggestion from Stack-overflow
( integration testing - Use rust cargo to run tests in workspace root - Stack Overflow )
and slightly modified or supplemented it

My toml-File now looks like this (excerpt)

criterion = { version = "0.5.1" }
neuronen = { path = "../korpus/neuronen" }
gehirn = { path = "../korpus/gehirn" }

name = "test_gehirn"
path = ""

name = "test_neuronen"
path = ""

name = "my_bench"
path = ""

harness = false

and everything works wonderfully.

I can use both cargo test and cargo bench and everything (as far as i have tested it now) runs correctly to my complete satisfaction

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.