Skip to content

Windows Installation

Tad Hardesty edited this page May 22, 2016 · 2 revisions

Following is a comprehensive guide to compiling discord-rs on Windows using MSYS2. If you find any errors or need help, please visit the Discord channel linked in the README.

  1. Visit https://msys2.github.io and download the appropriate binary based on your host system.
    1. i686 for 32-bit Windows.
    2. x86_64 for 64-bit Windows, even if you intend to compile 32-bit software.
  2. Run the installer, following the instructions on that page for installing updates.
    1. Choose a relatively short path with no spaces (say, C:\msys64 or D:\tools\msys2)
    2. If asked to restart MSYS, close the shell window and re-open it from the start menu. Any of the three choices will work for now.
    3. Note: Some MSYS versions have a bug where running a shell will open two windows. Use the one with the purple "M" logo, and close the other.
  3. Here's a brief explanation of the three different shortcuts in the start menu:
    1. MSYS2 Shell is used for developing software that will always run inside MSYS2.
    2. MinGW-w64 Win32 Shell is used for developing 32-bit Windows software.
    3. MinGW-w64 Win64 Shell is used for developing 64-bit Windows software. This will be your usual choice.
  4. It's time to install Rust. To allow for greatest flexibility, rustup.rs will be used. This is the latest iteration on the previous multirust.rs and multirust.sh tools. 2. Navigate to https://win.rustup.rs/ to download the rustup installer. 3. Run the installer. After reading the information, press Enter to accept the default options and begin installation. 4. The installer will advise you to restart your current shell - close it now, but do not reopen it yet.
  5. Create a shortcut to start MSYS2 with an important setting.
    1. Navigate to your MSYS2 installation and find mingw64_shell.bat.
    2. Right-click it and select "Create shortcut".
    3. Open the shortcut's properties and add the argument -use-full-path to the end of the Target.
    4. If desired, change the shortcut's icon to one of the icons available in the MSYS2 installation.
    5. Move the shortcut to your Desktop and/or Start Menu.
    6. Run the shortcut you just created to open the MINGW64 shell.
  6. Configure Rust to compile 64-bit by default.
    1. Run rustup default stable-x86_64-pc-windows-gnu (or replace stable with beta or nightly if desired)
    2. Running rustc -Vv should list your chosen Rust version, as well as host: x86_64-pc-windows-gnu
    3. If host: i686-pc-windows-gnu is displayed instead, you have done something wrong.
  7. Install all of discord-rs's required system packages: pacman -S mingw-w64-x86_64-pkg-config mingw-w64-x86_64-libsodium mingw-w64-x86_64-gcc mingw-w64-x86_64-openssl mingw-w64-x86_64-opus
  8. Use cd to navigate to a directory of your choosing to keep Rust projects in.
    1. The root directory, /, maps to the root of your MSYS2 install.
    2. The default working directory is /home/Username, displayed as ~.
    3. To get to a directory on drive C, write cd /c/path/to/directory.
  9. Compile a discord-rs examples to make sure everything is working.
    1. Install git by running pacman -S git.
    2. Clone discord-rs by running git clone https://github.com/SpaceManiac/discord-rs.
    3. Move into the directory: cd discord-rs.
    4. Use Cargo to build an example: cargo build --example dj. Be patient while it compiles.
    5. If it compiled successfully, you are good to go.
  10. Now that the example is compiling, try running it. Just a couple steps to go.
    1. The DJ example requires FFMPEG and Youtube-dl installed, which are only needed for voice features.
    2. Install FFMPEG using pacman -S mingw-w64-x86_64-ffmpeg.
    3. Download the "Windows exe" from the youtube-dl site and place it inside /mingw64/bin.
    4. Run export DISCORD_TOKEN=abcdefg, with your bot's token instead, to set the environment variable the DJ example will read.
    5. Run cargo run --example dj to start the bot.
    6. Join a voice channel on a server you have invited the bot to, and message !dj a-youtube-url.
    7. You should hear the bot playing audio.
  11. You can now create a project that depends on discord-rs with ease.
    1. To use the latest git version (which is often newer than the latest crates.io release), write in Cargo.toml:
      discord = { git = "https://github.com/SpaceManiac/discord-rs" }
Clone this wiki locally