This provides a powershell script (my-app-installer.ps1) which detects the current platform, fetches the best possible archive from your Artifact URL, copies the binary into your install-path, and attempts to add that path to the user's PATH (see the next section for details).
This kind of installer is ideal for bootstrapping setup on a fairly bare-bones system.
An "installer hint" will be provided that shows how to install via
irm | iex (the windows equivalent of
curl | sh), like so:
irm https://github.com/axodotdev/cargo-dist/releases/download/v0.0.5/cargo-dist-v0.0.5-installer.ps1 | iex
- Requires a well-defined Artifact URL
- Currently only really designed for "native windows", and won't detect other platforms properly
- Cannot detect situations where musl-based builds are appropriate (static or dynamic)
- Relies on the user's installation of
Expand-Archiveto unpack the files
- Relies on the the user's installation of
Net.Webclientto fetch the files
- Won't work if run in cmd instead of powershell
- Will throw out all files except for the binary, so the binary can't rely on assets included in the archive
- Cannot run any kind of custom install logic
On the scale of Windows (where many people are still running Windows 7) commands like "Expand-Archive" and "tar" are in fact relatively new innovations. Any system that predates 2016 (PowerShell 5.0) certainly has no hope of working. I believe that someone running Windows 10 is basically guaranteed to work, and anything before that gets sketchier.
In an ideal world most of these caveats improve (except for maybe the requirement of PowerShell >= 5.0 which is not pleasant to push past).
Here is a more fleshed out description of how the powershell installer attempts to add the install-path to the user's PATH, and the limitations of that process.
The most fundamental limitation is that installers fundamentally cannot edit the PATH of the currently running shell (it's a parent process). Powershell does not have an equivalent of
source, so to the best of our knowledge restarting the shell is the only option (which if using Windows Terminal seems to mean opening a whole new window, tabs aren't good enough). As such, it benefits an installer to try to install to a directory that will already be on PATH (such as CARGO_HOME). (rustup also sends a broadcast WM_SETTINGCHANGE message, but we couldn't find any evidence that this does anything useful.)
The process we use to add install-path to the user's PATH is roughly the same process that rustup uses (hopefully making us harmonious with running rustup before/after one of our installer scripts). In the following description we will use
$install-path as a placeholder for the path computed at install-time where the binaries get installed. Its actual value will likely look something like
- we load from the registry
HKCU:\Environment's "Path" Item
- we check if
$install-pathis contained within it already
- if not, we prepend it and write the value back
- prepending is used to ideally override system-installed binaries, as that is assumed to be desired when explicitly installing with not-your-system-package-manager
- if we edited the registry, we prompt the user to restart their shell