zccache 1.11.16

Local-first compiler cache for C/C++/Rust/Emscripten
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
//! Request-key normalization, fingerprinting, worktree-root resolution, request cache lookups.

use super::*;

pub(super) fn client_env_value<'a>(
    client_env: Option<&'a [(String, String)]>,
    name: &str,
) -> Option<&'a str> {
    client_env?
        .iter()
        .find_map(|(key, value)| (key == name).then_some(value.as_str()))
        .filter(|value| !value.is_empty())
}

pub(super) fn path_remap_auto_enabled(client_env: Option<&[(String, String)]>) -> bool {
    client_env_value(client_env, PATH_REMAP_ENV)
        .is_some_and(|value| value.eq_ignore_ascii_case("auto"))
}

/// Stringly tag of path-remap state for the depgraph-check diag line.
/// Issue #353: exposes the silent fallback case where `ZCCACHE_PATH_REMAP=auto`
/// was requested but `find_git_root` returned None — distinguishing it from
/// "remap disabled" (off) and "remap firing" (auto) lets cross-runner bisection
/// catch the case where two runners disagree on whether remap is active.
pub(super) fn diag_path_remap_state(
    client_env: Option<&[(String, String)]>,
    worktree_root_resolved: bool,
) -> &'static str {
    if path_remap_auto_enabled(client_env) {
        if worktree_root_resolved {
            "auto"
        } else {
            "auto_no_git"
        }
    } else {
        "off"
    }
}

pub(super) fn resolve_worktree_root(
    cwd: &Path,
    client_env: Option<&[(String, String)]>,
) -> Option<NormalizedPath> {
    if let Some(value) = client_env_value(client_env, WORKTREE_ROOT_ENV) {
        let configured = Path::new(value);
        let root = if configured.is_absolute() {
            configured.to_path_buf()
        } else {
            cwd.join(configured)
        };
        if root.is_dir() {
            return Some(root.into());
        }
    }

    find_git_root(cwd)
}

pub(super) fn find_git_root(cwd: &Path) -> Option<NormalizedPath> {
    for candidate in cwd.ancestors() {
        let dot_git = candidate.join(".git");
        if dot_git.is_dir() || dot_git.is_file() {
            return Some(candidate.into());
        }
    }
    None
}

pub(super) fn compile_worktree_root(
    state: &SharedState,
    sid: &SessionId,
    cwd: &Path,
    client_env: Option<&[(String, String)]>,
) -> Option<NormalizedPath> {
    if client_env_value(client_env, WORKTREE_ROOT_ENV).is_some() {
        return resolve_worktree_root(cwd, client_env);
    }

    let cwd_normalized: NormalizedPath = cwd.into();
    if let Some(cached) = state.session_worktree_roots.get(sid) {
        if let Some(root) = cached.root.as_ref() {
            if cwd_normalized.starts_with(root.as_path()) {
                return Some(root.clone());
            }
        } else if cwd_normalized.starts_with(cached.working_dir.as_path())
            && !path_remap_auto_enabled(client_env)
        {
            // Cached "no worktree" applies only when PATH_REMAP isn't requested.
            // Issue #353: when the user explicitly opts into auto-remap, prefer
            // the cwd fallback (below) over the sticky None so the compiler
            // still gets a `--remap-path-prefix=<cwd>=.` flag and embedded
            // paths in debug info / macros become path-independent.
            return None;
        }
    }

    if let Some(root) = resolve_worktree_root(cwd, client_env) {
        return Some(root);
    }

    // Issue #353: `ZCCACHE_PATH_REMAP=auto` was requested but no `.git/`
    // ancestor was found. Previously this silently fell through, so the
    // compiler ran with absolute paths in its output even though the user
    // asked for path normalization. Two GHA runners with byte-identical
    // checkouts but no `.git/` (e.g., shallow / git-archive workflows) would
    // produce divergent .rlib bytes and miss every cache lookup.
    //
    // Fall back to using the cwd itself as the worktree root: the remap flag
    // gets added (`--remap-path-prefix=<cwd>=.`) and the depgraph context_key
    // normalizes paths relative to a deterministic root. Behavior when the env
    // var isn't set is unchanged.
    if path_remap_auto_enabled(client_env) {
        return Some(cwd_normalized);
    }

    None
}

pub(super) fn normalize_path_for_request_key(path: &Path, key_root: Option<&Path>) -> String {
    if let Some(root) = key_root {
        if let Ok(relative) = path.strip_prefix(root) {
            let relative = crate::core::path::normalize_for_key(relative);
            if relative.is_empty() {
                return REQUEST_ROOT_MARKER.to_string();
            }
            return format!("{REQUEST_ROOT_MARKER}/{relative}");
        }
    }
    crate::core::path::normalize_for_key(path)
}

