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: Proof of concept: Use ubi as a library instead of as a binary #2290

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
242 changes: 187 additions & 55 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ tokio = { version = "1.37.0", features = [
] }
toml = { version = "0.8.12", features = ["parse"] }
toml_edit = { version = "0.22.12", features = ["parse"] }
ubi = "0.1.0"
url = "2.5.0"
usage-lib = { version = "0.3", features = ["clap"] }
versions = { version = "6.2.0", features = ["serde"] }
Expand Down
1 change: 0 additions & 1 deletion docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,6 @@ Examples:
$ mise registry
node core:node
poetry asdf:mise-plugins/mise-poetry
ubi cargo:ubi
```

## `mise reshim`
Expand Down
9 changes: 0 additions & 9 deletions docs/dev-tools/backends/ubi.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ You may install GitHub Releases and URL packages directly using [ubi](https://gi

The code for this is inside of the mise repository at [`./src/backend/ubi.rs`](https://github.com/jdx/mise/blob/main/src/backend/ubi.rs).

## Dependencies

This relies on having `ubi` installed. You can install it with or without mise.
Here is how to install `ubi` with mise:

```sh
mise use -g cargo:ubi
```

## Usage

The following installs the latest version of goreleaser
Expand Down
2 changes: 0 additions & 2 deletions e2e/backend/test_ubi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env bash

curl -sSf -L https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh | TARGET="$HOME/bin" sh

assert "mise x ubi:goreleaser/goreleaser@v1.25.0 -- goreleaser -v | grep -o 1.25.0" "1.25.0"
1 change: 0 additions & 1 deletion mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,6 @@ cmd "registry" help="[experimental] List available tools" {
$ mise registry
node core:node
poetry asdf:mise-plugins/mise-poetry
ubi cargo:ubi
"
}
cmd "reshim" help="rebuilds the shim farm" {
Expand Down
43 changes: 26 additions & 17 deletions src/backend/ubi.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::fmt::Debug;

use eyre::eyre;
use ubi::UbiBuilder;

use crate::backend::{Backend, BackendType};
use crate::cache::CacheManager;
use crate::cli::args::BackendArg;
use crate::cmd::CmdLineRunner;
use crate::config::{Config, Settings};
use crate::config::Settings;
use crate::env::GITHUB_TOKEN;
use crate::github;
use crate::install_context::InstallContext;
Expand All @@ -28,10 +30,9 @@ impl Backend for UbiBackend {
}

fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result<Vec<BackendArg>> {
Ok(vec!["cargo:ubi".into()])
Ok(vec![])
}

// TODO: v0.0.3 is stripped of 'v' such that it reports incorrectly in tool :-/
fn _list_remote_versions(&self) -> eyre::Result<Vec<String>> {
if name_is_url(self.name()) {
Ok(vec!["latest".to_string()])
Expand All @@ -49,31 +50,39 @@ impl Backend for UbiBackend {
}

fn install_version_impl(&self, ctx: &InstallContext) -> eyre::Result<()> {
let config = Config::try_get()?;
let settings = Settings::get();
let version = &ctx.tv.version;
settings.ensure_experimental("ubi backend")?;
// Workaround because of not knowing how to pull out the value correctly without quoting
let path_with_bin = ctx.tv.install_path().join("bin");

let mut cmd = CmdLineRunner::new("ubi")
.arg("--in")
.arg(path_with_bin)
.arg("--project")
.arg(self.name())
.with_pr(ctx.pr.as_ref())
.envs(ctx.ts.env_with_path(&config)?)
.prepend_path(ctx.ts.list_paths())?;
let mut builder = UbiBuilder::new()
.project(self.name())
.install_dir(path_with_bin);

if let Some(token) = &*GITHUB_TOKEN {
cmd = cmd.env("GITHUB_TOKEN", token);
builder = builder.github_token(token);
}

let version = &ctx.tv.version;
if version != "latest" {
cmd = cmd.arg("--tag").arg(version);
builder = builder.tag(version);
}

cmd.execute()
let exe = std::env::var("MISE_TOOL_OPTS__EXE").unwrap_or_default();
if !exe.is_empty() {
builder = builder.exe(&exe);
}
let matching = std::env::var("MISE_TOOL_OPTS__MATCHING").unwrap_or_default();
if !matching.is_empty() {
builder = builder.matching(&matching);
}

let u = builder.build().map_err(|e| eyre!(e))?;

let rt = tokio::runtime::Builder::new_current_thread()
.enable_io()
.build()?;
rt.block_on(u.install_binary()).map_err(|e| eyre!(e))
}
}

Expand Down
1 change: 0 additions & 1 deletion src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use once_cell::sync::Lazy;
use std::collections::BTreeMap;

const _REGISTRY: &[(&str, &str)] = &[
("ubi", "cargo:ubi"),
("cargo-binstall", "cargo:cargo-binstall"),
// ("elixir", "asdf:mise-plugins/mise-elixir"),
];
Expand Down
Loading