From a096949e83b3054c9aa237336a2347effd4f2f05 Mon Sep 17 00:00:00 2001 From: "N.N" <113419913+nnlq@users.noreply.github.com> Date: Mon, 7 Nov 2022 22:10:02 +0700 Subject: fix(rustfmt): use correct asset names and use unzip on windows (#644) --- lua/mason-registry/rustfmt/init.lua | 40 ++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'lua') diff --git a/lua/mason-registry/rustfmt/init.lua b/lua/mason-registry/rustfmt/init.lua index e8a03daf..c53aa98a 100644 --- a/lua/mason-registry/rustfmt/init.lua +++ b/lua/mason-registry/rustfmt/init.lua @@ -2,6 +2,7 @@ local Pkg = require "mason-core.package" local _ = require "mason-core.functional" local platform = require "mason-core.platform" local github = require "mason-core.managers.github" +local path = require "mason-core.path" local coalesce, when = _.coalesce, _.when @@ -11,22 +12,29 @@ return Pkg.new { homepage = "https://github.com/rust-lang/rustfmt", categories = { Pkg.Cat.Formatter }, languages = { Pkg.Lang.Rust }, + ---@async + ---@param ctx InstallContext install = function(ctx) - ---@param template_string string - local function release_file(template_string) - return _.compose(_.format(template_string), _.gsub("^v", "")) - end - - github - .untargz_release_file({ - repo = "rust-lang/rustfmt", - asset_file = coalesce( - when(platform.is.mac, release_file "rustfmt_macos-x86_64_%s.tar.gz"), - when(platform.is.linux_x64, release_file "rustfmt_linux-x86_64_%s.tar.gz"), - when(platform.is.win_x64, release_file "rustfmt_windows-x86_64-msvc_%s.tar.gz") - ), - }) - .with_receipt() - ctx:link_bin("rustfmt", platform.is.win and "rustfmt.exe" or "rustfmt") + platform.when { + unix = function() + local source = github.untargz_release_file { + repo = "rust-lang/rustfmt", + asset_file = coalesce( + when(platform.is.mac, _.format "rustfmt_macos-x86_64_%s.tar.gz"), + when(platform.is.linux_x64, _.format "rustfmt_linux-x86_64_%s.tar.gz") + ), + } + source.with_receipt() + ctx:link_bin("rustfmt", path.concat { source.asset_file:gsub("%.tar%.gz$", ""), "rustfmt" }) + end, + win = function() + local source = github.unzip_release_file { + repo = "rust-lang/rustfmt", + asset_file = coalesce(when(platform.is.win_x64, _.format "rustfmt_windows-x86_64-msvc_%s.zip")), + } + source.with_receipt() + ctx:link_bin("rustfmt", path.concat { source.asset_file:gsub("%.zip$", ""), "rustfmt.exe" }) + end, + } end, } -- cgit v1.2.3-70-g09d2