a simple portable CMake-based build system for magiskboot
magiskboot itself depends on the following libraries:
for build-time dependencies:
for Linux systems, please install libbsd as well
please ensure you have installed the above softwares before building
there are examples for some popular operating systems/distributions:
Linux
install nightly Rust via rustup first
sudo apt update
sudo apt upgrade # upgrade all existing packages (optional)
# replace clang-15, libc++-15-dev, libc++abi-15-dev with clang, libc++-dev and libc++abi-dev
# if your Ubuntu is too old, do the same for lld if you want to use it
sudo apt install build-essential lzma-dev liblzma-dev liblz4-dev libbz2-dev \
zlib1g-dev pkgconf clang-15 libc++-15-dev libc++abi-15-dev cmake \
ninja-build libbsd-dev # optional: lld-15
rustup component add rust-src # install STD library source
# the following cmds are only for Ubuntu jammy:
mkdir ~/.bin
ln -s `which clang-15` ~/.bin/clang
ln -s `which clang++-15` ~/.bin/clang++
# optional:
# ln -s `which lld-15` ~/.bin/lld
# finally
export PATH=~/.bin:$PATH
install nightly Rust via rustup (can be installed with apk
) first
sudo apk update
sudo apk upgrade # upgrade all existing packages (recommended)
sudo apk add build-base xz-dev xz-static lz4-dev lz4-static bzip2-dev bzip2-static \
zlib-dev zlib-static pkgconf clang libc++-dev libc++-dev-static cmake \
samurai libbsd-dev libbsd-static # optional: lld
rustup component add rust-src # install STD library source
install nightly Rust via rustup (can be installed with pacman
) first
sudo pacman -S --needed base-devel xz lz4 bzip2 zlib pkgconf clang libc++ cmake ninja libbsd # optional: lld
rustup component add rust-src # install STD library source
xiaoxindada/magiskboot_ndk_on_linux: minimal build system for magiskboot with ondk on Linux
macOS
install Homebrew first
brew update
brew upgrade # upgrade all existing packages (optional)
brew install xz lz4 bzip2 zlib pkg-config cmake ninja rustup-init
rustup-init # install nightly Rust here
rustup component add rust-src # install STD library source
Android
Termux build is not actively tested.
Recommend directly using libmagiskboot.so
extracted from the Magisk APK, it's just a static ELF program.
apt update
apt upgrade # upgrade all existing packages (optional)
apt install tur-repo # for nightly Rust package
apt install build-essentials liblzma liblz4 libbz2 zlib pkg-config \
clang lld rustc-nightly rust-src-nightly cmake ninja libbsd
Windows
Note A minor amount of POSIX functions in
src/winsup/*_compat.c
are currently stubbed and no-op (e.g. chmod, chown, mknod), but it shouldn't cause too much trouble for magiskboot to work.However, if you know a better way to do this, please feel free to open a Pull Request to change it :)
Install MSYS2 first, use the MINGW64 Terminal. Change the setting for mintty.exe
and give it administrator permission (needed for using native symlinks).
don't forget to set this environtment variable to allow symlinks to work properly: export MSYS=winsymlinks:native
(required for the build I guess)
install nightly Rust via rustup (Please choose the GNU ABI)
pacman -Syu # upgrade all existing packages (optional, you may need to do this for multiple times)
pacman -S base-devel mingw-w64-x86_64-{xz,lz4,bzip2,zlib,pkgconf,clang,lld,cmake,libc++,ninja}
rustup component add rust-src # install STD library source
There is also an old MinGW port, it works great:
svoboda18/magiskboot: a dirty Windows port with custom GNU Make based build system
Note Cygwin support is not actively tested currently
To build for Cygwin, you need to compile a nightly Rust toolchain from source, for more info: Cygwin Rust porting
Currently Cygwin Rust has no host tools support, so you have patch the CMakeLists and make it cross-compile for Cygwin.
NOTE: This project doesn't support cross-compiling for now, but it should be easy to get patched to support that.
You will also need to compile the LLVM/Clang from source to add Cygwin target, see: my unofficial cygports
For prebuilt binaries, go check GitHub Releases for selected CI builds.
First get and extract the latest source tarball (called magiskboot_<COMMIT_ID>_<VERCODE>-src.tar.xz
) from Github Releases.
Or clone this repository using Git with this option: --recurse-submodules
. (If you already have a cloned repository without using that option, run: git submodule update --init --recursive
instead)
cmake -G Ninja -B build -DCMAKE_BUILD_TYPE=Release # configure
cmake --build build -j $(nproc) # build
./build/magiskboot # running
# install to system (or to a directory specified by the `DESTDIR' environment variable)
sudo cmake --install install
If you prefer a statically linked binary (optional), pass -DPREFER_STATIC_LINKING=ON
to CMake while configuring, make sure your distribution provided you the static version of the depended libraries, otherwise you'll run into configure errors and you have to change your distribution or try to compile the static version of those libraries yourself and install them to your system for the static build.
If you want to perform LTO at the final link time, pass -DUSE_LTO_LINKER_PLUGIN=ON
to CMake during configuring.
And you will need to install LLD.
Note: you may need to make sure your LLVM and LLD are sharing the same LLVM version as your nightly Rust.
cmake -G Ninja -B build -DNO_TARGETS_OR_DEPS=ON # configure
cmake --build build -t package_source # make a source package
Make sure you passed -DNO_TARGETS_OR_DEPS=ON
to CMake while configuring, which will allow creating source tarball without installing the build dependencies.
you should be able to find your source package under the build
folder
Since we are using nightly, random breakage is expected. Report it by filing an Issue.
However, if your build fails with something like this:
[32/62] Building Rust static library libmagiskboot-rs.a
error: the `-Z` flag is only accepted on the nightly channel of Cargo, but this is the `stable` channel
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
That means you have installed a non-nightly Rust toolchain, and that is not supported currently, since the upstream uses nightly.
You may also run into issues if you don't have rust-src
(STD library sources) installed, just install it like in the Requirements section or simply follow the hint cargo gives you.
This project is very similiar to android-tools which just maintains a set of patches on top of a specific upstream Magisk commit and require manual adaption for compiling with newer version source.
Although I may update the version once in a while, Pull requests are welcome.
This project aims to be portable, and it should be possible to port it to new platforms, as long as your platform meets the the above requirements.
Not? Check out the Cygwin platform for example, maybe you can try to port those dependencies yourself.
Or, try to make a port without the missing dependencies (and you may need to rewrite some stuffs, this may not always be easy, for example the upstream Rust codebase is likely to grow). However, these are not covered by this project, just some friendly suggestions.
To quickly discard the current build
directory and dirty vendor/
submodule changes, please run make clean
.
To temporarily disable vendor/
projects patching, re-configure with -DPATCH_VENDOR_PROJECTS=OFF
(useful if you are patching them manually).
To enable it again, use -DPATCH_VENDOR_PROJECTS=ON
(Note this will clean up changes in vendor/
modules and re-apply all the patches).
If you modify something in the Rust part, you will have to perform rm build/libmagiskboot-rs.a
manually before rebuilding. (TODO: let CMake detect source changes)
Pass -DCMAKE_BUILD_TYPE=Debug
to CMake instead of Release
during configuring to make some error log more verbose.
For vendor/
submodules with their name starting with android_
, most of the patches are imported from android-tools, and don't always require updating.
When syncing upstream vendor/{android_libbase,Magisk}
changes, here is a few things to check:
build.py
changes{,{base,boot}/}Android.mk
updates- if
external
projects were added, deleted, or moved, update the list of excluded directories at the bottom ofCMakeLists.txt
accordingly - switch to
winsup
stub for MinGW for if any new file or spot reference to any of the following standard libc identifiers:- struct DIR
- struct dirent
- mkdir
- {open,read,close,rewind,seek,tell}dir
- open
- fopen
- fstat
- android-tools developers for many code and inspiration of this repository
- Magisk developers for the magiskboot utility
- all other used projects' developers (mentioned in the Requirements section)