Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ jobs:
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.cargo/git/checkouts/
~/.dylint_drivers/
target/dylint/libraries/
~/.dylint/cache/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Rustup
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This file records user-facing changes to packages `cargo_dylint`, `dylint`, `dylint_driver`, `dylint-link`, `dylint_linting`, and `dylint_testing`. If a change to one of those packages is missing, please [open an issue](https://github.com/trailofbits/dylint/issues).

## Unreleased

- FEATURE: Share compiler drivers and lint libraries across projects under `~/.dylint/cache`, with a `DYLINT_CACHE_DIR` override, compatible driver isolation, and automatic legacy cache migration without removing or overwriting existing data ([#2184](https://github.com/trailofbits/dylint/pull/2184), [#2142](https://github.com/trailofbits/dylint/issues/2142)) - [@dblock](https://github.com/dblock).
- Deprecate the driver-only `DYLINT_DRIVER_PATH` override in favor of `DYLINT_CACHE_DIR`, retaining its existing layout and precedence for drivers.

## 6.4.0

- FEATURE: Provide prebuilt binaries for Windows (x86-64) ([a551885](https://github.com/trailofbits/dylint/commit/a551885129c49a1d410125b212b8ea1fa7586326))
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ In addition, we recommend caching these directories:

```yaml
~/.cargo/git/checkouts/
~/.dylint_drivers/
~/.dylint/cache/
~/.rustup/toolchains/
```

Also, if you do not cache `target/`, we recommend at least caching `target/dylint/libraries/`.
Dylint shares compiler drivers and lint libraries across projects in `~/.dylint/cache/`. Override it with an absolute `DYLINT_CACHE_DIR` and cache that directory in CI. Legacy caches are preserved during automatic migration. Lint libraries share one cache per toolchain; `--no-build` does not validate their source.

## Utilities

Expand Down
4 changes: 2 additions & 2 deletions cargo-dylint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ In addition, we recommend caching these directories:

```yaml
~/.cargo/git/checkouts/
~/.dylint_drivers/
~/.dylint/cache/
~/.rustup/toolchains/
```

Also, if you do not cache `target/`, we recommend at least caching `target/dylint/libraries/`.
Dylint shares compiler drivers and lint libraries across projects in `~/.dylint/cache/`. Override it with an absolute `DYLINT_CACHE_DIR` and cache that directory in CI. Legacy caches are preserved during automatic migration. Lint libraries share one cache per toolchain; `--no-build` does not validate their source.

## Utilities

Expand Down
8 changes: 6 additions & 2 deletions cargo-dylint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ enum CargoSubcommand {
args_conflicts_with_subcommands = true,
after_help = r#"ENVIRONMENT VARIABLES:

DYLINT_CACHE_DIR (default: $HOME/.dylint/cache) is an absolute directory for all cached compiler
drivers and lint libraries. It is created as needed; libraries use libraries/<toolchain>/release/.

DYLINT_CLIPPY_REPO (default: none) is a path to a Dylint-exclusive clone of the Clippy repository.

DYLINT_DRIVER_PATH (default: $HOME/.dylint_drivers) is the directory where Dylint stores rustc
drivers.
DYLINT_DRIVER_PATH (deprecated, default: none) overrides only the compiler driver directory, with
one subdirectory per toolchain. It takes precedence over DYLINT_CACHE_DIR for drivers only.
Prefer DYLINT_CACHE_DIR to relocate all cached artifacts.

DYLINT_LIBRARY_PATH (deprecated, default: none) is a colon-separated list of directories where
Dylint searches for libraries. Prefer workspace metadata (described below) for naming libraries.
Expand Down
87 changes: 83 additions & 4 deletions cargo-dylint/tests/integration/dylint_driver_path.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
use super::dylint_with_home;
use assert_cmd::cargo::cargo_bin_cmd;
use dylint_internal::{
CommandExt, cargo, driver as dylint_driver, env,
rustup::{SanitizeEnvironment, toolchain_path},
testing::new_template,
rustup::{SanitizeEnvironment, active_toolchain, toolchain_path},
testing::{copy_dir, new_template},
};
use std::fs::create_dir_all;
use tempfile::tempdir_in;
use predicates::prelude::*;
use std::{
fs::{create_dir_all, read_dir, rename},
path::Path,
};
use tempfile::{tempdir, tempdir_in};

#[allow(deprecated)]
#[cfg_attr(dylint_lib = "general", allow(non_thread_safe_call_in_test))]
#[test]
fn dylint_driver_path() {
Expand Down Expand Up @@ -36,3 +43,75 @@ fn dylint_driver_path() {
.unwrap();
command.success().unwrap();
}

#[test]
#[allow(deprecated)]
#[cfg_attr(dylint_lib = "general", allow(non_thread_safe_call_in_test))]
fn cache_dir_relocates_artifacts() {
let home = tempdir().unwrap();
let fixture = tempdir_in("../fixtures").unwrap();
copy_dir(
Path::new("../fixtures/library_packages_in_dylint_toml"),
fixture.path(),
)
.unwrap();
let root = tempdir().unwrap();
let cache = root.path().join("custom cache");
let command = |cache: &Path| {
let mut command = dylint_with_home(home.path());
command
.current_dir(&fixture)
.env(env::DYLINT_CACHE_DIR, cache)
.env_remove(env::DYLINT_DRIVER_PATH)
.env(env::CARGO_TARGET_DIR, fixture.path().join("target"))
.env_remove(env::CARGO_BUILD_BUILD_DIR)
.args(["dylint", "--all"]);
command
};

command(&cache)
.assert()
.success()
.stderr(predicate::str::contains("DYLINT_DRIVER_PATH").not());
assert!(!home.path().join(".dylint").exists());
let drivers = read_dir(cache.join("dylint-driver"))
.unwrap()
.map(|entry| entry.unwrap().path())
.find(|path| path.is_dir())
.unwrap();
let toolchain =
active_toolchain(Path::new("../examples/restriction/collapsible_unwrap")).unwrap();
assert!(drivers.join(toolchain).join("dylint-driver").is_file());
assert!(cache.join("libraries").is_dir());

let other_cache = root.path().join("another cache");
create_dir_all(&other_cache).unwrap();
rename(cache.join("libraries"), other_cache.join("libraries")).unwrap();
command(&other_cache)
.env(env::DYLINT_DRIVER_PATH, &drivers)
.arg("--no-build")
.assert()
.success()
.stderr(predicate::str::contains(
"`DYLINT_DRIVER_PATH` is deprecated",
));
assert!(!other_cache.join("dylint-driver").exists());
assert!(!home.path().join(".dylint").exists());
}

#[test]
#[allow(deprecated)]
fn cache_dir_requires_absolute_path() {
for path in ["", "relative-cache"] {
cargo_bin_cmd!("cargo-dylint")
.current_dir("../fixtures/library_packages_in_dylint_toml")
.env(env::DYLINT_CACHE_DIR, path)
.env_remove(env::DYLINT_DRIVER_PATH)
.args(["dylint", "list", "--all", "--no-build"])
.assert()
.failure()
.stderr(predicate::str::contains(
"`DYLINT_CACHE_DIR` must be an absolute path",
));
}
}
Loading
Loading