pub(super) fn normalize_request_path_value(value: &str, key_root: Option<&Path>) -> Option<String> {
    let path = Path::new(value);
    if path.is_absolute() {
        return Some(normalize_path_for_request_key(path, key_root));
    }
    None
}

pub(super) fn normalize_rust_remap_path_prefix_value_for_key(
    value: &str,
    key_root: Option<&Path>,
) -> Option<String> {
    let (old, new) = value.split_once('=')?;
    normalize_request_path_value(old, key_root)
        .map(|normalized_old| format!("{normalized_old}={new}"))
}

pub(super) const CC_PREFIX_MAP_FLAGS: &[&str] = &[
    "-ffile-prefix-map",
    "-fmacro-prefix-map",
    "-fdebug-prefix-map",
    "-fcoverage-prefix-map",
    "-fprofile-prefix-map",
];

pub(super) fn split_cc_prefix_map_arg(arg: &str) -> Option<(&'static str, &str, &str)> {
    for flag in CC_PREFIX_MAP_FLAGS {
        if let Some(rest) = arg
            .strip_prefix(*flag)
            .and_then(|rest| rest.strip_prefix('='))
        {
            if let Some((old, new)) = rest.split_once('=') {
                return Some((*flag, old, new));
            }
        }
    }
    None
}

pub(super) fn normalize_cc_prefix_map_arg_for_key(
    arg: &str,
    key_root: Option<&Path>,
) -> Option<String> {
    let (flag, old, new) = split_cc_prefix_map_arg(arg)?;
    normalize_request_path_value(old, key_root)
        .map(|normalized_old| format!("{flag}={normalized_old}={new}"))
}

pub(super) fn same_key_path(left: &Path, right: &Path) -> bool {
    crate::core::path::normalize_for_key(left) == crate::core::path::normalize_for_key(right)
}

/// Does `args` contain a `<target_flag>=<old>=...` mapping (case- and
/// path-normalisation aware on the `old` side)? Used by the auto-injection
/// branch in [`effective_compile_args`] to skip adding redundant
/// `-ffile-prefix-map` / `-fmacro-prefix-map` / `-fdebug-prefix-map` flags
/// when the caller already passed one for the same `old` root (issue #474).
pub(super) fn has_cc_prefix_map_for_old(args: &[String], target_flag: &str, old: &Path) -> bool {
    args.iter().any(|arg| {
        let Some((flag, existing_old, _)) = split_cc_prefix_map_arg(arg) else {
            return false;
        };
        flag == target_flag && same_key_path(Path::new(existing_old), old)
    })
}

pub(super) fn compiler_supports_ffile_prefix_map(compiler_path: &Path) -> bool {
    matches!(
        crate::compiler::detect_family(&compiler_path.to_string_lossy()),
        crate::compiler::CompilerFamily::Clang | crate::compiler::CompilerFamily::Gcc
    )
}

/// Does this (family, source_mode) pair require the worktree-root to be
/// folded into the artifact cache key?
///
/// Returns `true` for compile invocations whose ARTIFACTS the compiler
/// embeds absolute paths inside, in a form the `-ffile-prefix-map` family
/// of flags can't scrub:
///
/// * **PCH builds** (`SourceMode::Header` with clang or gcc) — the `.pch` /
///   `.gch` binary serialises the AST's header-path table; even with
///   `-ffile-prefix-map` and friends, restoring a fastled9-built PCH into
///   fastled10 leaves fastled9 paths inside the AST (issue #474).
/// * **MSVC** (`CompilerFamily::Msvc`) — cl.exe has no `-fmacro-prefix-map`
///   equivalent. Object files emit absolute paths in debug info and the
///   `$$PDB` reference, with no compiler-side scrub available.
///
/// When this returns `true`, the cache key for the artifact must include
/// the `worktree_root` (or another stable per-worktree salt) so the cache
/// entry stays scoped to the worktree that built it. The trade-off is one
/// cold compile per worktree for the affected unit; everything else
/// continues to share across worktrees (issue #474 plan, Piece B).
#[must_use]
pub fn requires_worktree_in_key(
    family: crate::compiler::CompilerFamily,
    source_mode: crate::compiler::SourceMode,
) -> bool {
    use crate::compiler::{CompilerFamily, SourceMode};
    matches!(family, CompilerFamily::Msvc) || matches!(source_mode, SourceMode::Header)
}

pub(super) fn request_key_root(
    compiler_path: &Path,
    args: &[String],
    worktree_root: Option<&NormalizedPath>,
) -> Option<NormalizedPath> {
    if compiler_is_rustc_like(compiler_path) {
        rustc_request_key_root(args, worktree_root)
    } else {
        worktree_root.cloned()
    }
}

pub(super) fn effective_compile_args(
    expanded_args: &[String],
    compiler_path: &Path,
    cwd: &Path,
    worktree_root: Option<&NormalizedPath>,
    client_env: Option<&[(String, String)]>,
) -> Vec<String> {
    if !path_remap_auto_enabled(client_env) {
        return expanded_args.to_vec();
    }

    let Some(root) = worktree_root else {
        return expanded_args.to_vec();
    };

    let root_path = root.as_path();
    if compiler_is_rustc_like(compiler_path) {
        if rust_args_have_remap_for_old(expanded_args, root_path) {
            return expanded_args.to_vec();
        }

        let mut effective = Vec::with_capacity(expanded_args.len() + 2);
        effective.push("--remap-path-prefix".to_string());
        effective.push(format!("{}=.", root_path.to_string_lossy()));
        effective.extend_from_slice(expanded_args);
        return effective;
    }

    if !compiler_supports_ffile_prefix_map(compiler_path) {
        return expanded_args.to_vec();
    }

    // Inject the three siblings together. Modern clang treats
    // `-ffile-prefix-map` as the umbrella, but older clang (< 10) and
    // some gcc versions need `-fmacro-prefix-map` and `-fdebug-prefix-map`
    // explicitly. Issue #474: without the explicit macro form, `__FILE__`
    // strings in `.rodata` leak the original-clone path into artifacts
    // restored to a sibling worktree.
    const AUTO_PREFIX_MAP_FLAGS: &[&str] = &[
        "-ffile-prefix-map",
        "-fmacro-prefix-map",
        "-fdebug-prefix-map",
    ];

    let mut auto_args = Vec::with_capacity(AUTO_PREFIX_MAP_FLAGS.len() * 2);
    for flag in AUTO_PREFIX_MAP_FLAGS {
        if !has_cc_prefix_map_for_old(expanded_args, flag, root_path) {
            auto_args.push(format!("{}={}=.", flag, root_path.to_string_lossy()));
        }
    }

    if !same_key_path(root_path, cwd) {
        for flag in AUTO_PREFIX_MAP_FLAGS {
            if !has_cc_prefix_map_for_old(expanded_args, flag, cwd) {
                auto_args.push(format!("{}={}=.", flag, cwd.to_string_lossy()));
            }
        }
    }

    if auto_args.is_empty() {
        return expanded_args.to_vec();
    }

    let mut effective = Vec::with_capacity(auto_args.len() + expanded_args.len());
    effective.extend(auto_args);
    effective.extend_from_slice(expanded_args);
    effective
}

pub(super) fn normalize_request_arg(arg: &str, key_root: Option<&Path>) -> String {
    let Some(root) = key_root else {
        return arg.to_string();
    };

    if let Some(normalized) = normalize_cc_prefix_map_arg_for_key(arg, Some(root)) {
        return normalized;
    }

    if let Some(value) = arg.strip_prefix("--remap-path-prefix=") {
        if let Some(normalized) = normalize_rust_remap_path_prefix_value_for_key(value, Some(root))
        {
            return format!("--remap-path-prefix={normalized}");
        }
        return arg.to_string();
    }

    if let Some(normalized) = normalize_request_path_value(arg, Some(root)) {
        return normalized;
    }

    if let Some(rest) = arg.strip_prefix("-I").filter(|rest| !rest.is_empty()) {
        if let Some(normalized) = normalize_request_path_value(rest, Some(root)) {
            return format!("-I{normalized}");
        }
    }

    if let Some(rest) = arg.strip_prefix("-L").filter(|rest| !rest.is_empty()) {
        if let Some(normalized) = normalize_request_path_value(rest, Some(root)) {
            return format!("-L{normalized}");
        }
    }

    if let Some((left, right)) = arg.split_once('=') {
        if let Some(normalized_left) = normalize_request_path_value(left, Some(root)) {
            return format!("{normalized_left}={right}");
        }
        if let Some(normalized_right) = normalize_request_path_value(right, Some(root)) {
            return format!("{left}={normalized_right}");
        }
    }

    arg.to_string()
}

