Skip to content

Add PackageCache support for base packages#1166

Open
DavisVaughan wants to merge 1 commit intomainfrom
oak/base-package-cache
Open

Add PackageCache support for base packages#1166
DavisVaughan wants to merge 1 commit intomainfrom
oak/base-package-cache

Conversation

@DavisVaughan
Copy link
Copy Markdown
Contributor

The base packages aren't in the typical location, i.e. not in https://cran.r-project.org/src/contrib/.

Instead you must download the whole R tarball located at https://cran.r-project.org/src/base/R-4/, dig into it at src/library/{base_package}/R and copy over the R/ sources from there.

Because the R tarball is a whopping ~40mb, if we detect that we need to do this for any base package, then we go ahead and cache all ~14 base packages.


As a side note, Recommended packages like MASS are in the standard download and Archive/ locations, so we already supported those.

Comment on lines +296 to +301
// The `base` package itself has no NAMESPACE, for now we generate an empty
// NAMESPACE, but eventually we will want to fully populate it with a
// pseudo-NAMESPACE.
if package.name() == "base" {
std::fs::write(destination_lock.parent().join("NAMESPACE"), "")?;
crate::fs::set_readonly(destination_lock.parent().join("NAMESPACE"))?;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good enough for the moment, but we will need to fake it somehow. I couldn't come up with a solid plan for this yet.

Comment thread crates/oak_sources/src/download.rs Outdated

for mirror in mirrors {
let url = format!("{mirror}/{suffix}");
let response = reqwest::blocking::get(&url)?;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The download of the R tarball from r-project.org can be somewhat slow, normally taking around 10 seconds for me.

It seems to be faster from the rstudio.com mirror (I tried switching the ordering so RStudio's mirror comes first).

Note that if we hit 30 seconds for the download time, then reqwest will cancel the download and return an error here. I have seen that happen exactly one time. We may want to consider that case in more detail. I'm not sure what the right thing to do is here, maybe try to up it to 1 minute? Much longer than that would be a horrible user experience.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: We have a 10 second timeout on connection and a 40 second timeout for the download. If that times out we try the other CRAN mirror (which can be much faster, as mentioned above)

Comment on lines +7 to +13
pub(crate) struct InstalledPackage {
key: String,
name: String,
library_path: PathBuf,
description: Description,
description_hash: String,
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some details on how to create this struct have been extracted out because for the base package download I have to create one of these for each of the base packages.

@DavisVaughan DavisVaughan force-pushed the oak/base-package-cache branch from 05fd708 to d49ea97 Compare April 23, 2026 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant