Skip to content

Instantly share code, notes, and snippets.

@LOuroboros
Last active December 29, 2023 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LOuroboros/5dc867a0f376bd1effaf9fc934d90495 to your computer and use it in GitHub Desktop.
Save LOuroboros/5dc867a0f376bd1effaf9fc934d90495 to your computer and use it in GitHub Desktop.
[center]
27 of January from 2023. I'm rewriting this tutorial. I should have done it much sooner, but y'all know me; I'm lazy.
What are the goals? To explain in simple steps how to set up an environment to build Pret's Pokémon Decompilation Projects on WSL.
What is being added? Explanations on how to set up a WSL2 environment and considerations to keep in mind and such.
What's driving me to do this after so long? Devkitpro, in a way. I won't say more.
Let's get to it.
Before we start, I'll need you to make a choice; WSL1 or WSL2.
[size=4][b]List of Pros and Cons[/b][/size]:
[spoiler]
[b][color=SeaGreen]Advantages[/color] of using [u]WSL1[/u][/b]:
-Fast work speed on Windows' own filesystem.
-Much faster than Cygwin or MSys2.
[b][color=Red]Disadvantages[/color] of using [u]WSL1[/u][/b]:
-Considerably slower than WSL2, unless your hardware can power through to close the gap.
[b][color=SeaGreen]Advantages[/color] of using [u]WSL2[/u][/b]:
-Super fast work speed on its Linux distributions' own filesystem.
-Considerably faster than WSL1.
[b][color=Red]Disadvantages[/color] of using [u]WSL2[/u][/b]:
-Working on Windows' own filesystem is [i]slow[/i]. [url=https://github.com/microsoft/WSL/issues/4197]It's a known issue[/url]. This means you WILL want to do your work on the Linux filesystem exclusively.
[/spoiler]
After you made up your choice, follow the correspondent section of the tutorial.
Personally, I do my decomp work on the filesystem of my Ubuntu installation using WSL2.
[size=4][b]WSL1[/b][/size]:
[spoiler]
[B]1)[/B] Open the Windows Command Prompt as Administrator (look up "Command Prompt on your Start Menu, Right Click -> Run as Administrator).
After that, execute the following command:
[code]dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all[/code]
When the process finishes you'll have to restart your PC by pressing "Y" to finish the process. Keep that in mind.
[B]2)[/B] Go to the Microsoft Store and search "Ubuntu". Enter the page for the version with the highest version numer.
At the time of this writing, it's Ubuntu 22.04.1 LTS.
[I]If for X or Y reason you don't have access to the Microsoft Store, check the FAQ. I explain how to install Ubuntu manually through a .appx package there.[/I]
The installation is as straightforward as any other program's. Open it, hit Install and wait until it's done.
Launch Ubuntu when the installation finishes, so it can start its own setup.
When Ubuntu opens, we'll be greeted by a command line window telling us that Ubuntu is: "[I]Installing, this may take a few minutes...[/I]".
Once we're ready to proceed, we'll be asked to introduce a username [I](in lowercase letters)[/I] and a password. Don't worry if you can't see the latter as you're typing it, it's a security measure.
After that, the installation will be completed and we can safely close the window of Ubuntu.
Why is that? Because from here on, we'll run Ubuntu by typing "[B]wsl[/B]" on the Run window [I](Win Key + R)[/I].
By running WSL this way, we'll be taken directly to the Windows Filesystem instead of Ubuntu's. More specifically, WSL will always open pointing to the [B]C:\Users\USER[/B] folder.
[B]3)[/B] The very first thing you generally do after installing a distribution of Linux, is to update its list of packages.
To do this, we'll use the following merged command:
[code]sudo apt update -y && sudo apt upgrade -y[/code]
Once we hit Enter, we will see that Ubuntu will retrieve different lists of packages from multiple sources. This is done so it can find the latest versions of each package and library you need.
When that process is completed, Ubuntu will then update all the packages obtaining the latest files from said sources.
Keep in mind that [B]this process [I]may[/I] take a long time[/B]. There's nothing to be done about it. Endure it.
Thanks to the [icode]-y[/icode] argument, the process should happen completely on its own without any intervention of your own. Just let it run until it's all done.
Is it done yet? Good. Let's move on.
[B]4)[/B] Now we are ready to install the packages that the decomps need in order to be built.
To install them, we will use:
[code]sudo apt install build-essential git libpng-dev[/code]
Alternatively, if for whatever reason the command above gave you an error, try:
[code]sudo apt-get install build-essential git libpng-dev[/code]
We'll be asked to confirm the installation with "y". We do so, press Enter and wait.
At this point, [B]there's [U]2 options[/U] we can take[/B] in order to proceed.
The first one is to install devkitpro-pacman and through it, devkitARM, to get its own distribution of GCC which is used by both, older and newer versions of Pokeemerald, and perhaps Pokefirered.
The second is to install the package [icode]binutils-arm-none-eabi[/icode] in the exact same manner we installed the other prerequisite packages above.
What's the difference? Devkitpro allows you to run copies of Pokeemerald made both, before and after June 2021, while [icode]binutils-arm-none-eabi[/icode] does not.
Also keep in mind that devkitPro's developers do not offer support for certain operating systems after X amount of time.
If you came across unexpected errors here, please refer to the FAQ Section of this post.
Choose whichever option you prefer.
[B]devkitPro[/B]:
[spoiler][B]5)[/B] The next thing we'll do is to install devkiPro Pacman.
In order to do this we'll use the following commands:
[quote][center]
cd /mnt/c/Users/USER/Downloads
sudo apt install wget
wget [url]https://apt.devkitpro.org/install-devkitpro-pacman[/url]
chmod +x ./install-devkitpro-pacman
sudo ./install-devkitpro-pacman
[/center][/quote]
[I][B]Note[/B]: If your Windows account username contains empty spaces, you will need to use reverse backslashes to parse them.
For example, if your Windows username is "Alfredo's Computer", you will need to input your path like this: [icode]cd /mnt/c/Users/Alfredo's\ Computer/Downloads[/icode].[/I]
What these commands do is:
- Go to the user's Downloads folder.
-Download the script called "install-devkitpro-pacman" in there.
- Give permissions to execute it.
- Execute it.
Next we'll install the GBA Development package of devkitPro by using:
[code]sudo dkp-pacman -S gba-dev[/code]
After we input this command, devkitPro Pacman will let us choose specific packages within the gba-dev package to download.
We'll just press Enter to tell it that we want all of them, and then we'll be asked if we want to proceed with the installation, to which we'll say "y" and then press Enter again.
[B]6)[/B] Close WSL and open it again so devkitPro will make some variables that it needs for its correct functioning.
You can double check if they were made successfully by typing [icode]echo $DEVKITPRO[/icode] and/or [icode]echo $DEVKITARM[/icode].
If they return the following paths: [icode]/opt/devkitpro[/icode] and [icode]/opt/devkitpro/devkitARM[/icode] respectively, then we're done here.
Congratulations, now you're ready to build the decomps.[/spoiler]
[B]binutils[/B]:
[spoiler]
[B]5)[/B] [code]sudo apt install binutils-arm-none-eabi[/code]
Alternatively, if for whatever reason the command above gave you an error, try:
[code]sudo apt-get install binutils-arm-none-eabi[/code]
[B]6)[/B] Close WSL and open it again as previous told, Win Key + R -> [icode]wsl[/icode][/spoiler]
[B]7)[/B] Alright, so, we're currently in [B]C:\Users\USER[/B], aren't we? We did have to restart WSL just now, after all.
Let's make a dedicated folder to use for our decomps needs here. You know, to keep things clean.
[code]mkdir Decomps[/code]
Good, let's move to this new folder by using:
[code]cd Decomps[/code]
[B]8)[/B] Now, we have to clone agbcc, and our desired decompilation project.
[code]git clone https://github.com/pret/agbcc
git clone https://github.com/pret/pokeemerald[/code]
[I][B]Note[/B]: Pokeruby, Pokefirered and Pokeemerald all follow the exact same installation instructions.[/I]
If you came across unexpected errors here, please refer to the FAQ Section of this post.
[B]9)[/B] Let's build agbcc and install it in our decomp by using:
[code]cd agbcc
./build.sh
./install.sh ../pokeemerald[/code]
[B]10)[/B] And lastly, let's build a ROM.
[code]cd ../pokeemerald
make -jN[/code]
[I][B]Note[/B]: "N" stands for the number of CPU Threads you want to assign to the compiler. The more threads, the faster it'll go.[/I]
[I][B]Note2[/B]: You can use [icode]nproc[/icode] to quickly check the amount of threads your CPU has.[/I]
Also, keep in mind that every time you boot up WSL by using Win Key + R -> [icode]wsl[/icode], you'll start from [B]C:\Users\USER[/B], so you'll always start your work by doing:
[code]cd Decomps
cd pokeemerald[/code]
[/spoiler]
[size=4][b]WSL2[/b][/size]:
[spoiler]
[b]1)[/b] This bizarre adventure will start by opening an instance of the Windows Command Prompt or Windows PowerShell with Admin. rights, and typing in [icode]wsl --install[/icode].
This command will handle basically every single part of the setup automatically.
It will enable WSL, it will install any prerequisites, it will enable WSL2 and it will even install a copy of Linux Ubuntu for us.
We simply need to wait until it's done, and then restart our PC when we're told that "[i]Changes will not be effective until the system is rebooted.[/i]"
For those who don't like or can't rely on this painless and automatic method, refer to the FAQ. I'll mention how to enable WSL2 manually there.
[b]2)[/b] After we're back on Windows, we'll be greeted by a command line window telling us that WSL is resuming its installation of Ubuntu.
Once it's all done, we'll be asked to introduce a username [I](in lowercase letters)[/I] and a password.
[i]Don't worry if you can't see the latter as you're typing it, it's a security measure.[/i]
After we introduce our credentials, we're going to be thrown directly into the root folder of our installation of Ubuntu.
Unlike in WSL1, on WSL2 we'll work exclusively on the filesystem of our Linux Ubuntu installation.
[i]Check the list of pros and cons at the beginning of this post to learn why.[/i]
On WSL2 we will never want to do any operations inside the Windows filesystem, thus, we'll always work on Linux Ubuntu's home folder.
You can come back to this folder whenever you want by simply typing [icode]cd[/icode] as is, without specifying any arguments.
If we want or need to open this folder directlyc, the quickest way is to type in [icode]cd[/icode] followed by [icode]explorer.exe .[/icode] and hit Enter.
The latter will open an instance of Windows Explorer in the folder that our WSL terminal is currently looking at.
[i][b]Fun fact[/b]: this trick also works on the command prompt, on PowerShell, on Cygwin and also on MSys2.[/i]
Now that we know the basics about moving around on our Linux Ubuntu's filesystem, let us proceed.
[B]3)[/B] The very first thing we'll want to do after installing a distro of Linux, is to update its list of packages.
To do this, we'll use the following merged command:
[code]sudo apt update -y && sudo apt upgrade -y[/code]
Once we hit Enter, we will see that Ubuntu will retrieve different lists of packages from multiple sources. This is done so it can find the latest versions of each package and library you need.
When that process is completed, Ubuntu will then update all the packages obtaining the latest files from said sources.
Keep in mind that [B]this process [I]may[/I] take a long time[/B]. There's nothing to be done about it. Endure it.
Thanks to the [icode]-y[/icode] argument, the process should happen completely on its own without any intervention of your own. Just let it run until it's all done.
Is it done yet? Good. Let's move on.
[B]4)[/B] Now we are ready to install the packages that the decomps need in order to be built.
To install them, we will use:
[code]sudo apt install build-essential git libpng-dev[/code]
Alternatively, if for whatever reason the command above gave you an error, try:
[code]sudo apt-get install build-essential git libpng-dev[/code]
We'll be asked to confirm the installation with "y". We do so, press Enter and wait.
At this point, [B]there's [U]2 options[/U] we can take[/B] in order to proceed.
The first one is to install devkitpro-pacman and through it, devkitARM, to get its own distribution of GCC which is used by both, older and newer versions of Pokeemerald, and perhaps Pokefirered.
The second is to install the package [icode]binutils-arm-none-eabi[/icode] in the exact same manner we installed the other prerequisite packages above.
What's the difference? Devkitpro allows you to run copies of Pokeemerald made both, before and after June 2021, while [icode]binutils-arm-none-eabi[/icode] does not.
Also keep in mind that devkitPro's developers do not offer support for certain operating systems after X amount of time.
If you came across unexpected errors here, please refer to the FAQ Section of this post.
Choose whichever option you prefer.
[B]devkitPro[/B]:
[spoiler][B]5)[/B] The next thing we'll do is to install devkiPro Pacman.
In order to do this we'll use the following commands:
[quote][center]
sudo apt install wget
wget [url]https://apt.devkitpro.org/install-devkitpro-pacman[/url]
chmod +x ./install-devkitpro-pacman
sudo ./install-devkitpro-pacman
[/center][/quote]
What these commands do is:
-Download the script called "install-devkitpro-pacman" in whatever folder WSL2 is currently looking at.
- Give root permissions to execute it.
- Execute it.
Next we'll install the GBA Development package of devkitPro by using:
[code]sudo dkp-pacman -S gba-dev[/code]
After we input this command, devkitPro Pacman will let us choose specific packages within the gba-dev package to download.
We'll just press Enter to tell it that we want all of them, and then we'll be asked if we want to proceed with the installation, to which we'll say "y" and then press Enter again.
[B]6)[/B] Close WSL and open it again so devkitPro will make some variables that it needs for its correct functioning.
You can double check if they were made successfully by typing [icode]echo $DEVKITPRO[/icode] and/or [icode]echo $DEVKITARM[/icode].
If they return the following paths: [icode]/opt/devkitpro[/icode] and [icode]/opt/devkitpro/devkitARM[/icode] respectively, then we're done here.
Congratulations, now you're ready to build the decomps.[/spoiler]
[B]binutils[/B]:
[spoiler]
[B]5)[/B] [code]sudo apt install binutils-arm-none-eabi[/code]
Alternatively, if for whatever reason the command above gave you an error, try:
[code]sudo apt-get install binutils-arm-none-eabi[/code]
[B]6)[/B] Close WSL and open it again as previous told, Win Key + R -> [icode]wsl[/icode][/spoiler]
[B]7)[/B] Alright, so, we're currently in the root folder of the filesystem of our Linux Ubuntu installation, opened inside of WSL2.
We can either work here directly, or make a folder using the [icode]mkdir[/icode] command to work in and move to it using the [icode]cd name_of_the_folder[/icode] command. It's up to you.
Personally, I do my work in my root folder directly. That is, again, the folder that we're taken to when we type [icode]cd[/icode] as is.
[B]8)[/B] Now, we have to clone agbcc, and our desired decompilation project.
[code]git clone https://github.com/pret/agbcc
git clone https://github.com/pret/pokeemerald[/code]
[I][B]Note[/B]: Pokeruby, Pokefirered and Pokeemerald all follow the exact same installation instructions.[/I]
If you came across unexpected errors here, please refer to the FAQ Section of this post.
[B]9)[/B] Let's build agbcc and install it in our decomp by using:
[code]cd agbcc
./build.sh
./install.sh ../pokeemerald[/code]
[B]10)[/B] And lastly, let's build a ROM.
[code]cd ../pokeemerald
make -jN[/code]
[I][B]Note[/B]: "N" stands for the number of CPU Threads you want to assign to the compiler. The more threads, the faster it'll go.[/I]
[I][B]Note2[/B]: You can use [icode]nproc[/icode] to quickly check the amount of threads your CPU has.[/I]
[/spoiler]
[size=4][b][i](Not Really)[/i] Frequently Asked Questions [i](FAQ)[/i][/b][/size]:
[spoiler]
[b]1) You said we could install Ubuntu through a .appx package instead of using the Windows Store. Can you please elaborate?[/b]
.appx files are packages that act as compressed folders and installers at the same time.
You can [B][URL="https://learn.microsoft.com/en-us/windows/wsl/install-manual#downloading-distributions"]download Ubuntu in the form of a .appx package[/URL][/B], double click it, and then follow its installation process to get it installed on your computer.
[I][B]Note[/B]: The most commonly suggested distro to stick with is Ubuntu. Make sure to grab the latest version available, which at the time of writing is the v22.04[/I]
[b]But[/b], thanks to the fact that they're still compressed folders at their core, we can also [i](at least in this case)[/i] just uncompress the package using WinRAR or 7Zip and use its contents as is.
After decompressing the package, you'll notice it contains a couple of files, a folder with metadata and some .appx packages.
The one you'll want is "Ubuntu_2204.1.7.0_x64.appx". Just put its files in a folder of your choice that you know you won't mess around with, and then execute the Ubuntu.exe file.
As a matter of fact, [url=https://i.imgur.com/hwqMPwx.png]this is the way in which I install distributions for WSL myself[/url].[h2]
[/h2]
[b]2) While installing devkitPro-pacman, I got an error ("[i]You do not have sufficient permissions to read the pacman keyring.[/i]"), what do?[/b]
[url=https://www.pokecommunity.com/showpost.php?p=10541422&postcount=97]Originally found by Subzero Eclipse[/url] and [url=https://github.com/devkitPro/pacman/issues/41#issuecomment-1405219574]later confirmed by a mantainer of devkitPro Pacman's repository[/url], devkitPro cuts support short for certain operating systems without warnings.
Basically, if you got this error you're using a version of Linux Ubuntu that devkitPro-pacman does not support.
What can you do?
You can either uninstall your current version and install a new one, or you can update your version from within your current installation.
I had Ubuntu 20.04, and for unrelated reasons, I had to update to the latest LTS version of Ubuntu myself.
How did I do it? By using the following command:
[code]
sudo do-release-upgrade
[/code]
This didn't happen to me, but [url=https://github.com/microsoft/WSL/discussions/3489]sometimes[/url], there's a chance you'll also need to remove the [icode]snapd[/icode] package.
That's done by typing in [icode]sudo apt purge snapd[/icode] followed by a [icode]sudo apt update -y && sudo apt upgrade -y[/icode], in order for [icode]sudo do-release-upgrade[/icode] to work properly.[h2]
[/h2]
[b]3) I came across an error like "[I]error: chmod on /mnt/c/Users/Lunos/Home/pokeemerald/.git/config.lock failed: Operation not permitted[/I]", what do?[/b]
Type the following commands:
[code]cd
sudo umount /mnt/c
sudo mount -t drvfs C: /mnt/c -o metadata[/code]
Then close WSL and open it again.[h2]
[/h2]
[b]4) [icode]wsl --install[/icode] didn't work, can you tell me how to enable WSL2 manually?[/b]
[url=https://learn.microsoft.com/en-us/windows/wsl/install-manual]You basically have to follow this article written by Microsoft[/url].
In simple terms:
First, you need to enable WSL1 as I already explain in this very tutorial.
Secondly, you need to enable the "Virtual Machine Platform" which is a feature located inside Windows Features' window which I also explain how to access there.
Thirdly, you need to install the WSL Kernel, [url=https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi]which can be downloaded from here[/url]
Fourthly, you need to open a command prompt and type in [icode]wsl --set-default-version 2[/icode], so any and all Linux distros you install will default to WSL2.
And that's it. Go back to the WSL2 tutorial, install Ubuntu normally, and continue from Step 2.[h2]
[/h2]
[b]5) Is there any specific detail I need to know about WSL2?[/b]
As far as I can think? No, not really.
Porymap and VSCode both work fine on copies of the decomps that are put in the Linux filesystem, so you're pretty much set.
If you need to browse the Linux filesystem, for example to open your project's folder on Porymap, Windows establishes a shared network between Windows and WSL.
If I have a Pokeemerald folder in my Linux Ubuntu filesystem's root folder. I can access it from Porymap by typing a path like [icode]\\wsl$\Ubuntu\home\your_linux_username\pokemerald[/icode].
It's the same path that you can see if you open your project's folder on Windows Explorer via [icode]explorer.exe .[/icode].
[/spoiler]
In case of need, I'm keeping an archived copy of this post as a GitHub Gist. [url=https://gist.github.com/LOuroboros/5dc867a0f376bd1effaf9fc934d90495]Click here to check it[/url].
I'm going to update it whenever I make changes to this post.
And that's pretty much it.
[/center]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment