summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2021-07-22 02:00:20 +0200
committerLéo Lam <leo@leolam.fr>2021-07-22 02:45:01 +0200
commit5d7fa0aede10c21f0b0b3d98f62e101a4da43f43 (patch)
tree4018d11dda8786a273f28a579f41709597a3716d
parent8cf3dd776bf5a839f9941059ccb7b28e27c6791f (diff)
Simplify build setup by adding a setup script
-rw-r--r--README.md52
-rwxr-xr-xtools/setup.py87
2 files changed, 124 insertions, 15 deletions
diff --git a/README.md b/README.md
index 9a8179fa..0b5ccbfd 100644
--- a/README.md
+++ b/README.md
@@ -122,32 +122,54 @@ Just like other game decompilations, this project is probably in a legal gray zo
### Alright, how do I start contributing?
-First, set up the build environment by following the instructions below. Then follow the [contributing guidelines here](Contributing.md).
+First, set up the build environment by following the instructions below.
## Building
-### Dependencies
+Reminder: **this will not produce a playable game.** This project will not allow you to play the game if you don't already own it on a Switch.
+
+### For Windows users
+
+While Linux is not a hard requirement, it is strongly advised to [set up WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10) to simplify the setup process. Ubuntu 20.04 is usually a good choice.
-* Clang 4.0.1
- * Download [Clang 4.0.1](https://releases.llvm.org/download.html#4.0.1) and extract the archive to a convenient location of your choice.
- * You might also need libtinfo5. For Ubuntu or Debian users, install it with `sudo apt install libtinfo5`
+The instructions below assume that you are using Linux (native or WSL) or macOS.
+
+### 1. Set up dependencies
+
+* Python 3.6 or newer
* Ninja
- * For Ubuntu or Debian users, install it with `sudo apt install ninja-build`
* CMake 3.13+
- * If you are on Ubuntu 18.04, you must [update CMake by using the official CMake APT repository](https://apt.kitware.com/).
+ * If you are on Ubuntu 18.04, you must first [update CMake by using the official CMake APT repository](https://apt.kitware.com/).
+* [Optional] ccache (to speed up builds)
-Using Linux (or WSL) is recommended but not required. The rest of this guide assumes that you are using a Linux environment, though.
+Ubuntu users can install those dependencies by running:
-### Building for Switch
+```shell
+sudo apt install python3 ninja-build cmake ccache
+```
-1. After cloning this repository, run: `git submodule update --init --recursive`
-2. Run: `env UKING_CLANG=$$$$$ cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_TOOLCHAIN_FILE=toolchain/ToolchainNX64.cmake -B build`
- * Replace `$$$$$` with the path to the extracted Clang archive, such that `$1/bin/clang` exists. This should be an absolute path; use `/home/<name>` instead of `~`.
-3. Start the build by running: `ninja -C build`
+### 2. Set up the repository
-On subsequent builds, just run `ninja -C build` from the project root.
+1. Clone this repository.
+2. Run `git submodule update --init --recursive`
+3. Run `tools/setup.py`
+ * This will set up [Clang 4.0.1](https://releases.llvm.org/download.html#4.0.1) and create a build directory in `build/`.
-Reminder: **this will not produce a playable game.** This project will not allow you to play the game if you don't already own it on a Switch.
+### 3. Build
+
+To start the build, just run
+
+```shell
+ninja -C build
+```
+
+By default, Ninja will perform a multithreaded build. There is no need to pass -j manually.
+
+To check whether everything built correctly, just run `tools/check.py` after the build completes.
+
+## Contributing
+
+Follow the [contributing guidelines here](Contributing.md).
## Resources
diff --git a/tools/setup.py b/tools/setup.py
new file mode 100755
index 00000000..b495e89a
--- /dev/null
+++ b/tools/setup.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python3
+
+import os
+import platform
+from pathlib import Path
+import sys
+import tarfile
+import tempfile
+import urllib.request
+
+ROOT = Path(__file__).parent.parent
+
+
+def fail(error: str):
+ print(error)
+ sys.exit(1)
+
+
+def set_up_compiler():
+ compiler_dir = ROOT / "toolchain" / "clang"
+ if compiler_dir.is_dir():
+ print("clang is already set up: nothing to do")
+ return
+
+ system = platform.system()
+ machine = platform.machine()
+
+ builds = {
+ # Linux
+ ("Linux", "x86_64"): {
+ "url": "https://releases.llvm.org/4.0.1/clang+llvm-4.0.1-x86_64-linux-gnu-Fedora-25.tar.xz",
+ "dir_name": "clang+llvm-4.0.1-x86_64-linux-gnu-Fedora-25",
+ },
+ ("Linux", "aarch64"): {
+ "url": "https://releases.llvm.org/4.0.1/clang+llvm-4.0.1-aarch64-linux-gnu.tar.xz",
+ "dir_name": "clang+llvm-4.0.1-aarch64-linux-gnu",
+ },
+
+ # macOS
+ ("Darwin", "x86_64"): {
+ "url": "https://releases.llvm.org/4.0.1/clang+llvm-4.0.1-x86_64-apple-darwin.tar.xz",
+ "dir_name": "clang+llvm-4.0.1-x86_64-apple-darwin",
+ },
+ ("Darwin", "aarch64"): {
+ "url": "https://releases.llvm.org/4.0.1/clang+llvm-4.0.1-x86_64-apple-darwin.tar.xz",
+ "dir_name": "clang+llvm-4.0.1-x86_64-apple-darwin",
+ },
+ }
+
+ build_info = builds.get((system, machine))
+ if build_info is None:
+ fail(
+ f"unknown platform: {platform.platform()} (please report if you are on Linux and macOS)")
+
+ url: str = build_info["url"]
+ dir_name: str = build_info["dir_name"]
+
+ print(f"downloading Clang from {url}...")
+ with tempfile.TemporaryDirectory() as tmpdir:
+ path = tmpdir + "/" + url.split("/")[-1]
+ urllib.request.urlretrieve(url, path)
+
+ print(f"extracting Clang...")
+ with tarfile.open(path) as f:
+ f.extractall(compiler_dir.parent)
+ (compiler_dir.parent / dir_name).rename(compiler_dir)
+
+ print(">>> successfully set up Clang")
+
+
+def create_build_dir():
+ build_dir = ROOT / "build"
+ if build_dir.is_dir():
+ print("build directory already exists: nothing to do")
+ return
+
+ os.system("cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_TOOLCHAIN_FILE=toolchain/ToolchainNX64.cmake -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -B build/")
+ print(">>> created build directory")
+
+
+def main():
+ set_up_compiler()
+ create_build_dir()
+
+
+if __name__ == "__main__":
+ main()