Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added MISE_ARCH setting #3490

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions schema/mise.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@
}
}
},
"arch": {
"description": "Architecture to use for precompiled binaries.",
"type": "string"
},
"asdf": {
"description": "use asdf as a default plugin backend",
"type": "boolean",
Expand Down
11 changes: 11 additions & 0 deletions settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ type = "Bool"
default = true
description = "Use SLSA to verify aqua tool signatures."

[arch]
env = "MISE_ARCH"
type = "String"
description = "Architecture to use for precompiled binaries."
default_docs = '"x86_64" | "aarch64" | "arm" | "loongarch64" | "riscv64"'
optional = true
docs = """
Architecture to use for precompiled binaries. This is used to determine which precompiled binaries
to download. If unset, mise will use the system's architecture.
"""

[asdf]
env = "MISE_ASDF"
type = "Bool"
Expand Down
5 changes: 5 additions & 0 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use once_cell::sync::Lazy;
use serde::ser::Error;
use serde_derive::{Deserialize, Serialize};
use std::collections::{BTreeSet, HashSet};
use std::env::consts::ARCH;
use std::fmt::{Debug, Display, Formatter};
use std::path::{Path, PathBuf};
use std::str::FromStr;
Expand Down Expand Up @@ -416,6 +417,10 @@ impl Settings {
};
Ok(shell_words::split(sa)?)
}

pub fn arch(&self) -> &str {
self.arch.as_deref().unwrap_or(ARCH)
}
}

impl Display for Settings {
Expand Down
11 changes: 6 additions & 5 deletions src/plugins/core/deno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use versions::Versioning;

use crate::backend::Backend;
use crate::cli::args::BackendArg;
use crate::cli::version::{ARCH, OS};
use crate::cli::version::OS;
use crate::cmd::CmdLineRunner;
use crate::config::Config;
use crate::config::{Config, SETTINGS};
use crate::http::{HTTP, HTTP_FETCH};
use crate::install_context::InstallContext;
use crate::toolset::{ToolRequest, ToolVersion, Toolset};
Expand Down Expand Up @@ -159,12 +159,13 @@ fn os() -> &'static str {
}

