stack_wallet/docs/building.md

240 lines
10 KiB
Markdown
Raw Normal View History

2023-04-18 20:42:39 +00:00
# Building
Here you will find instructions on how to install the necessary tools for building and running the app.
## Prerequisites
2023-04-18 20:42:39 +00:00
- The only OS supported for building Android and Linux desktop is Ubuntu 20.04. Windows build are completed using Ubuntu 20.04 on WSL2. Advanced users may also be able to build on other Debian-based distributions like Linux Mint.
2023-05-03 17:55:49 +00:00
- Android setup ([Android Studio](https://developer.android.com/studio) and subsequent dependencies)
- 100 GB of storage
2023-04-18 20:42:39 +00:00
## Linux host
The following instructions are for building and running on a Linux host. This entire section (except for the Android Studio section) needs to be completed in WSL if building on a Windows host.
### Android Studio
Install Android Studio. Follow instructions here [https://developer.android.com/studio/install#linux](https://developer.android.com/studio/install#linux) or install via snap:
```
# setup android studio
sudo apt install -y openjdk-11-jdk
sudo snap install android-studio --classic
```
Use `Tools > SDK Manager` to install:
- `SDK Tools > Android SDK (API 30)`
- `SDK Tools > NDK`
- `SDK Tools > Android SDK command line tools`
- `SDK Tools > CMake`
Then in `File > Settings > Plugins`, install the **Flutter** and **Dart** plugins and restart the IDE. In `File > Settings > Languages & Frameworks > Flutter > Editor`, enable auto format on save to match the project's code style. If you have problems with the Dart SDK, make sure to run `flutter` in a terminal to download it (use `source ~/.bashrc` to update your environment variables if you're still using the same terminal from which you ran `setup.sh`). Run `flutter doctor` to install any missing dependencies and review and agree to any license agreements.
Make a Pixel 4 (API 30) x86_64 emulator with 2GB of storage space for emulation.
The following *may* be needed for Android studio:
```
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386
```
2023-04-18 20:42:39 +00:00
### Build dependencies
2023-04-18 20:42:39 +00:00
Install basic dependencies
```
sudo apt-get install libssl-dev curl unzip automake build-essential file pkg-config git python libtool libtinfo5 cmake libgit2-dev clang libncurses5-dev libncursesw5-dev zlib1g-dev llvm python3-distutils
```
2023-04-19 11:54:18 +00:00
Install [Rust](https://www.rust-lang.org/tools/install) with command:
```
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
2023-05-09 13:09:28 +00:00
source ~/.bashrc
rustup install 1.72.0 # For tor.
rustup install 1.67.1 # For flutter_libepiccash.
2023-05-04 15:44:47 +00:00
rustup default 1.67.1
2023-04-19 11:54:18 +00:00
```
Install the additional components for Rust:
2023-04-18 20:42:39 +00:00
```
cargo install cargo-ndk --version 2.12.7 --locked
```
Android specific dependencies:
```
sudo apt-get install libc6-dev-i386
2023-04-18 20:42:39 +00:00
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
```
2023-04-18 20:42:39 +00:00
Linux desktop specific dependencies:
```
sudo apt-get install clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev meson python3-pip libgirepository1.0-dev valac xsltproc docbook-xsl
2023-04-18 20:42:39 +00:00
pip3 install --upgrade meson==0.64.1 markdown==3.4.1 markupsafe==2.1.1 jinja2==3.1.2 pygments==2.13.0 toml==0.10.2 typogrify==2.0.7 tomli==2.0.1
```
After installing the prerequisites listed above, download the code and init the submodules
```
git clone https://github.com/cypherstack/stack_wallet.git
cd stack_wallet
git submodule update --init --recursive
```
Build the secure storage dependencies in order to target Linux (not needed for Windows or other platforms):
2023-04-18 20:42:39 +00:00
```
cd scripts/linux
./build_secure_storage_deps.sh
// when finished go back to the root directory
cd ../..
2023-04-18 20:42:39 +00:00
```
### Build coinlib
Coinlib's native secp256k1 library must be built prior to running Stack Wallet. It can be built from within the root `stack_wallet` folder on a...
- Linux host for Linux targets: `dart run coinlib:build_linux`, or
- Linux host for Windows targets: `dart run coinlib:build_windows_crosscompile`
- Windows host: `dart run coinlib:build_windows`
- WSL2 host: `dart run coinlib:build_wsl`
<!-- - macOS host: `dart run coinlib:build_macos` -->
2024-03-08 20:25:49 +00:00
To build coinlib on Linux, you will need `docker` (see [installation instructions](https://docs.docker.com/engine/install/ubuntu/)) or [`podman`](https://podman.io/docs/installation) (`sudo apt-get -y install podman`)
For Windows targets, you can use a `secp256k1.dll` produced by any of the three bottom<!--^H^H^H^H^H^Hmiddle--> options if the first attempt doesn't succeed!
2023-04-18 20:42:39 +00:00
### Run prebuild script
Certain test wallet parameter and API key template files must be created in order to run Stack Wallet. These can be created by script as in
```
cd scripts
./prebuild.sh
// when finished go back to the root directory
cd ..
```
or manually by creating the files referenced in that script with the specified content.
### Build plugins
#### Building plugins for Android
2023-04-19 11:54:18 +00:00
> Warning: This will take a long time, please be patient
2023-04-18 20:42:39 +00:00
```
cd scripts/android
2023-04-18 20:42:39 +00:00
./build_all.sh
```
#### Building plugins for Linux
```
cd scripts/linux
./build_all.sh
```
2023-04-18 20:42:39 +00:00
##### Remove system packages (may be needed for building flutter_libmonero)
[`flutter_libmonero`](https://github.com/cypherstack/flutter_libmonero) may have issues building due to conflicts with system packages: if so, follow this section.
Remove pre-installed system libraries for the following packages built by cryptography plugins in the crypto_plugins folder: `boost iconv libjson-dev libsecret openssl sodium unbound zmq`. You can use
```
sudo apt list --installed | grep boost
```
for example to find which pre-installed packages you may need to remove with `sudo apt remove`. Be careful, as some packages (especially boost) are linked to GNOME (GUI) packages: when in doubt, remove `-dev` packages first like with
```
sudo apt-get remove '^libboost.*-dev.*'
```
<!-- TODO: configure compiler to prefer built over system libraries. Should already use them? -->
#### Building plugins for Windows
2023-04-18 20:42:39 +00:00
```
cd scripts/windows
./deps.sh
2023-04-18 20:42:39 +00:00
./build_all.sh
```
### Running
#### Android
2023-04-18 20:42:39 +00:00
Plug in your android device or use the emulator available via Android Studio and then run the following commands:
```
flutter pub get
flutter run android
```
Note on Emulators: Only x86_64 emulators are supported, x86 emulators will not work
#### Linux
Run the following commands or launch via Android Studio:
2023-04-18 20:42:39 +00:00
```
flutter pub get
2023-04-18 20:42:39 +00:00
flutter run linux
```
## Windows host
### Visual Studio
Visual Studio is required for Windows development with the Flutter SDK. Download it at https://visualstudio.microsoft.com/downloads/ and install the "Desktop development with C++", "Linux development with C++", and "Visual C++ build tools" workloads. You may also need the Windows 10, 11, and/or Universal SDK workloads depending on your Windows version.
### Building libraries in WSL2
Set up Ubuntu 20.04 in WSL2. Follow the entire Linux host section in the WSL2 Ubuntu 20.04 host to get set up to build. The Android Studio section may be skipped in WSL (it's only needed on the Windows host).
Install the following libraries:
```
sudo apt-get install libgtk2.0-dev
```
You will also need to install MXE on the WSL2 Ubuntu 20.04 host and can do so by running `stack_wallet/scripts/windows/deps.sh`:
```
./stack_wallet/scripts/windows/deps.sh
```
2023-07-11 20:50:08 +00:00
The WSL2 host may optionally be navigated to the `stack_wallet` repository on the Windows host in order to build the plugins in-place and skip the next section in which you copy the `dll`s from WSL2 to Windows. Then build windows `dll` libraries by running the following script on the WSL2 Ubuntu 20.04 host:
- `stack_wallet/scripts/windows/build_all.sh`
Copy the resulting `dll`s to their respective positions on the Windows host:
- `stack_wallet/crypto_plugins/flutter_libepiccash/scripts/windows/build/libepic_cash_wallet.dll`
- `stack_wallet/crypto_plugins/flutter_liblelantus/scripts/windows/build/libmobileliblelantus.dll`
2023-07-11 20:50:08 +00:00
<!--
- `stack_wallet/crypto_plugins/flutter_libmonero/scripts/windows/build/libcw_monero.dll`
- `stack_wallet/crypto_plugins/flutter_libmonero/scripts/windows/build/libcw_wownero.dll`
-->
<!-- TODO: script the copying or installation of libraries from WSL2 to the parent Windows host -->
### Flutter
Install Flutter 3.16.0 on the Windows host (not in WSL2) by following these instructions: https://docs.flutter.dev/get-started/install/windows or by running `scripts/windows/deps.ps1`. You may still have to add `C:\development\flutter\bin` to PATH before proceeding, even if you ran `deps.ps1` (you may need to open a new terminal). Run `flutter doctor` in PowerShell to confirm its installation.
### Rust
Install [Rust](https://www.rust-lang.org/tools/install) on the Windows host (not in WSL2). Download the installer from [rustup.rs](https://rustup.rs), make sure it works on the commandline (you may need to open a new terminal), and install the following versions:
```
rustup install 1.72.0 # For tor.
rustup install 1.67.1 # For flutter_libepiccash.
rustup default 1.67.1
```
Also install `cargo-ndk`:
```
cargo install cargo-ndk --version 2.12.7 --locked
```
### Windows SDK and Developer Mode
Install the Windows SDK: https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/ You may need to install the [Windows 10 SDK](https://developer.microsoft.com/en-us/windows/downloads/sdk-archive/), which can be installed [by Visual Studio](https://stackoverflow.com/a/73923899) (`Tools > Get Tools and Features... > Modify > Individual Components > Windows 10 SDK`).
2023-06-05 21:36:55 +00:00
Enable Developer Mode for symlink support,
```
start ms-settings:developers
```
2023-06-05 21:36:55 +00:00
You may need to install NuGet and CppWinRT / C++/WinRT SDKs version `2.0.210806.1`:
2023-06-02 15:37:44 +00:00
```
winget install 9WZDNCRDMDM3 # NuGet, can also use Microsoft.NuGet
2023-06-05 21:36:55 +00:00
winget install Microsoft.Windows.CppWinRT -Version 2.0.210806.1
2023-06-02 15:37:44 +00:00
```
or [download the package](https://www.nuget.org/packages/Microsoft.Windows.CppWinRT/2.0.210806.1) and [manually install it](https://github.com/Baseflow/flutter-permission-handler/issues/1025#issuecomment-1518576722) by placing it in `flutter/bin` with [nuget.exe](https://dist.nuget.org/win-x86-commandline/latest/nuget.exe) and installing by running `nuget install Microsoft.Windows.CppWinRT -Version 2.0.210806.1` in the root `stack_wallet` folder.
<!-- TODO: script this NuGet and WinCppRT installation -->
2023-06-02 15:37:44 +00:00
### Run prebuild script
Certain test wallet parameter and API key template files must be created in order to run Stack Wallet on Windows. These can be created by script as in
```
cd scripts
./prebuild.ps1
// when finished go back to the root directory
cd ..
```
or manually by creating the files referenced in that script with the specified content.
2023-06-02 15:37:44 +00:00
### Running
Run the following commands:
```
flutter pub get
flutter run -d windows
```