• Stars
    star
    122
  • Rank 292,031 (Top 6 %)
  • Language
    Shell
  • License
    Apache License 2.0
  • Created over 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Oxidized NDK - NDK repackaged with Rust toolchain

Oxidized NDK

This is not an officially supported Google product.

Oxidized NDK (ONDK) is an unofficial repackaged Android NDK that includes a Rust toolchain. This repository hosts build scripts to build and package ONDK using GitHub Actions. Every file included in the final package either originates from the official NDK zip or is built in GitHub Actions.

This project does not include or attempt to do any modifications to Rust and LLVM.
This project is for experimental purposes, and does not guarantee any Android NDK or Rust functionality.
Use at your own risk.

Download the latest ONDK in releases.

Supports all NDK host platforms:
Linux (x64), Windows (x64), and macOS (x64 + arm64, universal binaries).

How to Use

For building C/C++ code, ONDK is just like any ordinary Android NDK, no special configurations are needed.

For building Rust code, link ONDK's Rust toolchain with rustup:

rustup toolchain link <name> <ondk>/toolchains/rust

The std crate is intentionally not prebuilt and included in ONDK, so building requires a little bit of setup.
Here is an example for building a project targeting API 21 for ARM64:

LLVM_BIN="<ondk>/toolchains/llvm/prebuilt/<os>-x86_64/bin"

# We need to tell cargo where to find the NDK linker for Android.
# You can also set this in config.toml, check the official documentation.
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="$LLVM_BIN/aarch64-linux-android21-clang"

# We also need to specify the NDK C compiler with proper flags.
# This is used for feature detection internally in std's build system.
export TARGET_CC="$LLVM_BIN/clang"
export TARGET_CFLAGS='--target=aarch64-linux-android21'

# Finally, build our project with -Z build-std
cargo <+name> build -Z build-std --target aarch64-linux-android

P.S. I strongly recommend checking out min-sized-rust to minimize Rust binaries.

How ONDK is Built

  • Download the latest Rust source code
  • Apply some patches to its build system (no patches to any code that is part of the final product)
  • Build a Rust sysroot with rustc + cargo + std source code + clang
  • Download the latest stable NDK zip
  • Replace only the LLVM/Clang executables of NDK, and copy the Rust sysroot into the package

FAQ

  • Q: Why do we need this? Doesn't the official Rust toolchains already work for Android?
    A: I started this project because I wanted to enable Cross-Language LTO. This allows C/C++ and Rust code to be optimized together during link time, extremely useful for mixed language projects. However, because NDK's Clang and official Rust toolchains are not built with the same LLVM, their LTO output format is very likely to be incompatible with each other. ONDK builds rustc and clang from scratch with the same LLVM source code to ensure cross-language LTO compatibility.

  • Q: Why is std not prebuilt for Android targets?
    A: I personally strongly dislike the idea of prebuilding any dependency that will be included in the final product of a project. Building std along with the project's compilation pipeline makes it easy to disable features, such as removing unwind for panic, and allow std to be LTO-ed with your project. The toolchain should not forcefully include and link code that is unnecessary for your project!

License

Copyright 2022 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

Magisk

The Magic Mask for Android
C++
47,811
star
2

libsu

A complete solution for apps using root permissions
Java
1,410
star
3

MagiskManager

Companion Android application for Magisk
Java
1,408
star
4

magisk_files

(Deprecated) Magisk File Host
644
star
5

magisk-module-installer

Obsolete
589
star
6

zygisk-module-sample

A sample project for building Zygisk modules
C++
511
star
7

magisk-files

Magisk File Host
336
star
8

magiskbot

The server of MagiskBot
TypeScript
208
star
9

ndk-busybox

BusyBox building with command ndk-build
C
188
star
10

ndk-box-kitchen

Patch sources and generate files for BusyBox on Android
Makefile
126
star
11

ProcGate

POC app to demo procfs leaks on Android systems
Java
107
star
12

FrankeNDK

Frankenstein NDK for building Magisk
C++
93
star
13

libcxx

LLVM libc++ without exception and RTTI, specifically for Android.
C++
75
star
14

room-runtime

Modified Room runtime library for Proguard/R8 obfuscation
Java
36
star
15

mincrypt

libmincrypt from AOSP
C
26
star
16

ndk-compression

Common compression tool libraries build with ndk-build command
C
22
star
17

lz4-java

lz4-java without Unsafe and native implementation
Java
22
star
18

CPI

CPI
C++
15
star
19

ADLxMLDS2017

Python
13
star
20

DSnP

C++
12
star
21

Web-Programming-Project

JavaScript
11
star
22

CAD-Contest-NP3

NP3: Non-exact Projective NPNP Boolean Matching
C
11
star
23

system_properties

C++
10
star
24

Real-OPT-Parameterization

Python
9
star
25

DSP_HW

C++
9
star
26

ML2016

Python
9
star
27

MakeNTU-2017

PlugMote!
Java
8
star
28

GT_Project

Pirate Game using Genetic Algorithm
C++
8
star
29

VR_RayTracing

VR course final project
C++
7
star
30

VR_Unity_Demo

C#
7
star