DEV Community

Cover image for Publish a simple executable from Rust on Chocolatey 🍫
Thomas Gotwig
Thomas Gotwig

Posted on • Updated on

Publish a simple executable from Rust on Chocolatey 🍫

The most comfortable way to install software on Windows is thorugh Chocolatey 🍫 And in this guide you will learn how to do that! 🀩 At least for simple executables 🐣

I successfully published my Rust app vidmerger in that way! 🎞✨

🐣 Initializing

First of all install the cli-tool for Chocolatey:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Enter fullscreen mode Exit fullscreen mode

Then run choco new my-app to generate a folder called my-app with the following content:

my-app
β”œβ”€β”€ ReadMe.md
β”œβ”€β”€ _TODO.txt
β”œβ”€β”€ my-app.nuspec
└── tools
    β”œβ”€β”€ LICENSE.txt
    β”œβ”€β”€ VERIFICATION.txt
    β”œβ”€β”€ chocolateybeforemodify.ps1
    β”œβ”€β”€ chocolateyinstall.ps1
    └── chocolateyuninstall.ps1
Enter fullscreen mode Exit fullscreen mode

The minimal setup for publishing would look like:

my-app
β”œβ”€β”€ my-app.nuspec
└── tools
    β”œβ”€β”€ LICENSE.txt
    └── VERIFICATION.txt
Enter fullscreen mode Exit fullscreen mode

The *.ps1 files are basically for defining shell commands which run on beforemodify, install and uninstall. We don't really need them for publishing a simple executable.

Put your *.exe file from Rust or whatever into the tools folder πŸ¦€

βš™οΈ Modifying

I think I'll just show you here my three modified files from my Rust app vidmerger, modify them accordingly πŸ‘‡

🎴 my-app.nuspec

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
  <metadata>
    <id>vidmerger</id>
    <version>0.1.2</version>
    <title>vidmerger</title>
    <authors>Thomas Gotwig</authors>
    <projectUrl>https://github.com/tgotwig/vidmerger</projectUrl>
    <tags>video cli</tags>
    <summary>A wrapper around ffmpeg which simplifies merging multiple videos 🎞</summary>
    <description>Vidmerger is a command-line-tool which uses `ffmpeg` to merge multiple video-files with the same file-extension together into one file called `output.FORMAT`. It includes a usage help which you can print out by `vidmerger --help` πŸ˜ƒ</description>
  </metadata>
  <files>
    <file src="tools\**" target="tools" />
  </files>
</package>
Enter fullscreen mode Exit fullscreen mode

🎴 LICENSE.txt

Copyright 2020 Thomas Gotwig

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Enter fullscreen mode Exit fullscreen mode

🎴 VERIFICATION.txt

Generated by `CertUtil -hashfile vidmerger.exe SHA256`:

1268967539be0449126438887170c779aaea6fdbf4d835e529c77d4c56a7f75d
Enter fullscreen mode Exit fullscreen mode

Think on updating the hash inside of VERIFICATION.txt before pushing 🧐

πŸš€ Pushing

Before you can push something, you'll need to login on your choco-cli first, to do so, go on https://chocolatey.org/account, do a login there and click on Show API Key, run that listed commands in your console.

Finally lets push it to Chocolatey! πŸ˜ƒ

cpack
Get-ChildItem *.nupkg | ren -NewName vidmerger.nupkg
choco push vidmerger.nupkg --source https://push.chocolatey.org
Remove-Item vidmerger.nupkg
Enter fullscreen mode Exit fullscreen mode

That's all! 😊🍫

Discussion (0)