Skip to content

Commit

Permalink
Add feature to make the runtime immutable
Browse files Browse the repository at this point in the history
This prevents installing and uninstalling the runtime using commands, and also stops patching the runtime when launching web apps. The runtime can still be patched manually from the extension settings or the patch command if the user has sufficient write permissions to do so.

This is meant for immutable systems like Guix or Nix where runtime might be provided by the package manager and pre-patched. See #204 for more.
  • Loading branch information
filips123 committed Jan 20, 2024
1 parent 8851dbd commit d167262
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ lto = true
[features]
portable = ["dep:phf"]
static = ["reqwest/native-tls-vendored", "bzip2/static"]
immutable-runtime = []

[dependencies]
ab_glyph = "0.2.23"
Expand Down
2 changes: 2 additions & 0 deletions native/src/components/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ impl Runtime {
Ok(Self { version, directory, executable, config })
}

#[cfg(not(feature = "immutable-runtime"))]
pub fn install(self) -> Result<()> {
const TEMP_FILE_ERROR: &str = "Failed to create a temporary file";
const DOWNLOAD_ERROR: &str = "Failed to download the runtime";
Expand Down Expand Up @@ -269,6 +270,7 @@ impl Runtime {
Ok(())
}

#[cfg(not(feature = "immutable-runtime"))]
pub fn uninstall(self) -> Result<()> {
info!("Uninstalling the runtime");
remove_dir_contents(self.directory).context("Failed to remove runtime directory")?;
Expand Down
12 changes: 12 additions & 0 deletions native/src/console/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::console::Run;
use crate::directories::ProjectDirs;

impl Run for RuntimeInstallCommand {
#[cfg(not(feature = "immutable-runtime"))]
fn run(&self) -> Result<()> {
cfg_if! {
if #[cfg(platform_windows)] {
Expand All @@ -31,15 +32,26 @@ impl Run for RuntimeInstallCommand {

Ok(())
}

#[cfg(feature = "immutable-runtime")]
fn run(&self) -> Result<()> {
anyhow::bail!("Cannot install runtime when the immutable runtime feature is enabled")
}
}

impl Run for RuntimeUninstallCommand {
#[cfg(not(feature = "immutable-runtime"))]
fn run(&self) -> Result<()> {
let dirs = ProjectDirs::new()?;
let runtime = Runtime::new(&dirs)?;

runtime.uninstall().context("Failed to uninstall runtime")
}

#[cfg(feature = "immutable-runtime")]
fn run(&self) -> Result<()> {
anyhow::bail!("Cannot uninstall runtime when the immutable runtime feature is enabled")
}
}

impl Run for RuntimePatchCommand {
Expand Down
1 change: 1 addition & 0 deletions native/src/console/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl Run for SiteLaunchCommand {
};

if should_patch {
#[cfg(not(feature = "immutable-runtime"))]
runtime.patch(&dirs, Some(site))?;
profile.patch(&dirs)?;
}
Expand Down

0 comments on commit d167262

Please sign in to comment.