diff --git a/aocsync.py b/aocsync.py index b85cab4..71898d8 100755 --- a/aocsync.py +++ b/aocsync.py @@ -636,28 +636,29 @@ class CargoAOCRunner: '-w', f'/repo/{work_dir_rel}', # Working directory in container ] - # Handle cargo registry cache + # Handle cargo registry cache and cargo home if registry_cache_dir: - # Use persistent registry cache + # Use persistent registry cache - mount entire CARGO_HOME directory registry_cache_path = Path(registry_cache_dir).resolve() registry_cache_path.mkdir(parents=True, exist_ok=True) - podman_cmd.extend(['-v', f'{registry_cache_path}:/root/.cargo/registry:rw']) - logger.info(f"Using persistent registry cache: {registry_cache_path}") + # Mount the parent directory as CARGO_HOME so both registry and bin are persisted + cargo_home_path = registry_cache_path.parent / 'cargo-home' + cargo_home_path.mkdir(parents=True, exist_ok=True) + podman_cmd.extend(['-v', f'{cargo_home_path}:/root/.cargo:rw']) + logger.info(f"Using persistent cargo home (registry + bin): {cargo_home_path}") else: - # Use tmpfs for registry cache (cleared after each run) - podman_cmd.extend(['--tmpfs', '/root/.cargo/registry:rw,noexec,nosuid,size=100m']) + # Use tmpfs for cargo home (cleared after each run) + podman_cmd.extend(['--tmpfs', '/root/.cargo:rw,noexec,nosuid,size=200m']) - # Handle cargo-aoc installation location (only needed if installing on-the-fly) - if needs_cargo_aoc_install: - # Need writable /root/.cargo/bin to install cargo-aoc - if registry_cache_dir: - # If using persistent registry cache, also persist cargo bin - cargo_bin_path = Path(registry_cache_dir).parent / 'cargo-bin' - cargo_bin_path.mkdir(parents=True, exist_ok=True) - podman_cmd.extend(['-v', f'{cargo_bin_path}:/root/.cargo/bin:rw']) - else: - # Use tmpfs for cargo bin (will be cleared, but allows installation) - podman_cmd.extend(['--tmpfs', '/root/.cargo/bin:rw,noexec,nosuid,size=50m']) + # Note: cargo-aoc installation location is handled above via CARGO_HOME mount + # If using persistent cache, cargo bin is already mounted via cargo-home + # If using tmpfs, cargo bin is already included in /root/.cargo tmpfs + + # Set environment variables in the container so cargo uses the mounted directories + # Set build directory (target directory for compiled artifacts) + podman_cmd.extend(['-e', 'CARGO_TARGET_DIR=/build/target']) + # Set cargo home to use the mounted registry cache + podman_cmd.extend(['-e', 'CARGO_HOME=/root/.cargo']) # Add Podman image and command if needs_cargo_aoc_install: @@ -674,16 +675,11 @@ class CargoAOCRunner: 'cargo', 'aoc', '--day', str(day) ]) - # Set CARGO_TARGET_DIR to use the mounted build directory - env = os.environ.copy() - env['CARGO_TARGET_DIR'] = '/build/target' - result = subprocess.run( podman_cmd, capture_output=True, text=True, - timeout=300, # 5 minute timeout - env=env + timeout=300 # 5 minute timeout ) return result