├── .gitignore ├── patches ├── support_ndk_llvm_r29.patch ├── support_ndk_llvm_r28.patch └── support_static_libcxx.patch ├── dist-macos.sh ├── bootstrap.toml ├── README.md ├── .github └── workflows │ └── build.yml ├── common.sh └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | /src 2 | /out 3 | /dist 4 | /tmp 5 | /*.zip 6 | -------------------------------------------------------------------------------- /patches/support_ndk_llvm_r29.patch: -------------------------------------------------------------------------------- 1 | diff --git a/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h b/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h 2 | index f6598f9f..3fc79f47 100644 3 | --- a/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h 4 | +++ b/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h 5 | @@ -14,6 +14,9 @@ 6 | 7 | #define LLVM_VERSION_LT(major, minor) (!LLVM_VERSION_GE((major), (minor))) 8 | 9 | +#undef LLVM_VERSION_MAJOR 10 | +#define LLVM_VERSION_MAJOR 20 11 | + 12 | extern "C" void LLVMRustSetLastError(const char *); 13 | 14 | enum class LLVMRustResult { Success, Failure }; 15 | -------------------------------------------------------------------------------- /dist-macos.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022-2025 Google LLC. 4 | # SPDX-License-Identifier: Apache-2.0 5 | 6 | # This script is for generating universal binaries 7 | 8 | set -e 9 | 10 | xz -d < tmp/out.x64.tar.xz | tar x 11 | mv out/collect out/collect.x64 12 | xz -d < tmp/out.arm64.tar.xz | tar x 13 | mv out/collect out/collect.arm64 14 | 15 | cp -af out/collect.x64 out/collect 16 | cp -an out/collect.arm64/. out/collect/. || true 17 | 18 | # Merge all Mach-O files as universal binary and adhoc codesign 19 | find out/collect -type f -exec sh -c "file {} | grep -q Mach-O" \; -print0 | \ 20 | while IFS= read -r -d '' o; do 21 | a="${o/collect/collect.x64}" 22 | b="${o/collect/collect.arm64}" 23 | if [ -f "$a" -a -f "$b" ]; then 24 | lipo -create -output "$o" "$a" "$b" 25 | fi 26 | codesign -s - "$o" 27 | done 28 | 29 | ./build.sh ndk dist 30 | -------------------------------------------------------------------------------- /bootstrap.toml: -------------------------------------------------------------------------------- 1 | change-id = 147888 2 | 3 | [llvm] 4 | download-ci-llvm = false 5 | link-shared = true 6 | 7 | [build] 8 | docs = false 9 | submodules = false 10 | extended = true 11 | tools = [ 12 | "cargo", 13 | "src", 14 | "clippy", 15 | "rustfmt", 16 | "rust-analyzer", 17 | "rust-analyzer-proc-macro-srv", 18 | ] 19 | cargo-native-static = true 20 | 21 | [install] 22 | prefix = "../../out/rust" 23 | sysconfdir = "etc" 24 | 25 | [rust] 26 | channel = "nightly" 27 | lto = "thin" 28 | strip = true 29 | lld = false 30 | codegen-units = 1 31 | 32 | [target.x86_64-unknown-linux-gnu] 33 | llvm-config = "../../out/llvm/bin/llvm-config" 34 | 35 | [target.aarch64-apple-darwin] 36 | llvm-config = "../../out/llvm/bin/llvm-config" 37 | jemalloc = true 38 | 39 | [target.x86_64-apple-darwin] 40 | llvm-config = "../../out/llvm/bin/llvm-config" 41 | jemalloc = true 42 | 43 | [target.x86_64-pc-windows-gnu] 44 | llvm-config = "../../out/llvm/bin/llvm-config.exe" 45 | cc = "clang" 46 | cxx = "clang++" 47 | linker = "clang" 48 | -------------------------------------------------------------------------------- /patches/support_ndk_llvm_r28.patch: -------------------------------------------------------------------------------- 1 | diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp 2 | index 90aa9188..f44ab406 100644 3 | --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp 4 | +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp 5 | @@ -1734,6 +1734,22 @@ extern "C" LLVMValueRef LLVMRustBuildMaxNum(LLVMBuilderRef B, LLVMValueRef LHS, 6 | return wrap(unwrap(B)->CreateMaxNum(unwrap(LHS), unwrap(RHS))); 7 | } 8 | 9 | +enum { 10 | + LLVMGEPFlagInBounds = (1 << 0), 11 | + LLVMGEPFlagNUSW = (1 << 1), 12 | + LLVMGEPFlagNUW = (1 << 2), 13 | +}; 14 | +extern "C" LLVMValueRef 15 | +LLVMBuildGEPWithNoWrapFlags(LLVMBuilderRef B, LLVMTypeRef Ty, 16 | + LLVMValueRef Pointer, LLVMValueRef *Indices, 17 | + unsigned NumIndices, const char *Name, 18 | + unsigned NoWrapFlags) { 19 | + if (NoWrapFlags & LLVMGEPFlagInBounds) 20 | + return LLVMBuildInBoundsGEP2(B, Ty, Pointer, Indices, NumIndices, Name); 21 | + else 22 | + return LLVMBuildGEP2(B, Ty, Pointer, Indices, NumIndices, Name); 23 | +} 24 | + 25 | // Transfers ownership of DiagnosticHandler unique_ptr to the caller. 26 | extern "C" DiagnosticHandler * 27 | LLVMRustContextGetDiagnosticHandler(LLVMContextRef C) { 28 | -------------------------------------------------------------------------------- /patches/support_static_libcxx.patch: -------------------------------------------------------------------------------- 1 | diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs 2 | index 9d21d0d2..c45978d9 100644 3 | --- a/compiler/rustc_llvm/build.rs 4 | +++ b/compiler/rustc_llvm/build.rs 5 | @@ -411,7 +411,6 @@ fn main() { 6 | // C++ runtime library 7 | if !target.contains("msvc") { 8 | if let Some(s) = llvm_static_stdcpp { 9 | - assert!(!cxxflags.contains("stdlib=libc++")); 10 | let path = PathBuf::from(s); 11 | println!("cargo:rustc-link-search=native={}", path.parent().unwrap().display()); 12 | if target.contains("windows") { 13 | diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs 14 | index 82fd1119..f79fb01a 100644 15 | --- a/src/bootstrap/src/core/build_steps/compile.rs 16 | +++ b/src/bootstrap/src/core/build_steps/compile.rs 17 | @@ -1452,8 +1452,11 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect 18 | && !target.contains("apple") 19 | && !target.contains("solaris") 20 | { 21 | - let libstdcxx_name = 22 | - if target.contains("windows-gnullvm") { "libc++.a" } else { "libstdc++.a" }; 23 | + let libstdcxx_name = if target.contains("windows-gnullvm") || builder.config.llvm_use_libcxx { 24 | + "libc++.a" 25 | + } else { 26 | + "libstdc++.a" 27 | + }; 28 | let file = compiler_file( 29 | builder, 30 | &builder.cxx(target).unwrap(), 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Oxidized NDK 2 | 3 | This is not an officially supported Google product. 4 | 5 | Oxidized NDK (ONDK) is an unofficial repackaged [Android NDK](https://developer.android.com/ndk) that includes a Rust toolchain. 6 | This repository hosts build scripts to build and package ONDK using [GitHub Actions](https://github.com/topjohnwu/ondk/actions). 7 | Every file included in the final package either originates from the official NDK zip or is built in GitHub Actions. 8 | 9 | This project does not include or attempt to do any modifications to Rust and LLVM.
10 | This project is for experimental purposes, and **does not** guarantee any Android NDK or Rust functionality.
11 | Use at your own risk. 12 | 13 | Download the latest ONDK in [releases](https://github.com/topjohnwu/ondk/releases/latest). 14 | 15 | Supports all NDK host platforms:
16 | Linux (x64), Windows (x64), and macOS (x64 + arm64, universal binaries). 17 | 18 | ## How to Use 19 | 20 | For building C/C++ code, ONDK is just like any ordinary Android NDK, no special configurations are needed. 21 | 22 | For building Rust code, link ONDK's Rust toolchain with `rustup`: 23 | 24 | ``` 25 | rustup toolchain link /toolchains/rust 26 | ``` 27 | 28 | The `std` crate is _intentionally_ not prebuilt and included in ONDK, so building requires a little bit of setup.
29 | Here is an example for building a project targeting API 21 for ARM64: 30 | 31 | ```bash 32 | LLVM_BIN="/toolchains/llvm/prebuilt/-x86_64/bin" 33 | 34 | # We need to tell cargo where to find the NDK linker for Android. 35 | # You can also set this in config.toml, check the official documentation. 36 | export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="$LLVM_BIN/aarch64-linux-android21-clang" 37 | 38 | # Finally, build our project with -Z build-std 39 | cargo <+name> build -Z build-std --target aarch64-linux-android 40 | ``` 41 | 42 | P.S. I strongly recommend checking out [min-sized-rust](https://github.com/johnthagen/min-sized-rust) to minimize Rust binaries. 43 | 44 | ## How ONDK is Built 45 | 46 | - Download the latest [Rust](https://github.com/rust-lang/rust) source code 47 | - Apply some patches to its build system (no patches to any code that is part of the final product) 48 | - Build a Rust sysroot with `rustc` + `cargo` + `std` source code + `clang` 49 | - Download the latest stable [NDK](https://developer.android.com/ndk/downloads) zip 50 | - Replace **only** the LLVM/Clang executables of NDK, and copy the Rust sysroot into the package 51 | 52 | ## FAQ 53 | 54 | - **Q: Why do we need this? Doesn't the official Rust toolchains already work for Android?**
55 | A: I started this project because I wanted to enable [Cross-Language LTO](https://doc.rust-lang.org/rustc/linker-plugin-lto.html). 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. 56 | 57 | - **Q: Why is `std` not prebuilt for Android targets?**
58 | 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! 59 | 60 | ## License 61 | 62 | Copyright 2022-2025 Google LLC 63 | 64 | Licensed under the Apache License, Version 2.0 (the "License"); 65 | you may not use this file except in compliance with the License. 66 | You may obtain a copy of the License at 67 | 68 | https://www.apache.org/licenses/LICENSE-2.0 69 | 70 | Unless required by applicable law or agreed to in writing, software 71 | distributed under the License is distributed on an "AS IS" BASIS, 72 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 73 | See the License for the specific language governing permissions and 74 | limitations under the License. 75 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: ondk build 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | linux: 8 | name: Build for Linux 9 | runs-on: ubuntu-22.04 10 | 11 | steps: 12 | - name: Check out 13 | uses: actions/checkout@v4 14 | with: 15 | fetch-depth: 1 16 | 17 | - name: Set up Python 3 18 | uses: actions/setup-python@v5 19 | with: 20 | python-version: "3.x" 21 | 22 | - name: Clean up storage 23 | run: | 24 | sudo rm -rf \ 25 | "$JAVA_HOME_8_X64" "$JAVA_HOME_11_X64" "$JAVA_HOME_17_X64" "$JAVA_HOME_21_X64" \ 26 | "$CHROMEWEBDRIVER" "$EDGEWEBDRIVER" "$GECKOWEBDRIVER" \ 27 | /usr/local/lib/android 28 | 29 | - name: Build toolchain 30 | run: | 31 | sudo apt-get update 32 | sudo apt-get -y install cmake ninja-build libzstd-dev binutils-dev 33 | wget https://apt.llvm.org/llvm.sh 34 | chmod +x llvm.sh 35 | sudo ./llvm.sh 20 36 | sudo apt-get -y install libc++-20-dev libc++abi-20-dev 37 | rm llvm.sh 38 | ./build.sh 39 | 40 | - name: Upload build artifact 41 | uses: actions/upload-artifact@v4 42 | with: 43 | name: ondk-linux 44 | path: dist/*.tar.xz 45 | 46 | windows: 47 | name: Build for Windows 48 | runs-on: windows-2025 49 | defaults: 50 | run: 51 | shell: msys2 {0} 52 | steps: 53 | - name: Check out 54 | uses: actions/checkout@v4 55 | with: 56 | fetch-depth: 1 57 | 58 | - name: Setup MSYS2 59 | uses: msys2/setup-msys2@v2 60 | with: 61 | msystem: MINGW64 62 | update: true 63 | install: make diffutils tar patch unzip gzip python 64 | pacboy: 7zip:p cmake:p gcc:p ninja:p zstd:p clang:p lld:p libc++:p 65 | 66 | - name: Build toolchain 67 | run: | 68 | # Remove libzstd.dll.a to make sure zstd is statically linked 69 | rm -f /mingw64/lib/libzstd.dll.a 70 | bash build-windows.sh 71 | 72 | - name: Upload build artifact 73 | uses: actions/upload-artifact@v4 74 | with: 75 | name: ondk-windows 76 | path: dist\*.tar.xz 77 | 78 | macos-x64-llvm: 79 | name: Build LLVM for macOS (x64) 80 | runs-on: macos-15-intel 81 | 82 | steps: 83 | - name: Check out 84 | uses: actions/checkout@v4 85 | with: 86 | fetch-depth: 1 87 | 88 | - name: Set up Python 3 89 | uses: actions/setup-python@v5 90 | with: 91 | python-version: "3.x" 92 | 93 | - name: Build LLVM 94 | run: | 95 | brew reinstall ninja zstd binutils gpatch 96 | ./build.sh clone-llvm build-llvm 97 | rm -rf out/llvm/build 98 | mkdir tmp 99 | tar c out/llvm | xz --x86 --lzma2 > tmp/llvm.x64.tar.xz 100 | 101 | - name: Upload LLVM artifact 102 | uses: actions/upload-artifact@v4 103 | with: 104 | name: macos-x64-llvm 105 | path: tmp/*.tar.xz 106 | 107 | macos-x64: 108 | name: Build for macOS (x64) 109 | runs-on: macos-15-intel 110 | needs: [macos-x64-llvm] 111 | 112 | steps: 113 | - name: Check out 114 | uses: actions/checkout@v4 115 | with: 116 | fetch-depth: 1 117 | 118 | - name: Set up Python 3 119 | uses: actions/setup-python@v5 120 | with: 121 | python-version: "3.x" 122 | 123 | - name: Download LLVM artifacts 124 | uses: actions/download-artifact@v4 125 | with: 126 | name: macos-x64-llvm 127 | path: tmp 128 | 129 | - name: Build toolchain 130 | run: | 131 | xz -d < tmp/llvm.x64.tar.xz | tar x 132 | rm tmp/llvm.x64.tar.xz 133 | brew reinstall ninja zstd binutils gpatch 134 | ./build.sh clone build-rust collect 135 | tar c out/collect | xz --x86 --lzma2 > tmp/out.x64.tar.xz 136 | 137 | - name: Remove LLVM artifact 138 | uses: geekyeggo/delete-artifact@v4 139 | with: 140 | name: macos-x64-llvm 141 | failOnError: false 142 | 143 | - name: Upload build artifact 144 | uses: actions/upload-artifact@v4 145 | with: 146 | name: macos-x64 147 | path: tmp/*.tar.xz 148 | 149 | macos-arm64: 150 | name: Build for macOS (arm64) 151 | runs-on: macos-15 152 | 153 | steps: 154 | - name: Check out 155 | uses: actions/checkout@v4 156 | with: 157 | fetch-depth: 1 158 | 159 | - name: Set up Python 3 160 | uses: actions/setup-python@v5 161 | with: 162 | python-version: "3.x" 163 | 164 | - name: Build toolchain 165 | run: | 166 | brew reinstall ninja zstd binutils gpatch 167 | ./build.sh clone build collect 168 | mkdir tmp 169 | tar c out/collect | xz > tmp/out.arm64.tar.xz 170 | 171 | - name: Upload build artifact 172 | uses: actions/upload-artifact@v4 173 | with: 174 | name: macos-arm64 175 | path: tmp/*.tar.xz 176 | 177 | macos: 178 | name: Build for macOS (Universal) 179 | runs-on: macos-15 180 | needs: [macos-x64, macos-arm64] 181 | 182 | steps: 183 | - name: Check out 184 | uses: actions/checkout@v4 185 | with: 186 | fetch-depth: 1 187 | 188 | - name: Download x64 artifacts 189 | uses: actions/download-artifact@v4 190 | with: 191 | name: macos-x64 192 | path: tmp 193 | 194 | - name: Download arm64 artifacts 195 | uses: actions/download-artifact@v4 196 | with: 197 | name: macos-arm64 198 | path: tmp 199 | 200 | - name: Build ONDK 201 | run: ./dist-macos.sh 202 | 203 | - name: Upload build artifact 204 | uses: actions/upload-artifact@v4 205 | with: 206 | name: ondk-macos 207 | path: dist/*.tar.xz 208 | 209 | - name: Remove x64 artifact 210 | uses: geekyeggo/delete-artifact@v4 211 | with: 212 | name: macos-x64 213 | failOnError: false 214 | 215 | - name: Remove arm64 artifact 216 | uses: geekyeggo/delete-artifact@v4 217 | with: 218 | name: macos-arm64 219 | failOnError: false 220 | -------------------------------------------------------------------------------- /common.sh: -------------------------------------------------------------------------------- 1 | # Copyright 2022-2025 Google LLC. 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | RUST_VERSION='1.92.0' 5 | 6 | NDK_VERSION='r29' 7 | NDK_DIR_VERSION=$NDK_VERSION 8 | 9 | # Android LLVM versions: 10 | # https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+/mirror-goog-main-llvm-toolchain-source/README.md 11 | # These revisions are obtained from the Android's LLVM manifest.xml 12 | LLVM_SVN='563880' 13 | LLVM_VERSION='5e96669f06077099aa41290cdb4c5e6fa0f59349' 14 | LLVM_ANDROID_VERSION='38546691df970516709cc907bc7387004f69c60c' 15 | TOOLCHAIN_UTILS_VERSION='e4ed541c00706c0108c57921ac4b95ca98e87ec5' 16 | 17 | OUTPUT_VERSION='r29.4' 18 | 19 | set -e 20 | shopt -s nullglob 21 | 22 | # key value 23 | set_llvm_cfg() { 24 | local cfg="\"-D${1}=$2\"" 25 | if [ -z "$LLVM_BUILD_CFG" ]; then 26 | LLVM_BUILD_CFG="$cfg" 27 | else 28 | LLVM_BUILD_CFG="$LLVM_BUILD_CFG $cfg" 29 | fi 30 | } 31 | 32 | # key value 33 | set_build_cfg() { 34 | RUST_CFG="$RUST_CFG '--set=$1=$2'" 35 | } 36 | 37 | strip_exe() { 38 | for path in bin llvm-bin lib; do 39 | find $path -maxdepth 1 -type f \ 40 | -exec sh -c "file {} | grep -q $EXE_FMT" \; \ 41 | -exec ../llvm/bin/llvm-strip -s {} \; 42 | done 43 | } 44 | 45 | # url sha 46 | git_clone_sha() { 47 | local dir=${1##*/} 48 | echo "Cloning into 'src/$dir'..." 49 | mkdir -p "src/$dir" 50 | cd "src/$dir" 51 | git init -q 52 | git remote add origin $1 53 | git fetch --depth 1 origin $2 54 | git reset --hard FETCH_HEAD 55 | cd ../../ 56 | } 57 | 58 | git_clone_branch() { 59 | local dir=${1##*/} 60 | git clone --single-branch --depth 1 --branch $2 $1 src/$dir 61 | } 62 | 63 | skip_submodule() { 64 | git config set -f .gitmodules "submodule.$1.update" none 65 | } 66 | 67 | clone_llvm() { 68 | rm -rf src/llvm-project src/llvm_android src/toolchain-utils 69 | 70 | git_clone_sha https://android.googlesource.com/toolchain/llvm-project $LLVM_VERSION 71 | git_clone_sha https://android.googlesource.com/toolchain/llvm_android $LLVM_ANDROID_VERSION 72 | git_clone_sha https://android.googlesource.com/platform/external/toolchain-utils $TOOLCHAIN_UTILS_VERSION 73 | 74 | # Patch the LLVM source code 75 | python3 src/toolchain-utils/py/bin/llvm_tools/patch_manager.py \ 76 | --svn_version $LLVM_SVN \ 77 | --patch_metadata_file src/llvm_android/patches/PATCHES.json \ 78 | --src_path src/llvm-project 79 | } 80 | 81 | clone_rust() { 82 | rm -rf src/rust 83 | 84 | git_clone_branch https://github.com/rust-lang/rust $RUST_VERSION 85 | cd src/rust 86 | 87 | # Skip unused submodules 88 | skip_submodule src/llvm-project 89 | skip_submodule src/gcc 90 | skip_submodule src/tools/enzyme 91 | 92 | # Clone submodules 93 | git submodule update --init --depth=1 94 | 95 | # Apply patches 96 | patch -p1 < ../../patches/support_ndk_llvm_r29.patch 97 | patch -p1 < ../../patches/support_static_libcxx.patch 98 | 99 | # Link NDK LLVM into Rust's source 100 | rm -rf src/llvm-project 101 | ln -s ../../llvm-project src/llvm-project 102 | 103 | cd ../../ 104 | } 105 | 106 | update_dir() { 107 | local src=$1 108 | local dest=$2 109 | 110 | for d in $dest/*; do 111 | local s=$src/$(basename $d) 112 | # Copy regular files first 113 | if [ -f $s ] && [ ! -L $s ]; then 114 | cp -af $s $d 115 | fi 116 | done 117 | 118 | for d in $dest/*; do 119 | local s=$src/$(basename $d) 120 | # Then copy over symlinks 121 | if [ -L $s ]; then 122 | cp -af $s $d 123 | fi 124 | done 125 | } 126 | 127 | common_config_llvm() { 128 | unset LLVM_BUILD_CFG 129 | set_llvm_cfg CMAKE_BUILD_TYPE Release 130 | set_llvm_cfg CMAKE_INSTALL_PREFIX ../ 131 | set_llvm_cfg LLVM_TARGETS_TO_BUILD "AArch64;ARM;X86;RISCV" 132 | set_llvm_cfg LLVM_VERSION_SUFFIX 133 | set_llvm_cfg LLVM_TARGET_ARCH $ARCH 134 | set_llvm_cfg LLVM_DEFAULT_TARGET_TRIPLE $TRIPLE 135 | set_llvm_cfg LLVM_ENABLE_ZLIB OFF 136 | set_llvm_cfg LLVM_ENABLE_LIBXML2 OFF 137 | set_llvm_cfg LLVM_ENABLE_ZSTD FORCE_ON 138 | set_llvm_cfg LLVM_USE_STATIC_ZSTD ON 139 | set_llvm_cfg LLVM_INCLUDE_TESTS OFF 140 | set_llvm_cfg LLVM_ENABLE_LIBEDIT OFF 141 | set_llvm_cfg LLVM_ENABLE_BINDINGS OFF 142 | set_llvm_cfg LLVM_ENABLE_Z3_SOLVER OFF 143 | set_llvm_cfg LLVM_ENABLE_ASSERTIONS OFF 144 | set_llvm_cfg LLVM_UNREACHABLE_OPTIMIZE OFF 145 | set_llvm_cfg LLVM_INCLUDE_EXAMPLES OFF 146 | set_llvm_cfg LLVM_INCLUDE_DOCS OFF 147 | set_llvm_cfg LLVM_INCLUDE_BENCHMARKS OFF 148 | set_llvm_cfg LLVM_ENABLE_WARNINGS OFF 149 | set_llvm_cfg LLVM_INSTALL_UTILS ON 150 | } 151 | 152 | build_rust() { 153 | rm -rf out/rust 154 | config_rust_build 155 | cd src/rust 156 | eval python3 ./x.py --config ../../bootstrap.toml --build $TRIPLE $RUST_CFG install 157 | cd ../../ 158 | } 159 | 160 | dl_ndk() { 161 | local NDK_ZIP="android-ndk-${NDK_VERSION}-${OS}.zip" 162 | local NDK_EXTRACT="android-ndk-${NDK_DIR_VERSION}" 163 | 164 | # Download and extract 165 | [ -f $NDK_ZIP ] || curl -O -L "https://dl.google.com/android/repository/$NDK_ZIP" 166 | rm -rf $NDK_EXTRACT 167 | unzip -q $NDK_ZIP 168 | mv $NDK_EXTRACT out/ndk 169 | echo $OUTPUT_VERSION > out/ndk/ONDK_VERSION 170 | } 171 | 172 | dist() { 173 | cd out 174 | mv ndk "ondk-${OUTPUT_VERSION}" 175 | mkdir ../dist 176 | tar c "ondk-${OUTPUT_VERSION}" | xz --x86 --lzma2 > "../dist/ondk-${OUTPUT_VERSION}-${OS}.tar.xz" 177 | cd ../ 178 | } 179 | 180 | run_cmd() { 181 | case $1 in 182 | clone) 183 | clone_llvm 184 | clone_rust 185 | ;; 186 | clone-llvm) 187 | clone_llvm 188 | ;; 189 | clone-rust) 190 | clone_rust 191 | ;; 192 | build) 193 | rm -rf out/llvm out/lld 194 | build_llvm 195 | build_rust 196 | ;; 197 | build-llvm) 198 | rm -rf out/llvm out/lld 199 | build_llvm 200 | ;; 201 | build-rust) 202 | build_rust 203 | ;; 204 | collect) 205 | rm -rf out/collect 206 | collect 207 | ;; 208 | ndk) 209 | rm -rf out/ndk 210 | ndk 211 | ;; 212 | dist) 213 | rm -rf dist out/ondk-* 214 | dist 215 | ;; 216 | clean) 217 | rm -rf src out dist tmp android-ndk-*.zip 218 | ;; 219 | *) 220 | echo "Unknown action \"$1\"" 221 | exit 1 222 | ;; 223 | esac 224 | } 225 | 226 | parse_args() { 227 | if [ $# -eq 0 ]; then 228 | run_cmd clone 229 | run_cmd build 230 | run_cmd collect 231 | run_cmd ndk 232 | run_cmd dist 233 | else 234 | for arg in $@; do 235 | run_cmd $arg 236 | done 237 | fi 238 | } 239 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------