fn arch() -> &'static str {
if cfg!(target_arch = "x86_64") {
let arch = SETTINGS.arch();
if arch == "x86_64" {
"x86_64"
} else if cfg!(target_arch = "aarch64") {
} else if arch == "aarch64" {
"aarch64"
} else {
&ARCH
arch
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/plugins/core/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::thread;

use crate::backend::Backend;
use crate::cli::args::BackendArg;
use crate::cli::version::{ARCH, OS};
use crate::cli::version::OS;
use crate::cmd::CmdLineRunner;
use crate::config::{Config, Settings, SETTINGS};
use crate::file::{TarFormat, TarOptions};
Expand Down Expand Up @@ -245,14 +245,15 @@ fn platform() -> &'static str {
}

fn arch() -> &'static str {
if cfg!(target_arch = "x86_64") {
let arch = SETTINGS.arch();
if arch == "x86_64" {
"amd64"
} else if cfg!(target_arch = "arm") {
} else if arch == "arm" {
"armv6l"
} else if cfg!(target_arch = "aarch64") {
} else if arch == "aarch64" {
"arm64"
} else {
&ARCH
arch
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/plugins/core/java.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::path::{Path, PathBuf};
use crate::backend::Backend;
use crate::cache::{CacheManager, CacheManagerBuilder};
use crate::cli::args::BackendArg;
use crate::cli::version::{ARCH, OS};
use crate::cli::version::OS;
use crate::cmd::CmdLineRunner;
use crate::config::{Config, SETTINGS};
use crate::file::{TarFormat, TarOptions};
Expand Down Expand Up @@ -438,14 +438,15 @@ fn os() -> &'static str {
}

fn arch() -> &'static str {
if cfg!(target_arch = "x86_64") {
let arch = SETTINGS.arch();
if arch == "x86_64" {
"x86_64"
} else if cfg!(target_arch = "arm") {
} else if arch == "arm" {
"arm32-vfp-hflt"
} else if cfg!(target_arch = "aarch64") {
} else if arch == "aarch64" {
"aarch64"
} else {
&ARCH
arch
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/plugins/core/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,24 +543,25 @@ fn os() -> &'static str {
}

fn arch() -> &'static str {
if cfg!(target_arch = "x86") {
let arch = SETTINGS.arch();
if arch == "x86" {
"x86"
} else if cfg!(target_arch = "x86_64") {
} else if arch == "x86_64" {
"x64"
} else if cfg!(target_arch = "arm") {
} else if arch == "arm" {
if cfg!(target_feature = "v6") {
"armv6l"
} else {
"armv7l"
}
} else if cfg!(target_arch = "loongarch64") {
} else if arch == "loongarch64" {
"loong64"
} else if cfg!(target_arch = "riscv64") {
} else if arch == "riscv64" {
"riscv64"
} else if cfg!(target_arch = "aarch64") {
} else if arch == "aarch64" {
"arm64"
} else {
built_info::CFG_TARGET_ARCH
arch
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/plugins/core/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,10 @@ fn python_arch() -> &'static str {
if let Some(arch) = &SETTINGS.python.precompiled_arch {
return arch.as_str();
}
let arch = SETTINGS.arch();
if cfg!(windows) {
"x86_64"
} else if cfg!(all(target_os = "linux", target_arch = "x86_64")) {
} else if cfg!(linux) && arch == "x86_64" {
if cfg!(target_feature = "avx512f") {
"x86_64_v4"
} else if cfg!(target_feature = "avx2") {
Expand All @@ -473,7 +474,7 @@ fn python_arch() -> &'static str {
"x86_64"
}
} else {
built_info::CFG_TARGET_ARCH
arch
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/plugins/core/swift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::http::HTTP;
use crate::install_context::InstallContext;
use crate::toolset::ToolVersion;
use crate::ui::progress_report::SingleReport;
use crate::{env, file, github, gpg, plugins};
use crate::{file, github, gpg, plugins};
use eyre::Result;
use std::path::{Path, PathBuf};
use tempfile::tempdir_in;
Expand Down Expand Up @@ -229,9 +229,10 @@ fn extension() -> &'static str {
}

fn architecture() -> Option<&'static str> {
if cfg!(target_os = "linux") && !cfg!(target_arch = "x86_64") {
return Some(env::consts::ARCH);
} else if cfg!(windows) && cfg!(target_arch = "aarch64") {
let arch = SETTINGS.arch();
if cfg!(target_os = "linux") && arch != "x86_64" {
return Some(arch);
} else if cfg!(windows) && arch == "aarch64" {
return Some("arm64");
}
None
Expand Down
14 changes: 8 additions & 6 deletions src/plugins/core/zig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use std::path::{Path, PathBuf};

use crate::backend::Backend;
use crate::cli::args::BackendArg;
use crate::cli::version::{ARCH, OS};
use crate::cli::version::OS;
use crate::cmd::CmdLineRunner;
use crate::config::SETTINGS;
use crate::http::{HTTP, HTTP_FETCH};
use crate::install_context::InstallContext;
use crate::toolset::{ToolRequest, ToolVersion};
Expand Down Expand Up @@ -161,16 +162,17 @@ fn os() -> &'static str {
}

fn arch() -> &'static str {
if cfg!(target_arch = "x86_64") {
let arch = SETTINGS.arch();
if arch == "x86_64" {
"x86_64"
} else if cfg!(target_arch = "aarch64") {
} else if arch == "aarch64" {
"aarch64"
} else if cfg!(target_arch = "arm") {
} else if arch == "arm" {
"armv7a"
} else if cfg!(target_arch = "riscv64") {
} else if arch == "riscv64" {
"riscv64"
} else {
&ARCH
arch
}
}

Expand Down
15 changes: 10 additions & 5 deletions src/plugins/script_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use indexmap::indexmap;
use once_cell::sync::Lazy;

use crate::cmd::{cmd, CmdLineRunner};
use crate::config::Settings;
use crate::config::{Settings, SETTINGS};
use crate::env::PATH_KEY;
use crate::errors::Error;
use crate::errors::Error::ScriptFailed;
Expand Down Expand Up @@ -167,10 +167,15 @@ impl ScriptManager {
pub fn run_by_line(&self, script: &Script, pr: &dyn SingleReport) -> Result<()> {
let path = self.get_script_path(script);
pr.set_message(display_path(&path));
let cmd = CmdLineRunner::new(path.clone())
.with_pr(pr)
.env_clear()
.envs(&self.env);
let mut cmd = CmdLineRunner::new(path.clone());
if let Some(arch) = &SETTINGS.arch {
if arch == "x86_64" && cfg!(macos) {
cmd = CmdLineRunner::new("/usr/bin/arch")
.arg("-x86_64")
.arg(path.clone());
}
}
let cmd = cmd.with_pr(pr).env_clear().envs(&self.env);
if let Err(e) = cmd.execute() {
let status = match e.downcast_ref::<Error>() {
Some(ScriptFailed(_, status)) => *status,
Expand Down
Loading