Fix cargo always treating nss crate as dirty#1042
Conversation
969a327 to
2a47fd8
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1042 +/- ##
==========================================
+ Coverage 88.00% 88.04% +0.04%
==========================================
Files 85 85
Lines 6026 6039 +13
Branches 111 111
==========================================
+ Hits 5303 5317 +14
- Misses 663 666 +3
+ Partials 60 56 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
e2e27bc to
dfd11fb
Compare
internal/testutils/rust.go
Outdated
| // Note that for developing purposes and avoiding keeping building the rust program dependencies, | ||
| // TEST_RUST_TARGET environment variable can be set to an absolute path to keep iterative | ||
| // build artifacts. | ||
| target := os.Getenv("TEST_RUST_TARGET") | ||
| if target == "" { | ||
| target = t.TempDir() | ||
| } | ||
| // Store the build artifacts in a common temp directory, so that they can be reused between tests. | ||
| target := filepath.Join(os.TempDir(), "authd-tests-rust-build-artifacts") |
There was a problem hiding this comment.
@3v1n0 I would like to avoid re-building Rust dependencies by default, because I keep forgetting to set TEST_RUST_TARGET when I run the tests. Do you see any cases where we shouldn't re-use build artifacts between tests?
There was a problem hiding this comment.
So, the tests use different library builds, as per different features.
For example, SSH tests use different flags compared to the NSS library, and doing this we may end up creating problems between them (races as one library may being rebuilt while used).
One thing you can do is adding to the the target path the features too, so that it will be unique.
Ideally I still would like to cleanup the path by default though, unless requested by the user, as leaving artifacts around is not nice in general.
There was a problem hiding this comment.
So, the tests use different library builds, as per different features.
For example, SSH tests use different flags compared to the NSS library, and doing this we may end up creating problems between them (races as one library may being rebuilt while used).
cargo is smart enough to rebuild the affected artifacts when different features are selected. You can try running
cargo build --verbose --features integration_tests,custom_socket
in the authd repo and afterwards
cargo build --verbose --features integration_tests
you should see:
Dirty nss v0.1.0 (/home/adrian.dombeck@gmail.com/projects/authd/nss): the list of features changed
Compiling nss v0.1.0 (/home/adrian.dombeck@gmail.com/projects/authd/nss)
There was a problem hiding this comment.
Ideally I still would like to cleanup the path by default though, unless requested by the user, as leaving artifacts around is not nice in general.
As a user of this test, I very much prefer a few MB of artifacts lying around in /tmp over having to wait ~30s longer each time I run one of the affected tests, so I'm in favor of keeping the artifacts by default. We could add an environment variable to delete them if you think that's useful.
There was a problem hiding this comment.
cargo is smart enough to rebuild the affected artifacts when different features are selected.
Sure, I'm aware of it, but we should not use the same build directory for different artifacts, no?
Otherwise we may have a test using features that another test is concurrently not in the need for
There was a problem hiding this comment.
Ah, now I get what you mean. I think we could avoid that by:
- Ensuring that only one build runs at a time, and
- Copying the resulting
.soto a directory that includes the features and other relevant options in its name
There was a problem hiding this comment.
done in commit tests: Avoid races when building/using the NSS library
6c238af to
18842d4
Compare
d0e51b1 to
1c1422d
Compare
1c1422d to
d137268
Compare
internal/testutils/rust.go
Outdated
| // Store the build artifacts in a common temp directory, so that they can be reused between tests. | ||
| target := filepath.Join(os.TempDir(), "authd-tests-rust-build-artifacts") | ||
| if v := os.Getenv("TEST_RUST_TARGET"); v != "" { | ||
| target = v |
There was a problem hiding this comment.
| target = v | |
| target := os.Getenv("TEST_RUST_TARGET") | |
| if target == "" { | |
| target = filepath.Join(os.TempDir(), "authd-tests-rust-build-artifacts") |
Otherwise we create a dir for no eason
d137268 to
0609f97
Compare
0609f97 to
46793c9
Compare
Rebuilding the NSS library takes an unexpectedly long time, even if the code hasn't changed. Let's print the output of the cargo build command to get a better picture of what's going on.
I couldn't figure out exactly why, but `cargo build` always treated the
nss crate as dirty and re-compiled it even when nothing changed in
between two runs:
cargo build --verbose
[...]
Dirty nss v0.1.0 (/home/user/projects/authd/nss): the file `nss/..` has changed (1756139002.017575102s, 2s after last build at 1756139000.627582074s)
Compiling nss v0.1.0 (/home/user/projects/authd/nss)
Using "../internal/proto" instead of "../" as the includes directory in
the compile_protos call fixes that.
Now that the issue that the library was rebuilt each time has been solved, we don't the verbose output anymore.
Speeds up the tests if the developer did not set TEST_RUST_TARGET in the test environment.
* Lock the target directory to avoid multiple tests running in parallel trying to build the library at the same time (possibly with different set of features or other options). * Copy the resulting library to a temporary directory only used by the current test, to allow other tests to reuse the target directory (so that they don't have to rebuild it from scratch).
46793c9 to
3d2b788
Compare
I couldn't figure out exactly why, but
cargo buildalways treated the nss crate as dirty and re-compiled it even when nothing changed in between two runs:Using
"../internal/proto"instead of"../"as the includes directory in thecompile_protoscall fixes that.UDENG-7825