Skip to content

Commit

Permalink
fix(ruby): fixed MISE_RUBY_BUILD_OPTS
Browse files Browse the repository at this point in the history
Fixes #2608
  • Loading branch information
jdx committed Sep 18, 2024
1 parent a92e7bc commit 50bdfb7
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 61 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ env:
SCCACHE_S3_NO_CREDENTIALS: ${{ secrets.MINIO_AWS_ACCESS_KEY_ID && '0' || '1' }}
MINIO_AWS_ACCESS_KEY_ID: ${{ secrets.MINIO_AWS_ACCESS_KEY_ID }}
MINIO_AWS_SECRET_ACCESS_KEY: ${{ secrets.MINIO_AWS_SECRET_ACCESS_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

permissions:
pull-requests: write
Expand Down
73 changes: 65 additions & 8 deletions docs/lang/ruby.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,71 @@ for additional settings and some troubleshooting.

`ruby-build` already has a
[handful of settings](https://github.com/rbenv/ruby-build?tab=readme-ov-file#custom-build-configuration),
in additional to that mise has a few extra configuration variables:

- `MISE_RUBY_INSTALL` [bool]: Build with ruby-install instead of ruby-build
- `MISE_RUBY_APPLY_PATCHES` [string]: A list of patches (files or URLs) to apply to the ruby source code
- `MISE_RUBY_VERBOSE_INSTALL` [bool]: Show verbose output during installation (passes --verbose to ruby-build)
- `MISE_RUBY_BUILD_OPTS` [string]: Command line options to pass to ruby-build when installing
- `MISE_RUBY_INSTALL_OPTS` [string]: Command line options to pass to ruby-install when installing (if MISE_RUBY_INSTALL=1)
- `MISE_RUBY_DEFAULT_PACKAGES_FILE` [string]: location of default gems file, defaults to `$HOME/.default-gems`
in additional to that mise has a few extra settings:

### `ruby.apply_patches`

* Type: `Option<String>`
* Env: `MISE_RUBY_APPLY_PATCHES`
* Default: `None`

A list of patches (files or URLs) to apply to the ruby source code.

### `ruby.verbose_install`

* Type: `Option<bool>`
* Env: `MISE_RUBY_VERBOSE_INSTALL`
* Default: `None` (behaves like `false` unless --verbose is passed to mise)

Show verbose output during installation (passes --verbose to ruby-build)

### `ruby.ruby_build_repo`

* Type: `String`
* Env: `MISE_RUBY_BUILD_REPO`
* Default: `https://github.com/rbenv/ruby-build.git`

The git repository to use for getting ruby-build.

### `ruby.ruby_build_opts`

* Type: `Option<String>`
* Env: `MISE_RUBY_BUILD_OPTS`
* Default: `None`

Command line options to pass to ruby-build when installing

### `ruby.ruby_install`

* Type: `bool`
* Env: `MISE_RUBY_INSTALL`
* Default: `false`

Build with [ruby-install](https://github.com/postmodern/ruby-install) instead of [ruby-build](https://github.com/rbenv/ruby-build).

### `ruby.ruby_install_repo`

* Type: `String`
* Env: `MISE_RUBY_INSTALL_REPO`
* Default: `https://github.com/postmodern/ruby-install.git`

The git repository to use for getting ruby-install.

### `ruby.ruby_install_opts`

* Type: `Option<String>`
* Env: `MISE_RUBY_INSTALL_OPTS`
* Default: `None`

Command line options to pass to ruby-install when installing (if MISE_RUBY_INSTALL=1)

### `ruby.default_packages_file`

* Type: `String`
* Env: `MISE_RUBY_DEFAULT_PACKAGES_FILE`
* Default: `$HOME/.default-gems`

Location of file containing a list of gems to install after installing a new ruby version.

## Default gems

Expand Down
39 changes: 39 additions & 0 deletions schema/mise.json
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,45 @@
"description": "path to file containing shorthand mappings",
"type": "string"
},
"ruby": {
"description": "settings specific to ruby",
"type": "object",
"additionalProperties": false,
"properties": {
"apply_patches": {
"description": "A list of patches (files or URLs) to apply to Ruby source code before building",
"type": "string"
},
"verbose_install": {
"description": "Show verbose output during installation (passes --verbose to ruby-build)",
"type": "boolean"
},
"ruby_build_repo": {
"description": "The git repository to use for getting ruby-build",
"type": "string"
},
"ruby_build_opts": {
"description": "Command line options to pass to ruby-build when installing",
"type": "string"
},
"ruby_install": {
"description": "Build with ruby-install instead of ruby-build",
"type": "boolean"
},
"ruby_install_repo": {
"description": "The git repository to use for getting ruby-install",
"type": "string"
},
"ruby_install_opts": {
"description": "Command line options to pass to ruby-install when installing (if MISE_RUBY_INSTALL=1)",
"type": "string"
},
"default_packages_file": {
"description": "Location of file containing a list of gems to install after installing a new ruby version.",
"type": "string"
}
}
},
"status": {
"description": "configure messages displayed when changing directories or executing tools",
"type": "object",
Expand Down
19 changes: 15 additions & 4 deletions src/cli/settings/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mod tests {
#[test]
fn test_settings_ls() {
reset();
assert_cli_snapshot!("settings", @r###"
assert_cli_snapshot!("settings", @r#"
activate_aggressive = false
all_compile = false
always_keep_download = true
Expand Down Expand Up @@ -97,17 +97,23 @@ mod tests {
vfox = false
yes = true
[ruby]
default_packages_file = "~/.default-gems"
ruby_build_repo = "https://github.com/rbenv/ruby-build.git"
ruby_install = false
ruby_install_repo = "https://github.com/postmodern/ruby-install.git"
[status]
missing_tools = "if_other_versions_installed"
show_env = false
show_tools = false
"###);
"#);
}

#[test]
fn test_settings_ls_keys() {
reset();
assert_cli_snapshot!("settings", "--keys", @r###"
assert_cli_snapshot!("settings", "--keys", @r#"
activate_aggressive
all_compile
always_keep_download
Expand Down Expand Up @@ -140,6 +146,11 @@ mod tests {
python_pyenv_repo
quiet
raw
ruby
ruby.default_packages_file
ruby.ruby_build_repo
ruby.ruby_install
ruby.ruby_install_repo
status
status.missing_tools
status.show_env
Expand All @@ -149,6 +160,6 @@ mod tests {
verbose
vfox
yes
"###);
"#);
}
}
10 changes: 8 additions & 2 deletions src/cli/settings/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub mod tests {
"1"
);

assert_cli_snapshot!("settings", @r###"
assert_cli_snapshot!("settings", @r#"
activate_aggressive = false
all_compile = false
always_keep_download = true
Expand Down Expand Up @@ -173,11 +173,17 @@ pub mod tests {
vfox = false
yes = true
[ruby]
default_packages_file = "~/.default-gems"
ruby_build_repo = "https://github.com/rbenv/ruby-build.git"
ruby_install = false
ruby_install_repo = "https://github.com/postmodern/ruby-install.git"
[status]
missing_tools = "never"
show_env = false
show_tools = false
"###);
"#);
reset();
}
}
10 changes: 8 additions & 2 deletions src/cli/settings/unset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod tests {

assert_cli!("settings", "unset", "jobs");

assert_cli_snapshot!("settings", @r###"
assert_cli_snapshot!("settings", @r#"
activate_aggressive = false
all_compile = false
always_keep_download = true
Expand Down Expand Up @@ -88,11 +88,17 @@ mod tests {
vfox = false
yes = true
[ruby]
default_packages_file = "~/.default-gems"
ruby_build_repo = "https://github.com/rbenv/ruby-build.git"
ruby_install = false
ruby_install_repo = "https://github.com/postmodern/ruby-install.git"
[status]
missing_tools = "if_other_versions_installed"
show_env = false
show_tools = false
"###);
"#);

reset();
}
Expand Down
32 changes: 28 additions & 4 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use std::iter::once;
use std::path::PathBuf;
use std::sync::{Arc, Mutex, RwLock};

use crate::config::{system_config_files, DEFAULT_CONFIG_FILENAMES};
use crate::file::FindUp;
use crate::{config, dirs, env, file};
#[allow(unused_imports)]
use confique::env::parse::{list_by_colon, list_by_comma};
use confique::{Config, Partial};
Expand All @@ -12,10 +15,6 @@ use once_cell::sync::Lazy;
use serde::ser::Error;
use serde_derive::{Deserialize, Serialize};

use crate::config::{system_config_files, DEFAULT_CONFIG_FILENAMES};
use crate::file::FindUp;
use crate::{config, dirs, env, file};

#[rustfmt::skip]
#[derive(Config, Default, Debug, Clone, Serialize)]
#[config(partial_attr(derive(Clone, Serialize, Default)))]
Expand Down Expand Up @@ -118,6 +117,8 @@ pub struct Settings {
pub python_pyenv_repo: String,
#[config(env = "MISE_RAW", default = false)]
pub raw: bool,
#[config(nested)]
pub ruby: SettingsRuby,
#[config(env = "MISE_SHORTHANDS_FILE")]
pub shorthands_file: Option<PathBuf>,
/// what level of status messages to display when entering directories
Expand Down Expand Up @@ -159,6 +160,29 @@ pub struct Settings {
pub python_venv_auto_create: bool,
}

#[derive(Config, Default, Debug, Clone, Serialize)]
#[config(partial_attr(derive(Clone, Serialize, Default)))]
#[config(partial_attr(serde(deny_unknown_fields)))]
#[rustfmt::skip]
pub struct SettingsRuby {
#[config(env = "MISE_RUBY_APPLY_PATCHES")]
pub apply_patches: Option<String>,
#[config(env = "MISE_RUBY_DEFAULT_PACKAGES_FILE", default = "~/.default-gems")]
pub default_packages_file: String,
#[config(env = "MISE_RUBY_BUILD_REPO", default = "https://github.com/rbenv/ruby-build.git")]
pub ruby_build_repo: String,
#[config(env = "MISE_RUBY_BUILD_OPTS")]
pub ruby_build_opts: Option<String>,
#[config(env = "MISE_RUBY_INSTALL", default = false)]
pub ruby_install: bool,
#[config(env = "MISE_RUBY_INSTALL_REPO", default = "https://github.com/postmodern/ruby-install.git")]
pub ruby_install_repo: String,
#[config(env = "MISE_RUBY_INSTALL_OPTS")]
pub ruby_install_opts: Option<String>,
#[config(env = "MISE_RUBY_VERBOSE_INSTALL")]
pub verbose_install: Option<bool>,
}

#[derive(Config, Default, Debug, Clone, Serialize)]
#[config(partial_attr(derive(Clone, Serialize, Default)))]
#[config(partial_attr(serde(deny_unknown_fields)))]
Expand Down
28 changes: 0 additions & 28 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,34 +232,6 @@ pub static NVM_DIR: Lazy<PathBuf> =
pub static NODENV_ROOT: Lazy<PathBuf> =
Lazy::new(|| var_path("NODENV_ROOT").unwrap_or_else(|| HOME.join(".nodenv")));

// ruby
#[cfg(unix)]
pub static MISE_RUBY_BUILD_REPO: Lazy<String> = Lazy::new(|| {
var("MISE_RUBY_BUILD_REPO").unwrap_or_else(|_| "https://github.com/rbenv/ruby-build.git".into())
});
#[cfg(unix)]
pub static MISE_RUBY_INSTALL_REPO: Lazy<String> = Lazy::new(|| {
var("MISE_RUBY_INSTALL_REPO")
.unwrap_or_else(|_| "https://github.com/postmodern/ruby-install.git".into())
});
#[cfg(unix)]
pub static MISE_RUBY_INSTALL: Lazy<bool> = Lazy::new(|| var_is_true("MISE_RUBY_INSTALL"));
#[cfg(unix)]
pub static MISE_RUBY_APPLY_PATCHES: Lazy<Option<String>> =
Lazy::new(|| var("MISE_RUBY_APPLY_PATCHES").ok());
#[cfg(unix)]
pub static MISE_RUBY_VERBOSE_INSTALL: Lazy<Option<bool>> =
Lazy::new(|| var_option_bool("MISE_RUBY_VERBOSE_INSTALL"));
#[cfg(unix)]
pub static MISE_RUBY_INSTALL_OPTS: Lazy<Result<Vec<String>, shell_words::ParseError>> =
Lazy::new(|| shell_words::split(&var("MISE_RUBY_INSTALL_OPTS").unwrap_or_default()));
#[cfg(unix)]
pub static MISE_RUBY_BUILD_OPTS: Lazy<Result<Vec<String>, shell_words::ParseError>> =
Lazy::new(|| shell_words::split(&var("MISE_RUBY_BUILD_OPTS").unwrap_or_default()));
pub static MISE_RUBY_DEFAULT_PACKAGES_FILE: Lazy<PathBuf> = Lazy::new(|| {
var_path("MISE_RUBY_DEFAULT_PACKAGES_FILE").unwrap_or_else(|| HOME.join(".default-gems"))
});

fn get_env_diff() -> EnvDiff {
let env = vars().collect::<HashMap<_, _>>();
match env.get("__MISE_DIFF") {
Expand Down
Loading

0 comments on commit 50bdfb7

Please sign in to comment.