pub(super) fn request_env_fingerprint_vars(
    client_env: Option<&[(String, String)]>,
) -> Vec<(&str, &str)> {
    let mut vars: Vec<(&str, &str)> = client_env
        .into_iter()
        .flatten()
        .filter_map(|(key, value)| {
            let key = key.as_str();
            // Mirror `VOLATILE_CARGO_ENV_VARS` in `depgraph::context`: the
            // request-level fingerprint must drop the same path-cascading
            // CARGO_* vars the rustc context key drops, otherwise the
            // fast-path miss/hit decision diverges from the slow-path key
            // computation and worktrees with different target-dir leaf names
            // never reach the artifact lookup (issue #396).
            let include = key.starts_with("CARGO_")
                && key != "CARGO_MAKEFLAGS"
                && key != "CARGO_INCREMENTAL"
                && key != "CARGO_MANIFEST_DIR"
                && key != "CARGO_MANIFEST_PATH"
                && key != "CARGO_TARGET_DIR";
            include.then_some((key, value.as_str()))
        })
        .collect();
    vars.sort_unstable();
    vars
}

/// Compute a fast fingerprint of a compile request for the request-level cache.
///
/// Streams bytes directly into blake3 without intermediate buffer allocation.
/// Zero-alloc: ~100ns for 10 args, ~500ns for 300 args.
/// Callers should pass the fully expanded argv so response-file content
/// changes also invalidate the request-level fast path.
pub(super) fn request_fingerprint(
    compiler: &Path,
    args: &[String],
    cwd: &Path,
    key_root: Option<&Path>,
    client_env: Option<&[(String, String)]>,
) -> ContentHash {
    let mut h = crate::hash::StreamHasher::new();
    h.update(b"zccache-request-v2\0");
    let compiler = crate::core::path::normalize_for_key(compiler);
    h.update(compiler.as_bytes());
    h.update(&[0]);
    let mut i = 0;
    while i < args.len() {
        let arg = &args[i];
        if arg == "--remap-path-prefix" {
            h.update(arg.as_bytes());
            h.update(&[0]);
            if let Some(value) = args.get(i + 1) {
                let value = normalize_rust_remap_path_prefix_value_for_key(value, key_root)
                    .unwrap_or_else(|| value.clone());
                h.update(value.as_bytes());
                h.update(&[0]);
            }
            i += 2;
            continue;
        }
        let arg = normalize_request_arg(arg, key_root);
        h.update(arg.as_bytes());
        h.update(&[0]);
        i += 1;
    }
    let cwd = normalize_path_for_request_key(cwd, key_root);
    h.update(cwd.as_bytes());
    h.update(&[0]);
    for (key, value) in request_env_fingerprint_vars(client_env) {
        h.update(key.as_bytes());
        h.update(b"=");
        h.update(value.as_bytes());
        h.update(&[0]);
    }
    h.finalize()
}

pub(super) fn request_cache_input_paths(
    state: &SharedState,
    context_key: &ContextKey,
    source_path: &NormalizedPath,
    ctx: &CompileContext,
) -> Vec<NormalizedPath> {
    let mut paths = Vec::new();
    paths.push(source_path.clone());
    if let Some(includes) = state.dep_graph.load().get_includes(context_key) {
        paths.extend(includes.iter().cloned());
    }
    if let Some(externs) = state.dep_graph.load().get_rustc_externs(context_key) {
        paths.extend(externs.into_iter().map(|(_, path)| path));
    }
    paths.extend(ctx.force_includes.iter().cloned());
    paths.sort();
    paths.dedup();
    paths
}

/// Build a request-cache entry.
///
/// `worktree_bound` must be `true` for any artifact whose bytes embed
/// absolute paths that no remap pass scrubs — PCH/GCH (`-include`-baked
/// header AST) and MSVC compiles (PDB/`/Fp`/`/Fd` paths). Setting it forces
/// `cross_root_shareable = false`, so the entry only matches lookups from
/// its originating worktree even when every captured path is technically
/// root-relative. See [`requires_worktree_in_key`] for the truth table and
/// issue #489 for the diagnostic / DLL-load failure that motivated this.
pub(super) fn request_cache_entry(
    context_key: ContextKey,
    source_path: &NormalizedPath,
    output_path: &NormalizedPath,
    depfile_path: Option<&NormalizedPath>,
    input_paths: Vec<NormalizedPath>,
    key_root: Option<&NormalizedPath>,
    worktree_bound: bool,
) -> RequestCacheEntry {
    let root = key_root.cloned();
    let root_path = key_root.map(|root| root.as_path());
    let source_path = CachedRequestPath::capture(source_path, root_path);
    let output_path = CachedRequestPath::capture(output_path, root_path);
    let depfile_path = depfile_path.map(|path| CachedRequestPath::capture(path, root_path));
    let input_paths: Vec<CachedRequestPath> = input_paths
        .iter()
        .map(|path| CachedRequestPath::capture(path, root_path))
        .collect();
    // Issue #643: the depfile destination, when present, must also be
    // root-relative for the cross-worktree fast path to share entries
    // safely — otherwise a hit in worktree B would write the depfile
    // back to worktree A's absolute path. When the user supplied an
    // absolute path that isn't under the key root, fall back to
    // worktree-bound semantics (`cross_root_shareable = false`).
    let cross_root_shareable = !worktree_bound
        && root.is_some()
        && source_path.is_root_relative()
        && output_path.is_root_relative()
        && depfile_path
            .as_ref()
            .is_none_or(CachedRequestPath::is_root_relative)
        && input_paths.iter().all(CachedRequestPath::is_root_relative);

    RequestCacheEntry {
        context_key,
        root,
        source_path,
        output_path,
        depfile_path,
        input_paths,
        cross_root_shareable,
        cached_at: std::time::Instant::now(),
    }
}

pub(super) fn request_cache_entry_matches_root(
    entry: &RequestCacheEntry,
    key_root: Option<&NormalizedPath>,
) -> bool {
    if entry.root.as_ref() == key_root {
        return true;
    }
    entry.cross_root_shareable && entry.root.is_some() && key_root.is_some()
}

pub(super) fn request_validation_key(
    request_fp: ContentHash,
    root: &NormalizedPath,
) -> RequestValidationKey {
    RequestValidationKey {
        request_fp,
        root: root.clone(),
    }
}

pub(super) fn request_cache_resolved_inputs(
    entry: &RequestCacheEntry,
    root: &NormalizedPath,
) -> Option<Vec<NormalizedPath>> {
    if !entry.cross_root_shareable {
        return None;
    }
    let mut paths = Vec::with_capacity(entry.input_paths.len());
    for cached_path in &entry.input_paths {
        if !cached_path.is_root_relative() {
            return None;
        }
        paths.push(cached_path.resolve(Some(root)));
    }
    Some(paths)
}

pub(super) fn request_cache_inputs_fresh_since(
    journal: &crate::fscache::ChangeJournal,
    paths: &[NormalizedPath],
    since: Clock,
) -> bool {
    paths.iter().all(|path| !journal.changed_since(path, since))
}

pub(super) fn request_cache_artifact_matches(
    state: &SharedState,
    entry: &RequestCacheEntry,
    request_fp: ContentHash,
    key_root: Option<&NormalizedPath>,
    expected_artifact_key_hex: &str,
    now: Instant,
    clock: Clock,
) -> bool {
    let Some(root) = key_root else {
        return false;
    };

    let Some(paths) = request_cache_resolved_inputs(entry, root) else {
        return false;
    };
    let validation_key = request_validation_key(request_fp, root);
    if let Some(validation) = state.request_validation_cache.get(&validation_key) {
        if validation.artifact_key_hex == expected_artifact_key_hex
            && cache_entry_fresh_at(now, validation.cached_at, EPHEMERAL_CACHE_MAX_AGE)
            && request_cache_inputs_fresh_since(
                state.cache_system.journal(),
                &paths,
                validation.clock,
            )
        {
            return true;
        }
    }

    state.cache_system.register_tracked(&paths);
    let validation_clock = state.cache_system.current_clock();

    let mut file_hashes = Vec::with_capacity(paths.len());
    for path in paths {
        let Ok(hash) = hash_file(&state.cache_system, &path, clock) else {
            return false;
        };
        file_hashes.push((path, hash));
    }

    let artifact_key = crate::depgraph::compute_artifact_key(
        &entry.context_key,
        &mut file_hashes,
        Some(root.as_path()),
    );
    let matches = artifact_key.hash().to_hex() == expected_artifact_key_hex;
    if matches {
        state.request_validation_cache.insert(
            validation_key,
            RequestValidationEntry {
                artifact_key_hex: expected_artifact_key_hex.to_string(),
                clock: validation_clock,
                cached_at: std::time::Instant::now(),
            },
        );
    }
    matches
}

pub(super) fn strict_paths_mode_from_client_env(
    client_env: Option<&[(String, String)]>,
) -> Result<crate::compiler::strict_paths::StrictPathsMode, String> {
    let Some(env) = client_env else {
        return Ok(crate::compiler::strict_paths::StrictPathsMode::Off);
    };
    crate::compiler::strict_paths::StrictPathsMode::from_env_vars(
        env.iter()
            .map(|(key, value)| (key.as_str(), value.as_str())),
    )
    .map_err(|err| err.to_string())
}